NullPointerException when using WebSockets with GlassFish v3 (Jetty embedded)

472 views
Skip to first unread message

Christian2M

unread,
Dec 16, 2010, 7:36:17 AM12/16/10
to cometd-users
Hello,

I am getting a NullPointerException when ivoking the HelloService
example on GlassFish using a WebSocket enabled browser. I have tested
this using Chrome 8.0.552.224. It fails to connect using WebSockets
and eventually switches to long-polling mode, which works fine. Yet an
exception is thrown on the server. See below for the complete debug
enabled server output.

Is there any way of getting WebSockets to work with cometd on
Glassfish (Jetty libraries embedded)?

Thanks for your advice.

Christian

=========
My Setup:
=========

Server: Glassfish Server Open Source Edition 3.1-b30 (build 30) with
Jetty v7.1.5.v20100705 Libraries.

Comet Libraries: cometd 2.0.0

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<servlet>
<servlet-name>cometd</servlet-name>
<servlet-class>org.cometd.server.CometdServlet</servlet-class>
<init-param>
<!-- The log level; 0 = warn, 1 = info, 2 = debug -->
<param-name>logLevel</param-name>
<param-value>3</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>cometd</servlet-name>
<url-pattern>/cometd/*</url-pattern>
</servlet-mapping>

<servlet>
<servlet-name>initializer</servlet-name>
<servlet-class>mein.BayeuxInitializer</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>

<filter>
<filter-name>cross-origin</filter-name>
<filter-class>org.eclipse.jetty.servlets.CrossOriginFilter</
filter-class>
<async-supported>true</async-supported>
</filter>
<filter-mapping>
<filter-name>cross-origin</filter-name>
<url-pattern>/cometd/*</url-pattern>
</filter-mapping>


<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
</web-app>







Listening for transport dt_socket at address: 53694
SEVERE: 2010-12-16 13:14:56.234:INFO:bayeux@2001113342:interval=0
SEVERE: 2010-12-16 13:14:56.234:INFO:bayeux@2001113342:jsonDebug=false
SEVERE: 2010-12-16 13:14:56.234:INFO:bayeux@2001113342:long-
polling.autoBatch=true
SEVERE: 2010-12-16 13:14:56.235:INFO:bayeux@2001113342:long-
polling.browserId=BAYEUX_BROWSER
SEVERE: 2010-12-16 13:14:56.235:INFO:bayeux@2001113342:long-
polling.json.metaConnectDeliverOnly=false
SEVERE: 2010-12-16 13:14:56.235:INFO:bayeux@2001113342:long-
polling.json.mimeType=application/json;charset=UTF-8
SEVERE: 2010-12-16 13:14:56.235:INFO:bayeux@2001113342:long-
polling.jsonp.callbackParameter=jsonp
SEVERE: 2010-12-16 13:14:56.235:INFO:bayeux@2001113342:long-
polling.jsonp.metaConnectDeliverOnly=true
SEVERE: 2010-12-16 13:14:56.235:INFO:bayeux@2001113342:long-
polling.jsonp.mimeType=text/javascript;charset=UTF-8
SEVERE: 2010-12-16 13:14:56.236:INFO:bayeux@2001113342:long-
polling.maxSessionsPerBrowser=1
SEVERE: 2010-12-16 13:14:56.335:INFO:bayeux@2001113342:long-
polling.multiSessionInterval=2000
SEVERE: 2010-12-16
13:14:56.335:INFO:bayeux@2001113342:maxInterval=10000
SEVERE: 2010-12-16
13:14:56.335:INFO:bayeux@2001113342:maxLazyTimeout=5000
SEVERE: 2010-12-16
13:14:56.335:INFO:bayeux@2001113342:metaConnectDeliverOnly=false
SEVERE: 2010-12-16
13:14:56.335:INFO:bayeux@2001113342:sweepIntervalMs=997
SEVERE: 2010-12-16
13:14:56.335:INFO:bayeux@2001113342:tickIntervalMs=97
SEVERE: 2010-12-16 13:14:56.335:INFO:bayeux@2001113342:timeout=10000
SEVERE: 2010-12-16
13:14:56.335:INFO:bayeux@2001113342:ws.bufferSize=8192
SEVERE: 2010-12-16
13:14:56.336:INFO:bayeux@2001113342:ws.interval=2500
SEVERE: 2010-12-16
13:14:56.336:INFO:bayeux@2001113342:ws.maxInterval=15000
SEVERE: 2010-12-16
13:14:56.336:INFO:bayeux@2001113342:ws.metaConnectDeliverOnly=false
SEVERE: 2010-12-16 13:14:56.336:INFO:bayeux@2001113342:ws.protocol=
SEVERE: 2010-12-16
13:14:56.336:INFO:bayeux@2001113342:ws.timeout=15000
SEVERE: 2010-12-16 13:14:56.448:DBUG:bayeux@2001113342:> {"channel":"/
meta/handshake","id":"1"} hello_11tnmxr4fgqaa31h21g4ncrftg1
SEVERE: 2010-12-16 13:14:56.448:DBUG:bayeux@2001113342:>> {"channel":"/
meta/handshake","id":"1"}
SEVERE: 2010-12-16 13:14:56.451:DBUG:bayeux@2001113342:<< {"channel":"/
meta/
handshake","clientId":"hello_11tnmxr4fgqaa31h21g4ncrftg1","version":"1.0","successful":true,"minimumVersion":"1.0","id":"1","supportedConnectionTypes":
["websocket","long-polling","callback-polling"]}
SEVERE: 2010-12-16 13:14:56.451:DBUG:bayeux@2001113342:< {"channel":"/
meta/
handshake","clientId":"hello_11tnmxr4fgqaa31h21g4ncrftg1","version":"1.0","successful":true,"minimumVersion":"1.0","id":"1","supportedConnectionTypes":
["websocket","long-polling","callback-polling"]}
SEVERE: 2010-12-16 13:14:56.554:DBUG:bayeux@2001113342:> {"channel":"/
meta/connect","clientId":"hello_11tnmxr4fgqaa31h21g4ncrftg1","advice":
{"interval":-1},"id":"2"} hello_11tnmxr4fgqaa31h21g4ncrftg1
SEVERE: 2010-12-16 13:14:56.554:DBUG:bayeux@2001113342:>> {"channel":"/
meta/connect","clientId":"hello_11tnmxr4fgqaa31h21g4ncrftg1","advice":
{"interval":-1},"id":"2"}
SEVERE: 2010-12-16 13:14:56.649:DBUG:bayeux@2001113342:<< {"channel":"/
meta/connect","successful":true,"id":"2"}
SEVERE: 2010-12-16 13:14:56.649:DBUG:bayeux@2001113342:< {"channel":"/
meta/connect","successful":true,"id":"2"}
SEVERE: 2010-12-16 13:14:56.650:DBUG:bayeux@2001113342:subscribe
hello#processHello to /service/hello
SEVERE: 2010-12-16 13:14:56.651:DBUG:bayeux@2001113342:added /service
SEVERE: 2010-12-16 13:14:56.651:DBUG:bayeux@2001113342:added /service/
hello
INFO: WEB0671: Loading application [WebApplication1] at [/
WebApplication1]
INFO: WebApplication1 was successfully deployed in 4.333 milliseconds.
WARNUNG: StandardWrapperValve[cometd]: PWC1406: Servlet.service() for
servlet cometd threw exception
java.lang.NullPointerException
at
org.eclipse.jetty.websocket.WebSocketFactory.upgrade(WebSocketFactory.java:
92)
at
org.cometd.server.transport.WebSocketTransport.handle(WebSocketTransport.java:
93)
at org.cometd.server.CometdServlet.service(CometdServlet.java:
201)
at org.cometd.server.CometdServlet.service(CometdServlet.java:
165)
at
org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:
1534)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:
343)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:
215)
at
org.eclipse.jetty.servlets.CrossOriginFilter.handle(CrossOriginFilter.java:
186)
at
org.eclipse.jetty.servlets.CrossOriginFilter.doFilter(CrossOriginFilter.java:
158)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:
256)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:
215)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:
279)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:
175)
at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:
655)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:
595)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:
98)
at
com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:
91)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:
162)
at
org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:
326)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:
227)
at
com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:
170)
at
com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:
817)
at
com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:718)
at
com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1007)
at
com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:
225)
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:619)

SEVERE: 2010-12-16 13:15:50.563:DBUG:bayeux@2001113342:> {"channel":"/
meta/handshake","advice":{"timeout":60000,"interval":
0},"version":"1.0","minimumVersion":"0.9","id":"2","supportedConnectionTypes":
["long-polling","callback-polling"]} null
SEVERE: 2010-12-16 13:15:50.564:DBUG:bayeux@2001113342:>> {"channel":"/
meta/handshake","advice":{"timeout":60000,"interval":
0},"version":"1.0","minimumVersion":"0.9","id":"2","supportedConnectionTypes":
["long-polling","callback-polling"]}
SEVERE: 2010-12-16 13:15:50.565:DBUG:bayeux@2001113342:<< {"channel":"/
meta/
handshake","clientId":"219uwok9hspick1n5and5qda4w6","version":"1.0","successful":true,"minimumVersion":"1.0","id":"2","supportedConnectionTypes":
["websocket","long-polling","callback-polling"]}
SEVERE: 2010-12-16 13:15:50.565:DBUG:bayeux@2001113342:< {"channel":"/
meta/
handshake","clientId":"219uwok9hspick1n5and5qda4w6","version":"1.0","successful":true,"minimumVersion":"1.0","id":"2","supportedConnectionTypes":
["websocket","long-polling","callback-polling"]}
SEVERE: 2010-12-16 13:15:50.711:DBUG:bayeux@2001113342:> {"channel":"/
meta/
subscribe","clientId":"219uwok9hspick1n5and5qda4w6","id":"3","subscription":"/
hello"} 219uwok9hspick1n5and5qda4w6
SEVERE: 2010-12-16 13:15:50.711:DBUG:bayeux@2001113342:>> {"channel":"/
meta/
subscribe","clientId":"219uwok9hspick1n5and5qda4w6","id":"3","subscription":"/
hello"}
SEVERE: 2010-12-16 13:15:50.764:DBUG:bayeux@2001113342:added /hello
SEVERE: 2010-12-16 13:15:50.764:DBUG:bayeux@2001113342:<< {"channel":"/
meta/subscribe","successful":true,"id":"3","subscription":"/hello"}
SEVERE: 2010-12-16 13:15:50.765:DBUG:bayeux@2001113342:< {"channel":"/
meta/subscribe","successful":true,"id":"3","subscription":"/hello"}
SEVERE: 2010-12-16 13:15:50.765:DBUG:bayeux@2001113342:> {"channel":"/
service/hello","clientId":"219uwok9hspick1n5and5qda4w6","data":
{"name":"World"},"id":"4"} 219uwok9hspick1n5and5qda4w6
SEVERE: 2010-12-16 13:15:50.865:DBUG:bayeux@2001113342:>> {"channel":"/
service/hello","clientId":"219uwok9hspick1n5and5qda4w6","data":
{"name":"World"},"id":"4"}
SEVERE: 2010-12-16 13:15:50.865:DBUG:bayeux@2001113342:< {"channel":"/
service/hello","data":{"name":"World"},"id":"4"}
SEVERE: 2010-12-16 13:15:50.865:DBUG:bayeux@2001113342:invoke
hello#processHello from 219uwok9hspick1n5and5qda4w6 with {name=World}
SEVERE: 2010-12-16 13:15:50.866:DBUG:bayeux@2001113342:< {"channel":"/
hello","data":{"greeting":"Hello, World"}}
SEVERE: 2010-12-16 13:15:50.866:DBUG:bayeux@2001113342:<< {"channel":"/
service/hello","successful":true,"id":"4"}
SEVERE: 2010-12-16 13:15:50.866:DBUG:bayeux@2001113342:< {"channel":"/
service/hello","successful":true,"id":"4"}
SEVERE: 2010-12-16 13:15:50.712:DBUG:bayeux@2001113342:> {"channel":"/
meta/connect","clientId":"219uwok9hspick1n5and5qda4w6","advice":
{"timeout":0},"connectionType":"long-polling","id":"5"}
219uwok9hspick1n5and5qda4w6
SEVERE: 2010-12-16 13:15:50.967:DBUG:bayeux@2001113342:>> {"channel":"/
meta/connect","clientId":"219uwok9hspick1n5and5qda4w6","advice":
{"timeout":0},"connectionType":"long-polling","id":"5"}
SEVERE: 2010-12-16 13:15:51.065:DBUG:bayeux@2001113342:<< {"channel":"/
meta/connect","advice":{"reconnect":"retry","interval":0,"timeout":
10000},"successful":true,"id":"5"}
SEVERE: 2010-12-16 13:15:51.066:DBUG:bayeux@2001113342:< {"channel":"/
meta/connect","advice":{"reconnect":"retry","interval":0,"timeout":
10000},"successful":true,"id":"5"}
SEVERE: 2010-12-16 13:15:51.216:DBUG:bayeux@2001113342:> {"channel":"/
meta/
connect","clientId":"219uwok9hspick1n5and5qda4w6","connectionType":"long-
polling","id":"6"} 219uwok9hspick1n5and5qda4w6
SEVERE: 2010-12-16 13:15:51.216:DBUG:bayeux@2001113342:>> {"channel":"/
meta/
connect","clientId":"219uwok9hspick1n5and5qda4w6","connectionType":"long-
polling","id":"6"}
SEVERE: 2010-12-16 13:15:51.265:DBUG:bayeux@2001113342:<< {"channel":"/
meta/connect","successful":true,"id":"6"}
SEVERE: 2010-12-16 13:15:55.035:DBUG:bayeux@2001113342:> {"channel":"/
meta/disconnect","clientId":"219uwok9hspick1n5and5qda4w6","id":"7"}
219uwok9hspick1n5and5qda4w6
SEVERE: 2010-12-16 13:15:55.035:DBUG:bayeux@2001113342:>> {"channel":"/
meta/disconnect","clientId":"219uwok9hspick1n5and5qda4w6","id":"7"}
SEVERE: 2010-12-16 13:15:55.035:DBUG:bayeux@2001113342:remove
219uwok9hspick1n5and5qda4w6
SEVERE: 2010-12-16 13:15:55.036:DBUG:bayeux@2001113342:<< {"channel":"/
meta/disconnect","successful":true,"id":"7"}
SEVERE: 2010-12-16 13:15:55.135:DBUG:bayeux@2001113342:< {"channel":"/
meta/disconnect","successful":true,"id":"7"}
SEVERE: 2010-12-16 13:15:55.037:DBUG:bayeux@2001113342:< {"channel":"/
meta/connect","successful":true,"id":"6"}
SEVERE: 2010-12-16 13:15:57.154:DBUG:bayeux@2001113342:removed /hello
SEVERE: 2010-12-16 13:16:15.100:DBUG:bayeux@2001113342:Swept browser
ID c683m16ja9emxcagghrm65gl137n

Simone Bordet

unread,
Dec 16, 2010, 5:40:11 PM12/16/10
to cometd...@googlegroups.com
Hi,

On Thu, Dec 16, 2010 at 13:36, Christian2M <Chris...@web.de> wrote:
> Hello,
>
> I am getting a NullPointerException when ivoking the HelloService
> example on GlassFish using a WebSocket enabled browser. I have tested
> this using Chrome 8.0.552.224. It fails to connect using WebSockets
> and eventually switches to long-polling mode, which works fine. Yet an
> exception is thrown on the server. See below for the complete debug
> enabled server output.
>
> Is there any way of getting WebSockets to work with cometd on
> Glassfish (Jetty libraries embedded)?
>
> Thanks for your advice.
>
> Christian
>
> =========
> My Setup:
> =========
>
> Server: Glassfish Server Open Source Edition 3.1-b30 (build 30) with
> Jetty v7.1.5.v20100705 Libraries.
>
> Comet Libraries: cometd 2.0.0

Can you please try 2.1.0.beta2 and tell if the problem is gone ? We
have made improvements to the JS websocket code since 2.0.0.

Thanks,

Simon
--
http://bordet.blogspot.com
---
Finally, no matter how good the architecture and design are,
to deliver bug-free software with optimal performance and reliability,
the implementation technique must be flawless.   Victoria Livschitz

Christian2M

unread,
Dec 17, 2010, 5:20:55 AM12/17/10
to cometd-users
Hi Simone,

unfortunately the problem persists.

To be sure I have tested it with following setups:

1) Server: Glassfish Server Open Source Edition 3.1-b30 (build 30)
with Jetty v7.1.5.v20100705 Libraries.
Comet Libraries: 2.1.0.beta2

2) Server: Glassfish Server Open Source Edition 3.1-b30 (build 30)
with Jetty v8.0.0.M2 Libraries.
Comet Libraries: 2.1.0.beta2

Both 1) and 2) throw the NPE.

Config 2) additionally prints the following line: SEVERE: Doing
dispatch on timed out continuation for null


I tried to debug the WebSocketFactory upgrade method. Maybe this is
helpful to you.

int draft=request.getIntHeader("Sec-WebSocket-Draft"); //draft
= -1
HttpConnection http = HttpConnection.getCurrentConnection(); //
http = null;
ConnectedEndPoint endp =
(ConnectedEndPoint)http.getEndPoint(); <--- Throws NPE



NPE thrown by 1) and 2):

WARNING: StandardWrapperValve[cometd]: PWC1406: Servlet.service() for
servlet cometd threw exception
java.lang.NullPointerException
at
org.eclipse.jetty.websocket.WebSocketFactory.upgrade(WebSocketFactory.java:
106)
at
org.cometd.server.transport.WebSocketTransport.handle(WebSocketTransport.java:
96)
at org.cometd.server.CometdServlet.service(CometdServlet.java:
152)
at org.cometd.server.CometdServlet.service(CometdServlet.java:
121)
On 16 Dez., 23:40, Simone Bordet <simone.bor...@gmail.com> wrote:
> Hi,
>
>
>
> On Thu, Dec 16, 2010 at 13:36, Christian2M <Christia...@web.de> wrote:
> > Hello,
>
> > I am getting a NullPointerException when ivoking the HelloService
> > example on GlassFish using a WebSocket enabled browser. I have tested
> > this using Chrome 8.0.552.224. It fails to connect using WebSockets
> > and eventually switches to long-polling mode, which works fine. Yet an
> > exception is thrown on the server. See below for the complete debug
> > enabled server output.
>
> > Is there any way of getting WebSockets to work with cometd on
> > Glassfish (Jetty libraries embedded)?
>
> > Thanks for your advice.
>
> > Christian
>
> > =========
> > My Setup:
> > =========
>
> > Server: Glassfish Server Open Source Edition 3.1-b30 (build 30) with
> > Jetty v7.1.5.v20100705 Libraries.
>
> > Comet Libraries: cometd 2.0.0
>
> Can you please try 2.1.0.beta2 and tell if the problem is gone ? We
> have made improvements to the JS websocket code since 2.0.0.
>
> Thanks,
>
> Simon
> --http://bordet.blogspot.com

Simone Bordet

unread,
Dec 17, 2010, 5:44:10 AM12/17/10
to cometd...@googlegroups.com
Hi,

On Fri, Dec 17, 2010 at 11:20, Christian2M <Chris...@web.de> wrote:
> Hi Simone,
>
> unfortunately the problem persists.
>
> To be sure I have tested it with following setups:
>
> 1) Server: Glassfish Server Open Source Edition 3.1-b30 (build 30)
> with Jetty v7.1.5.v20100705 Libraries.
>    Comet Libraries: 2.1.0.beta2
>
> 2) Server: Glassfish Server Open Source Edition 3.1-b30 (build 30)
> with Jetty v8.0.0.M2 Libraries.
>    Comet Libraries: 2.1.0.beta2
>
> Both 1) and 2) throw the NPE.
>
> Config 2) additionally prints the following line: SEVERE: Doing
> dispatch on timed out continuation for null
>
>
> I tried to debug the WebSocketFactory upgrade method. Maybe this is
> helpful to you.
>
>        int draft=request.getIntHeader("Sec-WebSocket-Draft"); //draft
> = -1
>        HttpConnection http = HttpConnection.getCurrentConnection(); //
> http = null;
>        ConnectedEndPoint endp =
> (ConnectedEndPoint)http.getEndPoint(); <--- Throws NPE

The WebSocket server side implementation only works in Jetty 7.
You cannot make it work in GlassFish, because it leverages Jetty
internals (every WebSocket server-side implementation has to do that
because there is no standard API yet).

The call HttpConnection.getCurrentConnection() asks for the Jetty
specific class that handles connections, so it returns null in
GlassFish.

The CometD library is portable across servlet containers, the
HTTP-based transports are portable across servlet containers, but the
WebSocket transport is servlet container specific (in this case to
Jetty).

You should either move your application to Jetty or use a WebSocket
implementation from GlassFish.

Simon
--

Christian2M

unread,
Dec 17, 2010, 7:23:37 AM12/17/10
to cometd-users
Hi Simone,

thanks for your quick response. I'm not sure if I completely
understand how HttpConnection works.

Are you suggesting:

1) I could use the grizzly-websockets and cometd 2.1.0.beta2 would
harness them instead of the native jetty libraries (which I have added
to the glassfish libraries, btw)

or

2) I should abandon cometd and rely on GF+WebSockets only.

Chris
> --http://bordet.blogspot.com

Simone Bordet

unread,
Dec 17, 2010, 9:31:16 AM12/17/10
to cometd...@googlegroups.com
Hi,

On Fri, Dec 17, 2010 at 13:23, Christian2M <Chris...@web.de> wrote:
> Hi Simone,
>
> thanks for your quick response. I'm not sure if I completely
> understand how HttpConnection works.
>
> Are you suggesting:
>
> 1) I could use the grizzly-websockets and cometd 2.1.0.beta2 would
> harness them instead of the native jetty libraries (which I have added
> to the glassfish libraries, btw)

A websocket communication starts with a HTTP request, a particular one
that tells the server that subsequent bytes on the connection will not
be anymore framed as HTTP, but framed as websocket.
Both Jetty and Glassfish are HTTP servers at their core, and both have
a websocket implementation, so they will know when a websocket initial
HTTP request arrives.
When it arrives, both Jetty and Glassfish send to the client a
particular HTTP response signaling to the client that they understood
that the next bytes will be websocket bytes.
Just after having done that, they need to switch their internal
implementation from HTTP to websocket: they need to change the parser
(do not parse HTTP anymore, but websocket now), the generator (which
should not format HTTP responses, but websocket ones), normally also
buffers and other stuff associated with HTTP that now must be
websocket.

Jetty's HttpConnection is the representation of a HTTP connection, and
must be switched to a Jetty's WebSocketConnection, and same with
parser and other stuff.
If you do not run inside Jetty, there will be no HttpConnection, but
there will be the Glassfish equivalent of that.

CometD uses a server-side websocket transport that is based on Jetty's
implementation of websocket.
Since there is no standard API for websocket, you should write a
CometD websocket server-side transport based on Glassfish websocket
implementation in order to be able to plug Glassfish into CometD.

> 2) I should abandon cometd and rely on GF+WebSockets only.

No.
CometD is an abstraction library on top of comet technique, among
which websocket is one. If you don't have websocket support, with
CometD you can fallback to other comet techniques, which you cannot do
if you only use websocket.

A last warning that websocket is still very experimental and it will
take a while to settle, despite browser vendors pushing out draft
implementation of websocket that are incompatible between browser
versions of the same brand.
So it's a nice to have if it works, but don't bet it will work without
problems like HTTP does.

Simon
--

Reply all
Reply to author
Forward
0 new messages