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

Unmarshal empty entity body as null entity parameter

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • 2.2.RC1
    • 2.0.1.GA
    • jaxrs
    • None

    Description

      Given e.g.

      @DELETE
      @Consumes(MediaType.APPLICATION_XML)
      @Path("

      {id}

      ")
      public void remove(@PathParam("id") String id, Foo foo);

      or:

      @POST
      @Path("install")
      public Response install(Action action);

      If an empty entity body is supplied, the following happens ...

      Without Content-type:

      DELETE /rhevm-api-mock/storagedomains/1 HTTP/1.1
      Host: localhost
      Accept: application/xml

      HTTP/1.1 400 content-type was null and expecting to extract a body into public abstract void com.redhat.rhevm.api.resource.StorageDomainsResource.remove(java.lang.String,com.redhat.rhevm.api.model.StorageDomain)
      Content-Length: 0

      With Content-type: application/xml:

      DELETE /rhevm-api-mock/storagedomains/1 HTTP/1.1
      Host: localhost
      Accept: application/xml
      Content-type: application/xml

      HTTP/1.1 500 Internal Server Error
      Content-Length: 0

      Exception is:

      org.jboss.resteasy.plugins.providers.jaxb.JAXBMarshalException: javax.xml.bind.UnmarshalException

      • with linked exception:
        [org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Premature end of file.]
        at org.jboss.resteasy.plugins.providers.jaxb.JAXBXmlTypeProvider.readFrom(JAXBXmlTypeProvider.java:99)
        at org.jboss.resteasy.core.interception.MessageBodyReaderContextImpl.proceed(MessageBodyReaderContextImpl.java:105)
        ...
        Caused by: javax.xml.bind.UnmarshalException
      • with linked exception:
        [org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Premature end of file.]
        at javax.xml.bind.helpers.AbstractUnmarshallerImpl.createUnmarshalException(AbstractUnmarshallerImpl.java:335)
        at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.createUnmarshalException(UnmarshallerImpl.java:514)
        at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:215)
        ...
        at org.jboss.resteasy.plugins.providers.jaxb.JAXBXmlTypeProvider.readFrom(JAXBXmlTypeProvider.java:85)
        ... 35 more
        ...
        Caused by: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Premature end of file.
        at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)
        at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:177)

      This hacky patch makes a null entity parameter be passed in the latter case:

      — a/tags/RESTEASY_JAXRS_2_0_1_GA/providers/jaxb/src/main/java/org/jboss/resteasy/plugins/providers/jaxb/JAXBXmlTypeProvider.java
      +++ b/tags/RESTEASY_JAXRS_2_0_1_GA/providers/jaxb/src/main/java/org/jboss/resteasy/plugins/providers/jaxb/JAXBXmlTypeProvider.java
      @@ -78,6 +78,9 @@ public class JAXBXmlTypeProvider extends AbstractJAXBProvider<Object>
      @Override
      public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, I
      {
      + if (entityStream.available() == 0)

      { + return null; + }

      try
      {
      JAXBContext jaxb = findJAXBContext(type, annotations, mediaType, true);

      Ideally, the former case (i.e. no Content-type specified) work work too

      Attachments

        Issue Links

          Activity

            People

              patriot1burke@gmail.com Bill Burke (Inactive)
              rhn-engineering-markmc Mark McLoughlin
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: