我正在嘗試使用Jersey客戶端來訪問遠程Web服務。這是我的代碼,使請求:嘗試使用Jersey客戶端時出現空指針異常
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
產生的原因:在javax.ws.rs.core.MediaType.valueOf顯示java.lang.NullPointerException (的MediaType的.java:119) 在com.sun.jersey.core.header.MediaTypes(MediaTypes.java:64) ... 142多個
我環顧四周,看到別人有過類似的錯誤,用的MediaType在不同的平臺上拋出NullPointerExceptions ..
有沒有人見過這個問題?
請顯示您的'web.xml'。 –
我沒有web.xml,我建立這個作爲一個OSGi包 – cowls
我發現有人在這裏有同樣的問題:http://jersey.576304.n2.nabble.com/MediaType-Delegate-is-null-td5548719。 html 他們建議它已在jersey1.3中修復,但我使用的是版本1.12,但仍然看到相同的問題。有點關注 – cowls