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

InboundSseEvent.readData doesn't appear to use registered providers

XMLWordPrintable

    • Hide

      Create any Client and register custom providers.
      Create an SseEventSource from the the Client.
      Attempt to call readData on any InboundSseEvent vended from the source, it will not use custom providers registered on the Client instance.

      Show
      Create any Client and register custom providers. Create an SseEventSource from the the Client. Attempt to call readData on any InboundSseEvent vended from the source, it will not use custom providers registered on the Client instance.

      An InboundSseEvent received from an SseEventSource built from a WebTarget which was in turn built from a Client that has registered a customer provider (in this specific case a ContextResolver<ObjectMapper> for customizing JSON serialization) will not see the custom providers when attempting to call readData on the event.

      class MyCustomJSONObjectMappResolver implements ContextResolver<ObjectMapper> { ... };
      
      Client client = ClientBuilder.newClient().register(MyCustomJSONObjectMapperResolver.class);
      WebTarget endpoint = client.target("http://server.example.com/events");
      SseEventSource source = SseEventSource.target(endpoint).build();
      
      source.register(event -> {
        // The following line will use the "default" ObjectMapper configured in ResteasyJackson2Provider instead of the one provided by MyCustomJSONObjectMapperResolver
        event.readData(MyCustomType.class, MediaType.APPLICATION_JSON_TYPE);
      });
      
      source.open();
      
      

      I believe the reason is fairly apparent. In InboundSseEventImpl.java:195 it magics up it's on instance of ResteasyProviderFactory and uses that to lookup providers. I believe the InboundSseEventImpl should carry a reference to the SseEventSource that spawned it and use the configuration available from its ClientWebtarget to lookup providers.

            rhn-engineering-ema Jim Ma
            kevinwooten Kevin Wooten (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: