Merge pull request #8619 from eclipse/jetty-12.0.x-8606-scopeListeners
Issue #8606 - Fix to ContextScopeListener for AsyncIOServletTest
This commit is contained in:
commit
04e1df9373
|
@ -1070,61 +1070,37 @@ public class ServletContextHandler extends ContextHandler implements Graceful
|
|||
@Override
|
||||
protected void doStart() throws Exception
|
||||
{
|
||||
getContext().call(() ->
|
||||
{
|
||||
_objFactory.addDecorator(new DeprecationWarning());
|
||||
getServletContext().setAttribute(DecoratedObjectFactory.ATTR, _objFactory);
|
||||
_objFactory.addDecorator(new DeprecationWarning());
|
||||
getServletContext().setAttribute(DecoratedObjectFactory.ATTR, _objFactory);
|
||||
|
||||
if (getContextPath() == null)
|
||||
throw new IllegalStateException("Null contextPath");
|
||||
if (getContextPath() == null)
|
||||
throw new IllegalStateException("Null contextPath");
|
||||
|
||||
Resource baseResource = getBaseResource();
|
||||
if (baseResource != null && baseResource.isAlias())
|
||||
LOG.warn("BaseResource {} is aliased to {} in {}. May not be supported in future releases.",
|
||||
baseResource, baseResource.getTargetURI(), this);
|
||||
Resource baseResource = getBaseResource();
|
||||
if (baseResource != null && baseResource.isAlias())
|
||||
LOG.warn("BaseResource {} is aliased to {} in {}. May not be supported in future releases.",
|
||||
baseResource, baseResource.getTargetURI(), this);
|
||||
|
||||
if (_logger == null)
|
||||
_logger = LoggerFactory.getLogger(ContextHandler.class.getName() + getLogNameSuffix());
|
||||
if (_logger == null)
|
||||
_logger = LoggerFactory.getLogger(ContextHandler.class.getName() + getLogNameSuffix());
|
||||
|
||||
ClassLoader oldClassloader = null;
|
||||
Thread currentThread = null;
|
||||
ContextHandler.Context oldContext = null;
|
||||
// TODO who uses this???
|
||||
if (getServer() != null)
|
||||
_servletContext.setAttribute("org.eclipse.jetty.server.Executor", getServer().getThreadPool());
|
||||
|
||||
// TODO who uses this???
|
||||
if (getServer() != null)
|
||||
_servletContext.setAttribute("org.eclipse.jetty.server.Executor", getServer().getThreadPool());
|
||||
if (_mimeTypes == null)
|
||||
_mimeTypes = new MimeTypes();
|
||||
|
||||
if (_mimeTypes == null)
|
||||
_mimeTypes = new MimeTypes();
|
||||
_durableListeners.addAll(getEventListeners());
|
||||
|
||||
_durableListeners.addAll(getEventListeners());
|
||||
|
||||
ClassLoader loader = getClassLoader();
|
||||
try
|
||||
{
|
||||
// Set the classloader, context and enter scope
|
||||
if (loader != null)
|
||||
{
|
||||
currentThread = Thread.currentThread();
|
||||
oldClassloader = currentThread.getContextClassLoader();
|
||||
currentThread.setContextClassLoader(loader);
|
||||
}
|
||||
|
||||
// defers the calling of super.doStart()
|
||||
startContext();
|
||||
|
||||
contextInitialized();
|
||||
|
||||
LOG.info("Started {}", this);
|
||||
}
|
||||
finally
|
||||
{
|
||||
exitScope(null);
|
||||
// reset the classloader
|
||||
if (loader != null && currentThread != null)
|
||||
currentThread.setContextClassLoader(oldClassloader);
|
||||
}
|
||||
getContext().call(() ->
|
||||
{
|
||||
// defers the calling of super.doStart()
|
||||
startContext();
|
||||
contextInitialized();
|
||||
}, null);
|
||||
|
||||
LOG.info("Started {}", this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -21,6 +21,7 @@ import java.io.UncheckedIOException;
|
|||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Deque;
|
||||
import java.util.Objects;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
@ -94,7 +95,6 @@ import static org.junit.jupiter.api.Assertions.assertSame;
|
|||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
// TODO: most of these tests do not work because the scope listener mechanism is broken.
|
||||
@Disabled
|
||||
public class AsyncIOServletTest extends AbstractTest
|
||||
{
|
||||
|
@ -1210,7 +1210,7 @@ public class AsyncIOServletTest extends AbstractTest
|
|||
{
|
||||
System.err.println("Service " + request);
|
||||
|
||||
HttpInput httpInput = ((ServletContextRequest)request).getHttpInput();
|
||||
HttpInput httpInput = Objects.requireNonNull(ServletContextRequest.getBaseRequest(request)).getHttpInput();
|
||||
httpInput.addInterceptor(new HttpInput.Interceptor()
|
||||
{
|
||||
int state = 0;
|
||||
|
|
|
@ -52,6 +52,7 @@ import org.eclipse.jetty.client.util.BufferingResponseListener;
|
|||
import org.eclipse.jetty.client.util.InputStreamRequestContent;
|
||||
import org.eclipse.jetty.client.util.OutputStreamRequestContent;
|
||||
import org.eclipse.jetty.client.util.StringRequestContent;
|
||||
import org.eclipse.jetty.ee9.nested.ContextHandler;
|
||||
import org.eclipse.jetty.ee9.nested.HttpInput;
|
||||
import org.eclipse.jetty.ee9.nested.HttpOutput;
|
||||
import org.eclipse.jetty.http.HttpHeader;
|
||||
|
@ -65,8 +66,6 @@ import org.eclipse.jetty.io.Connection;
|
|||
import org.eclipse.jetty.io.Content;
|
||||
import org.eclipse.jetty.io.EofException;
|
||||
import org.eclipse.jetty.logging.StacklessLogging;
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
import org.eclipse.jetty.server.internal.HttpChannelState;
|
||||
import org.eclipse.jetty.util.BufferUtil;
|
||||
import org.eclipse.jetty.util.Callback;
|
||||
|
@ -93,7 +92,6 @@ import static org.junit.jupiter.api.Assertions.assertSame;
|
|||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
// TODO: most of these tests do not work because the scope listener mechanism is broken.
|
||||
@Disabled
|
||||
public class AsyncIOServletTest extends AbstractTest
|
||||
{
|
||||
|
@ -107,14 +105,14 @@ public class AsyncIOServletTest extends AbstractTest
|
|||
servletContextHandler.addEventListener(new ContextHandler.ContextScopeListener()
|
||||
{
|
||||
@Override
|
||||
public void enterScope(org.eclipse.jetty.server.Context context, Request request)
|
||||
public void enterScope(ContextHandler.APIContext context, org.eclipse.jetty.ee9.nested.Request request, Object reason)
|
||||
{
|
||||
checkScope();
|
||||
scope.set(new RuntimeException());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exitScope(org.eclipse.jetty.server.Context context, Request request)
|
||||
public void exitScope(ContextHandler.APIContext context, org.eclipse.jetty.ee9.nested.Request request)
|
||||
{
|
||||
assertScope();
|
||||
scope.set(null);
|
||||
|
|
Loading…
Reference in New Issue