我正在尝试使用 Jersey 客户端访问远程 Web 服务。这是我发出请求的代码:
Client client = Client.create();
WebResource resource = client.resource(request.getUrl());
Builder builder = resource.accept("application/json");
String response = builder.post(String.class, request.getPayload());
我已将它捆绑到一个 OSGi 包中,并将其安装在 Adobe CQ CMS 上。
当尝试在 CMS 中运行请求代码时,我得到以下堆栈跟踪:
Caused by: java.lang.ExceptionInInitializerError
at com.sun.jersey.core.spi.factory.MessageBodyFactory.getMessageBodyWriterMediaTypes(MessageBodyFactory.java:444)
at com.sun.jersey.api.client.RequestWriter.getMediaType(RequestWriter.java:324)
at com.sun.jersey.api.client.RequestWriter.writeRequestEntity(RequestWriter.java:282)
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler._invoke(URLConnectionClientHandler.java:204)
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:147)
at com.sun.jersey.api.client.Client.handle(Client.java:648)
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:680)
at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
at com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:568)
at com.myapp.auth.request.impl.HttpRequestSender.sendRequest(HttpRequestSender.java:44)
at com.myapp.auth.ws.clients.impl.AuthenticateClientImpl.authenticate(AuthenticateClientImpl.java:47)
at com.myapp.auth.Authenticator.authenticate(Authenticator.java:31)
at org.apache.jsp.apps.angry_002dnerds.components.page.base.content_jsp._jspService(content_jsp.java:155)
at org.apache.sling.scripting.jsp.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:420)
... 126 more
原因:com.sun.jersey.core.header.MediaTypes.(MediaTypes.java:64) 处的 javax.ws.rs.core.MediaType.valueOf(MediaType.java:119) 处的 java.lang.NullPointerException ...还有 142 个
我环顾四周,发现其他人在 MediaType 在不同平台上抛出 NullPointerExceptions 时遇到了类似的错误。
有没有人见过这个问题?