From d44a5325ea063dc509e2179b133d4244ec174b06 Mon Sep 17 00:00:00 2001 From: Ludovic Orban Date: Fri, 29 Jan 2021 12:14:10 +0100 Subject: [PATCH] try to instantiate the handler before upgrading Signed-off-by: Ludovic Orban --- .../main/java/org/eclipse/jetty/server/Request.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java index c8913c1a5201..8c7eced85b49 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java @@ -2387,11 +2387,6 @@ public T upgrade(Class handlerClass) throws IO if (response.isCommitted()) throw new IllegalStateException("Cannot upgrade committed response"); - _channel.servletUpgrade(); // tell the channel that it is now handling an upgraded servlet - HttpConnection httpConnection = (HttpConnection)_channel.getConnection(); - httpConnection.getParser().servletUpgrade(); // tell the parser it's now parsing content - AsyncContext asyncContext = forceStartAsync(); // force the servlet in async mode - T handler; try { @@ -2402,6 +2397,11 @@ public T upgrade(Class handlerClass) throws IO throw new ServletException("Unable to instantiate handler class", e); } + _channel.servletUpgrade(); // tell the channel that it is now handling an upgraded servlet + HttpConnection httpConnection = (HttpConnection)_channel.getConnection(); + httpConnection.getParser().servletUpgrade(); // tell the parser it's now parsing content + AsyncContext asyncContext = forceStartAsync(); // force the servlet in async mode + ServletOutputStream outputStream = response.getOutputStream(); ServletInputStream inputStream = getInputStream(); handler.init(new WebConnection()