eureka19
eureka19

Reputation: 3070

JAX-RS GET: MessageBodyReader not found for media type=text/plain

I'm getting following error while trying to do JAX-RS GET request:

MessageBodyReader not found for media type=text/plain, type=class com.intuit.accountant.services.common.cdm.Job, genericType=class com.intuit.accountant.services.common.cdm.Job

Below is my code:

Response response = target("jobs/Hello")
        .request()
        .header("intuit_offeringid", "testOfferingId")
        .header(RequestHeaders.REALM, CommonUtil.DEFAULT_REALM_ID_FOR_INTUIT_EMPLOYEE)
        .header(RequestHeaders.AUTH, "002923")
        .header(RequestHeaders.TICKET,"00303")
        .get(Response.class);

What does this error mean? How can I fix this?

Upvotes: 0

Views: 4569

Answers (1)

Chris Hinshaw
Chris Hinshaw

Reputation: 7285

You need to post all the code. The error is almost assuredly not happening in that code sample you posted. The get(Response.class) is converting it to a generic http response where you can see the response payload, status, response headers etc.

What you didn't post would most likely look somemthing like this. response.readEntity(com.intuit.accountant.services.common.cdm.Job)

In this case you don't have a reader registered to convert a text/plain response from the server to an entity. I don't know if the response was supposed to be json/xml and you are receiving text because there was an error of some kind. You should check the response as text like this to see what you are getting. This will probably point you in the right direction. If you are getting text you would have to write an implementation of MessageBodyReader to convert the plain text into an entity.

Try this...

System.out.println("Response body is " + response.getEntity(String.class));

Upvotes: 1

Related Questions