无法在启用 Jaxrs-2.0 功能的情况下调用 REST 1.1 服务
unable to call REST 1.1 Service with Jaxrs-2.0 feature enabled
我在 Java 1.8 上使用 Liberty 配置文件 16,并启用了以下功能:
<featureManager>
<feature>jsp-2.3</feature>
<feature>wasJmsServer-1.0</feature>
<feature>wasJmsClient-2.0</feature>
<feature>jndi-1.0</feature>
<feature>ejbLite-3.2</feature>
<feature>servlet-3.1</feature>
<feature>jdbc-4.0</feature>
<feature>localConnector-1.0</feature>
<feature>jaxrs-2.0</feature>
</featureManager>
我在此使用 Apache Wink 作为我的休息提供者并将其添加为第三方库。
<library id="winkLib" >
<fileset dir="E:\Software\Jars\wink1.4\apache-wink-1.4\lib" includes="*.jar" scanInterval="5s"></fileset>
</library>
<enterpriseApplication location="E:\wlp9\usr\servers\servername\apps\myear.ear">
<classloader commonLibraryRef="winkLib" />
</enterpriseApplication>
REST 服务已成功注册,但当我尝试访问该服务时出现以下错误:
10:43:04,241 INFO [User=] [RequestInterceptor] Initializing Request Hanlder
10:43:04,256 INFO [User=] [ResponseInterceptor] Initializing response interceptor
[INFO ] The following error occurred during the invocation of the handlers chain: NullPointerException with message 'null' while processing POST request sent to http://localhost:8081/myapp/rest/login
10:43:04,287 WARN [User=] [RestExceptionHandler] Exception Hanlder Invoked
10:43:04,287 ERROR [User=] [RestExceptionHandler]
****************************************************************************************************
Message Info:java.lang.NullPointerException
****************************************************************************************************
[ERROR ] The system cannot determine the class of type null.
[ERROR ] An unhandled exception occurred which will be propagated to the container.
java.lang.NullPointerException
[ERROR ] SRVE0777E: Exception thrown by application class 'java.lang.Class.isAssignableFrom:-2'
java.lang.NullPointerException
at java.lang.Class.isAssignableFrom(Native Method)
at org.apache.wink.common.internal.registry.ProvidersRegistry$MediaTypeMap$OFHolder.compareTo(ProvidersRegistry.java:1008)
at org.apache.wink.common.internal.registry.ProvidersRegistry$MediaTypeMap$OFHolder.compareTo(ProvidersRegistry.java:906)
at java.util.Collections$ReverseComparator.compare(Collections.java:5117)
at java.util.Collections$ReverseComparator.compare(Collections.java:5108)
at java.util.TreeMap.put(TreeMap.java:552)
at java.util.TreeSet.add(TreeSet.java:255)
at org.apache.wink.common.internal.registry.ProvidersRegistry$MediaTypeMap.internalGetProvidersByMediaType(ProvidersRegistry.java:752)
at org.apache.wink.common.internal.registry.ProvidersRegistry$MediaTypeMap.getProvidersByMediaType(ProvidersRegistry.java:711)
at org.apache.wink.common.internal.registry.ProvidersRegistry.getMessageBodyWriter(ProvidersRegistry.java:445)
at org.apache.wink.common.internal.contexts.ProvidersImpl.getMessageBodyWriter(ProvidersImpl.java:72)
at org.apache.wink.server.internal.handlers.FlushResultHandler.handleResponse(FlushResultHandler.java:144)
at org.apache.wink.server.handlers.AbstractHandler.handleResponse(AbstractHandler.java:38)
at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:26)
at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:22)
at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:75)
at org.apache.wink.server.handlers.AbstractHandler.handleResponse(AbstractHandler.java:39)
at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:26)
at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:22)
at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:75)
at org.apache.wink.server.handlers.AbstractHandler.handleResponse(AbstractHandler.java:39)
at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:26)
at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:22)
at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:75)
at org.apache.wink.server.handlers.AbstractHandler.handleResponse(AbstractHandler.java:39)
at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:26)
at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:22)
at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:75)
at org.apache.wink.server.internal.log.Responses.handleResponse(Responses.java:90)
at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:26)
at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:22)
at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:75)
at org.apache.wink.server.handlers.AbstractHandlersChain.run(AbstractHandlersChain.java:60)
at org.apache.wink.server.internal.RequestProcessor.handleRequestWithoutFaultBarrier(RequestProcessor.java:232)
at org.apache.wink.server.internal.RequestProcessor.handleRequest(RequestProcessor.java:154)
at org.apache.wink.server.internal.servlet.RestServlet.service(RestServlet.java:124)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at [internal classes]
[INFO ] FFDC1015I: An FFDC Incident has been created: "java.lang.NullPointerException com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters 1105" at ffdc_17.03.09_10.43.04.0.log
[ERROR ] SRVE0315E: An exception occurred: java.lang.Throwable: java.lang.NullPointerException
at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:4983)
at [internal classes]
Caused by: java.lang.NullPointerException
at java.lang.Class.isAssignableFrom(Native Method)
at org.apache.wink.common.internal.registry.ProvidersRegistry$MediaTypeMap$OFHolder.compareTo(ProvidersRegistry.java:1008)
at org.apache.wink.common.internal.registry.ProvidersRegistry$MediaTypeMap$OFHolder.compareTo(ProvidersRegistry.java:906)
at java.util.Collections$ReverseComparator.compare(Collections.java:5117)
at java.util.Collections$ReverseComparator.compare(Collections.java:5108)
at java.util.TreeMap.put(TreeMap.java:552)
at java.util.TreeSet.add(TreeSet.java:255)
at org.apache.wink.common.internal.registry.ProvidersRegistry$MediaTypeMap.internalGetProvidersByMediaType(ProvidersRegistry.java:752)
at org.apache.wink.common.internal.registry.ProvidersRegistry$MediaTypeMap.getProvidersByMediaType(ProvidersRegistry.java:711)
at org.apache.wink.common.internal.registry.ProvidersRegistry.getMessageBodyWriter(ProvidersRegistry.java:445)
at org.apache.wink.common.internal.contexts.ProvidersImpl.getMessageBodyWriter(ProvidersImpl.java:72)
at org.apache.wink.server.internal.handlers.FlushResultHandler.handleResponse(FlushResultHandler.java:144)
at org.apache.wink.server.handlers.AbstractHandler.handleResponse(AbstractHandler.java:38)
at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:26)
at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:22)
at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:75)
at org.apache.wink.server.handlers.AbstractHandler.handleResponse(AbstractHandler.java:39)
at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:26)
at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:22)
at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:75)
at org.apache.wink.server.handlers.AbstractHandler.handleResponse(AbstractHandler.java:39)
at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:26)
at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:22)
at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:75)
at org.apache.wink.server.handlers.AbstractHandler.handleResponse(AbstractHandler.java:39)
at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:26)
at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:22)
at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:75)
at org.apache.wink.server.internal.log.Responses.handleResponse(Responses.java:90)
at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:26)
at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:22)
at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:75)
at org.apache.wink.server.handlers.AbstractHandlersChain.run(AbstractHandlersChain.java:60)
at org.apache.wink.server.internal.RequestProcessor.handleRequestWithoutFaultBarrier(RequestProcessor.java:232)
at org.apache.wink.server.internal.RequestProcessor.handleRequest(RequestProcessor.java:154)
at org.apache.wink.server.internal.servlet.RestServlet.service(RestServlet.java:124)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
... 1 more
这是我的 web.xml 样子:
<servlet>
<servlet-name>JAX-RS Servlet</servlet-name>
<servlet-class>org.apache.wink.server.internal.servlet.RestServlet</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>package.name.RestfulResourceLoader</param-value>
</init-param>
<init-param>
<param-name>propertiesLocation</param-name>
<param-value>handler.properties</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>JAX-RS Servlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
这看起来像是 Wink 中的错误。虽然您的共享库表明您使用的是 Wink 1.4,但堆栈跟踪中的源代码行号更接近于 Wink 1.2.1。也许这个问题在更新版本的 Wink 中得到了解决。
您的配置肯定容易出错,因为您使用的是 jaxrs-2.0 功能(除其他事项外,它告诉 Liberty 服务器使 JAX-RS 2.0 API 包可用于应用程序)但尝试使用不同的 JAX-RS 提供程序。这里还有一个版本冲突——Wink 实现了 JAX-RS 1.1。如果我对这个配置的理解正确,那么您正在使用 Wink 作为 JAX-RS 提供程序,但使用的是 Liberty 附带的 JAX-RS 2.0 APIs。即使这不是您所看到的问题的原因,以后也可能会导致问题。
如果您想使用 Wink,我建议您将其从您的应用程序中删除,然后使用 jaxrs-1.1 功能部件(而不是 jaxrs-2.0 功能部件)。 Liberty 的 jaxrs-1.1。实现是 Wink,它使许多特定于 Wink 的 API 可用。
如果您只需要一个 JAX-RS 提供程序(与 Wink 无关),那么我建议从您的应用程序中删除 Wink 库,并使用内置于 jaxrs-2.0 功能的 CXF 实现。这需要制作一些 changes to the web.xml.
安迪,希望这对你有所帮助
我在 Java 1.8 上使用 Liberty 配置文件 16,并启用了以下功能:
<featureManager>
<feature>jsp-2.3</feature>
<feature>wasJmsServer-1.0</feature>
<feature>wasJmsClient-2.0</feature>
<feature>jndi-1.0</feature>
<feature>ejbLite-3.2</feature>
<feature>servlet-3.1</feature>
<feature>jdbc-4.0</feature>
<feature>localConnector-1.0</feature>
<feature>jaxrs-2.0</feature>
</featureManager>
我在此使用 Apache Wink 作为我的休息提供者并将其添加为第三方库。
<library id="winkLib" >
<fileset dir="E:\Software\Jars\wink1.4\apache-wink-1.4\lib" includes="*.jar" scanInterval="5s"></fileset>
</library>
<enterpriseApplication location="E:\wlp9\usr\servers\servername\apps\myear.ear">
<classloader commonLibraryRef="winkLib" />
</enterpriseApplication>
REST 服务已成功注册,但当我尝试访问该服务时出现以下错误:
10:43:04,241 INFO [User=] [RequestInterceptor] Initializing Request Hanlder
10:43:04,256 INFO [User=] [ResponseInterceptor] Initializing response interceptor
[INFO ] The following error occurred during the invocation of the handlers chain: NullPointerException with message 'null' while processing POST request sent to http://localhost:8081/myapp/rest/login
10:43:04,287 WARN [User=] [RestExceptionHandler] Exception Hanlder Invoked
10:43:04,287 ERROR [User=] [RestExceptionHandler]
****************************************************************************************************
Message Info:java.lang.NullPointerException
****************************************************************************************************
[ERROR ] The system cannot determine the class of type null.
[ERROR ] An unhandled exception occurred which will be propagated to the container.
java.lang.NullPointerException
[ERROR ] SRVE0777E: Exception thrown by application class 'java.lang.Class.isAssignableFrom:-2'
java.lang.NullPointerException
at java.lang.Class.isAssignableFrom(Native Method)
at org.apache.wink.common.internal.registry.ProvidersRegistry$MediaTypeMap$OFHolder.compareTo(ProvidersRegistry.java:1008)
at org.apache.wink.common.internal.registry.ProvidersRegistry$MediaTypeMap$OFHolder.compareTo(ProvidersRegistry.java:906)
at java.util.Collections$ReverseComparator.compare(Collections.java:5117)
at java.util.Collections$ReverseComparator.compare(Collections.java:5108)
at java.util.TreeMap.put(TreeMap.java:552)
at java.util.TreeSet.add(TreeSet.java:255)
at org.apache.wink.common.internal.registry.ProvidersRegistry$MediaTypeMap.internalGetProvidersByMediaType(ProvidersRegistry.java:752)
at org.apache.wink.common.internal.registry.ProvidersRegistry$MediaTypeMap.getProvidersByMediaType(ProvidersRegistry.java:711)
at org.apache.wink.common.internal.registry.ProvidersRegistry.getMessageBodyWriter(ProvidersRegistry.java:445)
at org.apache.wink.common.internal.contexts.ProvidersImpl.getMessageBodyWriter(ProvidersImpl.java:72)
at org.apache.wink.server.internal.handlers.FlushResultHandler.handleResponse(FlushResultHandler.java:144)
at org.apache.wink.server.handlers.AbstractHandler.handleResponse(AbstractHandler.java:38)
at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:26)
at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:22)
at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:75)
at org.apache.wink.server.handlers.AbstractHandler.handleResponse(AbstractHandler.java:39)
at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:26)
at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:22)
at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:75)
at org.apache.wink.server.handlers.AbstractHandler.handleResponse(AbstractHandler.java:39)
at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:26)
at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:22)
at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:75)
at org.apache.wink.server.handlers.AbstractHandler.handleResponse(AbstractHandler.java:39)
at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:26)
at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:22)
at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:75)
at org.apache.wink.server.internal.log.Responses.handleResponse(Responses.java:90)
at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:26)
at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:22)
at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:75)
at org.apache.wink.server.handlers.AbstractHandlersChain.run(AbstractHandlersChain.java:60)
at org.apache.wink.server.internal.RequestProcessor.handleRequestWithoutFaultBarrier(RequestProcessor.java:232)
at org.apache.wink.server.internal.RequestProcessor.handleRequest(RequestProcessor.java:154)
at org.apache.wink.server.internal.servlet.RestServlet.service(RestServlet.java:124)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at [internal classes]
[INFO ] FFDC1015I: An FFDC Incident has been created: "java.lang.NullPointerException com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters 1105" at ffdc_17.03.09_10.43.04.0.log
[ERROR ] SRVE0315E: An exception occurred: java.lang.Throwable: java.lang.NullPointerException
at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:4983)
at [internal classes]
Caused by: java.lang.NullPointerException
at java.lang.Class.isAssignableFrom(Native Method)
at org.apache.wink.common.internal.registry.ProvidersRegistry$MediaTypeMap$OFHolder.compareTo(ProvidersRegistry.java:1008)
at org.apache.wink.common.internal.registry.ProvidersRegistry$MediaTypeMap$OFHolder.compareTo(ProvidersRegistry.java:906)
at java.util.Collections$ReverseComparator.compare(Collections.java:5117)
at java.util.Collections$ReverseComparator.compare(Collections.java:5108)
at java.util.TreeMap.put(TreeMap.java:552)
at java.util.TreeSet.add(TreeSet.java:255)
at org.apache.wink.common.internal.registry.ProvidersRegistry$MediaTypeMap.internalGetProvidersByMediaType(ProvidersRegistry.java:752)
at org.apache.wink.common.internal.registry.ProvidersRegistry$MediaTypeMap.getProvidersByMediaType(ProvidersRegistry.java:711)
at org.apache.wink.common.internal.registry.ProvidersRegistry.getMessageBodyWriter(ProvidersRegistry.java:445)
at org.apache.wink.common.internal.contexts.ProvidersImpl.getMessageBodyWriter(ProvidersImpl.java:72)
at org.apache.wink.server.internal.handlers.FlushResultHandler.handleResponse(FlushResultHandler.java:144)
at org.apache.wink.server.handlers.AbstractHandler.handleResponse(AbstractHandler.java:38)
at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:26)
at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:22)
at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:75)
at org.apache.wink.server.handlers.AbstractHandler.handleResponse(AbstractHandler.java:39)
at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:26)
at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:22)
at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:75)
at org.apache.wink.server.handlers.AbstractHandler.handleResponse(AbstractHandler.java:39)
at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:26)
at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:22)
at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:75)
at org.apache.wink.server.handlers.AbstractHandler.handleResponse(AbstractHandler.java:39)
at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:26)
at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:22)
at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:75)
at org.apache.wink.server.internal.log.Responses.handleResponse(Responses.java:90)
at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:26)
at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:22)
at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:75)
at org.apache.wink.server.handlers.AbstractHandlersChain.run(AbstractHandlersChain.java:60)
at org.apache.wink.server.internal.RequestProcessor.handleRequestWithoutFaultBarrier(RequestProcessor.java:232)
at org.apache.wink.server.internal.RequestProcessor.handleRequest(RequestProcessor.java:154)
at org.apache.wink.server.internal.servlet.RestServlet.service(RestServlet.java:124)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
... 1 more
这是我的 web.xml 样子:
<servlet>
<servlet-name>JAX-RS Servlet</servlet-name>
<servlet-class>org.apache.wink.server.internal.servlet.RestServlet</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>package.name.RestfulResourceLoader</param-value>
</init-param>
<init-param>
<param-name>propertiesLocation</param-name>
<param-value>handler.properties</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>JAX-RS Servlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
这看起来像是 Wink 中的错误。虽然您的共享库表明您使用的是 Wink 1.4,但堆栈跟踪中的源代码行号更接近于 Wink 1.2.1。也许这个问题在更新版本的 Wink 中得到了解决。
您的配置肯定容易出错,因为您使用的是 jaxrs-2.0 功能(除其他事项外,它告诉 Liberty 服务器使 JAX-RS 2.0 API 包可用于应用程序)但尝试使用不同的 JAX-RS 提供程序。这里还有一个版本冲突——Wink 实现了 JAX-RS 1.1。如果我对这个配置的理解正确,那么您正在使用 Wink 作为 JAX-RS 提供程序,但使用的是 Liberty 附带的 JAX-RS 2.0 APIs。即使这不是您所看到的问题的原因,以后也可能会导致问题。
如果您想使用 Wink,我建议您将其从您的应用程序中删除,然后使用 jaxrs-1.1 功能部件(而不是 jaxrs-2.0 功能部件)。 Liberty 的 jaxrs-1.1。实现是 Wink,它使许多特定于 Wink 的 API 可用。
如果您只需要一个 JAX-RS 提供程序(与 Wink 无关),那么我建议从您的应用程序中删除 Wink 库,并使用内置于 jaxrs-2.0 功能的 CXF 实现。这需要制作一些 changes to the web.xml.
安迪,希望这对你有所帮助