1

I am trying to write a simple Resteasy client to access mt rest web service. Unfortunately I am getting the error:

Exception in thread "main" org.jboss.resteasy.client.ClientResponseFailure: Unable to find a MessageBodyReader of content-type application/json and type null
    at org.jboss.resteasy.client.core.BaseClientResponse.createResponseFailure(BaseClientResponse.java:523)
    at org.jboss.resteasy.client.core.BaseClientResponse.createResponseFailure(BaseClientResponse.java:514)
    at org.jboss.resteasy.client.core.BaseClientResponse.readFrom(BaseClientResponse.java:415)
    at org.jboss.resteasy.client.core.BaseClientResponse.getEntity(BaseClientResponse.java:377)
    at org.jboss.resteasy.client.core.BaseClientResponse.getEntity(BaseClientResponse.java:350)
    at org.jboss.resteasy.client.core.BaseClientResponse.getEntity(BaseClientResponse.java:344)
    at com.test.client.rest.employee.EmployeeClient.main(EmployeeClient.java:29)

Client code:

ClientRequest request = new ClientRequest(ROOT_URL + "getEmp/GS");

    ClientResponse<Employee> resp = request.get(Employee.class);
    //Response resp = request.get();
    if(resp.getResponseStatus().getStatusCode() == 200)
    {
        System.out.println("resp ok!!!");
    }

    Employee e = resp.getEntity(Employee.class);
    System.out.println("path:" + e);

Rest Service code:

@GET
    @Path("getEmp/{name}")
    @Produces("application/json")
    public Employee getEmployee(@PathParam("name") String name)
    {
        if(em.containsKey(name))
            return em.get(name);
        else
            throw new EmployeeNotFoundException("Employee with name '" + name + "' does not exists!");
    }

Client code response is ok. i.e. 200. The same url works fine with Mozilla Rest client. Any help would be appreciated

G.S
  • 10,413
  • 7
  • 36
  • 52

2 Answers2

1

Make sure you have all the jackson libraries in your client project. If you are using maven, you should have this:

<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jackson-provider</artifactId>
    <version>xxx</version>
</dependency>

EDIT: The jars used by resteasy-jaxrs and resteasy-jackson-provider are

[INFO] +- org.jboss.resteasy:resteasy-jaxrs:jar:2.2.1.GA:compile
[INFO] |  +- org.jboss.resteasy:jaxrs-api:jar:2.2.1.GA:compile
[INFO] |  +- org.scannotation:scannotation:jar:1.0.3:compile
[INFO] |  |  \- javassist:javassist:jar:3.12.1.GA:compile
[INFO] |  +- javax.annotation:jsr250-api:jar:1.0:compile
[INFO] |  +- javax.activation:activation:jar:1.1:compile
[INFO] |  +- commons-httpclient:commons-httpclient:jar:3.1:compile
[INFO] |  |  +- commons-logging:commons-logging:jar:1.0.4:compile
[INFO] |  |  \- commons-codec:commons-codec:jar:1.2:compile
[INFO] |  +- org.apache.httpcomponents:httpclient:jar:4.0.3:compile
[INFO] |  |  \- org.apache.httpcomponents:httpcore:jar:4.0.1:compile
[INFO] |  \- net.jcip:jcip-annotations:jar:1.0:compile
[INFO] \- org.jboss.resteasy:resteasy-jackson-provider:jar:2.2.1.GA:compile
[INFO]    +- org.codehaus.jackson:jackson-core-asl:jar:1.6.3:compile
[INFO]    +- org.codehaus.jackson:jackson-mapper-asl:jar:1.6.3:compile
[INFO]    +- org.codehaus.jackson:jackson-jaxrs:jar:1.6.3:compile
[INFO]    \- org.codehaus.jackson:jackson-xc:jar:1.6.3:compile

You could also try setting the accepts content type in your client implementation

request.accept("application/json");
mendieta
  • 3,470
  • 2
  • 20
  • 23
  • Unfortunately I am not using maven. I have created a simple main class and added `resteasy-jackson-provider.2.3.2.Final.jar` and `resteasy-jackson-provider.2.3.2.Final=jandex.jar` in the build path of the project which I took from JBOSS home. – G.S Oct 23 '14 at 07:11
  • I posted all the jars needed.. If that doesn't help, you can check this post http://stackoverflow.com/questions/12175564/unable-to-find-a-messagebodyreader-of-content-type-application-json-and-type-cla – mendieta Oct 23 '14 at 12:56
  • Thank you very much for the answer. But the jettison jars were the culprit. I added them and the error disappeared. – G.S Oct 23 '14 at 14:51
  • Your welcome! I thought you were using jackson as your json provider! – mendieta Oct 23 '14 at 14:57
0

After adding the jettison provider jars, the issue got resolved.

Still I feel Resteasy-2.3.2 has some problem and eventually i upgraded my Reateasy to 2.3.5 and the client is working perfectly.

G.S
  • 10,413
  • 7
  • 36
  • 52