I’ve been meaning to write about this on my blog to help others out there who come across this problem with using jersey-client in their code.
So I was working with the jersey-client for the first time and everything was going fine. My code hits a restful api somewhere, retrieves some useful metrics, and then acts on it.
However when I compiled my code and ran it on our teams dev server I got the following com.sun.jersey.api.client.ClientHandlerException below.
Anyway, it turns out the reason for this error was because I was using maven-shade-plugin to build an uber jar of the project (a requirement for this project) and the transformer I was using was overwriting the metadata in META-INF for each jersey service and not appending the metadata like it should.
So the fix:
Updated my pom file. Note that this fix is only for building shaded uber jar with maven when using jersey-client. Hope this helps someone else out there.
For search engines…
Exception in thread “main” com.sun.jersey.api.client.ClientHandlerException: com.sun.jersey.api.client.ClientHandlerException: A message body writer for Java type, class java.lang.String, and MIME media type, application/json, was not found
Caused by: com.sun.jersey.api.client.ClientHandlerException: A message body writer for Java type, class java.lang.String, and MIME media type, application/json, was not found