Skip to content

Commit

Permalink
Merge pull request #8619 from eclipse/jetty-12.0.x-8606-scopeListeners
Browse files Browse the repository at this point in the history
Issue #8606 - Fix to ContextScopeListener for AsyncIOServletTest
  • Loading branch information
lachlan-roberts authored Sep 30, 2022
2 parents 597a6af + b893186 commit 04e1df9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1070,61 +1070,37 @@ private void relinkHandlers()
@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);

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());
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 (_mimeTypes == null)
_mimeTypes = new MimeTypes();
if (_logger == null)
_logger = LoggerFactory.getLogger(ContextHandler.class.getName() + getLogNameSuffix());

_durableListeners.addAll(getEventListeners());
// TODO who uses this???
if (getServer() != null)
_servletContext.setAttribute("org.eclipse.jetty.server.Executor", getServer().getThreadPool());

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();
if (_mimeTypes == null)
_mimeTypes = new MimeTypes();

contextInitialized();
_durableListeners.addAll(getEventListeners());

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
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;
Expand Down Expand Up @@ -94,7 +95,6 @@
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
{
Expand Down Expand Up @@ -1210,7 +1210,7 @@ protected void service(HttpServletRequest request, HttpServletResponse response)
{
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
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;
Expand All @@ -65,8 +66,6 @@
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;
Expand All @@ -93,7 +92,6 @@
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
{
Expand All @@ -107,14 +105,14 @@ protected void prepareServer(Transport transport, HttpServlet servlet) throws Ex
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);
Expand Down

0 comments on commit 04e1df9

Please sign in to comment.