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

Resteasy ignores custom JAXBContext for unmarshalling

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • 3.5.0.CR1, 4.0.0.Beta2
    • 3.1.4.Final
    • jaxrs
    • None
    • Hide

      1) Deploy the WAR demo-1.0.0-SNAPSHOT_resteasy.war
      2) Execute the following REST Call

      POST http://localhost:8080/<contextpath>/service/demo/users
      Content-Type application/xml
      Accept application/xml
      
      <user xmlns="http://creaity.de/homecontrol/rest/types/v1">
          <id>id</id>
          <credentials>
              <loginId>test</loginId>
          </credentials>
          <roles>
              <role>USER</role>
          </roles>
      </user>
      

      3) Response will be 200 OK and the same XML is returned.
      4) In Standard out, the message
      "Creating marshaller" appears
      The message "Creating unmarshaller" is missing

      If the same steps are done with the jersey war file, both messages are printed

      Show
      1) Deploy the WAR demo-1.0.0-SNAPSHOT_resteasy.war 2) Execute the following REST Call POST http://localhost:8080/<contextpath>/service/demo/users Content-Type application/xml Accept application/xml <user xmlns="http://creaity.de/homecontrol/rest/types/v1"> <id>id</id> <credentials> <loginId>test</loginId> </credentials> <roles> <role>USER</role> </roles> </user> 3) Response will be 200 OK and the same XML is returned. 4) In Standard out, the message "Creating marshaller" appears The message "Creating unmarshaller" is missing If the same steps are done with the jersey war file, both messages are printed

    Description

      If a ContextResolver for JAXBContext is used, RestEasy uses the custom JAXBContext only for creating a Marshaller object. The Unmarshaller is never used.

      I have attached two war files. One with the reference implementation jersey and one with resteasy 3.1.4.Final. Boath are runnable on Tomcat 8.5.23. (Sources are also attached)

      Implemented is a demo service, with a post method. The service accepts a UserType object and returns the same object.

      If the jersey implementation is used, the marshaller and the unmarshaller from the custom context are used.

      If resteasy is used, only the marshaller is used. The createUnmarshaller Method is never called.

      Because of that, it is impossible to configure the JAX-BContext (e.g. for schema validation)

      Sources of the custom JAXB Provider (Full sources can be found in src.zip)

      @Provider
      @Produces(MediaType.APPLICATION_XML)
      @Consumes(MediaType.APPLICATION_XML)
      public class JaxbProvider implements ContextResolver<JAXBContext> {
      
          @Override
          public JAXBContext getContext(Class<?> type) {
              return new CustomJAXBContext(type);
          }
      }
      

      Source of CustomJAXBContext

      public class CustomJAXBContext extends JAXBContext {
      
          private JAXBContext delegate;
      
          public CustomJAXBContext(Class<?> type) {
              try {
                  this.delegate = JAXBContext.newInstance(type.getPackage().getName());
              } catch (JAXBException e) {
                  throw new IllegalStateException("Error creating JAXBContext", e);
              }
          }
      
          @Override
          public Unmarshaller createUnmarshaller() throws JAXBException {
              System.out.println("Creating unmarshaller");
              return this.delegate.createUnmarshaller();
          }
      
          @Override
          public Marshaller createMarshaller() throws JAXBException {
              System.out.println("Creating marshaller");
              return this.delegate.createMarshaller();
          }
      
          @Override
          public Validator createValidator() throws JAXBException {
              return this.delegate.createValidator();
          }
      }
      

      Attachments

        Activity

          People

            rsearls r searls
            jzink_jira Jochen Zink (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: