Betree Betree - 4 months ago 52
JSON Question

JBoss + RestEasy + Jackson : org.jboss.resteasy.core.ServerResponse cannot be cast to org.jboss.resteasy.specimpl.BuiltResponse

I work on a REST Api with JBoss (AS 7.1), RestEasy and Jackson. The web service return an "Account" object, it's a simple POJO that used to be serialized in JSon without any problem.

After some modifications in the code, the server pop an exception after each call to my method. The execution of :

@POST
@Path("/auth")
@Produces(MediaType.APPLICATION_JSON)
public Account authentification(final Account account) throws AuthenticationException {
Logger.debug(this, "Authenticate");
Account returnedAccount = // Some authentication code that build a correct Account object
Logger.debug(this, "Authenticated, return now !");
return returnedAccount;
}


Print an output as following :

(DEBUG) Authenticate
(DEBUG) Authenticated, return now !
(ERROR) java.lang.ClassCastException: org.jboss.resteasy.core.ServerResponse cannot be cast to org.jboss.resteasy.specimpl.BuiltResponse
at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:340)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:234)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:221)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:356)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179)
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
at com.mypackage.filter.MyFilter.doFilter(MyFilter.java:55)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50)
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930)
at java.lang.Thread.run(Thread.java:662)


The only thing i found on google was this ticket on JBOSS issues tracker but it doesn't help much.

Any help would be much appreciated !

Answer

After lot of investigation, the bug came from a conflict in JBoss libraries. It cames out after adding a JMS Queue to our JBOSS configuration.

To resolve it we first kicked out all our dependencies to javax.ws.rs-api-x.x < 2.0, then we updated to javax.ws.rs-api-2.0 on our servers.

To do that :

  • Add the new Jar
wget https://repository.liferay.com/nexus/content/groups/public/javax/ws/rs/javax.ws.rs-api/2.0/javax.ws.rs-api-2.0.jar -O /usr/local/bin/jboss-as-7.1.1.Final/modules/javax/ws/rs/api/main/javax.ws.rs-api-2.0.jar && md5sum /usr/local/bin/jboss-as-7.1.1.Final/modules/javax/ws/rs/api/main/javax.ws.rs-api-2.0.jar

Be sure the printed MD5 is 3bc8176d36becb7746e1f2594346ed66, otherwise it's not the good package.

  • Update module.xml

Again in "/usr/local/bin/jboss-as-7.1.1.Final/modules/javax/ws/rs/api/main" change the module.xml file to match this content :

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="javax.ws.rs.api">
<resources>
    <resource-root path="javax.ws.rs-api-2.0.jar"/>
</resources>
<dependencies>
    <module name="org.jboss.resteasy.resteasy-jaxrs" services="export"/>
</dependencies>
</module>
Comments