Skip to content

Commit

Permalink
Test for ee10 response commit (#9048)
Browse files Browse the repository at this point in the history
* cleanups of ServletRequestState
* pass in context in constructor when creating the AsyncContextEvent

Signed-off-by: Lachlan Roberts <[email protected]>
Co-authored-by: Lachlan Roberts <[email protected]>
  • Loading branch information
gregw and lachlan-roberts authored Dec 22, 2022
1 parent 3d4bb49 commit 040ed85
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 147 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,14 @@ private Content.Chunk produceChunk()
LOG.debug("channel has no new chunk {}", this);
return null;
}
else
{
_servletChannel.getState().onContentAdded();
}
}

assert _chunk != null;
// Release the chunk immediately, if it is empty.
if (!_chunk.hasRemaining() && !_chunk.isTerminal())
if (_chunk != null && !_chunk.hasRemaining() && !_chunk.isTerminal())
{
if (LOG.isDebugEnabled())
LOG.debug("releasing empty chunk {}", this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.util.function.BiConsumer;
import java.util.function.Consumer;

import jakarta.servlet.DispatcherType;
import jakarta.servlet.RequestDispatcher;
import org.eclipse.jetty.ee10.servlet.ServletRequestState.Action;
import org.eclipse.jetty.ee10.servlet.security.Authentication;
Expand Down Expand Up @@ -418,9 +417,8 @@ public boolean handle()

case DISPATCH:
{
dispatch(DispatcherType.REQUEST, () ->
dispatch(() ->
{
ServletContextHandler.ServletContextApi servletContextApi = getServletContextContext();
ServletHandler servletHandler = _context.getServletContextHandler().getServletHandler();
ServletHandler.MappedServlet mappedServlet = _servletContextRequest._mappedServlet;

Expand All @@ -432,7 +430,7 @@ public boolean handle()

case ASYNC_DISPATCH:
{
dispatch(DispatcherType.ASYNC, () ->
dispatch(() ->
{
HttpURI uri;
String pathInContext = Request.getPathInContext(_servletContextRequest);
Expand Down Expand Up @@ -486,7 +484,7 @@ public boolean handle()
code = HttpStatus.INTERNAL_SERVER_ERROR_500;
getResponse().setStatus(code);

// The handling of the original dispatch failed and we are now going to either generate
// The handling of the original dispatch failed, and we are now going to either generate
// and error response ourselves or dispatch for an error page. If there is content left over
// from the failed dispatch, then we try to consume it here and if we fail we add a
// Connection:close. This can't be deferred to COMPLETE as the response will be committed
Expand All @@ -508,7 +506,7 @@ public boolean handle()
// _state.completing();
try (Blocker.Callback blocker = Blocker.callback())
{
dispatch(DispatcherType.ERROR, () -> errorProcessor.process(_servletContextRequest, getResponse(), blocker));
dispatch(() -> errorProcessor.process(_servletContextRequest, getResponse(), blocker));
blocker.block();
}
}
Expand Down Expand Up @@ -646,7 +644,7 @@ public boolean sendErrorOrAbort(String message)
return false;
}

private void dispatch(DispatcherType type, Dispatchable dispatchable) throws Exception
private void dispatch(Dispatchable dispatchable) throws Exception
{
try
{
Expand Down Expand Up @@ -758,11 +756,6 @@ public boolean isExpecting100Continue()
return _expects100Continue;
}

public boolean isExpecting102Processing()
{
return false;
}

@Override
public String toString()
{
Expand Down Expand Up @@ -920,6 +913,7 @@ interface Dispatchable
* then an instance of {@code TransientListeners} must be added to the connector
* in order for them to be invoked.
*/
// TODO: looks like a lot of these methods are never called.
public interface Listener extends EventListener
{
/**
Expand Down Expand Up @@ -1066,7 +1060,7 @@ default void onComplete(Request request)
}
}

private class Listeners implements Listener
private static class Listeners implements Listener
{
private final List<Listener> _listeners;

Expand Down Expand Up @@ -1132,7 +1126,7 @@ public void onRequestEnd(Request request)
@Override
public void onRequestFailure(Request request, Throwable failure)
{
_listeners.forEach(l -> notify(l::onDispatchFailure, request, failure));
_listeners.forEach(l -> notify(l::onRequestFailure, request, failure));
}

@Override
Expand All @@ -1150,7 +1144,7 @@ public void onResponseCommit(Request request)
@Override
public void onResponseContent(Request request, ByteBuffer content)
{
_listeners.forEach(l -> notify(l::onRequestContent, request, content));
_listeners.forEach(l -> notify(l::onResponseContent, request, content));
}

@Override
Expand All @@ -1162,7 +1156,7 @@ public void onResponseEnd(Request request)
@Override
public void onResponseFailure(Request request, Throwable failure)
{
_listeners.forEach(l -> notify(l::onDispatchFailure, request, failure));
_listeners.forEach(l -> notify(l::onResponseFailure, request, failure));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1364,8 +1364,7 @@ public AsyncContext startAsync() throws IllegalStateException
ServletRequestState state = getState();
if (_async == null)
_async = new AsyncContextState(state);
// TODO adapt to new context and base Request
AsyncContextEvent event = new AsyncContextEvent(null, _async, state, this, _response.getHttpServletResponse());
AsyncContextEvent event = new AsyncContextEvent(getContext(), _async, state, this, _response.getHttpServletResponse());
state.startAsync(event);
return _async;
}
Expand All @@ -1378,8 +1377,7 @@ public AsyncContext startAsync(ServletRequest servletRequest, ServletResponse se
ServletRequestState state = getState();
if (_async == null)
_async = new AsyncContextState(state);
// TODO adapt to new context and base Request
AsyncContextEvent event = new AsyncContextEvent(null, _async, state, servletRequest, servletResponse);
AsyncContextEvent event = new AsyncContextEvent(getContext(), _async, state, servletRequest, servletResponse);
state.startAsync(event);
return _async;
}
Expand Down
Loading

0 comments on commit 040ed85

Please sign in to comment.