Reputation: 489
I have jersey-client-2.25.1 on my build path and I know it has the default provider to convert javax.ws.rs.core.Form to application/x-www-form-urlencoded.
But for this code:
private ClientResponse getResponse(Authorization authInstance, Form formData) {
return webResourceInstance.type(MediaType.APPLICATION_FORM_URLENCODED).
header("Authorization",encode(authInstance)).
post(ClientResponse.class, formData);
}
I keep getting:
com.sun.jersey.api.client.ClientHandlerException: com.sun.jersey.api.client.ClientHandlerException: A message body writer for Java type, class javax.ws.rs.core.Form, and MIME media type, application/x-www-form-urlencoded, was not found
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:155)
I should not have to register a MultiPart class as per this.
Upvotes: 0
Views: 2480
Reputation: 208944
I have jersey-client-2.25.1 on my build path
Yeah, but you're not using it. You're using the Jersey 1.x client. ClientResposne,WebResource
, that is jersey 1.x. Jersey (JAX-RS) 1, doesn't support javax.ws.rs.core.Form
. That is a JAX-RS 2 class. If you do use your Jersey 2 client, it would work.
If you want to stick with the Jersey 1.x client, then (with application/x-www-form-urlencoded), it supports com.sun.jersey.api.representation.Form
and MultivaluedMap
Upvotes: 3