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()