Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-510

Custom MessageBodyWriter not found

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Cannot Reproduce
    • Affects Version/s: 2.1.0.GA
    • Fix Version/s: 2.2-beta-1
    • Component/s: jaxrs
    • Labels:

      Description

      I'm developping a sample JAX-RS/CDI based application, that I deploy into JBoss AS 6.0 (Final). I do not add any dependency, all my code relies on the artefacts provided by the server. So, I'm running with RESTEasy 2.1.0.GA.

      I have a few entities that are transformed into 'representation' objects that have JAXB annotations on them.

      Here is an extract of my CustomerResource :

       
      @Stateless
      @Path(CustomerResource.URI_BASE)
      @Consumes(MediaType.APPLICATION_XML)
      @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
      public class CustomerResource {
      
        @GET
        @Path("{id}")
        @Formatted
        public Response getCustomer(@PathParam("id") Integer id,
          @Context UriInfo uriInfo, @Context HttpServletRequest request) {
          ...
        }
      
        @GET
        @Path("{id}")
        @Produces({ "text/x-vcard" })
        public Response getCustomerAsVCard(@PathParam("id") Integer id, @Context UriInfo uriInfo) {
          ...
        }
      
      }
      

      The response objects have an instance of 'CustomerRepresentation' as an entity.

       
      @XmlRootElement(name = "customer")
      @XmlType(propOrder = { "firstName", "lastName", "address", "orders", "selfLinks" })
      public class CustomerRepresentation {
        ...
      }
      

      And the custom Customer MessageBodyWriter :

       
      @Provider
      @Produces("text/x-vcard")
      public class CustomerVCardMessageBodyWriter implements
      MessageBodyWriter<CustomerRepresentation> {
       ...
      }
      

      Yet, when the request header 'accept' is set to 'text/x-vcard', the right CustomerResource method is called, but then I get the following error:

       
      13:55:11,942 WARN  [org.jboss.resteasy.core.SynchronousDispatcher] Failed executing GET /customers/1: org.jboss.resteasy.plugins.providers.jaxb.JAXBMarshalException: Could not find JAXBContextFinder for media type: text/x-vcard
      at org.jboss.resteasy.plugins.providers.jaxb.AbstractJAXBProvider.findJAXBContext(AbstractJAXBProvider.java:50) [:6.0.0.Final]
      at org.jboss.resteasy.plugins.providers.jaxb.AbstractJAXBProvider.getMarshaller(AbstractJAXBProvider.java:127) [:6.0.0.Final]
      at org.jboss.resteasy.plugins.providers.jaxb.AbstractJAXBProvider.writeTo(AbstractJAXBProvider.java:103) [:6.0.0.Final]
      at org.jboss.resteasy.core.interception.MessageBodyWriterContextImpl.proceed(MessageBodyWriterContextImpl.java:117) [:6.0.0.Final]
      at org.jboss.resteasy.plugins.interceptors.encoding.GZIPEncodingInterceptor.write(GZIPEncodingInterceptor.java:48) [:6.0.0.Final]
      at org.jboss.resteasy.core.interception.MessageBodyWriterContextImpl.proceed(MessageBodyWriterContextImpl.java:123) [:6.0.0.Final]
      at org.jboss.resteasy.core.ServerResponse.writeTo(ServerResponse.java:222) [:6.0.0.Final]
      at org.jboss.resteasy.core.SynchronousDispatcher.writeJaxrsResponse(SynchronousDispatcher.java:563) [:6.0.0.Final]
      at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:484) [:6.0.0.Final]
      

      Putting breakpoints in all the MBW methods shows that this class is not called, event though it was properly registered during app startup:

       
      13:53:21,020 INFO  [org.jboss.resteasy.integration.deployers.ResteasyIntegrationDeployer] *** Adding JAX-RS provider classes: org.bytesparadise.tools.jaxrs.sample.services.providers.CustomerVCardMessageBodyWriter
      

      It seems that since the returned object has JAXB annotation, the built-in JAXB provider is picked up before my custom MBW.

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                bill.burke Bill Burke
                Reporter:
                xcoulon Xavier Coulon
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: