我正在尝试使用Request Builder从服务器端方法返回JSON字符串。在@Produces("application/xml")
的情况下工作正常,但在@Produces("application/json")
的情况下却没有。
使用的罐子:
jersey-servlet-1.17.jar
jersey-bundle-1.17.jar
jersey-core-1.8.jar
jersey-client-1.8.jar
asm-3.3.1.jar
还包含在web.xmml:
中 `<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>`
示例服务器端代码:
@GET
@Path("getScreenList")
// @Produces("application/xml") // this works fine.
// @Produces({ MediaType.APPLICATION_JSON })
// @Produces("application/json")
@Produces({ "application/xml", "application/json" })
public ListItems getScreenList() {
ListItems li = new ListItems("Query Builder", "Query Builder");
return li;
}
Cliet side code:
String url = "/gxtUI/screenService/getScreenList";
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,
URL.encode(url));
builder.setCallback(new RequestCallback() {
@Override
public void onResponseReceived(Request request, Response response) {
System.out.println("List Store Request Builder Response:: "+response.getText());
}
@Override
public void onError(Request request, Throwable exception) {
System.out.println("List Store Request Builder Failure:: "+exception);
}
});
try {
builder.send();
} catch (RequestException e) {
e.printStackTrace();
}
在'aplication / json'的情况下我得到的感受:
SEVERE: Mapped exception to response: 500 (Internal Server Error)
javax.ws.rs.WebApplicationException: com.sun.jersey.api.MessageException: A message body writer for Java class
com.gxt.ui.client.model.ListItems, and Java type class com.gxt.ui.client.model.ListItems, and MIME media type application/xml was not found
at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:285)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1479)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1391)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1381)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:538)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:716)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:324)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:829)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:513)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
Caused by: com.sun.jersey.api.MessageException: A message body writer for Java class com.gxt.ui.client.model.ListItems, and Java type class com.gxt.ui.client.model.ListItems, and MIME media type application/xml was not found