Hi Markus,

the JaxRs API uses exactly this pattern of a @GET annotated resource with the corresponding @Produces annotation to provide SSE.

But this constellation doesn't follow the ordinary request-response behavior. The connection between the sender and receiver stays open. It is a typical publish and subscribe behavior. Whereas ordinary GET requests return a response or timeout after a certain time, these SSE connections stay open. So there is nothing to return. If the connection is lost, then there is also a reconnect support in the JaxRs SSE.

Please note, that the OSGi JaxRs Whiteboard specification does not change the behavior described in the JaxRs specification. It provides a way to deal with JaxRs in an OSGi way, to service-enable applications, resources and extensions.

So SSE should behave like described in chapter 9 of the JaxRs 2.1 specification.

Regards,

Mark


Am 23.01.20 um 11:51 schrieb Markus Rathgeb via osgi-dev:
Hi,

I have a question about the Server Sent Events mechanism.
I migrated a few projects from Jersey to the Aries JAX-RS Whiteboard
implementation and there is now a question about the specification at
all.

There is an example in the specification that demonstrates the use of
Server Sent Events in the specification.
https://osgi.org/specification/osgi.cmpn/7.0.0/service.jaxrs.html#d0e133342

Instead of a Response object this example returns "void".

There is a REST endpoint that is marked to  produce SSE.
First it checks some stuff.
On failure a response "not found" (or another one e.g. "bad request")
is returned.
On success the "SseEventSink" is used to write events.
If writing of an event throws an exception the event sink is closed.

To return "not found" I currently use an argument "@Context
HttpServletResponse response".
response.setStatus(Status.NOT_FOUND.getStatusCode());
After setting this status the method returns.
Is this okay or do I need to write a not found web application exception?
If I set the status and return, do I also need to close the event sink?
If I throw a web application excpetion, to I need to close the event
think explicit?
If some of mine code throws a runtime exception (e.g. NPE), must I
ensure the event sink is closed or should this be handled by the
whiteboard implementation?

On success, I want to inject additional headers. For example
"X-Accel-Buffering: no" and "Content-Encoding: identity".
Currently I am using "reponse.addHeader(..., ...)", too.
Can I also change the method signatur and return a Response object?
Should this be considered by the whiteboard implementation?
That way I could return e.g.
"Response.status(Status.NOT_FOUND).build()" or
"Response.ok().header(..., ...).header(..., ...).build()".

I am using an implementation of a "ContainerResponseFilter". It is
marked with "JaxrsExtension" annotations etc. and works for all my
REST endpoints.
Except for the SSE one...
Currently the implementations checks if the component is configured to
allow CORS and if allowed it adds headers to the response context.
Should such a container response filter be considered for endpoints
producing SSE or not?

Best regards,
Markus
_______________________________________________
OSGi Developer Mail List
osgi-dev@mail.osgi.org
https://mail.osgi.org/mailman/listinfo/osgi-dev

--
Mark Hoffmann
M.A. Dipl.-Betriebswirt (FH)
CEO/CTO

Phone:   +49 3641 384 910 0
Mobile:  +49 175 701 2201
E-Mail: m.hoffm...@data-in-motion.biz
Web: www.datainmotion.de

Data In Motion Consulting GmbH
Kahlaische Strasse 4
07745 Jena
Germany

Geschäftsführer/CEO
Mark Hoffmann
Jürgen Albert

Jena HRB 513025
Steuernummer 162/107/05779
USt-Id DE310002614

_______________________________________________
OSGi Developer Mail List
osgi-dev@mail.osgi.org
https://mail.osgi.org/mailman/listinfo/osgi-dev

Reply via email to