[英]NoSuchMethodError with CXF Response Object
This is the error I get when running my code on Websphere. 这是在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 在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. 现在,该呼叫是从一个Web服务器到另一个Web服务器。 If I call the target with my Tomcat, it works, if I call it from Websphere, is errors. 如果我使用Tomcat调用目标,则从Websphere调用目标时会出错。
The instance of Response object is a Response对象的实例是
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. Websphere中的类加载设置为“上一个上级”。
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. 如果我调试并尝试进入对readEntity的调用,则此刻它会出错。
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; 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) 在com.ptservice.impl.internal.PtServiceInternalImpl.sendRequest(PtServiceInternalImpl.java:191)处在com.ptservice.impl.internal.PtServiceInternalImpl.processPt(PtServiceInternalImpl.java:126)在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)在java.lang.reflect.Method.invoke(Method.java:611)
remote debug shows... 远程调试显示...
r.getClass().getDeclaredMethods()[31] 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 (java.lang.reflect.Method)公共java.lang.Object org.apache.cxf.jaxrs.impl.ResponseImpl.readEntity(java.lang.Class)抛出javax.ws.rs.MessageProcessingException,java.lang.IllegalStateException
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;
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.