English 中文(简体)
试图使用泽西岛客户时, Null 指针例外
原标题:Null pointer exception whilst trying to use Jersey client

我试图利用泽西岛客户访问远程网络服务。

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 I 中运行请求代码时, 得到以下的堆放跟踪 :

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

Caused by: java.lang.NullPointerException at javax.ws.rs.core.MediaType.valueOf(MediaType.java:119) at com.sun.jersey.core.header.MediaTypes.(MediaTypes.java:64) ... 142 more

其它人也有类似的错误, 在不同的平台上投掷NullPointer例外。

有人见过这个问题吗?

最佳回答

根据"http://jersey.java.net/nonav/documentation/latest/chapter_deps.html#d4e1727" rel=“no follow”>Jersey deps ,您需要将 jersey-json 模块装在您的依附/类路径中。

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签