Skip to content

Commit

Permalink
Fix for #386 [websocket] GlassFish's WebSocket implementation scope i…
Browse files Browse the repository at this point in the history
…ssue
  • Loading branch information
jfarcand committed May 29, 2012
1 parent 9d88b64 commit 63c9297
Showing 1 changed file with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void init(ServletConfig sc) throws ServletException {
public void shutdown() {
WebSocketEngine.getEngine().unregister(application);
super.shutdown();
}
}

/**
* {@inheritDoc}
Expand All @@ -108,8 +108,7 @@ public Action service(AtmosphereRequest request, AtmosphereResponse response)
if (!Utils.webSocketEnabled(request)) {
return super.service(request, response);
} else {
Action action = suspended(request, response);
return action;
return suspended(request, response);;
}
}

Expand All @@ -126,7 +125,6 @@ public String getContainerName() {
private final static class GrizzlyApplication extends WebSocketApplication {

private final AtmosphereConfig config;
private WebSocketProcessor webSocketProcessor;

public GrizzlyApplication(AtmosphereConfig config) {
this.config = config;
Expand Down Expand Up @@ -154,7 +152,9 @@ public void onConnect(com.sun.grizzly.websockets.WebSocket w) {
logger.trace("", e);
}

webSocketProcessor = new WebSocketProcessor(config.framework(), new GrizzlyWebSocket(webSocket, config), config.framework().getWebSocketProtocol());
WebSocketProcessor webSocketProcessor = new WebSocketProcessor(config.framework(),
new GrizzlyWebSocket(webSocket, config), config.framework().getWebSocketProtocol());
webSocket.getRequest().setAttribute("grizzly.webSocketProcessor", webSocketProcessor);
webSocketProcessor.dispatch(r);
} catch (Exception e) {
logger.warn("failed to connect to web socket", e);
Expand All @@ -170,20 +170,31 @@ public boolean isApplicationRequest(Request request) {
public void onClose(com.sun.grizzly.websockets.WebSocket w, DataFrame df) {
super.onClose(w, df);
logger.trace("onClose {} ", w);
// TODO: Need to talk to Ryan about that one.
webSocketProcessor.close(1000);
DefaultWebSocket webSocket = DefaultWebSocket.class.cast(w);
if (webSocket.getRequest().getAttribute("grizzly.webSocketProcessor") != null) {
WebSocketProcessor webSocketProcessor = (WebSocketProcessor) webSocket.getRequest().getAttribute("grizzly.webSocketProcessor");
webSocketProcessor.close(1000);
}
}

@Override
public void onMessage(com.sun.grizzly.websockets.WebSocket w, String text) {
logger.trace("onMessage {} ", w);
webSocketProcessor.invokeWebSocketProtocol(text);
DefaultWebSocket webSocket = DefaultWebSocket.class.cast(w);
if (webSocket.getRequest().getAttribute("grizzly.webSocketProcessor") != null) {
WebSocketProcessor webSocketProcessor = (WebSocketProcessor) webSocket.getRequest().getAttribute("grizzly.webSocketProcessor");
webSocketProcessor.invokeWebSocketProtocol(text);
}
}

@Override
public void onMessage(com.sun.grizzly.websockets.WebSocket w, byte[] bytes) {
logger.trace("onMessage (bytes) {} ", w);
webSocketProcessor.invokeWebSocketProtocol(bytes, 0, bytes.length);
DefaultWebSocket webSocket = DefaultWebSocket.class.cast(w);
if (webSocket.getRequest().getAttribute("grizzly.webSocketProcessor") != null) {
WebSocketProcessor webSocketProcessor = (WebSocketProcessor) webSocket.getRequest().getAttribute("grizzly.webSocketProcessor");
webSocketProcessor.invokeWebSocketProtocol(bytes, 0, bytes.length);
}
}

@Override
Expand Down

0 comments on commit 63c9297

Please sign in to comment.