You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Luca Merolla <lu...@gmail.com> on 2012/09/05 11:02:42 UTC

@ServerSentEvent in TomEE

Hi,

I was just wondering if we have something similar to @ServerSentEventContext
annotation in TomEE.
It would be nice to have it, combined with the fact that TomEE ships the
latest Tomcat which does support WebSocket can be a very cool feature IMHO.

Luca

Re: @ServerSentEvent in TomEE

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi,

back to "SSE".

i just pushed on github this small project:
https://github.com/rmannibucau/cdi-tomcat-sse

Including it you can:
1) define your Server (the class managing connections)
-> simply extend SSEWebSocket

it basically looks like:

@WebServlet(urlPatterns = "/my-sse-endpoint")
public class SSEImpl extends SSEWebSocket {}


but some more hooks are available (see
https://github.com/rmannibucau/cdi-tomcat-sse/blob/master/src/test/java/com/github/rmannibucau/sse/test/SSEImpl.java)


2) use SSESender class to broadcast to connected client some data

    @Inject
    @SSE("/my-sse-endpoint")
    private SSESender sse;

    sse.sendMessage("In message\r\n");

*3) *the javascript part is a websocket one (the url is not the right
one but basic stuff is here):
https://github.com/rmannibucau/cdi-tomcat-sse/blob/master/src/test/resources/index.html

That's not a real SSE (we don't use EventSource in js and
text/event-stream on server side) but it does the job.


Implementing a real SSE is finally not so hard. I started to work on
it then wonder which abstraction could really be needed. The drawback
of SSE through servlets is you get a servlet connection/client.


If you have any idea feel free to fork/submit them.


Currently it doesn't need TomEE for anything else than tests but we
could think to go further if we find good reasons ;). Why i chose to
avoid it today was the fact WebSocket are still young and their API
can change.




*Romain Manni-Bucau*
*Twitter: @rmannibucau*
*Blog: http://rmannibucau.wordpress.com*




2012/9/6 Romain Manni-Bucau <rm...@gmail.com>

> Maybe create another thread with details on your apps and your needs.
>
> Side note: ear are not managed the same way between containers and all
> have drawbacks (compared to war which are closer)
> Le 5 sept. 2012 23:06, "Luca Merolla" <lu...@gmail.com> a écrit :
>
> It would be cool. I need to find the time though :(
>>
>> I was looking for some inspiration for the issue that I'm having with the
>> EJB.jar that needs to call another EJB placed inside a WAR.
>> Still I haven't get it to work on TomEE, while it was working on JBoss.
>>
>> That's why I finished looking on that topic. If I will came up with
>> something that can be useful for both my project and tomee, I would be
>> glad
>> to share it.
>>
>> On Wed, Sep 5, 2012 at 1:41 PM, Romain Manni-Bucau <rmannibucau@gmail.com
>> >wrote:
>>
>> > Yeah, wonder if it should be in tomee, atmosphere, other.
>> >
>> > Btw the code is pretty easy so we can in a first time host it i think.
>> >
>> > Do you want to give it a try?
>> > Le 5 sept. 2012 13:37, "Luca Merolla" <lu...@gmail.com> a écrit
>> :
>> >
>> > > It looks close to some features provided by atmosphere, in fact
>> > atmosphere
>> > > does support SSE transport.
>> > >
>> > > Yes, I read somewhere it is going to be a CDI extension.
>> > >
>> > > The interesting thing is what you can do with the CDI annotations. You
>> > can
>> > > very easily produce something like this:
>> > >
>> > > @Startup
>> > > @Stateless
>> > > public class SimpleEvent {
>> > >
>> > >  @Inject @ServerSentEventContext("/simple")
>> > >  ServerSentEventHandlerContext<MySimpleHandler> simpleHandlers;
>> > >
>> > >  @Schedule(hour="*", minute="*", second="*/10")
>> > >  public void sendDate() {
>> > >  for(MySimpleHandler handler : simpleHandlers.getHandlers()) {
>> > >  handler.sendMessage(new Date().toString());
>> > >  }
>> > >  }
>> > > }
>> > >
>> > > In case of Tomcat with WebSocket instead of MySimpleHandler we would
>> have
>> > > something that extends MessageInbound and inside the for cycle
>> > > handler.getWsOutbound().writeTextMessage(...)
>> > >
>> > >
>> > > On Wed, Sep 5, 2012 at 12:40 PM, Romain Manni-Bucau
>> > > <rm...@gmail.com>wrote:
>> > >
>> > > > Currently not but looks pretty close to atmosphere, no?
>> > > >
>> > > > Since it islinked to cdi it should be an extension to cdi and maybe
>> not
>> > > > sthg brought by the container.
>> > > >
>> > > > Wdyt?
>> > > > Le 5 sept. 2012 11:03, "Luca Merolla" <lu...@gmail.com> a
>> > écrit :
>> > > >
>> > > > > An example is shown here:
>> > > > >
>> > > > >
>> > > > >
>> > > >
>> > >
>> >
>> http://weblogs.java.net/blog/bhaktimehta/archive/2012/04/21/server-sent-events-sample-glassfish
>> > > > >
>> > > > > On Wed, Sep 5, 2012 at 11:02 AM, Luca Merolla <
>> > luca.merolla@gmail.com
>> > > > > >wrote:
>> > > > >
>> > > > > > Hi,
>> > > > > >
>> > > > > > I was just wondering if we have something similar to
>> > > > > @ServerSentEventContext
>> > > > > > annotation in TomEE.
>> > > > > > It would be nice to have it, combined with the fact that TomEE
>> > ships
>> > > > the
>> > > > > > latest Tomcat which does support WebSocket can be a very cool
>> > feature
>> > > > > IMHO.
>> > > > > >
>> > > > > > Luca
>> > > > > >
>> > > > >
>> > > > >
>> > > > >
>> > > > > --
>> > > > >    *Luca Merolla*
>> > > > > Management, Business & Technology Consultant
>> > > > >
>> > > > >
>> > > > >  <http://maps.google.com/maps?q=&hl=en>  *Mobile:* +393774569974
>> > > > > *Email:* luca.merolla@gmail.com
>> > > > >  *http://nl.linkedin.com/in/lucamerolla*
>> > > > > *Blog <http://lucamerolla.wordpress.com>*
>> > > > >
>> > > > >
>> > > > > Merolla Consulting Limited
>> > > > >
>> > >
>> >
>>
>

Re: @ServerSentEvent in TomEE

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Maybe create another thread with details on your apps and your needs.

Side note: ear are not managed the same way between containers and all have
drawbacks (compared to war which are closer)
Le 5 sept. 2012 23:06, "Luca Merolla" <lu...@gmail.com> a écrit :

> It would be cool. I need to find the time though :(
>
> I was looking for some inspiration for the issue that I'm having with the
> EJB.jar that needs to call another EJB placed inside a WAR.
> Still I haven't get it to work on TomEE, while it was working on JBoss.
>
> That's why I finished looking on that topic. If I will came up with
> something that can be useful for both my project and tomee, I would be glad
> to share it.
>
> On Wed, Sep 5, 2012 at 1:41 PM, Romain Manni-Bucau <rmannibucau@gmail.com
> >wrote:
>
> > Yeah, wonder if it should be in tomee, atmosphere, other.
> >
> > Btw the code is pretty easy so we can in a first time host it i think.
> >
> > Do you want to give it a try?
> > Le 5 sept. 2012 13:37, "Luca Merolla" <lu...@gmail.com> a écrit :
> >
> > > It looks close to some features provided by atmosphere, in fact
> > atmosphere
> > > does support SSE transport.
> > >
> > > Yes, I read somewhere it is going to be a CDI extension.
> > >
> > > The interesting thing is what you can do with the CDI annotations. You
> > can
> > > very easily produce something like this:
> > >
> > > @Startup
> > > @Stateless
> > > public class SimpleEvent {
> > >
> > >  @Inject @ServerSentEventContext("/simple")
> > >  ServerSentEventHandlerContext<MySimpleHandler> simpleHandlers;
> > >
> > >  @Schedule(hour="*", minute="*", second="*/10")
> > >  public void sendDate() {
> > >  for(MySimpleHandler handler : simpleHandlers.getHandlers()) {
> > >  handler.sendMessage(new Date().toString());
> > >  }
> > >  }
> > > }
> > >
> > > In case of Tomcat with WebSocket instead of MySimpleHandler we would
> have
> > > something that extends MessageInbound and inside the for cycle
> > > handler.getWsOutbound().writeTextMessage(...)
> > >
> > >
> > > On Wed, Sep 5, 2012 at 12:40 PM, Romain Manni-Bucau
> > > <rm...@gmail.com>wrote:
> > >
> > > > Currently not but looks pretty close to atmosphere, no?
> > > >
> > > > Since it islinked to cdi it should be an extension to cdi and maybe
> not
> > > > sthg brought by the container.
> > > >
> > > > Wdyt?
> > > > Le 5 sept. 2012 11:03, "Luca Merolla" <lu...@gmail.com> a
> > écrit :
> > > >
> > > > > An example is shown here:
> > > > >
> > > > >
> > > > >
> > > >
> > >
> >
> http://weblogs.java.net/blog/bhaktimehta/archive/2012/04/21/server-sent-events-sample-glassfish
> > > > >
> > > > > On Wed, Sep 5, 2012 at 11:02 AM, Luca Merolla <
> > luca.merolla@gmail.com
> > > > > >wrote:
> > > > >
> > > > > > Hi,
> > > > > >
> > > > > > I was just wondering if we have something similar to
> > > > > @ServerSentEventContext
> > > > > > annotation in TomEE.
> > > > > > It would be nice to have it, combined with the fact that TomEE
> > ships
> > > > the
> > > > > > latest Tomcat which does support WebSocket can be a very cool
> > feature
> > > > > IMHO.
> > > > > >
> > > > > > Luca
> > > > > >
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > >    *Luca Merolla*
> > > > > Management, Business & Technology Consultant
> > > > >
> > > > >
> > > > >  <http://maps.google.com/maps?q=&hl=en>  *Mobile:* +393774569974
> > > > > *Email:* luca.merolla@gmail.com
> > > > >  *http://nl.linkedin.com/in/lucamerolla*
> > > > > *Blog <http://lucamerolla.wordpress.com>*
> > > > >
> > > > >
> > > > > Merolla Consulting Limited
> > > > >
> > >
> >
>

Re: @ServerSentEvent in TomEE

Posted by Luca Merolla <lu...@gmail.com>.
It would be cool. I need to find the time though :(

I was looking for some inspiration for the issue that I'm having with the
EJB.jar that needs to call another EJB placed inside a WAR.
Still I haven't get it to work on TomEE, while it was working on JBoss.

That's why I finished looking on that topic. If I will came up with
something that can be useful for both my project and tomee, I would be glad
to share it.

On Wed, Sep 5, 2012 at 1:41 PM, Romain Manni-Bucau <rm...@gmail.com>wrote:

> Yeah, wonder if it should be in tomee, atmosphere, other.
>
> Btw the code is pretty easy so we can in a first time host it i think.
>
> Do you want to give it a try?
> Le 5 sept. 2012 13:37, "Luca Merolla" <lu...@gmail.com> a écrit :
>
> > It looks close to some features provided by atmosphere, in fact
> atmosphere
> > does support SSE transport.
> >
> > Yes, I read somewhere it is going to be a CDI extension.
> >
> > The interesting thing is what you can do with the CDI annotations. You
> can
> > very easily produce something like this:
> >
> > @Startup
> > @Stateless
> > public class SimpleEvent {
> >
> >  @Inject @ServerSentEventContext("/simple")
> >  ServerSentEventHandlerContext<MySimpleHandler> simpleHandlers;
> >
> >  @Schedule(hour="*", minute="*", second="*/10")
> >  public void sendDate() {
> >  for(MySimpleHandler handler : simpleHandlers.getHandlers()) {
> >  handler.sendMessage(new Date().toString());
> >  }
> >  }
> > }
> >
> > In case of Tomcat with WebSocket instead of MySimpleHandler we would have
> > something that extends MessageInbound and inside the for cycle
> > handler.getWsOutbound().writeTextMessage(...)
> >
> >
> > On Wed, Sep 5, 2012 at 12:40 PM, Romain Manni-Bucau
> > <rm...@gmail.com>wrote:
> >
> > > Currently not but looks pretty close to atmosphere, no?
> > >
> > > Since it islinked to cdi it should be an extension to cdi and maybe not
> > > sthg brought by the container.
> > >
> > > Wdyt?
> > > Le 5 sept. 2012 11:03, "Luca Merolla" <lu...@gmail.com> a
> écrit :
> > >
> > > > An example is shown here:
> > > >
> > > >
> > > >
> > >
> >
> http://weblogs.java.net/blog/bhaktimehta/archive/2012/04/21/server-sent-events-sample-glassfish
> > > >
> > > > On Wed, Sep 5, 2012 at 11:02 AM, Luca Merolla <
> luca.merolla@gmail.com
> > > > >wrote:
> > > >
> > > > > Hi,
> > > > >
> > > > > I was just wondering if we have something similar to
> > > > @ServerSentEventContext
> > > > > annotation in TomEE.
> > > > > It would be nice to have it, combined with the fact that TomEE
> ships
> > > the
> > > > > latest Tomcat which does support WebSocket can be a very cool
> feature
> > > > IMHO.
> > > > >
> > > > > Luca
> > > > >
> > > >
> > > >
> > > >
> > > > --
> > > >    *Luca Merolla*
> > > > Management, Business & Technology Consultant
> > > >
> > > >
> > > >  <http://maps.google.com/maps?q=&hl=en>  *Mobile:* +393774569974
> > > > *Email:* luca.merolla@gmail.com
> > > >  *http://nl.linkedin.com/in/lucamerolla*
> > > > *Blog <http://lucamerolla.wordpress.com>*
> > > >
> > > >
> > > > Merolla Consulting Limited
> > > >
> >
>

Re: @ServerSentEvent in TomEE

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Yeah, wonder if it should be in tomee, atmosphere, other.

Btw the code is pretty easy so we can in a first time host it i think.

Do you want to give it a try?
Le 5 sept. 2012 13:37, "Luca Merolla" <lu...@gmail.com> a écrit :

> It looks close to some features provided by atmosphere, in fact atmosphere
> does support SSE transport.
>
> Yes, I read somewhere it is going to be a CDI extension.
>
> The interesting thing is what you can do with the CDI annotations. You can
> very easily produce something like this:
>
> @Startup
> @Stateless
> public class SimpleEvent {
>
>  @Inject @ServerSentEventContext("/simple")
>  ServerSentEventHandlerContext<MySimpleHandler> simpleHandlers;
>
>  @Schedule(hour="*", minute="*", second="*/10")
>  public void sendDate() {
>  for(MySimpleHandler handler : simpleHandlers.getHandlers()) {
>  handler.sendMessage(new Date().toString());
>  }
>  }
> }
>
> In case of Tomcat with WebSocket instead of MySimpleHandler we would have
> something that extends MessageInbound and inside the for cycle
> handler.getWsOutbound().writeTextMessage(...)
>
>
> On Wed, Sep 5, 2012 at 12:40 PM, Romain Manni-Bucau
> <rm...@gmail.com>wrote:
>
> > Currently not but looks pretty close to atmosphere, no?
> >
> > Since it islinked to cdi it should be an extension to cdi and maybe not
> > sthg brought by the container.
> >
> > Wdyt?
> > Le 5 sept. 2012 11:03, "Luca Merolla" <lu...@gmail.com> a écrit :
> >
> > > An example is shown here:
> > >
> > >
> > >
> >
> http://weblogs.java.net/blog/bhaktimehta/archive/2012/04/21/server-sent-events-sample-glassfish
> > >
> > > On Wed, Sep 5, 2012 at 11:02 AM, Luca Merolla <luca.merolla@gmail.com
> > > >wrote:
> > >
> > > > Hi,
> > > >
> > > > I was just wondering if we have something similar to
> > > @ServerSentEventContext
> > > > annotation in TomEE.
> > > > It would be nice to have it, combined with the fact that TomEE ships
> > the
> > > > latest Tomcat which does support WebSocket can be a very cool feature
> > > IMHO.
> > > >
> > > > Luca
> > > >
> > >
> > >
> > >
> > > --
> > >    *Luca Merolla*
> > > Management, Business & Technology Consultant
> > >
> > >
> > >  <http://maps.google.com/maps?q=&hl=en>  *Mobile:* +393774569974
> > > *Email:* luca.merolla@gmail.com
> > >  *http://nl.linkedin.com/in/lucamerolla*
> > > *Blog <http://lucamerolla.wordpress.com>*
> > >
> > >
> > > Merolla Consulting Limited
> > >
>

Re: @ServerSentEvent in TomEE

Posted by Luca Merolla <lu...@gmail.com>.
It looks close to some features provided by atmosphere, in fact atmosphere
does support SSE transport.

Yes, I read somewhere it is going to be a CDI extension.

The interesting thing is what you can do with the CDI annotations. You can
very easily produce something like this:

@Startup
@Stateless
public class SimpleEvent {

 @Inject @ServerSentEventContext("/simple")
 ServerSentEventHandlerContext<MySimpleHandler> simpleHandlers;

 @Schedule(hour="*", minute="*", second="*/10")
 public void sendDate() {
 for(MySimpleHandler handler : simpleHandlers.getHandlers()) {
 handler.sendMessage(new Date().toString());
 }
 }
}

In case of Tomcat with WebSocket instead of MySimpleHandler we would have
something that extends MessageInbound and inside the for cycle
handler.getWsOutbound().writeTextMessage(...)


On Wed, Sep 5, 2012 at 12:40 PM, Romain Manni-Bucau
<rm...@gmail.com>wrote:

> Currently not but looks pretty close to atmosphere, no?
>
> Since it islinked to cdi it should be an extension to cdi and maybe not
> sthg brought by the container.
>
> Wdyt?
> Le 5 sept. 2012 11:03, "Luca Merolla" <lu...@gmail.com> a écrit :
>
> > An example is shown here:
> >
> >
> >
> http://weblogs.java.net/blog/bhaktimehta/archive/2012/04/21/server-sent-events-sample-glassfish
> >
> > On Wed, Sep 5, 2012 at 11:02 AM, Luca Merolla <luca.merolla@gmail.com
> > >wrote:
> >
> > > Hi,
> > >
> > > I was just wondering if we have something similar to
> > @ServerSentEventContext
> > > annotation in TomEE.
> > > It would be nice to have it, combined with the fact that TomEE ships
> the
> > > latest Tomcat which does support WebSocket can be a very cool feature
> > IMHO.
> > >
> > > Luca
> > >
> >
> >
> >
> > --
> >    *Luca Merolla*
> > Management, Business & Technology Consultant
> >
> >
> >  <http://maps.google.com/maps?q=&hl=en>  *Mobile:* +393774569974
> > *Email:* luca.merolla@gmail.com
> >  *http://nl.linkedin.com/in/lucamerolla*
> > *Blog <http://lucamerolla.wordpress.com>*
> >
> >
> > Merolla Consulting Limited
> >

Re: @ServerSentEvent in TomEE

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Currently not but looks pretty close to atmosphere, no?

Since it islinked to cdi it should be an extension to cdi and maybe not
sthg brought by the container.

Wdyt?
Le 5 sept. 2012 11:03, "Luca Merolla" <lu...@gmail.com> a écrit :

> An example is shown here:
>
>
> http://weblogs.java.net/blog/bhaktimehta/archive/2012/04/21/server-sent-events-sample-glassfish
>
> On Wed, Sep 5, 2012 at 11:02 AM, Luca Merolla <luca.merolla@gmail.com
> >wrote:
>
> > Hi,
> >
> > I was just wondering if we have something similar to
> @ServerSentEventContext
> > annotation in TomEE.
> > It would be nice to have it, combined with the fact that TomEE ships the
> > latest Tomcat which does support WebSocket can be a very cool feature
> IMHO.
> >
> > Luca
> >
>
>
>
> --
>    *Luca Merolla*
> Management, Business & Technology Consultant
>
>
>  <http://maps.google.com/maps?q=&hl=en>  *Mobile:* +393774569974
> *Email:* luca.merolla@gmail.com
>  *http://nl.linkedin.com/in/lucamerolla*
> *Blog <http://lucamerolla.wordpress.com>*
>
>
> Merolla Consulting Limited
>

Re: @ServerSentEvent in TomEE

Posted by Luca Merolla <lu...@gmail.com>.
An example is shown here:

http://weblogs.java.net/blog/bhaktimehta/archive/2012/04/21/server-sent-events-sample-glassfish

On Wed, Sep 5, 2012 at 11:02 AM, Luca Merolla <lu...@gmail.com>wrote:

> Hi,
>
> I was just wondering if we have something similar to @ServerSentEventContext
> annotation in TomEE.
> It would be nice to have it, combined with the fact that TomEE ships the
> latest Tomcat which does support WebSocket can be a very cool feature IMHO.
>
> Luca
>



-- 
   *Luca Merolla*
Management, Business & Technology Consultant


 <http://maps.google.com/maps?q=&hl=en>  *Mobile:* +393774569974
*Email:* luca.merolla@gmail.com
 *http://nl.linkedin.com/in/lucamerolla*
*Blog <http://lucamerolla.wordpress.com>*


Merolla Consulting Limited