jersey
  1. jersey
  2. JERSEY-1494

MessageBodyReader not found for media type=text/xml, type=class javax.xml.bind.JAXBElement, genericType=class javax.xml.bind.JAXBElement.

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Blocker Blocker
    • Resolution: Works as designed
    • Affects Version/s: 2.0-m09
    • Fix Version/s: 2.0-m12, 2.0
    • Component/s: core
    • Labels:
      None

      Description

      Spec., section 4.2.4 Standard Entity Providers, says:

      javax.xml.bind.JAXBElement and application-supplied JAXB classes XML media types (text/xml, application/xml and application/*+xml).

      StackTrace:

      ERROR: org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyReader not found
      for media type=text/xml, type=class javax.xml.bind.JAXBElement, genericType=class javax.xml.bind.JAXBElement.
      at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.aroundReadFrom(ReaderInterceptorExecutor.java:198)
      at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:158)
      at org.glassfish.jersey.message.internal.ExceptionWrapperInterceptor.aroundReadFrom(ExceptionWrapperInterceptor.java:70)
      at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:158)
      at org.glassfish.jersey.message.internal.MessageBodyFactory.readFrom(MessageBodyFactory.java:807)
      at org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:862)
      at org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:807)
      at org.glassfish.jersey.client.InboundJaxrsResponse.readEntity(InboundJaxrsResponse.java:94)
      at org.glassfish.jersey.client.ScopedJaxrsResponse.access$001(ScopedJaxrsResponse.java:56)
      at org.glassfish.jersey.client.ScopedJaxrsResponse$1.call(ScopedJaxrsResponse.java:77)
      at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:395)
      at org.glassfish.jersey.client.ScopedJaxrsResponse.readEntity(ScopedJaxrsResponse.java:74)
      ....

        Activity

        Hide
        jan.supol added a comment - - edited

        Server side:

        @Path("resource")
        public class Resource {
        	@DELETE
        	@Path("delete")
        	public String delete() {
        		return "delete";
        	}
        }
        

        The exception is thrown on client side:

         Client client = ClientFactory.newClient();
         WebTarget target = client.target("http://localhost:8080/web/resource");
         Invocation.Builder builder;
         builder = target.request("text/xml");
         builder.header("Accept","text/xml");
         Invocation i;
         i=builder.build("GET");
         Response r = i.invoke();
         r.readEntity(JAXBElement.class); //here it is thrown
        
        
        Show
        jan.supol added a comment - - edited Server side: @Path( "resource" ) public class Resource { @DELETE @Path( "delete" ) public String delete() { return "delete" ; } } The exception is thrown on client side: Client client = ClientFactory.newClient(); WebTarget target = client.target( "http: //localhost:8080/web/resource" ); Invocation.Builder builder; builder = target.request( "text/xml" ); builder.header( "Accept" , "text/xml" ); Invocation i; i=builder.build( "GET" ); Response r = i.invoke(); r.readEntity(JAXBElement.class); //here it is thrown
        Hide
        Miroslav Fuksa added a comment -

        The problem is in the example. The JAXBElement.class must be defined as ParametrizedType using GenericType. To read entity as JAXBElement the following can be used.

        GenericType<JAXBElement<String>> genericType = new GenericType<JAXBElement<String>>() {};
        final JAXBElement jaxbElement = r.readEntity(genericType);

        This works correctly. We have agreed with Jan to close the issue.

        Show
        Miroslav Fuksa added a comment - The problem is in the example. The JAXBElement.class must be defined as ParametrizedType using GenericType. To read entity as JAXBElement the following can be used. GenericType<JAXBElement<String>> genericType = new GenericType<JAXBElement<String>>() {}; final JAXBElement jaxbElement = r.readEntity(genericType); This works correctly. We have agreed with Jan to close the issue.
        Hide
        Miroslav Fuksa added a comment -

        Works as desired. See comments.

        Show
        Miroslav Fuksa added a comment - Works as desired. See comments.

          People

          • Assignee:
            Miroslav Fuksa
            Reporter:
            jan.supol
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 3 hours
              3h
              Remaining:
              Remaining Estimate - 0 minutes
              0m
              Logged:
              Time Spent - 30 minutes Time Not Required
              30m