Skip to content

Commit

Permalink
Fixes #1729
Browse files Browse the repository at this point in the history
  • Loading branch information
jfarcand committed Oct 2, 2014
1 parent d35c50d commit 2e099c9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@
import weblogic.websocket.WebSocketContext;
import weblogic.websocket.WebSocketListener;

import javax.servlet.ServletContext;
import java.io.IOException;

import static org.atmosphere.cpr.Broadcaster.ROOT_MASTER;

@weblogic.websocket.annotation.WebSocket(pathPatterns = "/ws/*", timeout = -1, maxMessageSize=8192)
@weblogic.websocket.annotation.WebSocket(pathPatterns = "/ws/*", timeout = -1, maxMessageSize = 8192)
public class WeblogicWebSocketHandler implements WebSocketListener {

private final Logger logger = LoggerFactory.getLogger(WeblogicWebSocketHandler.class);
Expand All @@ -49,6 +48,8 @@ public class WeblogicWebSocketHandler implements WebSocketListener {

@Override
public void init(WebSocketContext webSocketContext) {
logger.info("WebSocketContext initialized {}", webSocketContext);
configure(webSocketContext.getServletContext());
}

@Override
Expand All @@ -64,25 +65,18 @@ public boolean accept(WSHandshakeRequest wsHandshakeRequest, WSHandshakeResponse

@Override
public void onOpen(WebSocketConnection webSocketConnection) {
if (config == null) {
configure();
}

if (webSocketWriteTimeout != -1) webSocketConnection.getWebSocketContext().setTimeoutSecs(webSocketWriteTimeout);
if (webSocketWriteTimeout != -1)
webSocketConnection.getWebSocketContext().setTimeoutSecs(webSocketWriteTimeout);
if (maxTextBufferSize != -1) webSocketConnection.getWebSocketContext().setMaxMessageSize(maxTextBufferSize);

WebSocket webSocket = new WebLogicWebSocket(webSocketConnection, config);
// TODO: Dangerous
webSocketConnection.getWebSocketContext().getServletContext().setAttribute(webSocketConnection.toString(), webSocket);

AtmosphereRequest ar = AtmosphereRequest.cloneRequest(request.get(), true, false, true);

String pathInfo = ar.getPathInfo();
String servletPath = ar.getServletPath();
ar.pathInfo(null).servletPath(pathInfo).contextPath(ar.getContextPath() + servletPath);
request.set(null);
try {
webSocketProcessor.open(webSocket, ar , AtmosphereResponse.newInstance(config, ar, webSocket));
webSocketProcessor.open(webSocket, ar, AtmosphereResponse.newInstance(config, ar, webSocket));
} catch (IOException e) {
logger.error("{}", e);
}
Expand Down Expand Up @@ -148,24 +142,22 @@ public void onClose(WebSocketConnection webSocketConnection, ClosingMessage clos
webSocketProcessor.close(webSocket, closingMessage.getStatusCode());
}

private void configure() {
synchronized(this) {
config = config.getBroadcasterFactory().lookup(ROOT_MASTER).getBroadcasterConfig().getAtmosphereConfig();
webSocketProcessor = WebSocketProcessorFactory.getDefault().getWebSocketProcessor(config.framework());

String s = config.getInitParameter(ApplicationConfig.WEBSOCKET_IDLETIME);
if (s != null) {
webSocketWriteTimeout = Integer.valueOf(s);
} else {
webSocketWriteTimeout = -1;
}

s = config.getInitParameter(ApplicationConfig.WEBSOCKET_MAXTEXTSIZE);
if (s != null) {
maxTextBufferSize = Integer.valueOf(s);
} else {
maxTextBufferSize = -1;
}
private void configure(ServletContext servletContext) {
config = (AtmosphereConfig) servletContext.getAttribute(AtmosphereConfig.class.getName());
webSocketProcessor = WebSocketProcessorFactory.getDefault().getWebSocketProcessor(config.framework());

String s = config.getInitParameter(ApplicationConfig.WEBSOCKET_IDLETIME);
if (s != null) {
webSocketWriteTimeout = Integer.valueOf(s);
} else {
webSocketWriteTimeout = -1;
}

s = config.getInitParameter(ApplicationConfig.WEBSOCKET_MAXTEXTSIZE);
if (s != null) {
maxTextBufferSize = Integer.valueOf(s);
} else {
maxTextBufferSize = -1;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.atmosphere.config.FrameworkConfiguration;
import org.atmosphere.container.BlockingIOCometSupport;
import org.atmosphere.container.Tomcat7BIOSupportWithWebSocket;
import org.atmosphere.container.WebLogicServlet30WithWebSocket;
import org.atmosphere.handler.AbstractReflectorAtmosphereHandler;
import org.atmosphere.handler.ReflectorServletProcessor;
import org.atmosphere.inject.InjectableObjectFactory;
Expand Down Expand Up @@ -915,6 +916,11 @@ public Enumeration<String> getInitParameterNames() {
isInit = true;
config.initComplete();

// wlc 12.x
if (WebLogicServlet30WithWebSocket.class.isAssignableFrom(asyncSupport.getClass())) {
servletConfig.getServletContext().setAttribute(AtmosphereConfig.class.getName(), config);
}

return this;
}

Expand Down

0 comments on commit 2e099c9

Please sign in to comment.