PR #12441 - changes from review

Signed-off-by: Lachlan Roberts <lachlan.p.roberts@gmail.com>
This commit is contained in:
Lachlan Roberts 2024-11-08 11:24:51 +11:00
parent 89cc46f500
commit 7eb54fa9aa
No known key found for this signature in database
GPG Key ID: 5663FB7A8FF7E348
7 changed files with 12 additions and 27 deletions

View File

@ -15,9 +15,7 @@ package org.eclipse.jetty.websocket.core.server.internal;
import java.util.concurrent.atomic.AtomicReference;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.server.Context;
import org.eclipse.jetty.server.Response;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.websocket.core.FrameHandler;
import org.eclipse.jetty.websocket.core.server.FrameHandlerFactory;
@ -61,7 +59,7 @@ public class CreatorNegotiator extends WebSocketNegotiator.AbstractNegotiator
}
catch (Throwable t)
{
Response.writeError(request, response, callback, HttpStatus.INTERNAL_SERVER_ERROR_500, t.getMessage());
callback.failed(t);
return null;
}
@ -70,7 +68,7 @@ public class CreatorNegotiator extends WebSocketNegotiator.AbstractNegotiator
FrameHandler frameHandler = factory.newFrameHandler(websocketPojo, request, response);
if (frameHandler == null)
Response.writeError(request, response, callback, HttpStatus.INTERNAL_SERVER_ERROR_500, "No WebSocket FrameHandler was created");
callback.failed(new IllegalStateException("No WebSocket FrameHandler was created"));
return frameHandler;
}

View File

@ -20,7 +20,6 @@ import java.util.List;
import java.util.concurrent.Executor;
import java.util.function.Consumer;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.http.pathmap.PathSpec;
import org.eclipse.jetty.server.Context;
import org.eclipse.jetty.server.Handler;
@ -365,8 +364,8 @@ public class ServerWebSocketContainer extends ContainerLifeCycle implements WebS
catch (Throwable x)
{
if (LOG.isDebugEnabled())
LOG.debug("Could not create WebSocket endpoint");
Response.writeError(rq, rs, cb, HttpStatus.INTERNAL_SERVER_ERROR_500, "Could not create WebSocket endpoint");
LOG.debug("Could not create WebSocket endpoint", x);
cb.failed(x);
return null;
}
};

View File

@ -168,7 +168,7 @@ public class JakartaWebSocketCreator implements WebSocketCreator
{
if (LOG.isDebugEnabled())
LOG.debug("Unable to create websocket: {}", config.getEndpointClass().getName(), x);
Response.writeError(request, response, callback, HttpStatus.INTERNAL_SERVER_ERROR_500, "Unable to create WebSocket");
callback.failed(x);
return null;
}
}

View File

@ -32,9 +32,7 @@ import org.eclipse.jetty.ee10.websocket.server.internal.DelegatedServerUpgradeRe
import org.eclipse.jetty.ee10.websocket.server.internal.DelegatedServerUpgradeResponse;
import org.eclipse.jetty.ee10.websocket.server.internal.JettyServerFrameHandlerFactory;
import org.eclipse.jetty.ee10.websocket.servlet.WebSocketUpgradeFilter;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.http.pathmap.PathSpec;
import org.eclipse.jetty.server.Response;
import org.eclipse.jetty.util.Blocker;
import org.eclipse.jetty.util.component.ContainerLifeCycle;
import org.eclipse.jetty.util.component.Dumpable;
@ -162,7 +160,7 @@ public class JettyWebSocketServerContainer extends ContainerLifeCycle implements
{
if (LOG.isDebugEnabled())
LOG.debug("Could not create WebSocket endpoint", t);
Response.writeError(req, resp, cb, HttpStatus.INTERNAL_SERVER_ERROR_500, "Could not create WebSocket endpoint");
cb.failed(t);
return null;
}
};
@ -215,7 +213,7 @@ public class JettyWebSocketServerContainer extends ContainerLifeCycle implements
{
if (LOG.isDebugEnabled())
LOG.debug("Could not create WebSocket endpoint", t);
Response.writeError(req, resp, cb, HttpStatus.INTERNAL_SERVER_ERROR_500, "Could not create WebSocket endpoint");
cb.failed(t);
return null;
}
};

View File

@ -168,7 +168,7 @@ public class JakartaWebSocketCreator implements WebSocketCreator
{
if (LOG.isDebugEnabled())
LOG.debug("Unable to create WebSocket: {}", config.getEndpointClass().getName(), x);
Response.writeError(request, response, callback, HttpStatus.INTERNAL_SERVER_ERROR_500, "Unable to create WebSocket");
callback.failed(x);
return null;
}
}

View File

@ -37,7 +37,6 @@ import org.eclipse.jetty.ee9.websocket.server.internal.DelegatedServerUpgradeReq
import org.eclipse.jetty.ee9.websocket.server.internal.DelegatedServerUpgradeResponse;
import org.eclipse.jetty.ee9.websocket.server.internal.JettyServerFrameHandlerFactory;
import org.eclipse.jetty.ee9.websocket.servlet.WebSocketUpgradeFilter;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.http.pathmap.PathSpec;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Response;
@ -164,7 +163,7 @@ public class JettyWebSocketServerContainer extends ContainerLifeCycle implements
{
if (LOG.isDebugEnabled())
LOG.debug("Could not create WebSocket endpoint", t);
Response.writeError(req, resp, cb, HttpStatus.INTERNAL_SERVER_ERROR_500, "Could not create WebSocket endpoint");
cb.failed(t);
return null;
}
};
@ -210,14 +209,14 @@ public class JettyWebSocketServerContainer extends ContainerLifeCycle implements
{
Object webSocket = creator.createWebSocket(new DelegatedServerUpgradeRequest(req), new DelegatedServerUpgradeResponse(resp));
if (webSocket == null)
Response.writeError(req, resp, cb, HttpStatus.INTERNAL_SERVER_ERROR_500, "Could not create WebSocket endpoint");
cb.succeeded();
return webSocket;
}
catch (Throwable t)
{
if (LOG.isDebugEnabled())
LOG.debug("Could not create WebSocket endpoint", t);
Response.writeError(req, resp, cb, HttpStatus.INTERNAL_SERVER_ERROR_500, "Could not create WebSocket endpoint");
cb.failed(t);
return null;
}
};

View File

@ -30,7 +30,6 @@ import org.eclipse.jetty.ee9.websocket.server.internal.DelegatedServerUpgradeReq
import org.eclipse.jetty.ee9.websocket.server.internal.DelegatedServerUpgradeResponse;
import org.eclipse.jetty.ee9.websocket.server.internal.JettyServerFrameHandlerFactory;
import org.eclipse.jetty.ee9.websocket.servlet.WebSocketUpgradeFilter;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Response;
import org.eclipse.jetty.util.Callback;
@ -320,15 +319,7 @@ public abstract class JettyWebSocketServlet extends HttpServlet
}
catch (Throwable t)
{
try
{
response.sendError(HttpStatus.INTERNAL_SERVER_ERROR_500, "Could not create WebSocket endpoint");
callback.succeeded();
}
catch (Throwable x)
{
callback.failed(x);
}
callback.failed(t);
return null;
}
}