I keep receiving a 406 HTTP response when I try to execute code structured in this way. I have tried restructuring the code and the inputs many times, but I still receive this error, and I've gotten to the point I don't even really know what to debug. The exception seems to indicate that the post()
method isn't supplying the @FormParam
s in the desired format, but as you can see the .accept(MediaType.APPLICATION_FORM_URLENCODED)
and the @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
do indeed match up.
I am using the Firefox add-on HTTPRequester to pass in the @FormParam
s and have ensured that I am passing them in with the appropriate Content-Type (application/x-www-form-urlencoded
). I've run out of things to check. Does anyone have any ideas?
The Proxy Service
Client client = Client.create();
WebResource service = client.resource(myURL);
Form form = new Form();
form.add("value1", value1);
form.add("value2", value2);
form.add("valueN", valueN);
String returnValue = service.accept(MediaType.APPLICATION_FORM_URLENCODED).post(String.class, form);
The Actual Service
@POST
@Produces(MediaType.APPLICATION_XML)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("/theService")
public String theService(
@FormParam("value1") String value1,
@FormParam("value2") String value2,
@FormParam("valueN") String valueN) {
String returnValue = null;
/*
* Do Stuff
*/
return returnValue;
}
The Exception
com.sun.jersey.api.client.UniformInterfaceException: POST http://theURL/theService returned a response status of 406
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:563)
at com.sun.jersey.api.client.WebResource.access$300(WebResource.java:69)
at com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:499)