1 2 Previous Next 16 Replies Latest reply on Jun 13, 2012 8:25 AM by davidmiller

    Problem with Resteasy: NoMessageBodyWriterFoundFailure

    jhollerer

      I tried the RESTEasy configuration (for interconnection with GWT) by modifying the components.xml file but when calling the method i get the failure:



      02:40:18,452 ERROR [SynchronousDispatcher] Failed executing GET /customer
      org.jboss.resteasy.core.NoMessageBodyWriterFoundFailure: Could not find MessageBodyWriter for response object of type: java.util.ArrayList of media type: application/xml
           at org.jboss.resteasy.core.ServerResponse.writeTo(ServerResponse.java:167)
           at org.jboss.resteasy.core.SynchronousDispatcher.writeJaxrsResponse(SynchronousDispatcher.java:413)
           at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:376)
           at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:160)
           at org.jboss.seam.resteasy.ResteasyResourceAdapter$1.process(ResteasyResourceAdapter.java:145)
           at org.jboss.seam.servlet.ContextualHttpServletRequest.run(ContextualHttpServletRequest.java:53)
           at org.jboss.seam.resteasy.ResteasyResourceAdapter.getResource(ResteasyResourceAdapter.java:121)
           at org.jboss.seam.servlet.SeamResourceServlet.service(SeamResourceServlet.java:80)
           at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)



      The configuration is like that:




      <framework:entity-home name="customerHome"
                             entity-class="com.amergy.restfultestapp.entity.Customer"
                             auto-create="true"/>
      
      <framework:entity-query name="customerQuery"
                        ejbql="select c from Customer c" order="lastname"/>
      
      <resteasy:resource-home path="/customer" name="resourceCustomerHome"
                              entity-home="#{customerHome}" entity-id-class="java.lang.Long"
                              media-types="application/xml application/json"/>
      
      <resteasy:resource-query path="/customer" name="resourceCustomerQuery"
                               entity-query="#{customerQuery}" entity-class="com.amergy.restfultestapp.entity.Customer"
                               media-types="application/xml application/json"/>




      Can someone point me a hint - what the problem is - as i cannot define any Writer within the Components.xml file ??
      Is there some docu regarding that configuration within the components.xml file ?




        • 1. Re: Problem with Resteasy: NoMessageBodyWriterFoundFailure
          jhollerer

          Solved it - the problem where some missing jars !


          thanks
          johannes

          • 2. Re: Problem with Resteasy: NoMessageBodyWriterFoundFailure
            jhollerer

            It still does not work !!


            When i make the whole function manually with functions (and specify as return type application/xml - it works!
            But when i try to use the build in function out of the components.xml it still shows the error !



            • 3. Re: Problem with Resteasy: NoMessageBodyWriterFoundFailure
              jharting

              Is the exception still the same? If yes you are probably missing the resteasy-jaxb-provider.jar in your classpath. This library contains ready-made reader and writer support for JAXB classes. Thus you do not need to implement the writer yourself.
              Also make sure you have @XMLRoot annotation on your Customer class.

              • 4. Re: Problem with Resteasy: NoMessageBodyWriterFoundFailure
                jhollerer

                Yes the issue is still the same - i included the resteasy-jaxrs.jar, resteasy-jaxb-provider.jar, resteasy-atom-provider.jar, jaxb-impl-2.1.12.jar, resteasy-jaxb-provider-1.2.1.GA.jar (and some other which he complained at startup) and the jboss-seam-resteasy.jar within my ear project! My classes are annotated with the @XMLRootElement on the class level!


                And the strange thing is - that if i use that class within an manual written code - the transformation takes place without any error.



                This works:



                @GET
                @Path("/list")
                @Produces("application/json")
                public List<Customer> getList();





                But with the definition within the components.xml i get still the error from above !
                I use JBOSS AS 5.1 - could there be any issue ??

                • 5. Re: Problem with Resteasy: NoMessageBodyWriterFoundFailure
                  jharting

                  I believe this is a configuration issue. Take a look at the Seam Tasks example (bundled with Seam distribution). That one uses ResourceQuery set up via components.xml and is tested on JBoss AS 5.1. Or if you provide a reproducible code, I can take a look.

                  • 6. Re: Problem with Resteasy: NoMessageBodyWriterFoundFailure
                    jhollerer

                    I stripped the example down - still the problem exists - how should i make the code available to you ?

                    • 7. Re: Problem with Resteasy: NoMessageBodyWriterFoundFailure
                      jharting

                      Can you create a JIRA issue for this and attach the application?

                      • 8. Re: Problem with Resteasy: NoMessageBodyWriterFoundFailure
                        ibenjes

                        Hi,


                        has the cause for this problem been found? I am having the same problem. I started by using the task example and added my own entity classes. When I configure a resource query in components.xml I get the same exception





                        org.jboss.resteasy.core.NoMessageBodyWriterFoundFailure: Could not find MessageBodyWriter for response object of type: java.util.ArrayList of media type: application/xml
                                at org.jboss.resteasy.core.ServerResponse.writeTo(ServerResponse.java:167)
                                at org.jboss.resteasy.core.SynchronousDispatcher.writeJaxrsResponse(SynchronousDispatcher.java:413)
                                at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:376)
                                at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:160)








                        When I try to use a ResourceHome in Java I get the following exeption:





                        Caused by: java.lang.IllegalArgumentException: You must use either EntityHome or HibernateEntityHome instance.
                                at org.jboss.seam.resteasy.EntityHomeWrapper.<init>(EntityHomeWrapper.java:56)
                                at org.jboss.seam.resteasy.ResourceHome.setEntityHome(ResourceHome.java:315)
                                at org.jboss.seam.resteasy.ResourceHome.create(ResourceHome.java:84)





                        This is the Java class:



                        import javax.ws.rs.Path;
                        
                        import org.jboss.seam.annotations.In;
                        import org.jboss.seam.annotations.Name;
                        import org.jboss.seam.framework.EntityHome;
                        import org.jboss.seam.framework.Home;
                        import org.jboss.seam.resteasy.ResourceHome;
                        
                        import com.strokeaverage.rest.entity.Course;
                        
                        @Name("courseRestHome")
                        @Path("course")
                        public class CourseResourceHome extends ResourceHome<Course, Long>{
                             
                                   @In
                                private EntityHome<Course> courseHome;
                        
                                @Override
                                public Home<?, Course> getEntityHome()
                                {
                                   return courseHome;
                                }
                                
                                
                        
                                public CourseResourceHome()
                                {
                                   setMediaTypes(new String[] { "application/xml", "application/json" });
                                }
                        
                        }




                        Any idea of what might go wrong here?


                        Regards


                        Immo

                        • 9. Re: Problem with Resteasy: NoMessageBodyWriterFoundFailure
                          jharting

                          I cannot see any problem with your class. Could you provide your modified tasks application so that I can reproduce?

                          • 10. Re: Problem with Resteasy: NoMessageBodyWriterFoundFailure
                            ibenjes

                            I managed to solve my earlier problem by starting again with seam-gen this time (before I used the Eclipse based seam tools).


                            I still had to do some other config work as described here:
                            My Link


                            It now works for ResourceQuery and ResourceHome.


                            Then I wrote my own class using AbstractResource and MatrixParameters to return a List of entities. Works fine.


                            But now I am trying to return a simple String List only to get the






                            
                            org.jboss.resteasy.core.NoMessageBodyWriterFoundFailure: Could not find MessageBodyWriter for response object of type: java.util.ArrayList of media type: application/xml
                                    at org.jboss.resteasy.core.ServerResponse.writeTo(ServerResponse.java:166)
                                    at org.jboss.resteasy.core.SynchronousDispatcher.writeJaxrsResponse(SynchronousDispatcher.java:530)
                                    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:467)
                                    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:117)
                                    at org.jboss.seam.resteasy.ResteasyResourceAdapter$1.process(ResteasyResourceAdapter.java:146)
                                    at org.jboss.seam.servlet.ContextualHttpServletRequest.run(ContextualHttpServletRequest.java:65)
                                    at org.jboss.seam.resteasy.ResteasyResourceAdapter.getResource(ResteasyResourceAdapter.java:122)
                                    at org.jboss.seam.servlet.SeamResourceServlet.service(SeamResourceServlet.java:80)
                                    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
                                    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
                                    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                                    at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
                                    at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
                                    at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                                    at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
                                    at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                                    at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
                                    at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                                    at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
                                    at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                                    at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:206)
                                    at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
                                    at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
                                    at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
                                    at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
                                    at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                                    at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
                                    at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                                    at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:73)
                                    at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
                                    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                                    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                                    at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
                                    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                                    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                                    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
                                    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
                                    at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
                                    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
                                    at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
                                    at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
                                    at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
                                    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)
                                    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                                    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
                                    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
                                    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
                                    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
                                    at java.lang.Thread.run(Thread.java:637)




                            This is the class:


                            import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
                            import static javax.ws.rs.core.Response.Status.UNSUPPORTED_MEDIA_TYPE;
                            
                            import java.lang.reflect.ParameterizedType;
                            import java.lang.reflect.Type;
                            import java.util.List;
                            
                            import javax.persistence.EntityManager;
                            import javax.ws.rs.DefaultValue;
                            import javax.ws.rs.GET;
                            import javax.ws.rs.MatrixParam;
                            import javax.ws.rs.Path;
                            import javax.ws.rs.QueryParam;
                            import javax.ws.rs.core.GenericEntity;
                            import javax.ws.rs.core.MediaType;
                            import javax.ws.rs.core.Response;
                            
                            import org.jboss.resteasy.annotations.providers.jaxb.Wrapped;
                            import org.jboss.seam.annotations.In;
                            import org.jboss.seam.annotations.Logger;
                            import org.jboss.seam.annotations.Name;
                            import org.jboss.seam.log.Log;
                            import org.jboss.seam.resteasy.AbstractResource;
                            
                            import com.strokeaverage.webservice.model.CourseInfo;
                            
                            @Name("courseInfoSearch")
                            @Path("/search")
                            public class CourseInfoSearch extends AbstractResource<CourseInfo>{
                            
                                 @Logger
                                 private static Log log;
                                 
                                 public CourseInfoSearch(){
                                      setMediaTypes(new String[] {"application/xml","application/json", "application/fastinfoset" });
                                 }
                                 
                                 @In 
                                 private EntityManager entityManager;
                                 
                                 
                                 
                                 
                                 @GET
                                 @Path("/countries")
                                 @Wrapped
                                 public Response getCountryList(){
                                      MediaType selectedMediaType = selectResponseMediaType();
                                       if (selectedMediaType == null)
                                       {
                                          return Response.status(UNSUPPORTED_MEDIA_TYPE).build();
                                       }
                                       List<String> countryList = entityManager.createQuery("select DISTINCT(ci.country) from CourseInfo ci")
                                       .setMaxResults(100)
                                       .getResultList();
                                       for(String s:countryList){
                                            log.info("#0", s);
                                       }
                                       GenericEntity<List<String>> entity = new GenericEntity<List<String>>(countryList) {};
                                       return Response.ok(entity, selectedMediaType).build();
                                 }
                                 
                                    @GET
                                    @Path("/course")
                                    @Wrapped
                                    public Response getResourceList(@MatrixParam("name") String name, @MatrixParam("country") String country, @MatrixParam("county") String county, @MatrixParam("start") @DefaultValue("0") int start, @MatrixParam("show") @DefaultValue("25") int show)
                                    {
                                         log.info("name #0, country #1, county #2, start #3 show #4",name,country,county,start,show);
                                       MediaType selectedMediaType = selectResponseMediaType();
                                       if (selectedMediaType == null)
                                       {
                                          return Response.status(UNSUPPORTED_MEDIA_TYPE).build();
                                       }
                            
                                       if ((start < 0) || (show < 0))
                                       {
                                          return Response.status(BAD_REQUEST).build();
                                       }
                            
                                       final List<CourseInfo> result = entityManager.createQuery("select ci from CourseInfo ci where " +
                                                     "(:name IS NULL OR (ci.golfClubName LIKE '%'||:name||'%')) " +
                                                     "AND (:country IS NULL OR (ci.country LIKE :country||'%')) " +
                                                     "AND (:county IS NULL OR (ci.county LIKE :county||'%')) " +
                                                     "ORDER BY ci.golfClubName")
                                                     .setParameter("name", name)
                                                     .setParameter("country", country)
                                                     .setParameter("county", county)
                                                     .setMaxResults(show)
                                                      .setFirstResult(start)
                                                     .getResultList();
                                       // create a proper response type
                                       Type responseType = new ParameterizedType()
                                       {
                            
                                          public Type getRawType()
                                          {
                                             return result.getClass();
                                          }
                            
                                          public Type getOwnerType()
                                          {
                                             return null;
                                          }
                            
                                          public Type[] getActualTypeArguments()
                                          {
                                             return new Type[]{getEntityClass()};
                                          }
                                       };
                                       return Response.ok(new GenericEntity(result, responseType)
                                       {
                                       }, selectedMediaType).build();
                                    }
                                 
                                 
                            }
                            


                            The getResourceList() Method works fine but the getCountryList() throws that NoMessageBodyWriterFoundFailure.


                            This is the lists of jars I am including (from deployed-jars.list)




                            antlr-runtime.jar
                            commons-beanutils.jar
                            commons-digester.jar
                            core.jar
                            drools-templates.jar
                            drools-decisiontables.jar
                            drools-api.jar
                            drools-compiler.jar
                            drools-core.jar
                            janino.jar
                            jboss-el.jar
                            jboss-seam.jar
                            jboss-seam-debug.jar
                            jboss-seam-excel.jar
                            jboss-seam-ioc.jar
                            jboss-seam-mail.jar
                            jboss-seam-pdf.jar
                            jboss-seam-remoting.jar
                            jboss-seam-rss.jar
                            jboss-seam-ui.jar
                            jbpm-jpdl.jar
                            jsf-facelets.jar
                            jxl.jar
                            mvel2.jar
                            richfaces-api.jar
                            richfaces-impl.jar
                            richfaces-ui.jar
                            jboss-seam-resteasy.jar
                            jaxrs-api.jar
                            resteasy-jaxrs.jar
                            resteasy-atom-provider.jar
                            resteasy-jaxb-provider.jar
                            resteasy-jettison-provider.jar
                            # You can remove the JARs for themes you aren't using
                            darkX.jar
                            glassX.jar
                            laguna.jar
                            
                            



                            No changes made to the default components.xml, web.xml and pages.xml


                            • 11. Re: Problem with Resteasy: NoMessageBodyWriterFoundFailure

                              Do you have resteasy built-in providers enabled in the resteasy project web xml?




                                   <context-param>
                                       <param-name>resteasy.use.builtin.providers</param-name>
                                       <param-value>true</param-value>
                                     </context-param>



                              • 12. Re: Problem with Resteasy: NoMessageBodyWriterFoundFailure
                                jharting

                                Your problem is related to JAXB. While getResourceList() returns a list of @XmlRootElements, getCountryList() returns a list of Strings (which are not JAXB classes). Therefore, you need to create a list wrapper

                                • 13. Re: Problem with Resteasy: NoMessageBodyWriterFoundFailure
                                  ibenjes

                                  Hi,


                                  I've tried the list wrapper




                                  @XmlRootElement
                                  public class JaxbList<T>{
                                      protected List<T> list;
                                  
                                      public JaxbList(){}
                                  
                                      public JaxbList(List<T> list){
                                          this.list=list;
                                      }
                                  
                                      @XmlElement(name="Item")
                                      public List<T> getList(){
                                          return list;
                                      }
                                  }



                                  and changed my code to:


                                         


                                  @GET
                                       @Path("/countries")
                                       @Wrapped
                                       public Response getCountryList(){
                                            MediaType selectedMediaType = selectResponseMediaType();
                                             if (selectedMediaType == null)
                                             {
                                                return Response.status(UNSUPPORTED_MEDIA_TYPE).build();
                                             }
                                             List<String> countryList = entityManager.createQuery("select  DISTINCT(ci.country) from CourseInfo ci")
                                             .setMaxResults(100)
                                             .getResultList();
                                             for(String s:countryList){
                                                  log.info("#0", s);
                                             }
                                             JaxbList<String> jlist = new JaxbList<String>(countryList);
                                             GenericEntity<JaxbList<String>> entity = new GenericEntity<JaxbList<String>>(jlist) {};
                                             return Response.ok(entity, selectedMediaType).build();
                                             
                                       }
                                  


                                  Only to get this Exception:



                                  Caused by: java.lang.IllegalStateException: Invalid JSON namespace: http://www.w3.org/2001/XMLSchema-instance
                                          at org.codehaus.jettison.mapped.MappedNamespaceConvention.getJSONNamespace(MappedNamespaceConvention.java:148)
                                          at org.codehaus.jettison.mapped.MappedNamespaceConvention.createAttributeKey(MappedNamespaceConvention.java:136)
                                          at org.codehaus.jettison.mapped.MappedXMLStreamWriter.writeAttribute(MappedXMLStreamWriter.java:89)
                                          at com.sun.xml.bind.v2.runtime.output.XMLStreamWriterOutput.attribute(XMLStreamWriterOutput.java:133)
                                          at com.sun.xml.bind.v2.runtime.XMLSerializer.attribute(XMLSerializer.java:431)
                                          at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:676)
                                          at com.sun.xml.bind.v2.runtime.property.ArrayElementNodeProperty.serializeItem(ArrayElementNodeProperty.java:65)
                                          at com.sun.xml.bind.v2.runtime.property.ArrayElementProperty.serializeListBody(ArrayElementProperty.java:168)
                                          at com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:152)
                                          at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:322)
                                          at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsSoleContent(XMLSerializer.java:589)
                                          at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:312)
                                          at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:490)
                                          at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:325)
                                          at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:172)
                                          at org.jboss.resteasy.plugins.providers.jaxb.json.JettisonMappedMarshaller.marshal(JettisonMappedMarshaller.java:71)
                                          at org.jboss.resteasy.plugins.providers.jaxb.BaseMarshaller.marshal(BaseMarshaller.java:24)
                                          at org.jboss.resteasy.plugins.providers.jaxb.AbstractJAXBProvider.writeTo(AbstractJAXBProvider.java:105)
                                          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:186)



                                  Not sure what's going wrong now.
                                  I managed to work around it by creating a wrapper class for a String which has @XmlRootElement etc. But that is just a hack, I would like to know what is going wrong. It seems to work for others so something in my setup must be wrong.


                                  The context-parm for web.xml didn't seem to make a difference.


                                  Thanks for your help. Very much appreciated.


                                  Regards


                                  Immo


                                  • 14. Re: Problem with Resteasy: NoMessageBodyWriterFoundFailure
                                    janakiram521

                                    Can you Please tell me the list of jar files included

                                    1 2 Previous Next