Building Shaded Uber Jar with Jersey-Client And Getting ClientHandlerException

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.

Fun, right?

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
com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:570)
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

Advertisements
This entry was posted in code example, coding, github, java, Learning to Code, programming and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s