CXF
  1. CXF
  2. CXF-5235

Cannot use multiple ResponseReaderS

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Won't Fix
    • Affects Version/s: 2.6.8
    • Fix Version/s: Invalid
    • Component/s: JAX-RS
    • Labels:
      None
    • Estimated Complexity:
      Unknown

      Description

      I've created a factory that uses JAXRSClientFactory to create implementations of my service interface classes.

      In the body of each method I create a list of providers to be used by JAXRSClientFactory.create, some of them being ResponseReaderS. Here's an example:

      JAXBElementProvider jaxbProvider = new JAXBElementProvider();
      JSONProvider jsonProvider = new JSONProvider();
      jsonProvider.setDropRootElement(true);
      jsonProvider.setSupportUnwrapped(true);
      jsonProvider.setConsumeMediaTypes(Service.ContentTypeSummary.PRODUCE_MEDIA_TYPES);
      jsonProvider.setProduceMediaTypes(Service.ContentTypeSummary.CONSUME_MEDIA_TYPES);
      List<Object> providers = Lists.newArrayList();
      providers.add(jaxbProvider);
      providers.add(jsonProvider);
      providers.add(new ResponseReader(MyListV1.class));
      providers.add(new ResponseReader(MyV1.class));
      providers.add(new LoggingOutInterceptor(new PrintWriter(System.out)));
      providers.add(new LoggingInInterceptor(new PrintWriter(System.out)));
      return JAXRSClientFactory.create(
      System.getProperty("service.url"),
      MyRestfulService.class,
      providers,
      true);

      This particular service has two methods: one that returns a list of MyV1 and another one that just returns a MyV1. Now, it seems that the web client under hood always uses the first registered ResponseReader for any sort of response. If I call getMyV1 with the above order, I get a CCE. It works fine when I call getMyListV1, though. If I switch the order around, the service calls work vice versa as well.

        Activity

        Hide
        Sergey Beryozkin added a comment -

        Well, the problem is, if you have multiple methods returning Response, on the client side we do not know what kind of typed payload that Response may represent, this knowledge can only be encoded at the point of retrieving the actual data. Using ResponseReader to deal with multiple Responses is possible but only using the pattern documented at
        http://cxf.apache.org/docs/jax-rs-client-api.html#JAX-RSClientAPI-Limitations

        Note, starting from CXF 2.7.x, 2.0 API has Response.readEntity(Class) method, the idea is basically the same, the type info is provided at the point of getting the data

        Show
        Sergey Beryozkin added a comment - Well, the problem is, if you have multiple methods returning Response, on the client side we do not know what kind of typed payload that Response may represent, this knowledge can only be encoded at the point of retrieving the actual data. Using ResponseReader to deal with multiple Responses is possible but only using the pattern documented at http://cxf.apache.org/docs/jax-rs-client-api.html#JAX-RSClientAPI-Limitations Note, starting from CXF 2.7.x, 2.0 API has Response.readEntity(Class) method, the idea is basically the same, the type info is provided at the point of getting the data
        Hide
        Sergey Beryozkin added a comment -

        Unfortunately not fixable due to the lack of type information in a given Response

        Show
        Sergey Beryozkin added a comment - Unfortunately not fixable due to the lack of type information in a given Response

          People

          • Assignee:
            Sergey Beryozkin
            Reporter:
            Chris Eineke
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development