Re: FW: [jersey/jersey] SseEventSink invokes custom WriterInterceptor with wrong type, then throws NPE (#3592)
yes, the issue is that mostly, you wouldn't want to mix "standard" response processing and SSE.
MessageBodyWriter is slightly different, since there is a type,
the ultimate definition of that provider, which can be used for
lookup and the registered provider won't have any consequence on
running app, unless used as a return type. WriterInterceptor
doesn't have anything like that - how would you mark the provider
as "please use it only with some particular EventSink"? Also, if
we'd think about symmetry - that would mean that we need to invoke
ReaderInterceptor per each received client event.
EventSink is not a resource method, we have almost no control of the context from which it is invoked from. Allowing MessageBodyWriters to be invoked is a simplest enhancement compared to "writing only strings". Server sent event is supposed to be lightweight and cheap to send - notice that it doesn't need to be used, writing a string is still supported.
And your usecase - WriterInterceptor is not what you want to use in described scenario. You can implement a MessageBodyWriter, unwrap, lookup the MBW for the type you've unwrapped using injected Providers instance.
On 26/06/2017 21:45, Markus KARG wrote: