fix websocket test failures
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
parent
43d4e47056
commit
c1cf35d7d5
|
@ -30,6 +30,7 @@ import jakarta.websocket.server.ServerEndpointConfig;
|
|||
import org.eclipse.jetty.client.HttpClient;
|
||||
import org.eclipse.jetty.ee10.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.ee10.servlet.ServletContextRequest;
|
||||
import org.eclipse.jetty.ee10.servlet.ServletContextResponse;
|
||||
import org.eclipse.jetty.ee10.websocket.jakarta.client.internal.JakartaWebSocketClientContainer;
|
||||
import org.eclipse.jetty.ee10.websocket.jakarta.server.config.ContainerDefaultConfigurator;
|
||||
import org.eclipse.jetty.ee10.websocket.jakarta.server.config.JakartaWebSocketServletContainerInitializer;
|
||||
|
@ -301,11 +302,24 @@ public class JakartaWebSocketServerContainer extends JakartaWebSocketClientConta
|
|||
ServletContextRequest baseRequest = ServletContextRequest.getBaseRequest(request);
|
||||
if (baseRequest == null)
|
||||
throw new IllegalStateException();
|
||||
ServletContextResponse baseResponse = baseRequest.getResponse();
|
||||
|
||||
try (Blocker.Callback callback = Blocker.callback())
|
||||
{
|
||||
handshaker.upgradeRequest(negotiator, baseRequest, baseRequest.getResponse(), callback, components, defaultCustomizer);
|
||||
callback.block();
|
||||
// Set the wrapped req and resp as attachments on the ServletContext Request/Response, so they
|
||||
// are accessible when websocket-core calls back the Jetty WebSocket creator.
|
||||
baseRequest.setAttachment(request);
|
||||
baseResponse.setAttachment(response);
|
||||
|
||||
if (handshaker.upgradeRequest(negotiator, baseRequest, baseResponse, callback, components, defaultCustomizer))
|
||||
{
|
||||
callback.block();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
baseRequest.setAttachment(null);
|
||||
baseResponse.setAttachment(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ import jakarta.servlet.http.HttpServletRequest;
|
|||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.eclipse.jetty.ee10.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.ee10.servlet.ServletContextRequest;
|
||||
import org.eclipse.jetty.ee10.servlet.ServletContextResponse;
|
||||
import org.eclipse.jetty.ee10.websocket.api.Session;
|
||||
import org.eclipse.jetty.ee10.websocket.api.WebSocketBehavior;
|
||||
import org.eclipse.jetty.ee10.websocket.api.WebSocketContainer;
|
||||
|
@ -212,16 +213,31 @@ public class JettyWebSocketServerContainer extends ContainerLifeCycle implements
|
|||
ServletContextRequest baseRequest = ServletContextRequest.getBaseRequest(request);
|
||||
if (baseRequest == null)
|
||||
throw new IllegalStateException("Base Request not available");
|
||||
ServletContextResponse baseResponse = baseRequest.getResponse();
|
||||
|
||||
WebSocketNegotiator negotiator = new CreatorNegotiator(coreCreator, frameHandlerFactory);
|
||||
Handshaker handshaker = webSocketMappings.getHandshaker();
|
||||
|
||||
try (Blocker.Callback callback = Blocker.callback())
|
||||
{
|
||||
boolean upgraded = handshaker.upgradeRequest(negotiator, baseRequest, baseRequest.getResponse(), callback, components, customizer);
|
||||
callback.block();
|
||||
return upgraded;
|
||||
// Set the wrapped req and resp as attachments on the ServletContext Request/Response, so they
|
||||
// are accessible when websocket-core calls back the Jetty WebSocket creator.
|
||||
baseRequest.setAttachment(request);
|
||||
baseResponse.setAttachment(response);
|
||||
|
||||
if (handshaker.upgradeRequest(negotiator, baseRequest, baseResponse, callback, components, customizer))
|
||||
{
|
||||
callback.block();
|
||||
return !baseResponse.isCommitted();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
baseRequest.setAttachment(null);
|
||||
baseResponse.setAttachment(null);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -172,7 +172,7 @@ public class WebSocketUpgradeFilter implements Filter, Dumpable
|
|||
baseRequest.setAttachment(request);
|
||||
baseResponse.setAttachment(response);
|
||||
|
||||
if (mappings.upgrade(baseRequest, baseResponse, callback, null))
|
||||
if (mappings.upgrade(baseRequest, baseResponse, callback, defaultCustomizer))
|
||||
{
|
||||
callback.block();
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue