1 Reply Latest reply on May 18, 2011 5:14 AM by nimo stephan

    resteasy in jboss 6

    nimo stephan Master

      I use jboss as 6.1 snapshot and have a restful ws-method, which works only for application/json, but not for application/xml.

       

      @Path("myresource")

      // I do NOT use a scope, such as @RequestScoped

      public class MyResource {

       

      @GET

      @Path("user/{id}")

      @Produces({"application/xml", "application/json"})

      public User getUser@PathParam("id") int id){

      ..

      return u;

      }

       

       

      I have declared my User-Bean with @XmlRootElement, so I make use of build-in resteasy-jaxb-provider.

       

      However, it only works for application/json and not for application/xml.

       

      With Request-Header "application/xml", I get this error:

       

      16:31:32,891 WARN  [org.jboss.resteasy.core.SynchronousDispatcher] Failed executing GET /myresource/user/1: org.jboss.resteasy.spi.WriterException: java.lang.NullPointerException

                at org.jboss.resteasy.core.ServerResponse.writeTo(ServerResponse.java:233) [:]

                at org.jboss.resteasy.core.SynchronousDispatcher.writeJaxrsResponse(SynchronousDispatcher.java:563) [:]

                at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:484) [:]

                at org.jboss.resteasy.core.SynchronousDispatcher.invokePropagateNotFound(SynchronousDispatcher.java:139) [:]

                at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:211) [:]

                at org.jboss.resteasy.plugins.server.servlet.FilterDispatcher.doFilter(FilterDispatcher.java:59) [:]

                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274) [:]

                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:]

                at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:67) [:6.1.0-SNAPSHOT]

                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274) [:]

                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:]

                at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [:]

                at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:191) [:]

                at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java) [:]

                at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181) [:6.1.0-SNAPSHOT]

                at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285) [:1.1.0.Final]

                at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261) [:1.1.0.Final]

                at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88) [:6.1.0-SNAPSHOT]

                at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100) [:6.1.0-SNAPSHOT]

                at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) [:]

                at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [:]

                at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) [:6.1.0-SNAPSHOT]

                at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [:]

                at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53) [:6.1.0-SNAPSHOT]

                at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [:]

                at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:893) [:]

                at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:600) [:]

                at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:2019) [:]

                at java.lang.Thread.run(Thread.java:619) [:1.6.0_21]

      Caused by: java.lang.NullPointerException

                at org.jboss.resteasy.plugins.providers.jaxb.AbstractJAXBProvider.findJAXBContext(AbstractJAXBProvider.java:46) [:]

                at org.jboss.resteasy.plugins.providers.jaxb.AbstractJAXBProvider.getMarshaller(AbstractJAXBProvider.java:127) [:]

                at org.jboss.resteasy.plugins.providers.jaxb.AbstractJAXBProvider.writeTo(AbstractJAXBProvider.java:103) [:]

                at org.jboss.resteasy.core.interception.MessageBodyWriterContextImpl.proceed(MessageBodyWriterContextImpl.java:117) [:]

                at org.jboss.resteasy.plugins.interceptors.encoding.GZIPEncodingInterceptor.write(GZIPEncodingInterceptor.java:48) [:]

                at org.jboss.resteasy.core.interception.MessageBodyWriterContextImpl.proceed(MessageBodyWriterContextImpl.java:123) [:]

                at org.jboss.resteasy.core.ServerResponse.writeTo(ServerResponse.java:222) [:]

                ... 28 more

       

       

      As Jboss AS does not integrate the lib "resteasy-jaxb-provider", I have included by myself via Maven:

       

          <dependency>

                          <groupId>org.jboss.resteasy</groupId>

                          <artifactId>resteasy-jaxrs</artifactId>

                <scope>provided</provided>

                </dependency>

       

            <dependency>

                          <groupId>org.jboss.resteasy</groupId>

                          <artifactId>resteasy-jaxb-provider</artifactId>

                </dependency>

       

       

      Is that a bug?

        • 1. Re: resteasy in jboss 6
          nimo stephan Master

          According to jee6 spec,a jee6 container has build in support for (un)marshalling objects to xml via jaxb when using jax-rs. I have tried it with geronimo and it works like a charm without configuring any libs or the like.

           

          In Jboss 6, this is not the case:

           

          I have to include resteasy-jaxb-provider (I cannot find it in jboss common/lib or lib-dir). And even I do, it does not work. I get the error above.

           

          When not including the lib, then the error occurs "No MessageBodyWriter found..(org.jboss.resteasy.core.NoMessageBodyWriterFoundFailure: )",

          so I have to implement myself:

          I have to implement my own MyMarshaller for marshalling objects to xml to get this work.


          @Provider

          @Produces("application/xml")

          public class MyMarshaller implements MessageBodyReader, MessageBodyWriter{

           

          ..

          }

           

          why is that so?