我正在尝试在我的骨干应用程序上使用jsonp。在我的web服务中,我正在尝试使用Jersey库来使用JSONWithPadding响应。
问题是,看起来不支持“application / x-javascript”。
我的代码是:
@GET
@Path("/issues/jsonp")
@Produces("application/x-javascript")
public JSONWithPadding getIssuesJsonp(@Context HttpServletRequest req,
@PathParam("ppid") String qppid,
@QueryParam("callback") String callback) {
Principal principal = req.getUserPrincipal();
String username = principal.getName();
try {
List<IssueDTO> list = service.getIssuesDTO(username, qppid);
IssuesResult r = new IssuesResult();
r.setIssues(list);
System.out.println("CALLBACK:" + callback);
return new JSONWithPadding(r,callback);
} catch (Exception e) {
String message = "Internal Server Error";
LOG.error(message, e);
Result r = new Result(PPStatusCode.INTERNAL_SERVER_ERROR, message);
return new JSONWithPadding(noCache(500, r),callback);
}
}
结果是:
Etat HTTP 500 - 找不到类型的响应对象的MessageBodyWriter:com.sun.jersey.api.json.JSONWithPadding媒体类型:application / javascript
有人可以帮助我吗?
编辑:完整的堆栈跟踪:
18:52:33,243 WARN [org.jboss.resteasy.core.SynchronousDispatcher] (http - 127.0.0.1-8080-1)执行GET pp / fn / issues / jsonp失败: org.jboss.resteasy.core.NoMessageBodyWriterFoundFailure:不能 找到类型的响应对象的MessageBodyWriter: com.sun.jersey.api.json.JSONWithPadding媒体类型: application / x-javascript at org.jboss.resteasy.core.ServerResponse.writeTo(ServerResponse.java:216) [resteasy-jaxrs-2.3.2.Final.jar:] at org.jboss.resteasy.core.SynchronousDispatcher.writeJaxrsResponse(SynchronousDispatcher.java:585) [resteasy-jaxrs-2.3.2.Final.jar:] at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:506) [resteasy-jaxrs-2.3.2.Final.jar:] at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:119) [resteasy-jaxrs-2.3.2.Final.jar:] at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208) [resteasy-jaxrs-2.3.2.Final.jar:] at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55) [resteasy-jaxrs-2.3.2.Final.jar:] at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50) [resteasy-jaxrs-2.3.2.Final.jar:] at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:] at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:489) [jbossweb-7.0.13.Final.jar:] at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final] at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:] at org.apache.coyote.http11.Http11Protocol $ Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:] at org.apache.tomcat.util.net.JIoEndpoint $ Worker.run(JIoEndpoint.java:930) java.lang.Thread.run上的[jbossweb-7.0.13.Final.jar:](Thread.java:722) [rt.jar中:1.7.0_11]
艾伦
答案 0 :(得分:1)
基于堆栈跟踪,看起来JBoss中提供的Resteasy无法从JSONWithPaddingProvider
中找到jersey-json.jar
,而你(我猜)已经捆绑在你的WAR中。 JSONWithPadding
是泽西岛特定类,如果你想使用它,你有两个选择:
web.xml
中所述禁用Resteasy,以确保您的应用程序使用Jersey作为JAX-RS实现< / LI>
jersey-json.jar
添加到JBoss类路径中,以便Resteasy能够找到位于此jar中的MessageBodyWriter
(JSONWithPaddingProvider
)答案 1 :(得分:0)
RestEasy已经拥有JacksonJsonpInterceptor
- 如果你使用Guice和RestEasy,你可以在适当的模块中bind(JacksonJsonpInterceptor.class)
,否则你应该将它配置为正常的RestEasy(参见https://docs.jboss.org/resteasy/docs/1.1.GA/userguide/html/Interceptors.html第29.6节:
它们可以在web.xml中的resteasy.providers context-param中列出,或者作为Application.getClasses()或Appication.getSingletons()方法中的类或对象返回。