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

RESTEASY-1125: JAXB MessageBodyReader providers not recognized when using generics in a complex inheritance structure

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Critical
    • Wanted But Unscheduled
    • 2.3.7.Final
    • jaxrs
    • None

    Description

      At the scenario given below, RESTeasy is not able to find the correct MessageBodyReader for an incoming XML HTTP Body.

      I have the abstract resource:

      AbstractResource.java
      public class AbstractResource<T> {
      
      	@POST
      	@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
      	public Response createEntity(T entity) {
      		return Response.ok("Success!").build();
      	}
      
      }
      

      Then an intermediary class:

      OtherAbstractResource.java
      public class OtherAbstractResource<T> extends AbstractResource<T>{}
      

      And two resources test(doesn't work) and test2(will work in any scenario):

      ConcreteClassThatWorks.java
      @Path("test2")
      @Stateless
      public class ConcreteClassThatWorks extends AbstractResource<Model>{
      
      }
      
      @Stateless
      @Path("/test")
      public class ConcreteResource extends OtherAbstractResource<Model> {
      
      }
      

      I deploy my application and test both resources for XML, see:

      [wsiqueir@wsiqueir secured-servlet]$ curl -X POST --data '<model></model>' -H 'content-type: application/xml' http://localhost:8080/generics-resteasy/test
      <html><head><title>JBoss Web/7.2.2.Final-redhat-1 - JBWEB000064: Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>JBWEB000065: HTTP Status 400 - Could not find message body reader for type: T of content type: application/xml</h1><HR size="1" noshade="noshade"><p><b>JBWEB000309: type</b> JBWEB000067: Status report</p><p><b>JBWEB000068: message</b> <u>Could not find message body reader for type: T of content type: application/xml</u></p><p><b>JBWEB000069: description</b> <u>JBWEB000120: The request sent by the client was syntactically incorrect.</u></p><HR size="1" noshade="noshade"><h3>JBoss Web/7.2.2.Final-redhat-1</h3></body></html>
      
      
      [wsiqueir@wsiqueir secured-servlet]$ curl -X POST --data '<model></model>' -H 'content-type: application/xml' http://localhost:8080/generics-resteasy/test2
      Success!
      

      Both will work for JSON, see:

      [wsiqueir@wsiqueir secured-servlet]$ curl -X POST --data '{}' -H 'content-type: application/json' http://localhost:8080/generics-resteasy/test2
      Success!
      
      [wsiqueir@wsiqueir secured-servlet]$ curl -X POST --data '{}' -H 'content-type: application/json' http://localhost:8080/generics-resteasy/test
      Success!
      

      Everything works fine in Wildfly 8.1.

      Attachments

        Activity

          People

            weli@redhat.com Weinan Li
            rhn-support-wsiqueir William Siqueira
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: