Jersey through Websockets

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Jersey through Websockets

schp
Hi,

I would like to write an application where RESTful requests can be made
via both HTTP and Websockets; in the latter case, it would be ideal if
multiple requests could be made through the same socket. I was able to
install Atmosphere (0.7.2) and invoke RESTful methods through it, but
so far I had only limited success invoking RESTful methods through
Websockets. Are there documentation or some examples regarding this
scenario?

           Thanks,
                  Peter
Reply | Threaded
Open this post in threaded view
|

Re: Jersey through Websockets

Jeanfrancois Arcand-4
Salut,

the best way to use Jersey + WebSocket and by downloading the pubsub
sample. See this blog for more information. Using 0.8-SNAPSHOT makes it
simpler BTW:

> http://jfarcand.wordpress.com/2011/06/29/rest-websocket-applications-why-not-using-the-atmosphere-framework/

Let me know how it goes. You can do the same with the 0.7.2, but this
time you will need to add some BroadcastFilter to make it work. Take a
look at the pubsub-redis sample's web.xml for more information. Download
sample from here

> http://oss.sonatype.org/content/repositories/snapshots/org/atmosphere/

A+

-- jeanfrancois

On 11-07-13 11:18 AM, [hidden email] wrote:

> Hi,
>
> I would like to write an application where RESTful requests can be made
> via both HTTP and Websockets; in the latter case, it would be ideal if
> multiple requests could be made through the same socket. I was able to
> install Atmosphere (0.7.2) and invoke RESTful methods through it, but
> so far I had only limited success invoking RESTful methods through
> Websockets. Are there documentation or some examples regarding this
> scenario?
>
>   Thanks,
>  Peter
>
Reply | Threaded
Open this post in threaded view
|

Re: Jersey through Websockets

schp
Hi,

Merci beaucoup pour la réponse rapide :)

I followed your instructions: set up the project to use the latest 0.8 snapshot (I am using Jersey 1.8), set up web.xml as

  <servlet>
    <servlet-name>AtmosphereServlet</servlet-name>
    <servlet-class>org.atmosphere.cpr.AtmosphereServlet</servlet-class>
    <init-param>
      <param-name>grizzly.application.path</param-name>
      <param-value>/sample</param-value>
    </init-param>
    <init-param>
      <param-name>org.atmosphere.useWebSocket</param-name>
      <param-value>true</param-value>
    </init-param>
    <init-param>
      <param-name>org.atmosphere.useNative</param-name>
      <param-value>true</param-value>
    </init-param>
    <load-on-startup>0</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>AtmosphereServlet</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>

and wrote a simple class

@Path("/sample")
public class Handler {
      
    @GET
    public SuspendResponse<String> initiate() {
        JerseyBroadcaster bc = new JerseyBroadcaster ("id#1");
        return new SuspendResponse.SuspendResponseBuilder<String>()
                .outputComments(true)
                .broadcaster (bc)
                .build();
    }
}

However, when I issued a websocket request by hand (through telnet), the server responded with a regular way, it did not finish the handshake. The websocket request was:

GET /testapp/ HTTP/1.1
Upgrade: WebSocket
Connection: Upgrade
Host: localhost
Origin: http://localhost/
Sec-WebSocket-Key1: 4 @1  46546xW%0l 1 5
Sec-WebSocket-Key2: 12998 5 Y3 1  .P00
 
^n:ds[4U

Is there some other configuration in Glassfish or Atmosphere which I did not notice?

             Thanks,
                  Peter

2011/7/13 jfarcand <[hidden email]>
Salut,

the best way to use Jersey + WebSocket and by downloading the pubsub sample. See this blog for more information. Using 0.8-SNAPSHOT makes it simpler BTW:

http://jfarcand.wordpress.com/2011/06/29/rest-websocket-applications-why-not-using-the-atmosphere-framework/

Let me know how it goes. You can do the same with the 0.7.2, but this time you will need to add some BroadcastFilter to make it work. Take a look at the pubsub-redis sample's web.xml for more information. Download sample from here

http://oss.sonatype.org/content/repositories/snapshots/org/atmosphere/

A+

-- jeanfrancois


On 11-07-13 11:18 AM, [hidden email] wrote:
Hi,

I would like to write an application where RESTful requests can be made
via both HTTP and Websockets; in the latter case, it would be ideal if
multiple requests could be made through the same socket. I was able to
install Atmosphere (0.7.2) and invoke RESTful methods through it, but
so far I had only limited success invoking RESTful methods through
Websockets. Are there documentation or some examples regarding this
scenario?

          Thanks,
                 Peter


Reply | Threaded
Open this post in threaded view
|

Re: Jersey through Websockets

agi_m
In reply to this post by Jeanfrancois Arcand-4
Hello,

I'm also trying to establish a WebSocket connection over Atmosphere Jersey. I have a simple Comet counter (similar to that one in the samples), which works great using streaming and long-polling (I am using the Atmosphere jQuery plugin), but fails with WebSocket. I don't believe my code or configuration are broken, as the jQuery PubSub example doesn't work either. I am deploying on GlassFish 3.1 (Grizzly 1.9.31 using the -76 WebSocket protocol draft). WebSocket support on GlassFish is enabled. I've implemented the same WebSocket application using the GlassFish's WebSocket API proving that the WebSocket connection works on GlassFish.

When I try to establish the WebSocket connection using my REST application or the PubSub jQuery sample, the following exception is raised:
SEVERE: java.lang.IllegalStateException: WEB9031: WebappClassLoader unable to load resource [com.sun.grizzly.websockets.BaseServerWebSocket], because it has not yet been started, or was already stopped
        at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1410)
        at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1368)
        at org.atmosphere.container.GlassFishWebSocketSupport$GrizzlyApplication.onConnect(GlassFishWebSocketSupport.java:118)
        at com.sun.grizzly.websockets.BaseWebSocket.onConnect(BaseWebSocket.java:119)
        at com.sun.grizzly.websockets.ServerNetworkHandler.handshake(ServerNetworkHandler.java:102)
        at com.sun.grizzly.websockets.WebSocketEngine.upgrade(WebSocketEngine.java:147)
        at com.sun.grizzly.websockets.WebSocketAsyncFilter.doFilter(WebSocketAsyncFilter.java:52)
        at com.sun.grizzly.arp.DefaultAsyncExecutor.invokeFilters(DefaultAsyncExecutor.java:171)
        at com.sun.grizzly.arp.DefaultAsyncExecutor.interrupt(DefaultAsyncExecutor.java:143)
        at com.sun.grizzly.arp.AsyncProcessorTask.doTask(AsyncProcessorTask.java:94)
        at com.sun.grizzly.http.TaskBase.run(TaskBase.java:193)
        at com.sun.grizzly.http.TaskBase.execute(TaskBase.java:175)
        at com.sun.grizzly.arp.DefaultAsyncHandler.handle(DefaultAsyncHandler.java:145)
        at com.sun.grizzly.arp.AsyncProtocolFilter.execute(AsyncProtocolFilter.java:204)
        at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
        at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
        at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
        at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
        at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
        at java.lang.Thread.run(Thread.java:662)

What does the error mean? Is it possible that Atmosphere doesn't support my older version of the WebSocket support in Grizzly?
Reply | Threaded
Open this post in threaded view
|

Re: Jersey through Websockets

agi_m
When I deploy the PubSub jQuery example to Jetty 7.4.4 (which I looked up implements hybi-09), trying to establish the WebSocket connection with Chrome 15.0.849.0 dev -m (which has hybi-10 support), the following exception is raised:
java.lang.IllegalAccessError: org.atmosphere.cpr.AtmosphereServlet.doWebSocketConnect(Ljavax/servlet/http/HttpServletRequest;Ljava/lang/String;)Lorg/eclipse/jetty/websocket/WebSocket;
        at org.eclipse.jetty.websocket.WebSocketFactory.acceptWebSocket(WebSocketFactory.java:214)
        at org.eclipse.jetty.websocket.WebSocketServlet.service(WebSocketServlet.java:63)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:538)
        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:478)
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
        at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:480)
        at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:225)
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:937)
        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:406)
        at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:183)
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:871)
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
        at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:247)
        at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:149)
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:110)
        at org.eclipse.jetty.server.Server.handle(Server.java:346)
        at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:589)
        at org.eclipse.jetty.server.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:1048)
        at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:601)
        at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:214)
        at org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java:411)
        at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:535)
        at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:40)
        at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:529)
        at java.lang.Thread.run(Unknown Source)

Thank you for any pointers.


On Sun, Aug 14, 2011 at 7:45 PM, agi_m [via Atmosphere users mailling list] <[hidden email]> wrote:
Hello,

I'm also trying to establish a WebSocket connection over Atmosphere Jersey. I have a simple Comet counter (similar to that one in the samples), which works great using streaming and long-polling (I am using the Atmosphere jQuery plugin), but fails with WebSocket. I don't believe my code or configuration are broken, as the jQuery PubSub example doesn't work either. I am deploying on GlassFish 3.1 (Grizzly 1.9.31 using the -76 WebSocket protocol draft). WebSocket support on GlassFish is enabled. I've implemented the same WebSocket application using the GlassFish's WebSocket API proving that the WebSocket connection works on GlassFish.

When I try to establish the WebSocket connection using my REST application or the PubSub jQuery sample, the following exception is raised:
SEVERE: java.lang.IllegalStateException: WEB9031: WebappClassLoader unable to load resource [com.sun.grizzly.websockets.BaseServerWebSocket], because it has not yet been started, or was already stopped
        at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1410)
        at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1368)
        at org.atmosphere.container.GlassFishWebSocketSupport$GrizzlyApplication.onConnect(GlassFishWebSocketSupport.java:118)
        at com.sun.grizzly.websockets.BaseWebSocket.onConnect(BaseWebSocket.java:119)
        at com.sun.grizzly.websockets.ServerNetworkHandler.handshake(ServerNetworkHandler.java:102)
        at com.sun.grizzly.websockets.WebSocketEngine.upgrade(WebSocketEngine.java:147)
        at com.sun.grizzly.websockets.WebSocketAsyncFilter.doFilter(WebSocketAsyncFilter.java:52)
        at com.sun.grizzly.arp.DefaultAsyncExecutor.invokeFilters(DefaultAsyncExecutor.java:171)
        at com.sun.grizzly.arp.DefaultAsyncExecutor.interrupt(DefaultAsyncExecutor.java:143)
        at com.sun.grizzly.arp.AsyncProcessorTask.doTask(AsyncProcessorTask.java:94)
        at com.sun.grizzly.http.TaskBase.run(TaskBase.java:193)
        at com.sun.grizzly.http.TaskBase.execute(TaskBase.java:175)
        at com.sun.grizzly.arp.DefaultAsyncHandler.handle(DefaultAsyncHandler.java:145)
        at com.sun.grizzly.arp.AsyncProtocolFilter.execute(AsyncProtocolFilter.java:204)
        at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
        at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
        at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
        at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
        at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
        at java.lang.Thread.run(Thread.java:662)

What does the error mean? Is it possible that Atmosphere doesn't support my older version of the WebSocket support in Grizzly?


If you reply to this email, your message will be added to the discussion below:
http://atmosphere-users-mailling-list.2493822.n2.nabble.com/Jersey-through-Websockets-tp6579407p6685354.html
To unsubscribe from Jersey through Websockets, click here.

Reply | Threaded
Open this post in threaded view
|

Re: Jersey through Websockets

agi_m
In reply to this post by agi_m
One last test case...:)

Deploying the PubSub application on GlassFish 3.1.1 (with Grizzly 1.9.36 which provides support for hybi-06), initializing a WebSocket connection with Firefox 6.0 (supporting hiby-07) fires the following exception on GlassFish:
SEVERE: Invalid Connection header returned: 'keep-alive, Upgrade'
com.sun.grizzly.websockets.HandshakeException: Invalid Connection header returned: 'keep-alive, Upgrade'
        at com.sun.grizzly.websockets.ServerHandShake.checkForHeader(ServerHandShake.java:84)
        at com.sun.grizzly.websockets.ServerHandShake.<init>(ServerHandShake.java:64)
        at com.sun.grizzly.websockets.ServerNetworkHandler.handshake(ServerNetworkHandler.java:95)
        at com.sun.grizzly.websockets.WebSocketEngine.upgrade(WebSocketEngine.java:136)
        at com.sun.grizzly.websockets.WebSocketAsyncFilter.doFilter(WebSocketAsyncFilter.java:52)
        at com.sun.grizzly.arp.DefaultAsyncExecutor.invokeFilters(DefaultAsyncExecutor.java:171)
        at com.sun.grizzly.arp.DefaultAsyncExecutor.interrupt(DefaultAsyncExecutor.java:143)
        at com.sun.grizzly.arp.AsyncProcessorTask.doTask(AsyncProcessorTask.java:94)
        at com.sun.grizzly.http.TaskBase.run(TaskBase.java:193)
        at com.sun.grizzly.http.TaskBase.execute(TaskBase.java:175)
        at com.sun.grizzly.arp.DefaultAsyncHandler.handle(DefaultAsyncHandler.java:145)
        at com.sun.grizzly.arp.AsyncProtocolFilter.execute(AsyncProtocolFilter.java:204)
        at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
        at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
        at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
        at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
        at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
        at java.lang.Thread.run(Thread.java:662)
Reply | Threaded
Open this post in threaded view
|

Re: Jersey through Websockets

jfarcand
Administrator
Hi,

this is clearly a GlassFish issue, not Atmosphere. Please report the issue at http://grizzly.java.net where Justin (the websocket guru) can take a look.

Thanks!

-- Jeanfrancois