diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java index 8f423e463ff..95b4f59a9ea 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java @@ -29,6 +29,7 @@ import java.nio.channels.ClosedChannelException; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicReference; import javax.servlet.DispatcherType; import javax.servlet.RequestDispatcher; @@ -264,6 +265,8 @@ public class HttpChannel implements Runnable, HttpOutput.Interceptor handle(); } + AtomicReference caller = new AtomicReference<>(); + /** * @return True if the channel is ready to continue handling (ie it is not suspended) */ @@ -297,7 +300,6 @@ public class HttpChannel implements Runnable, HttpOutput.Interceptor throw new IllegalStateException("state=" + _state); _request.setHandled(false); _response.getHttpOutput().reopen(); - _request.setDispatcherType(DispatcherType.REQUEST); List customizers = _configuration.getCustomizers(); if (!customizers.isEmpty()) @@ -305,7 +307,15 @@ public class HttpChannel implements Runnable, HttpOutput.Interceptor for (HttpConfiguration.Customizer customizer : customizers) customizer.customize(getConnector(), _configuration, _request); } - getServer().handle(this); + try + { + _request.setDispatcherType(DispatcherType.REQUEST); + getServer().handle(this); + } + finally + { + _request.setDispatcherType(null); + } break; } @@ -313,8 +323,16 @@ public class HttpChannel implements Runnable, HttpOutput.Interceptor { _request.setHandled(false); _response.getHttpOutput().reopen(); - _request.setDispatcherType(DispatcherType.ASYNC); - getServer().handleAsync(this); + + try + { + _request.setDispatcherType(DispatcherType.ASYNC); + getServer().handleAsync(this); + } + finally + { + _request.setDispatcherType(null); + } break; } @@ -336,8 +354,16 @@ public class HttpChannel implements Runnable, HttpOutput.Interceptor _request.setAttribute(ERROR_STATUS_CODE,code); _request.setHandled(false); _response.getHttpOutput().reopen(); - _request.setDispatcherType(DispatcherType.ERROR); - getServer().handle(this); + + try + { + _request.setDispatcherType(DispatcherType.ERROR); + getServer().handle(this); + } + finally + { + _request.setDispatcherType(null); + } } break; } @@ -390,10 +416,6 @@ public class HttpChannel implements Runnable, HttpOutput.Interceptor else handleException(failure); } - finally - { - _request.setDispatcherType(null); - } action = _state.unhandle(); } 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 44342e23749..8cf22eb9fbc 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 @@ -40,6 +40,7 @@ import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.concurrent.ConcurrentLinkedQueue; import javax.servlet.AsyncContext; import javax.servlet.AsyncListener; @@ -1754,7 +1755,7 @@ public class Request implements HttpServletRequest * @param request the Request metadata */ public void setMetaData(org.eclipse.jetty.http.MetaData.Request request) - { + { _metadata=request; _originalURI=_metadata.getURIString(); setMethod(request.getMethod());