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
logger.trace("WebSocket-checkOrigin request {} with origin {}", request.getRequestURI(), origin);
return true;
}
public org.eclipse.jetty.websocket.WebSocket doWebSocketConnect(HttpServletRequest request, String protocol) {
logger.trace("WebSocket-connect request {} with protocol {}", request.getRequestURI(), protocol);
boolean isDestroyable = false;
String s = config.getInitParameter(ApplicationConfig.RECYCLE_ATMOSPHERE_REQUEST_RESPONSE);
if (s != null && Boolean.valueOf(s)) {
isDestroyable = true;
}
if (!webSocketProcessor.handshake(request)) {
// res.sendError(HttpServletResponse.SC_FORBIDDEN, "WebSocket requests rejected.");
throw new IllegalStateException();
}
return new JettyWebSocketHandler(AtmosphereRequest.cloneRequest(request, false, useBuildInSession.get(), isDestroyable),
config.framework(), webSocketProcessor);
}
});
int bufferSize = 8192;
if (config.getInitParameter(ApplicationConfig.WEBSOCKET_BUFFER_SIZE) != null) {
bufferSize = Integer.valueOf(config.getInitParameter(ApplicationConfig.WEBSOCKET_BUFFER_SIZE));
}
logger.debug("WebSocket Buffer size {}", bufferSize);
webSocketFactory.setBufferSize(bufferSize);
int timeOut = 5 * 60000;
if (config.getInitParameter(ApplicationConfig.WEBSOCKET_IDLETIME) != null) {
timeOut = Integer.valueOf(config.getInitParameter(ApplicationConfig.WEBSOCKET_IDLETIME));
}
logger.debug("WebSocket idle timeout {}", timeOut);
webSocketFactory.setMaxIdleTime(timeOut);
int maxTextBufferSize = 8192;
if (config.getInitParameter(ApplicationConfig.WEBSOCKET_MAXTEXTSIZE) != null) {
maxTextBufferSize = Integer.valueOf(config.getInitParameter(ApplicationConfig.WEBSOCKET_MAXTEXTSIZE));
}
logger.debug("WebSocket maxTextBufferSize {}", maxTextBufferSize);
webSocketFactory.setMaxTextMessageSize(maxTextBufferSize);
int maxBinaryBufferSize = 8192;
if (config.getInitParameter(ApplicationConfig.WEBSOCKET_MAXBINARYSIZE) != null) {
maxBinaryBufferSize = Integer.valueOf(config.getInitParameter(ApplicationConfig.WEBSOCKET_MAXBINARYSIZE));
}
logger.debug("WebSocket maxBinaryBufferSize {}", maxBinaryBufferSize);
webSocketFactory.setMaxBinaryMessageSize(maxBinaryBufferSize);
if (config.getInitParameter(ApplicationConfig.JETTY_WEBSOCKET_MIN_VERSION) != null) {
int minVersion = Integer.valueOf(config.getInitParameter(ApplicationConfig.JETTY_WEBSOCKET_MIN_VERSION));
webSocketFactory.setMinVersion(minVersion);
logger.debug("WebSocket Jetty minVersion {}", minVersion);
}
return webSocketFactory;
}