Skip to content

Commit

Permalink
Fixes #1269
Browse files Browse the repository at this point in the history
  • Loading branch information
jfarcand committed Sep 10, 2013
1 parent d4f16af commit f03ddb4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public Jetty9WebSocketHandler(HttpServletRequest request, AtmosphereFramework fr
private AtmosphereRequest cloneRequest(final HttpServletRequest request) {
try {
AtmosphereRequest r = AtmosphereRequest.wrap(request);
return AtmosphereRequest.cloneRequest(r, false, framework.getAtmosphereConfig().isSupportSession(), false);
return AtmosphereRequest.cloneRequest(r, false, false, false);
} catch (Exception ex) {
logger.error("", ex);
throw new RuntimeException("Invalid WebSocket Request");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

import static org.atmosphere.cpr.HeaderConfig.X_ATMOSPHERE_ERROR;
import java.util.concurrent.atomic.AtomicBoolean;

public class JettyWebSocketUtil {

Expand Down Expand Up @@ -80,6 +79,14 @@ public final static Action doService(AsynchronousProcessor cometSupport,
}

public final static WebSocketFactory getFactory(final AtmosphereConfig config, final WebSocketProcessor webSocketProcessor) {

final AtomicBoolean useBuildInSession = new AtomicBoolean(false);
// Override the value.
String s = config.getInitParameter(ApplicationConfig.BUILT_IN_SESSION);
if (s != null) {
useBuildInSession.set(Boolean.valueOf(s));
}

WebSocketFactory webSocketFactory = new WebSocketFactory(new WebSocketFactory.Acceptor() {
public boolean checkOrigin(HttpServletRequest request, String origin) {
// Allow all origins
Expand All @@ -95,7 +102,7 @@ public org.eclipse.jetty.websocket.WebSocket doWebSocketConnect(HttpServletReque
if (s != null && Boolean.valueOf(s)) {
isDestroyable = true;
}
return new JettyWebSocketHandler(AtmosphereRequest.cloneRequest(request, false, config.isSupportSession(), isDestroyable),
return new JettyWebSocketHandler(AtmosphereRequest.cloneRequest(request, false, useBuildInSession.get(), isDestroyable),
config.framework(), webSocketProcessor);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ public static Action doService(AtmosphereRequest req, AtmosphereResponse res,
WebSocketProcessor webSocketProcessor) throws IOException, ServletException {
// First, handshake
if (req.getAttribute(WebSocket.WEBSOCKET_SUSPEND) == null) {

boolean useBuildInSession = true;
// Override the value.
String s = config.getInitParameter(ApplicationConfig.BUILT_IN_SESSION);
if (s != null) {
useBuildInSession= Boolean.valueOf(s);
}

// Information required to send the server handshake message
String key;
String subProtocol = null;
Expand Down Expand Up @@ -122,11 +130,11 @@ public static Action doService(AtmosphereRequest req, AtmosphereResponse res,

RequestFacade facade = (RequestFacade) hsr;
boolean isDestroyable = false;
String s = config.getInitParameter(ApplicationConfig.RECYCLE_ATMOSPHERE_REQUEST_RESPONSE);
s = config.getInitParameter(ApplicationConfig.RECYCLE_ATMOSPHERE_REQUEST_RESPONSE);
if (s != null && Boolean.valueOf(s)) {
isDestroyable = true;
}
StreamInbound inbound = new TomcatWebSocketHandler(AtmosphereRequest.cloneRequest(req, true, config.isSupportSession(), isDestroyable),
StreamInbound inbound = new TomcatWebSocketHandler(AtmosphereRequest.cloneRequest(req, true, useBuildInSession, isDestroyable),
config.framework(), webSocketProcessor);
facade.doUpgrade(inbound);
return new Action(Action.TYPE.CREATED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -606,5 +606,12 @@ public interface ApplicationConfig {
* Value: org.atmosphere.cpr.scanClassPath
*/
String SCAN_CLASSPATH = ApplicationConfig.class.getName() + ".scanClassPath";
/**
* Use a build in {@link javax.servlet.http.HttpSession} when using native WebSocket implementation.
* <p>
* Default: false<br>
* Value: org.atmosphere.cpr.useBuildInSession
*/
String BUILT_IN_SESSION = ApplicationConfig.class.getName() + ".useBuildInSession";
}

0 comments on commit f03ddb4

Please sign in to comment.