Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-6380

Context provider not working

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.0.3
    • None
    • JAX-RS
    • None
    • Unknown

    Description

      Come from a TCK test. In the test, there is an Entity provider with readFrom returns null. And a context provider which provides a customized JAXBContext and corresponding Marshaller and unmarshaller.
      @Provider
      public class JaxbContextProvider
      implements ContextResolver
      {
      public JAXBContext getContext(Class type)

      { JAXBContext ctx = new MyJaxbContext(); return ctx; }

      public volatile Object getContext(Class clazz)

      { return getContext(clazz); }

      }

      @Provider
      public class MyJaxbProvider
      implements MessageBodyReader, MessageBodyWriter
      {

      ......

      public JAXBElement readFrom(Class type, Type genericType, Annotation annotations[], MediaType mediatype, MultivaluedMap multivaluedmap, InputStream inputstream)
      throws IOException, WebApplicationException

      { return null; }

      ......

      }
      And there is a resource class which returns a JAXBElement object.
      @Path("resource")
      public class Resource
      {
      @Path("jaxb")
      @POST
      public JAXBElement jaxb(JAXBElement jaxb)

      { return jaxb; }

      }
      When accessing this resource, I found only the entity provider is working, and null response(status code 204) is returned. And the context Provider was not working(getContext method defined in this provider was not triggered at all).
      When removing this entity provider from our test application, the context provider is working and an JAXB object is mashalled to the response(with status code 200).

      In the JSR339, I only found following declaration about the usage of entity provider and context provider.

      See 4.2.4
      An implementation MUST support application-provided entity providers and MUST use those in preference
      to its own pre-packaged providers when either could handle the same request. More precisely, step
      4 in Section 4.2.1 and step 5 in Section 4.2.2 MUST prefer application-provided over pre-packaged entity
      providers.

      In my understanding, if user only defines its own context provider without customized entity provider, application providered context provider should be preferred over CXF default implmentation of entity provider.

      And this usage of both customized context provider and customerized entity provider, which provider should be prefered is out of specification definition.

      But when testing on Apache/Jersy with this test applicatoin, response with status code 200 is returned.

      Would you please advice if this can be a defect in CXF, or you think it's out of specification definition.

      Attachments

        Issue Links

          Activity

            People

              sergey_beryozkin Sergey Beryozkin
              weiz Wei Zheng
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: