无法找到类型为:com.sun.jersey.api.json的MessageBodyWriter。媒体类型的JSONWithPadding: application/x-javascript

时间:2021-01-02 07:24:01

I'm trying to use jsonp on my backbone application. In my webservice, I'm trying to use the Jersey library to use the JSONWithPadding response.

我正在尝试在我的主干应用程序中使用jsonp。在我的webservice中,我尝试使用Jersey库来使用JSONWithPadding响应。

Problem is, looks like the "application/x-javascript" is not supported.

问题是,看起来不支持“application/x-javascript”。

My code is :

我的代码是:

@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);
}
}

And the result is:

结果是:

Etat HTTP 500 - Could not find MessageBodyWriter for response object of type: com.sun.jersey.api.json.JSONWithPadding of media type: application/javascript

Etat HTTP 500 -无法找到类型为:com.sun.jersey.api.json的MessageBodyWriter。媒体类型的JSONWithPadding: application/javascript

Can someone help me ?

谁能帮帮我吗?

Edit: the full stacktrace:

编辑:完整的异常堆栈:

18:52:33,243 WARN [org.jboss.resteasy.core.SynchronousDispatcher] (http--127.0.0.1-8080-1) Failed executing GET pp/fn/issues/jsonp: org.jboss.resteasy.core.NoMessageBodyWriterFoundFailure: Could not find MessageBodyWriter for response object of type: com.sun.jersey.api.json.JSONWithPadding of media type: 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) [jbossweb-7.0.13.Final.jar:] at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_11]

(org.jboss.resteasy.core 18:52:33,243警告。(http——127.0.1 -8080-1)执行GET pp/fn/issues/jsonp: org. jboss.resteas.core失败。失败:无法找到类型为:com.sun.jersey.api.json的MessageBodyWriter。媒体类型的JSONWithPadding: application/x-javascript at org.jboss.resteas.core.serverresponse . writeto (ServerResponse.java:216) [reste -jaxrs-2.3.2. final]jar:]org.jboss.resteasy.core.SynchronousDispatcher.writeJaxrsResponse(SynchronousDispatcher.java:585)[resteasy-jaxrs-2.3.2.Final。jar:]org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:506)[resteasy-jaxrs-2.3.2.Final。jar:]org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:119)[resteasy-jaxrs-2.3.2.Final。jar:]org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208)[resteasy-jaxrs-2.3.2.Final。jar:]org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55)[resteasy-jaxrs-2.3.2.Final。jar:]org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(resteasy-jaxrs-2.3.2.Final(HttpServletDispatcher.java:50)。jar:]javax.servlet.http.HttpServlet.service(HttpServlet.java:847)[jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0。最终]org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)[jbossweb-7.0.13.Final。jar:]org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)[jbossweb-7.0.13.Final。jar:]org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)[jbossweb-7.0.13.Final。jar:]org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)[jbossweb-7.0.13.Final。jar:]org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:489)[jbossweb-7.0.13.Final。jar:]org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50)[安装7.1.1 jboss-as-jpa-7.1.1.Final.jar:。最终]org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153)[安装7.1.1 jboss-as-web-7.1.1.Final.jar:。最终]org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)[jbossweb-7.0.13.Final。jar:]org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)[jbossweb-7.0.13.Final。jar:]org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)[jbossweb-7.0.13.Final。jar:]org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368)[jbossweb-7.0.13.Final。jar:]org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)[jbossweb-7.0.13.Final。jar:]org.apache.coyote.http11.Http11Protocol Http11ConnectionHandler.process美元(Http11Protocol.java:671)[jbossweb-7.0.13.Final。jar:]org.apache.tomcat.util.net.JIoEndpoint Worker.run美元(JIoEndpoint.java:930)[jbossweb-7.0.13.Final。jar:]java.lang.Thread.run(Thread.java:722)[rt.jar 1.7.0_11):

Alan

艾伦

2 个解决方案

#1


1  

Based on the stacktrace it looks like Resteasy provided in JBoss is unable to find JSONWithPaddingProvider from jersey-json.jar which you have (I suppose) bundled in your WAR. JSONWithPadding is Jersey specific class and if you want to use it you have 2 options:

基于stacktrace,看起来JBoss提供的Resteasy无法从jerchy -json找到JSONWithPaddingProvider。jar,我想是你在战争中捆绑的。JSONWithPadding是Jersey特定的类如果你想使用它你有两个选项:

  • add Jersey libs to your WAR (if you don't have them there already) and disable Resteasy in web.xml as described in Deploying a Jersey webapp on Jboss AS 7 to make sure your application uses Jersey as JAX-RS implementation
  • 在您的战争中添加泽西岛的libs(如果您还没有的话),并在web中禁用Resteasy。如在Jboss上部署Jersey webapp as 7中所描述的xml,以确保应用程序使用Jersey作为JAX-RS实现
  • add jersey-json.jar to the JBoss classpath so Resteasy is able to find MessageBodyWriter (JSONWithPaddingProvider) located in this jar
  • 添加jersey-json。jar到JBoss类路径,这样Resteasy才能找到位于这个jar中的MessageBodyWriter (JSONWithPaddingProvider)

#2


0  

RestEasy also has the JacksonJsonpInterceptor already - if you are using Guice with RestEasy, you can bind(JacksonJsonpInterceptor.class) in an appropriate module, otherwise you will should configure it as normal for RestEasy (see https://docs.jboss.org/resteasy/docs/1.1.GA/userguide/html/Interceptors.html section 29.6):

RestEasy也已经拥有了JacksonJsonpInterceptor——如果你使用的是带有RestEasy属性的Guice,你可以在一个适当的模块中绑定(JacksonJsonpInterceptor.class),否则你应该将它配置为RestEasy的正常属性(参见https://docs.jboss.org/restey/docs/docs/1.1.1.1.1.user29./interceps.html):

they can be listed in the resteasy.providers context-param in web.xml or returned as a class or object in the Application.getClasses() or Appication.getSingletons() method.

它们可以列在resteasy上。提供者context-param在web。在Application.getClasses()或appic.getsingletons()方法中作为类或对象返回。

#1


1  

Based on the stacktrace it looks like Resteasy provided in JBoss is unable to find JSONWithPaddingProvider from jersey-json.jar which you have (I suppose) bundled in your WAR. JSONWithPadding is Jersey specific class and if you want to use it you have 2 options:

基于stacktrace,看起来JBoss提供的Resteasy无法从jerchy -json找到JSONWithPaddingProvider。jar,我想是你在战争中捆绑的。JSONWithPadding是Jersey特定的类如果你想使用它你有两个选项:

  • add Jersey libs to your WAR (if you don't have them there already) and disable Resteasy in web.xml as described in Deploying a Jersey webapp on Jboss AS 7 to make sure your application uses Jersey as JAX-RS implementation
  • 在您的战争中添加泽西岛的libs(如果您还没有的话),并在web中禁用Resteasy。如在Jboss上部署Jersey webapp as 7中所描述的xml,以确保应用程序使用Jersey作为JAX-RS实现
  • add jersey-json.jar to the JBoss classpath so Resteasy is able to find MessageBodyWriter (JSONWithPaddingProvider) located in this jar
  • 添加jersey-json。jar到JBoss类路径,这样Resteasy才能找到位于这个jar中的MessageBodyWriter (JSONWithPaddingProvider)

#2


0  

RestEasy also has the JacksonJsonpInterceptor already - if you are using Guice with RestEasy, you can bind(JacksonJsonpInterceptor.class) in an appropriate module, otherwise you will should configure it as normal for RestEasy (see https://docs.jboss.org/resteasy/docs/1.1.GA/userguide/html/Interceptors.html section 29.6):

RestEasy也已经拥有了JacksonJsonpInterceptor——如果你使用的是带有RestEasy属性的Guice,你可以在一个适当的模块中绑定(JacksonJsonpInterceptor.class),否则你应该将它配置为RestEasy的正常属性(参见https://docs.jboss.org/restey/docs/docs/1.1.1.1.1.user29./interceps.html):

they can be listed in the resteasy.providers context-param in web.xml or returned as a class or object in the Application.getClasses() or Appication.getSingletons() method.

它们可以列在resteasy上。提供者context-param在web。在Application.getClasses()或appic.getsingletons()方法中作为类或对象返回。