fix websocket test failures

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
Lachlan Roberts 2022-08-04 16:20:48 +10:00
parent 43d4e47056
commit c1cf35d7d5
3 changed files with 36 additions and 6 deletions

View File

@ -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);
}
}

View File

@ -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

View File

@ -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;