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

OutboundSseEventImpl.Builder does not follow the java doc requirements

XMLWordPrintable

      The Resteasy implementation for javax.ws.rs.sse.OutboundSseEvent.Builder break few javadoc requirements:

      • According to Builder mediaType(final MediaType mediaType) doc the default media type should be MediaType.TEXT_PLAIN
      • Builder mediaType(final MediaType mediaType) and all Builder data(...) methods should throw NullPointerException when input parameter is null.
      • OutboundSseEvent build() should throw IllegalArgumentException if neither comment nor data are set

      Also when building a OutboundSseEvent from a builder using a javax.ws.rs.core.GenericEntity<> as follow:

      GenericEntity<List<String>> genericEntity = new GenericEntity<List<String>>(new ArrayList<>()) {};
      OutboundSseEvent outboundSseEvent = new OutboundSseEventImpl.BuilderImpl().data(genericEntity).build();
      

      I was expecting the result of outboundSseEvent.getType() to be the same as genericEntity.getRawType().
      Actually it was not since the builder is building a GenericType<?> using only the genericType taken from genericEntity.getType().

      So at runtime the MBW used to write the SseEvent will not be called with the exact data type as it would be if we were dealing with a classic response return such as:

      GenericEntity<List<String>> genericEntity = new GenericEntity<List<String>>(new ArrayList<>()) {};
      return Response.ok().entity(genericEntity).build();
      

      In the example above the MBW will be called with the exact data type since org.jboss.resteasy.specimpl.BuiltResponse.getEntityClass() return the exact same type as genericEntity.getRawType()

            rhn-support-asoldano Alessio Soldano
            nicones Nicolas NESMON
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: