6 Replies Latest reply on Aug 12, 2017 5:13 PM by Nuno Godinho de Matos

    Use EclipseLink MOXy as jaxb provider in AS 7.1.1 RestEasy

    sousarka Newbie

      Hi,

       

      Is there any way to configure MOXy as the Jaxb provider instead of using default Jackson or Jettison? Here's what I've tried so far:

       

      1.     Added eclipselink.jar in the classpath
      2.     Followed steps: http://blog.bdoughan.com/2012/05/moxy-as-your-jax-rs-json-provider.html
      3.     Created a module "org.eclipse.persistence" in <jboss-home>/modules and placed eclipselink.jar along with module.xml
      4.     Created jboss-deployment-structure.xml to exclude the default providers and placed it in EAR/META-INF

       

      <?xml version="1.0" encoding="UTF-8"?>
      <jboss-deployment-structure>
          <deployment>
          </deployment>
          <sub-deployment name="webservWeb.war">
              <exclusions>
                  <module name="org.jboss.resteasy.resteasy-jackson-provider" />
                  <module name="org.jboss.resteasy.resteasy-jettison-provider" />
              </exclusions>
              <dependencies>
                  <module name="org.eclipse.persistence" />
              </dependencies>
          </sub-deployment>
      </jboss-deployment-structure>
      

       

      But still, the server isn't picking up MOXy and throwing the following error during execution:

       

      01:44:49,110 WARN  [org.jboss.resteasy.core.SynchronousDispatcher] (http-localhost-127.0.0.1-8080-2) Failed executing GET /FilmService/films/: org.jboss.resteasy.core.NoMessageBodyWriterFoundFailure: Could not find MessageBodyWriter for response object of type: java.util.ArrayList of media type: application/json

          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.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:662) [rt.jar:1.6.0_31]

      Can someone please advise?

       

      I'm using JBoss AS 7.1.1.

       

      Thanks,

      Soumik

        • 1. Re: Use EclipseLink MOXy as jaxb provider in AS 7.1.1 RestEasy
          Blaise Doughan Newbie

          Hi Soumik,

           

          EclipseLink MOXy provides MOXyJsonProvider which is an implementation of the standard MessageBodyReader/MessageBodyWriter classes that should work with any JAX-RS implementation.  Below is an example of how to use MOXyJsonProvider:

           

          -Blaise

          • 2. Re: Use EclipseLink MOXy as jaxb provider in AS 7.1.1 RestEasy
            sousarka Newbie

            Hi Blaise,

             

            I tried to debug the above issue and couldn't. But, Now I'm able to use MOXy atleast. Here's what I currently have:

             

            1. Created a META-INF/services inside eclipselink.jar file as javax.ws.rs.ext.Providers with one line in it: org.eclipse.persistence.jaxb.rs.MOXyJsonProvider
            2. Added MoxyJSonProvider web.xml as a context-param

             

              <context-param>
                <param-name>resteasy.providers</param-name>
                <param-value>org.eclipse.persistence.jaxb.rs.MOXyJsonProvider</param-value>
              </context-param>
            

             

               3.  Changed the jboss-deployment-structure.xml to exclude the default restwasy-jaxb-providers

             

             

            <jboss-deployment-structure>
                <deployment>
                </deployment>
                <sub-deployment name="webservWeb.war">
                    <exclusions>
                        <module name="org.jboss.resteasy.resteasy-jackson-provider" />
                        <module name="org.jboss.resteasy.resteasy-jettison-provider" />
                        <module name="org.jboss.resteasy.resteasy-jaxb-provider" />
                    </exclusions>
                    <dependencies>
                        <module name="org.eclipse.persistence" />
                    </dependencies>
                </sub-deployment>
            </jboss-deployment-structure>
            

             

             

              4.  Now, my deployed app doesn't know about any other JAXB providers but MOXy. But when it tries to marsall the json, its throwing the following exception coming from getDomainClass(). Here are the actual parameter: AbstractList<E>

             

             

            16:49:12,025 WARN  [org.jboss.resteasy.core.SynchronousDispatcher] (http-localhost-127.0.0.1-8080-2) Failed executing GET /FilmService/films/: org.jboss.resteasy.spi.WriterException: java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.TypeVariableImpl cannot be cast to java.lang.Class

                at org.jboss.resteasy.core.ServerResponse.writeTo(ServerResponse.java:262) [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.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:662) [rt.jar:1.6.0_31]

            Caused by: java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.TypeVariableImpl cannot be cast to java.lang.Class

                at org.eclipse.persistence.jaxb.rs.MOXyJsonProvider.getDomainClass(MOXyJsonProvider.java:249) [eclipselink-2.5.0.jar:]

                at org.eclipse.persistence.jaxb.rs.MOXyJsonProvider.writeTo(MOXyJsonProvider.java:572) [eclipselink-2.5.0.jar:]

                at org.jboss.resteasy.core.interception.MessageBodyWriterContextImpl.proceed(MessageBodyWriterContextImpl.java:117) [resteasy-jaxrs-2.3.2.Final.jar:]

                at org.jboss.resteasy.plugins.interceptors.encoding.GZIPEncodingInterceptor.write(GZIPEncodingInterceptor.java:100) [resteasy-jaxrs-2.3.2.Final.jar:]

                at org.jboss.resteasy.core.interception.MessageBodyWriterContextImpl.proceed(MessageBodyWriterContextImpl.java:123) [resteasy-jaxrs-2.3.2.Final.jar:]

                at org.jboss.resteasy.core.ServerResponse.writeTo(ServerResponse.java:250) [resteasy-jaxrs-2.3.2.Final.jar:]

             

            What am I missing? Somehow, I think, the resteasy infrastructure is not able to read the jaxb.properties file I've placed in the same package alongwitht the entity classes.

             

            Please let me know.

             

            Thanks,

            Soumik

            • 3. Re: Use EclipseLink MOXy as jaxb provider in AS 7.1.1 RestEasy
              Blaise Doughan Newbie

              Hi Soumik,

               

              I have made some bug fixes related to different collection types in EclipseLink 2.4.1 (see link below).  Do you mind giving the latest nightly download a try to see if it resolves the issue?  You could also try using List or ArrayList instead of AbstractList.

               

               

              -Blaise

              • 4. Re: Use EclipseLink MOXy as jaxb provider in AS 7.1.1 RestEasy
                sousarka Newbie

                Hi Blaise,

                 

                I'm using the nightly build ID # 20120823 and still getting the error.

                 

                On the other ppoint, I'm actually using List<MyEntity>. But the genericType actual paramter is getting the value from "Type genericType" from the writeTo method which has the value AbstractList<E>.

                 

                The real problem may not be the list, since the getDomainClass method is trying to get the underlying entity from the List. Which is where it's failing to evaluate the actualType <E>. The exception is coming from the code "return (Class<?>) type;". As E is a generic type and not of type MyEntity.

                 

                This has led me to believe, the resteasy infrastructure is not able to read the jaxb.properties file I've placed in the same package alongwitht the entity classes. Otherwise, it should work fine like it does in GlassFish or Weblogic.

                 

                Please let me know your thoughts.

                 

                Thanks,

                Soumik

                • 5. Re: Use EclipseLink MOXy as jaxb provider in AS 7.1.1 RestEasy
                  sousarka Newbie

                  Hi Blaise,

                   

                  My bad. It was a problem with my code:

                   

                  I was using:

                  new GenericEntity<List<MyEntity>>(myList, myList.getClass().getGenericSuperclass())

                   

                  This was sending the AbstarctList<E> to the genericType.

                   

                  I changed my code to:

                   

                  new GenericEntity<List<FilmEntity>>(filmList) {};

                   

                  Now, the List<MyEntity> is going in and its working perfectly.

                   

                  Will keep exploring the MOXy provider and keep bugging you with similar silly questions.

                  • 6. Re: Use EclipseLink MOXy as jaxb provider in AS 7.1.1 RestEasy
                    Nuno Godinho de Matos Newbie

                    On the topic of Using Moxy on Wildfly, I am adding the following reference.jax rs - Weblogic 12.2.1.2 - How to tune the object Serializer to use Jackson 2 and strange phenomena on jaxrs enablemen…

                     


                    I was trying to get Weblogic to use Jackson, once i found out weblogic was using Jersey.
                    Ultimately, to get consistency between Weblogic and Wildfly, I have tuned rest easy to use Moxy using the web.xml context parameter exaplained at the top of this thread.

                    And finally, the eclipse persistence module needed to be tuned to gain an extra dependency jax rest api.

                     

                    Rest easy was really is to switch around to make it use Moxy.

                     

                    I have only checked this in a tiny sample application, but it does look promising.

                     

                    I would recommend that for Future reference, the Wildfly documentation on the Rest chapter should describe a little bit possibilities of tuning rest rendering behavior both on tuning Jackson defaults (e.g. dedicated providers) or if necessary switching around the implementation of the json serialization/deserialization provided to other libraries like Moxy that are also supported by restEasy.

                     

                    This is relevatively important for developers that need to support an application a multitude of containers ... since you end up having to struggle with any tiny bit of difference on this subystem and that here and there.

                     

                    Many thanks, this thread was very useful.