1

This is the error I get when running my code on Websphere.

NoSuchMethodError: javax/ws/rs/core/Response.readEntity(Ljava/lang/Class;)Ljava/lang/Object;

I don't get the same error when running on Tomcat

The code is (its the last line that throws the exception)

  WebClient client = WebClient.create("http://x.x.x.:8080/webp/services/RS/webp/pt/" );
  client.accept(APPLICATION_XML);
  Response r = client.post(request);
  WebPTResponse resp = r.readEntity(WebPTResponse.class);

Now, the call is from one web server to another. If I call the target with my Tomcat, it works, if I call it from Websphere, is errors.

The instance of Response object is a

wsjar:file:/opt/was/profiles/WTUKCWASESI01_NODE01/installedApps/BS_Cell/ESIPTService.ear/ESIPTService.war/WEB-INF/lib/cxf-rt-frontend-jaxrs-2.7.7.jar!/org/apache/cxf/jaxrs/impl/ResponseImpl.class

The class loading in Websphere set to Parent Last.

I'm stuck for what to try next.

If I debug and try to step into the call to readEntity, it errors at that point.

Can anyone suggest a reason or something else I can test?

Full stack.

java.lang.NoSuchMethodError: javax/ws/rs/core/Response.readEntity(Ljava/lang/Class;)Ljava/lang/Object; at com.ptservice.impl.internal.PtServiceInternalImpl.sendRequest(PtServiceInternalImpl.java:191) at com.ptservice.impl.internal.PtServiceInternalImpl.processPt(PtServiceInternalImpl.java:126) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37) at java.lang.reflect.Method.invoke(Method.java:611)


remote debug shows...

r.getClass().getDeclaredMethods()[31]

(java.lang.reflect.Method) public java.lang.Object org.apache.cxf.jaxrs.impl.ResponseImpl.readEntity(java.lang.Class) throws javax.ws.rs.MessageProcessingException,java.lang.IllegalStateException

Subodh Joshi
  • 12,717
  • 29
  • 108
  • 202
jeff porter
  • 6,560
  • 13
  • 65
  • 123
  • Can you share the full stacktrace please? – Priyesh May 14 '14 at 14:46
  • Hello, Were you able to resolve this issue? I am also facing similar issue. Please refer to http://stackoverflow.com/questions/24139097/resteasy-client-nosuchmethoderror – user613114 Jun 11 '14 at 04:58

1 Answers1

0

In the end I've put this piece of code in place.

Its not nice, and I don't like it, but it works.

  if (r instanceof org.apache.cxf.jaxrs.impl.ResponseImpl)
  {
    webResource = ((org.apache.cxf.jaxrs.impl.ResponseImpl)r).readEntity(WebPEDResponse.class);
  } else
  {
    webResource = r.readEntity(WebPEDResponse.class);
  }

If you really want to have some belt/braces approach you can add an extra catch and use reflection to get the value as well.

    private WebPEDResponse getResponseHandleIBMJDKIssue(Response r)
      {
        WebPEDResponse webResource = null;
        try {
          if (r instanceof org.apache.cxf.jaxrs.impl.ResponseImpl)
          {
            webResource = ((org.apache.cxf.jaxrs.impl.ResponseImpl)r).readEntity(WebPEDResponse.class);
          } else
          {
            webResource = r.readEntity(WebPEDResponse.class);
          }
} catch (Throwable e)
{
  LOG.trace("IBM JDK ISSUE: will try to call 'readEntity' via reflection", e);
}

if (webResource == null)
{
  try 
  {
    if (r.getClass().getDeclaredMethods()[31].getName().equals("readEntity"))
    {
      webResource = (WebPEDResponse) r.getClass().getDeclaredMethods()[31].invoke(r, WebPEDResponse.class);
    }

    if (webResource == null)
    {
      Method[] declaredMethods = r.getClass().getDeclaredMethods();
      for (Method method : declaredMethods)
      {
        if (method.getName().equals("readEntity"))
        {
          webResource = (WebPEDResponse) method.invoke(r, WebPEDResponse.class);
        }
      }
    }
  }
  catch (Throwable e)
  {
    LOG.error("IBM JDK ISSUE: tried to call 'readEntity' via reflection, didnt work.", e);
  }
}
return webResource;

}

jeff porter
  • 6,560
  • 13
  • 65
  • 123