IWebSocketConnection connection = connectionRegistry.getConnection(application, sessionId, key);
if (connection != null && connection.isOpen())
{
Application oldApplication = ThreadContext.getApplication();
Session oldSession = ThreadContext.getSession();
RequestCycle oldRequestCycle = ThreadContext.getRequestCycle();
WebSocketResponse webResponse = new WebSocketResponse(connection);
try
{
RequestCycle requestCycle;
if (oldRequestCycle == null || message instanceof IWebSocketPushMessage)
{
RequestCycleContext context = new RequestCycleContext(webRequest, webResponse,
application.getRootRequestMapper(), application.getExceptionMapperProvider().get());
requestCycle = application.getRequestCycleProvider().get(context);
requestCycle.getUrlRenderer().setBaseUrl(baseUrl);
ThreadContext.setRequestCycle(requestCycle);
}
else
{
requestCycle = oldRequestCycle;
}
ThreadContext.setApplication(application);
Session session;
if (oldSession == null || message instanceof IWebSocketPushMessage)
{
ISessionStore sessionStore = application.getSessionStore();
session = sessionStore.lookup(webRequest);
ThreadContext.setSession(session);
}
else
{
session = oldSession;
}
IPageManager pageManager = session.getPageManager();
try
{
Page page = getPage(pageManager);
WebSocketRequestHandler requestHandler = new WebSocketRequestHandler(page, connection);