---
.../eclipse/jetty/ee9/nested/ContextHandler.java | 7 -------
.../eclipse/jetty/ee9/nested/ErrorHandler.java | 4 +---
.../eclipse/jetty/ee9/nested/HttpChannel.java | 12 ++----------
.../jetty/ee9/nested/HttpChannelState.java | 3 +--
.../org/eclipse/jetty/ee9/nested/Request.java | 16 ++++++++++++++++
.../jetty/ee9/servlet/ServletHandler.java | 5 -----
6 files changed, 20 insertions(+), 27 deletions(-)
diff --git a/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/ContextHandler.java b/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/ContextHandler.java
index b45ea51b149..c270128d6cb 100644
--- a/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/ContextHandler.java
+++ b/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/ContextHandler.java
@@ -97,9 +97,6 @@ import org.eclipse.jetty.util.security.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static org.eclipse.jetty.ee9.nested.HttpChannel.SERVLET_CONTEXT_ATTRIBUTE;
-import static org.eclipse.jetty.ee9.nested.HttpChannel.SERVLET_PATH_IN_CONTEXT_ATTRIBUTE;
-
/**
* ContextHandler.
*
@@ -905,10 +902,6 @@ public class ContextHandler extends ScopedHandler implements Attributes, Supplie
(DispatcherType.INCLUDE.equals(dispatch) || !target.startsWith("/")) ? oldPathInContext : pathInContext);
org.eclipse.jetty.server.handler.ContextHandler.ScopedContext context = getCoreContextHandler().getContext();
-
- baseRequest.setAttribute(SERVLET_CONTEXT_ATTRIBUTE, _apiContext);
- baseRequest.setAttribute(SERVLET_PATH_IN_CONTEXT_ATTRIBUTE, baseRequest.getPathInContext());
-
if (context == org.eclipse.jetty.server.handler.ContextHandler.getCurrentContext())
{
nextScope(target, baseRequest, request, response);
diff --git a/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/ErrorHandler.java b/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/ErrorHandler.java
index 141fc78fce5..eb86c025fd8 100644
--- a/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/ErrorHandler.java
+++ b/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/ErrorHandler.java
@@ -45,8 +45,6 @@ import org.eclipse.jetty.util.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static org.eclipse.jetty.ee9.nested.HttpChannel.SERVLET_CONTEXT_ATTRIBUTE;
-
/**
* Handler for Error pages
*/
@@ -91,7 +89,7 @@ public class ErrorHandler extends AbstractHandler
// This logic really should be in ErrorPageErrorHandler, but some implementations extend ErrorHandler
// and implement ErrorPageMapper directly, so we do this here in the base class.
String errorPage = (this instanceof ErrorPageMapper) ? ((ErrorPageMapper)this).getErrorPage(request) : null;
- ServletContext context = (ServletContext)request.getAttribute(SERVLET_CONTEXT_ATTRIBUTE);
+ ServletContext context = baseRequest.getLastContext();
Dispatcher errorDispatcher = (errorPage != null && context != null)
? (Dispatcher)context.getRequestDispatcher(errorPage) : null;
diff --git a/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/HttpChannel.java b/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/HttpChannel.java
index 38ed7c9144f..843745510c4 100644
--- a/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/HttpChannel.java
+++ b/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/HttpChannel.java
@@ -32,7 +32,6 @@ import java.util.stream.Stream;
import jakarta.servlet.DispatcherType;
import jakarta.servlet.RequestDispatcher;
-import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import org.eclipse.jetty.http.BadMessageException;
import org.eclipse.jetty.http.HttpException;
@@ -73,9 +72,6 @@ import static org.eclipse.jetty.util.thread.Invocable.InvocationType.NON_BLOCKIN
public class HttpChannel implements Runnable, HttpOutput.Interceptor
{
private static final Logger LOG = LoggerFactory.getLogger(HttpChannel.class);
- public static final String SERVLET_CONTEXT_ATTRIBUTE = "jetty.servletContext.attribute";
- public static final String SERVLET_NAME_ATTRIBUTE = "jetty.servletName.attribute";
- public static final String SERVLET_PATH_IN_CONTEXT_ATTRIBUTE = "jetty.servletPathInContext.attribute";
private final ContextHandler _contextHandler;
private final ConnectionMetaData _connectionMetaData;
@@ -1014,15 +1010,11 @@ public class HttpChannel implements Runnable, HttpOutput.Interceptor
if (idleTO >= 0 && getIdleTimeout() != _oldIdleTimeout)
setIdleTimeout(_oldIdleTimeout);
- // TODO: We're not in scope for the servlet context so this won't always work.
if (getServer().getRequestLog() instanceof CustomRequestLog)
{
- String servletName = (String)_request.getAttribute(SERVLET_NAME_ATTRIBUTE);
- String pathInContext = (String)_request.getAttribute(SERVLET_PATH_IN_CONTEXT_ATTRIBUTE);
- ServletContext servletContext = (ServletContext)_request.getAttribute(SERVLET_CONTEXT_ATTRIBUTE);
CustomRequestLog.LogDetail logDetail = new CustomRequestLog.LogDetail(
- servletName,
- servletContext.getRealPath(pathInContext)
+ _request.getServletName(),
+ _request.getLastContext().getRealPath(_request.getLastPathInContext())
);
_request.setAttribute(CustomRequestLog.LOG_DETAIL, logDetail);
}
diff --git a/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/HttpChannelState.java b/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/HttpChannelState.java
index 75c57d36dca..ce17bdea656 100644
--- a/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/HttpChannelState.java
+++ b/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/HttpChannelState.java
@@ -35,7 +35,6 @@ import static jakarta.servlet.RequestDispatcher.ERROR_MESSAGE;
import static jakarta.servlet.RequestDispatcher.ERROR_REQUEST_URI;
import static jakarta.servlet.RequestDispatcher.ERROR_SERVLET_NAME;
import static jakarta.servlet.RequestDispatcher.ERROR_STATUS_CODE;
-import static org.eclipse.jetty.ee9.nested.HttpChannel.SERVLET_CONTEXT_ATTRIBUTE;
/**
* Implementation of AsyncContext interface that holds the state of request-response cycle.
@@ -923,7 +922,7 @@ public class HttpChannelState
response.setStatus(code);
response.errorClose();
- ServletContext errorContext = (ServletContext)request.getAttribute(SERVLET_CONTEXT_ATTRIBUTE);
+ ServletContext errorContext = request.getLastContext();
request.setAttribute(ErrorHandler.ERROR_CONTEXT, errorContext);
request.setAttribute(ERROR_REQUEST_URI, request.getRequestURI());
request.setAttribute(ERROR_SERVLET_NAME, request.getServletName());
diff --git a/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/Request.java b/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/Request.java
index 294f9a655de..8bf16a94abe 100644
--- a/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/Request.java
+++ b/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/Request.java
@@ -188,6 +188,8 @@ public class Request implements HttpServletRequest
private long _timeStamp;
private MultiPartFormInputStream _multiParts; //if the request is a multi-part mime
private AsyncContextState _async;
+ private String _lastPathInContext;
+ private ContextHandler.APIContext _lastContext;
public Request(HttpChannel channel, HttpInput input)
{
@@ -700,8 +702,22 @@ public class Request implements HttpServletRequest
{
_context = context;
_pathInContext = pathInContext;
+ if (context != null)
+ {
+ _lastContext = context;
+ _lastPathInContext = pathInContext;
+ }
}
+ public ContextHandler.APIContext getLastContext()
+ {
+ return _lastContext;
+ }
+
+ public String getLastPathInContext()
+ {
+ return _lastPathInContext;
+ }
@Override
public String getContextPath()
{
diff --git a/jetty-ee9/jetty-ee9-servlet/src/main/java/org/eclipse/jetty/ee9/servlet/ServletHandler.java b/jetty-ee9/jetty-ee9-servlet/src/main/java/org/eclipse/jetty/ee9/servlet/ServletHandler.java
index 6ee23353b9f..c192fce8108 100644
--- a/jetty-ee9/jetty-ee9-servlet/src/main/java/org/eclipse/jetty/ee9/servlet/ServletHandler.java
+++ b/jetty-ee9/jetty-ee9-servlet/src/main/java/org/eclipse/jetty/ee9/servlet/ServletHandler.java
@@ -70,8 +70,6 @@ import org.eclipse.jetty.util.thread.AutoLock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static org.eclipse.jetty.ee9.nested.HttpChannel.SERVLET_NAME_ATTRIBUTE;
-
/**
* Servlet HttpHandler.
*
@@ -470,10 +468,7 @@ public class ServletHandler extends ScopedHandler
ServletPathMapping servletPathMapping = mappedServlet.getServletPathMapping(target, matched.getMatchedPath());
if (servletPathMapping != null)
- {
baseRequest.setServletPathMapping(servletPathMapping);
- baseRequest.setAttribute(SERVLET_NAME_ATTRIBUTE, servletPathMapping.getServletName());
- }
}
if (LOG.isDebugEnabled())
From d5c81f9f93fafab99fc4938aa22f67c0eefbfca3 Mon Sep 17 00:00:00 2001
From: Lachlan Roberts
Date: Thu, 22 Jun 2023 21:07:09 +1000
Subject: [PATCH 25/63] fix checkstyle error
Signed-off-by: Lachlan Roberts
---
.../src/main/java/org/eclipse/jetty/ee9/nested/Request.java | 1 +
1 file changed, 1 insertion(+)
diff --git a/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/Request.java b/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/Request.java
index 8bf16a94abe..b978e217849 100644
--- a/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/Request.java
+++ b/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/Request.java
@@ -718,6 +718,7 @@ public class Request implements HttpServletRequest
{
return _lastPathInContext;
}
+
@Override
public String getContextPath()
{
From 0b1c28a8883bb70421a228d1a72644d6125f2baa Mon Sep 17 00:00:00 2001
From: Greg Wilkins
Date: Thu, 22 Jun 2023 17:04:49 +0200
Subject: [PATCH 26/63] Jetty 12 inserted handler in ee10 servlet context
(#9927)
This PR refactors the ee10 handing of servlet API request and response objects:
+ The ServletContextHandler matches the request to a servlet and creates a one time only ServletContextRequest and a ServletContextResponse
+ A reusable ServletChannel object with all the heavy weight HttpInput and HttpOutput object is associated with the ServletContextRequest and ServletContextResponse.
+ Once the handling reaches the ServletHandler, the possibly wrapped request, response and callback are associated with the ServletChannel before handling.
+ Were possible the ServletApiRequest and ServletApiResponse use the possibly wrapped request/response
Added tests to check that GzipHandler can now be nested inside of an EE10 context.
---------
Signed-off-by: Ludovic Orban
Signed-off-by: gregw
Co-authored-by: Ludovic Orban
---
.../org/eclipse/jetty/http/HttpFields.java | 169 +++++++++-
.../eclipse/jetty/http/HttpFieldsTest.java | 1 +
.../eclipse/jetty/server/ResourceService.java | 8 +-
.../server/handler/gzip/GzipHandler.java | 14 +-
.../server/internal/HttpChannelState.java | 20 +-
.../java/org/eclipse/jetty/util/Blocker.java | 1 -
.../core/server/ServerUpgradeResponse.java | 2 +
.../server/internal/HttpFieldsWrapper.java | 166 ----------
.../internal/ServerUpgradeResponseImpl.java | 11 +-
.../internal/WebSocketHttpFieldsWrapper.java | 116 ++++---
.../ee10/servlet/AsyncContentProducer.java | 19 +-
.../jetty/ee10/servlet/AsyncContextState.java | 2 +-
.../jetty/ee10/servlet/DebugListener.java | 26 +-
.../jetty/ee10/servlet/DefaultServlet.java | 15 +-
.../jetty/ee10/servlet/Dispatcher.java | 2 +-
.../jetty/ee10/servlet/ErrorHandler.java | 10 +-
.../eclipse/jetty/ee10/servlet/HttpInput.java | 4 +-
.../jetty/ee10/servlet/HttpOutput.java | 102 +++---
.../jetty/ee10/servlet/PushBuilderImpl.java | 2 +-
.../jetty/ee10/servlet/ServletApiRequest.java | 255 +++++++--------
.../ee10/servlet/ServletApiResponse.java | 302 ++++++++----------
.../jetty/ee10/servlet/ServletChannel.java | 186 +++++++----
.../ee10/servlet/ServletContextHandler.java | 121 ++++++-
.../ee10/servlet/ServletContextRequest.java | 101 +++---
.../ee10/servlet/ServletContextResponse.java | 283 ++++++++++++----
.../jetty/ee10/servlet/ServletHandler.java | 13 +-
.../servlet/ServletMultiPartFormData.java | 4 +-
.../ee10/servlet/ServletRequestState.java | 10 +-
.../jetty/ee10/servlet/SessionHandler.java | 2 +-
.../jetty/ee10/servlet/AsyncServletTest.java | 2 +-
.../jetty/ee10/servlet/GzipHandlerTest.java | 175 ++++++----
.../servlet/ServletContextHandlerTest.java | 7 +-
.../ee10/servlet/ServletHandlerTest.java | 1 -
.../ee10/test/GzipWithSendErrorTest.java | 3 +-
.../test/resources/add-jetty-test-webapp.xml | 18 +-
.../jetty/ee10/webapp/WebAppContext.java | 6 +-
.../JakartaWebSocketServerContainer.java | 2 +-
.../server/JettyWebSocketServerContainer.java | 2 +-
.../server/JettyWebSocketServlet.java | 2 +-
.../servlet/WebSocketUpgradeFilter.java | 2 +-
.../eclipse/jetty/ee9/nested/HttpOutput.java | 3 +-
.../ee9/servlets/CloseableDoSFilterTest.java | 2 -
.../src/main/resources/modules/demo-root.mod | 1 +
.../resources/modules/demo.d/root/favicon.ico | Bin 0 -> 1150 bytes
.../tests/distribution/DemoModulesTests.java | 62 ++++
45 files changed, 1314 insertions(+), 941 deletions(-)
delete mode 100644 jetty-core/jetty-websocket/jetty-websocket-core-server/src/main/java/org/eclipse/jetty/websocket/core/server/internal/HttpFieldsWrapper.java
create mode 100644 jetty-home/src/main/resources/modules/demo.d/root/favicon.ico
diff --git a/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java b/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java
index 393732e4c21..26a2b4969c5 100644
--- a/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java
+++ b/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java
@@ -1204,6 +1204,167 @@ public interface HttpFields extends Iterable, Supplier
// return a merged header with missing ensured values added
return new HttpField(ensure.getHeader(), ensure.getName(), v.toString());
}
+
+ /**
+ * A wrapper of {@link HttpFields}.
+ */
+ class Wrapper implements Mutable
+ {
+ private final Mutable _fields;
+
+ public Wrapper(Mutable fields)
+ {
+ _fields = fields;
+ }
+
+ /**
+ * Called when a field is added (including as part of a put).
+ * @param field The field being added.
+ * @return The field to add, or null if the add is to be ignored.
+ */
+ public HttpField onAddField(HttpField field)
+ {
+ return field;
+ }
+
+ /**
+ * Called when a field is removed (including as part of a put).
+ * @param field The field being removed.
+ * @return True if the field should be removed, false otherwise.
+ */
+ public boolean onRemoveField(HttpField field)
+ {
+ return true;
+ }
+
+ @Override
+ public HttpFields takeAsImmutable()
+ {
+ return Mutable.super.takeAsImmutable();
+ }
+
+ @Override
+ public int size()
+ {
+ // This impl needed only as an optimization
+ return _fields.size();
+ }
+
+ @Override
+ public Stream stream()
+ {
+ // This impl needed only as an optimization
+ return _fields.stream();
+ }
+
+ @Override
+ public Mutable add(HttpField field)
+ {
+ // This impl needed only as an optimization
+ if (field != null)
+ {
+ field = onAddField(field);
+ if (field != null)
+ return _fields.add(field);
+ }
+ return this;
+ }
+
+ @Override
+ public ListIterator listIterator()
+ {
+ ListIterator i = _fields.listIterator();
+ return new ListIterator<>()
+ {
+ HttpField last;
+
+ @Override
+ public boolean hasNext()
+ {
+ return i.hasNext();
+ }
+
+ @Override
+ public HttpField next()
+ {
+ return last = i.next();
+ }
+
+ @Override
+ public boolean hasPrevious()
+ {
+ return i.hasPrevious();
+ }
+
+ @Override
+ public HttpField previous()
+ {
+ return last = i.previous();
+ }
+
+ @Override
+ public int nextIndex()
+ {
+ return i.nextIndex();
+ }
+
+ @Override
+ public int previousIndex()
+ {
+ return i.previousIndex();
+ }
+
+ @Override
+ public void remove()
+ {
+ if (last != null && onRemoveField(last))
+ {
+ last = null;
+ i.remove();
+ }
+ }
+
+ @Override
+ public void set(HttpField field)
+ {
+ if (field == null)
+ {
+ if (last != null && onRemoveField(last))
+ {
+ last = null;
+ i.remove();
+ }
+ }
+ else
+ {
+ if (last != null && onRemoveField(last))
+ {
+ field = onAddField(field);
+ if (field != null)
+ {
+ last = null;
+ i.set(field);
+ }
+ }
+ }
+ }
+
+ @Override
+ public void add(HttpField field)
+ {
+ if (field != null)
+ {
+ field = onAddField(field);
+ if (field != null)
+ {
+ last = null;
+ i.add(field);
+ }
+ }
+ }
+ };
+ }
+ }
}
/**
@@ -1391,8 +1552,12 @@ public interface HttpFields extends Iterable, Supplier
public int hashCode()
{
int hash = 0;
- for (int i = _fields.length; i-- > 0; )
- hash ^= _fields[i].hashCode();
+ for (int i = _size; i-- > 0; )
+ {
+ HttpField field = _fields[i];
+ if (field != null)
+ hash ^= field.hashCode();
+ }
return hash;
}
diff --git a/jetty-core/jetty-http/src/test/java/org/eclipse/jetty/http/HttpFieldsTest.java b/jetty-core/jetty-http/src/test/java/org/eclipse/jetty/http/HttpFieldsTest.java
index 8e1b6f1fbb7..6d848fca80c 100644
--- a/jetty-core/jetty-http/src/test/java/org/eclipse/jetty/http/HttpFieldsTest.java
+++ b/jetty-core/jetty-http/src/test/java/org/eclipse/jetty/http/HttpFieldsTest.java
@@ -54,6 +54,7 @@ public class HttpFieldsTest
return Stream.of(
HttpFields.build(),
HttpFields.build(0),
+ new HttpFields.Mutable.Wrapper(HttpFields.build()),
new HttpFields.Mutable()
{
private final HttpFields.Mutable fields = HttpFields.build();
diff --git a/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/ResourceService.java b/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/ResourceService.java
index bdd623f7829..48d998ddf6a 100644
--- a/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/ResourceService.java
+++ b/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/ResourceService.java
@@ -589,11 +589,8 @@ public class ResourceService
return null;
String contextPath = request.getContext().getContextPath();
-
- if (LOG.isDebugEnabled())
- LOG.debug("welcome={}", welcomeTarget);
-
WelcomeMode welcomeMode = getWelcomeMode();
+
welcomeTarget = switch (welcomeMode)
{
case REDIRECT, REHANDLE -> HttpURI.build(request.getHttpURI())
@@ -602,6 +599,9 @@ public class ResourceService
case SERVE -> welcomeTarget;
};
+ if (LOG.isDebugEnabled())
+ LOG.debug("welcome {} {}", welcomeMode, welcomeTarget);
+
return new WelcomeAction(welcomeTarget, welcomeMode);
}
diff --git a/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/gzip/GzipHandler.java b/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/gzip/GzipHandler.java
index e74dd489361..f9e10e33dfe 100644
--- a/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/gzip/GzipHandler.java
+++ b/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/gzip/GzipHandler.java
@@ -526,9 +526,9 @@ public class GzipHandler extends Handler.Wrapper implements GzipFactory
if (Request.as(request, GzipRequest.class) != null)
return next.handle(request, response, callback);
- String path = Request.getPathInContext(request);
- boolean tryInflate = getInflateBufferSize() >= 0 && isPathInflatable(path);
- boolean tryDeflate = _methods.test(request.getMethod()) && isPathDeflatable(path) && isMimeTypeDeflatable(request.getContext().getMimeTypes(), path);
+ String pathInContext = Request.getPathInContext(request);
+ boolean tryInflate = getInflateBufferSize() >= 0 && isPathInflatable(pathInContext);
+ boolean tryDeflate = _methods.test(request.getMethod()) && isPathDeflatable(pathInContext) && isMimeTypeDeflatable(request.getContext().getMimeTypes(), pathInContext);
// Can we skip looking at the request and wrapping request or response?
if (!tryInflate && !tryDeflate)
@@ -624,15 +624,15 @@ public class GzipHandler extends Handler.Wrapper implements GzipFactory
/**
* Test if the provided Request URI is allowed to be inflated based on the Path Specs filters.
*
- * @param requestURI the request uri
+ * @param pathInContext the request path in context
* @return whether decompressing is allowed for the given the path.
*/
- protected boolean isPathInflatable(String requestURI)
+ protected boolean isPathInflatable(String pathInContext)
{
- if (requestURI == null)
+ if (pathInContext == null)
return true;
- return _inflatePaths.test(requestURI);
+ return _inflatePaths.test(pathInContext);
}
/**
diff --git a/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/internal/HttpChannelState.java b/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/internal/HttpChannelState.java
index 31173e8cf4b..f4315df47da 100644
--- a/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/internal/HttpChannelState.java
+++ b/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/internal/HttpChannelState.java
@@ -104,7 +104,6 @@ public class HttpChannelState implements HttpChannel, Components
private final HandlerInvoker _handlerInvoker = new HandlerInvoker();
private final ConnectionMetaData _connectionMetaData;
private final SerializedInvoker _serializedInvoker;
- private final Attributes _requestAttributes = new Attributes.Lazy();
private final ResponseHttpFields _responseHeaders = new ResponseHttpFields();
private Thread _handling;
private boolean _handled;
@@ -157,7 +156,6 @@ public class HttpChannelState implements HttpChannel, Components
_streamSendState = StreamSendState.SENDING;
// Recycle.
- _requestAttributes.clearAttributes();
_responseHeaders.reset();
_handling = null;
_handled = false;
@@ -741,6 +739,7 @@ public class HttpChannelState implements HttpChannel, Components
private final MetaData.Request _metaData;
private final AutoLock _lock;
private final LongAdder _contentBytesRead = new LongAdder();
+ private final Attributes _attributes = new Attributes.Lazy();
private HttpChannelState _httpChannelState;
private Request _loggedRequest;
private HttpFields _trailers;
@@ -777,26 +776,25 @@ public class HttpChannelState implements HttpChannel, Components
@Override
public Object getAttribute(String name)
{
- HttpChannelState httpChannel = getHttpChannelState();
if (name.startsWith("org.eclipse.jetty"))
{
if (Server.class.getName().equals(name))
- return httpChannel.getConnectionMetaData().getConnector().getServer();
+ return getConnectionMetaData().getConnector().getServer();
if (HttpChannelState.class.getName().equals(name))
- return httpChannel;
+ return getHttpChannelState();
// TODO: is the instanceof needed?
// TODO: possibly remove this if statement or move to Servlet.
if (HttpConnection.class.getName().equals(name) &&
getConnectionMetaData().getConnection() instanceof HttpConnection)
return getConnectionMetaData().getConnection();
}
- return httpChannel._requestAttributes.getAttribute(name);
+ return _attributes.getAttribute(name);
}
@Override
public Object removeAttribute(String name)
{
- return getHttpChannelState()._requestAttributes.removeAttribute(name);
+ return _attributes.removeAttribute(name);
}
@Override
@@ -804,19 +802,19 @@ public class HttpChannelState implements HttpChannel, Components
{
if (Server.class.getName().equals(name) || HttpChannelState.class.getName().equals(name) || HttpConnection.class.getName().equals(name))
return null;
- return getHttpChannelState()._requestAttributes.setAttribute(name, attribute);
+ return _attributes.setAttribute(name, attribute);
}
@Override
public Set getAttributeNameSet()
{
- return getHttpChannelState()._requestAttributes.getAttributeNameSet();
+ return _attributes.getAttributeNameSet();
}
@Override
public void clearAttributes()
{
- getHttpChannelState()._requestAttributes.clearAttributes();
+ _attributes.clearAttributes();
}
@Override
@@ -837,7 +835,7 @@ public class HttpChannelState implements HttpChannel, Components
return _connectionMetaData;
}
- HttpChannelState getHttpChannelState()
+ private HttpChannelState getHttpChannelState()
{
try (AutoLock ignore = _lock.lock())
{
diff --git a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/Blocker.java b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/Blocker.java
index 529f612c3d3..2aa2c1814b7 100644
--- a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/Blocker.java
+++ b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/Blocker.java
@@ -208,7 +208,6 @@ public class Blocker
/**
* A shared reusable Blocking source.
- * TODO Review need for this, as it is currently unused.
*/
public static class Shared
{
diff --git a/jetty-core/jetty-websocket/jetty-websocket-core-server/src/main/java/org/eclipse/jetty/websocket/core/server/ServerUpgradeResponse.java b/jetty-core/jetty-websocket/jetty-websocket-core-server/src/main/java/org/eclipse/jetty/websocket/core/server/ServerUpgradeResponse.java
index 1341f0147c5..5d4b2c58ff3 100644
--- a/jetty-core/jetty-websocket/jetty-websocket-core-server/src/main/java/org/eclipse/jetty/websocket/core/server/ServerUpgradeResponse.java
+++ b/jetty-core/jetty-websocket/jetty-websocket-core-server/src/main/java/org/eclipse/jetty/websocket/core/server/ServerUpgradeResponse.java
@@ -28,5 +28,7 @@ public interface ServerUpgradeResponse extends Response
void addExtensions(List configs);
+ void removeExtensions(List configs);
+
void setExtensions(List configs);
}
diff --git a/jetty-core/jetty-websocket/jetty-websocket-core-server/src/main/java/org/eclipse/jetty/websocket/core/server/internal/HttpFieldsWrapper.java b/jetty-core/jetty-websocket/jetty-websocket-core-server/src/main/java/org/eclipse/jetty/websocket/core/server/internal/HttpFieldsWrapper.java
deleted file mode 100644
index 24ed32ad407..00000000000
--- a/jetty-core/jetty-websocket/jetty-websocket-core-server/src/main/java/org/eclipse/jetty/websocket/core/server/internal/HttpFieldsWrapper.java
+++ /dev/null
@@ -1,166 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others.
-//
-// This program and the accompanying materials are made available under the
-// terms of the Eclipse Public License v. 2.0 which is available at
-// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
-// which is available at https://www.apache.org/licenses/LICENSE-2.0.
-//
-// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
-// ========================================================================
-//
-
-package org.eclipse.jetty.websocket.core.server.internal;
-
-import java.util.EnumSet;
-import java.util.Iterator;
-import java.util.ListIterator;
-
-import org.eclipse.jetty.http.HttpField;
-import org.eclipse.jetty.http.HttpFields;
-import org.eclipse.jetty.http.HttpHeader;
-import org.eclipse.jetty.http.HttpHeaderValue;
-
-public class HttpFieldsWrapper implements HttpFields.Mutable
-{
- private final HttpFields.Mutable _fields;
-
- public HttpFieldsWrapper(HttpFields.Mutable fields)
- {
- _fields = fields;
- }
-
- public boolean onPutField(String name, String value)
- {
- return true;
- }
-
- public boolean onAddField(String name, String value)
- {
- return true;
- }
-
- public boolean onRemoveField(String name)
- {
- return true;
- }
-
- @Override
- public Mutable add(String name, String value)
- {
- if (onAddField(name, value))
- return _fields.add(name, value);
- return this;
- }
-
- @Override
- public Mutable add(HttpHeader header, HttpHeaderValue value)
- {
- if (onAddField(header.asString(), value.asString()))
- return _fields.add(header, value);
- return this;
- }
-
- @Override
- public Mutable add(HttpHeader header, String value)
- {
- if (onAddField(header.asString(), value))
- return _fields.add(header, value);
- return this;
- }
-
- @Override
- public Mutable add(HttpField field)
- {
- if (onAddField(field.getName(), field.getValue()))
- return _fields.add(field);
- return this;
- }
-
- @Override
- public Mutable add(HttpFields fields)
- {
- for (HttpField field : fields)
- {
- add(field);
- }
- return this;
- }
-
- @Override
- public Mutable clear()
- {
- return _fields.clear();
- }
-
- @Override
- public Iterator iterator()
- {
- return _fields.iterator();
- }
-
- @Override
- public ListIterator listIterator()
- {
- return _fields.listIterator();
- }
-
- @Override
- public Mutable put(HttpField field)
- {
- if (onPutField(field.getName(), field.getValue()))
- return _fields.put(field);
- return this;
- }
-
- @Override
- public Mutable put(String name, String value)
- {
- if (onPutField(name, value))
- return _fields.put(name, value);
- return this;
- }
-
- @Override
- public Mutable put(HttpHeader header, HttpHeaderValue value)
- {
- if (onPutField(header.asString(), value.asString()))
- return _fields.put(header, value);
- return this;
- }
-
- @Override
- public Mutable put(HttpHeader header, String value)
- {
- if (onPutField(header.asString(), value))
- return _fields.put(header, value);
- return this;
- }
-
- @Override
- public Mutable remove(HttpHeader header)
- {
- if (onRemoveField(header.asString()))
- return _fields.remove(header);
- return this;
- }
-
- @Override
- public Mutable remove(EnumSet fields)
- {
- for (HttpHeader header : fields)
- {
- remove(header);
- }
- return this;
- }
-
- @Override
- public Mutable remove(String name)
- {
- if (onRemoveField(name))
- return _fields.remove(name);
- return this;
- }
-}
diff --git a/jetty-core/jetty-websocket/jetty-websocket-core-server/src/main/java/org/eclipse/jetty/websocket/core/server/internal/ServerUpgradeResponseImpl.java b/jetty-core/jetty-websocket/jetty-websocket-core-server/src/main/java/org/eclipse/jetty/websocket/core/server/internal/ServerUpgradeResponseImpl.java
index 3a024c95902..41c7106dc5a 100644
--- a/jetty-core/jetty-websocket/jetty-websocket-core-server/src/main/java/org/eclipse/jetty/websocket/core/server/internal/ServerUpgradeResponseImpl.java
+++ b/jetty-core/jetty-websocket/jetty-websocket-core-server/src/main/java/org/eclipse/jetty/websocket/core/server/internal/ServerUpgradeResponseImpl.java
@@ -69,12 +69,19 @@ public class ServerUpgradeResponseImpl extends Response.Wrapper implements Serve
@Override
public void addExtensions(List configs)
{
- ArrayList combinedConfig = new ArrayList<>();
- combinedConfig.addAll(getExtensions());
+ ArrayList combinedConfig = new ArrayList<>(getExtensions());
combinedConfig.addAll(configs);
setExtensions(combinedConfig);
}
+ @Override
+ public void removeExtensions(List configs)
+ {
+ ArrayList trimmedExtensions = new ArrayList<>(getExtensions());
+ trimmedExtensions.removeAll(configs);
+ setExtensions(trimmedExtensions);
+ }
+
@Override
public void setExtensions(List configs)
{
diff --git a/jetty-core/jetty-websocket/jetty-websocket-core-server/src/main/java/org/eclipse/jetty/websocket/core/server/internal/WebSocketHttpFieldsWrapper.java b/jetty-core/jetty-websocket/jetty-websocket-core-server/src/main/java/org/eclipse/jetty/websocket/core/server/internal/WebSocketHttpFieldsWrapper.java
index 07dbae33312..22b5b377f6e 100644
--- a/jetty-core/jetty-websocket/jetty-websocket-core-server/src/main/java/org/eclipse/jetty/websocket/core/server/internal/WebSocketHttpFieldsWrapper.java
+++ b/jetty-core/jetty-websocket/jetty-websocket-core-server/src/main/java/org/eclipse/jetty/websocket/core/server/internal/WebSocketHttpFieldsWrapper.java
@@ -14,75 +14,117 @@
package org.eclipse.jetty.websocket.core.server.internal;
import java.util.Collections;
+import java.util.List;
+import org.eclipse.jetty.http.HttpField;
+import org.eclipse.jetty.http.HttpFields;
import org.eclipse.jetty.http.HttpHeader;
+import org.eclipse.jetty.http.HttpHeaderValue;
import org.eclipse.jetty.websocket.core.ExtensionConfig;
import org.eclipse.jetty.websocket.core.server.ServerUpgradeResponse;
-public class WebSocketHttpFieldsWrapper extends HttpFieldsWrapper
+public class WebSocketHttpFieldsWrapper extends HttpFields.Mutable.Wrapper
{
- private final WebSocketNegotiation _negotiation;
private final ServerUpgradeResponse _response;
public WebSocketHttpFieldsWrapper(Mutable fields, ServerUpgradeResponse response, WebSocketNegotiation negotiation)
{
super(fields);
- _negotiation = negotiation;
_response = response;
}
@Override
- public boolean onPutField(String name, String value)
+ public HttpField onAddField(HttpField field)
{
- if (HttpHeader.SEC_WEBSOCKET_SUBPROTOCOL.is(name))
+ if (field.getHeader() != null)
{
- _response.setAcceptedSubProtocol(value);
- return false;
- }
+ return switch (field.getHeader())
+ {
+ case SEC_WEBSOCKET_SUBPROTOCOL ->
+ {
+ _response.setAcceptedSubProtocol(field.getValue());
+ yield null;
+ }
- if (HttpHeader.SEC_WEBSOCKET_EXTENSIONS.is(name))
- {
- _response.setExtensions(ExtensionConfig.parseList(value));
- return false;
- }
+ case SEC_WEBSOCKET_EXTENSIONS ->
+ {
+ _response.addExtensions(ExtensionConfig.parseList(field.getValue()));
+ yield null;
+ }
- return super.onPutField(name, value);
+ default -> super.onAddField(field);
+ };
+ }
+ return super.onAddField(field);
}
@Override
- public boolean onAddField(String name, String value)
+ public boolean onRemoveField(HttpField field)
{
- if (HttpHeader.SEC_WEBSOCKET_SUBPROTOCOL.is(name))
+ if (field.getHeader() != null)
{
- _response.setAcceptedSubProtocol(value);
- return false;
- }
+ return switch (field.getHeader())
+ {
+ case SEC_WEBSOCKET_SUBPROTOCOL ->
+ {
+ _response.setAcceptedSubProtocol(null);
+ yield true;
+ }
- if (HttpHeader.SEC_WEBSOCKET_EXTENSIONS.is(name))
- {
- _response.addExtensions(ExtensionConfig.parseList(value));
- return false;
- }
+ case SEC_WEBSOCKET_EXTENSIONS ->
+ {
+ _response.removeExtensions(ExtensionConfig.parseList(field.getValue()));
+ yield true;
+ }
- return super.onAddField(name, value);
+ default -> super.onRemoveField(field);
+ };
+ }
+ return super.onRemoveField(field);
}
@Override
- public boolean onRemoveField(String name)
+ public Mutable put(HttpField field)
{
- if (HttpHeader.SEC_WEBSOCKET_SUBPROTOCOL.is(name))
- {
- _response.setAcceptedSubProtocol(null);
- return false;
- }
+ // Need to override put methods as putting extensions clears them, even if field does not exist.
+ if (field.getHeader() == HttpHeader.SEC_WEBSOCKET_EXTENSIONS)
+ _response.setExtensions(Collections.emptyList());
+ return super.put(field);
+ }
+ @Override
+ public Mutable put(String name, String value)
+ {
+ // Need to override put methods as putting extensions clears them, even if field does not exist.
if (HttpHeader.SEC_WEBSOCKET_EXTENSIONS.is(name))
- {
- // TODO: why add extensions??
- _response.addExtensions(Collections.emptyList());
- return false;
- }
+ _response.setExtensions(Collections.emptyList());
+ return super.put(name, value);
+ }
- return super.onRemoveField(name);
+ @Override
+ public Mutable put(HttpHeader header, HttpHeaderValue value)
+ {
+ // Need to override put methods as putting extensions clears them, even if field does not exist.
+ if (header == HttpHeader.SEC_WEBSOCKET_EXTENSIONS)
+ _response.setExtensions(Collections.emptyList());
+ return super.put(header, value);
+ }
+
+ @Override
+ public Mutable put(HttpHeader header, String value)
+ {
+ // Need to override put methods as putting extensions clears them, even if field does not exist.
+ if (header == HttpHeader.SEC_WEBSOCKET_EXTENSIONS)
+ _response.setExtensions(Collections.emptyList());
+ return super.put(header, value);
+ }
+
+ @Override
+ public Mutable put(String name, List list)
+ {
+ // Need to override put methods as putting extensions clears them, even if field does not exist.
+ if (HttpHeader.SEC_WEBSOCKET_EXTENSIONS.is(name))
+ _response.setExtensions(Collections.emptyList());
+ return super.put(name, list);
}
}
diff --git a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/AsyncContentProducer.java b/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/AsyncContentProducer.java
index f173cba11c1..b222c8ddd71 100644
--- a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/AsyncContentProducer.java
+++ b/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/AsyncContentProducer.java
@@ -126,7 +126,7 @@ class AsyncContentProducer implements ContentProducer
LOG.debug("checkMinDataRate check failed {}", this);
BadMessageException bad = new BadMessageException(HttpStatus.REQUEST_TIMEOUT_408,
String.format("Request content data rate < %d B/s", minRequestDataRate));
- if (_servletChannel.getState().isResponseCommitted())
+ if (_servletChannel.getServletRequestState().isResponseCommitted())
{
if (LOG.isDebugEnabled())
LOG.debug("checkMinDataRate aborting channel {}", this);
@@ -180,7 +180,7 @@ class AsyncContentProducer implements ContentProducer
private boolean consumeAvailableChunks()
{
- return _servletChannel.getServletContextRequest().consumeAvailable();
+ return _servletChannel.getRequest().consumeAvailable();
}
@Override
@@ -189,7 +189,7 @@ class AsyncContentProducer implements ContentProducer
assertLocked();
if (LOG.isDebugEnabled())
LOG.debug("onContentProducible {}", this);
- return _servletChannel.getState().onReadReady();
+ return _servletChannel.getServletRequestState().onReadReady();
}
@Override
@@ -200,7 +200,7 @@ class AsyncContentProducer implements ContentProducer
if (LOG.isDebugEnabled())
LOG.debug("nextChunk = {} {}", chunk, this);
if (chunk != null)
- _servletChannel.getState().onReadIdle();
+ _servletChannel.getServletRequestState().onReadIdle();
return chunk;
}
@@ -227,8 +227,8 @@ class AsyncContentProducer implements ContentProducer
return true;
}
- _servletChannel.getState().onReadUnready();
- _servletChannel.getServletContextRequest().demand(() ->
+ _servletChannel.getServletRequestState().onReadUnready();
+ _servletChannel.getRequest().demand(() ->
{
if (_servletChannel.getHttpInput().onContentProducible())
_servletChannel.handle();
@@ -241,7 +241,7 @@ class AsyncContentProducer implements ContentProducer
boolean isUnready()
{
- return _servletChannel.getState().isInputUnready();
+ return _servletChannel.getServletRequestState().isInputUnready();
}
private Content.Chunk produceChunk()
@@ -280,7 +280,7 @@ class AsyncContentProducer implements ContentProducer
}
else
{
- _servletChannel.getState().onContentAdded();
+ _servletChannel.getServletRequestState().onContentAdded();
}
}
@@ -297,7 +297,7 @@ class AsyncContentProducer implements ContentProducer
private Content.Chunk readChunk()
{
- Content.Chunk chunk = _servletChannel.getServletContextRequest().read();
+ Content.Chunk chunk = _servletChannel.getRequest().read();
if (chunk != null)
{
_bytesArrived += chunk.remaining();
@@ -305,7 +305,6 @@ class AsyncContentProducer implements ContentProducer
_firstByteNanoTime = NanoTime.now();
if (LOG.isDebugEnabled())
LOG.debug("readChunk() updated _bytesArrived to {} and _firstByteTimeStamp to {} {}", _bytesArrived, _firstByteNanoTime, this);
- // TODO: notify channel listeners (see ee9)?
if (chunk instanceof Trailers trailers)
_servletChannel.onTrailers(trailers.getTrailers());
}
diff --git a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/AsyncContextState.java b/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/AsyncContextState.java
index 0271a05675f..29c65d004ec 100644
--- a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/AsyncContextState.java
+++ b/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/AsyncContextState.java
@@ -117,7 +117,7 @@ public class AsyncContextState implements AsyncContext
ServletResponse servletResponse = getResponse();
ServletChannel servletChannel = _state.getServletChannel();
HttpServletRequest originalHttpServletRequest = servletChannel.getServletContextRequest().getServletApiRequest();
- HttpServletResponse originalHttpServletResponse = servletChannel.getResponse().getHttpServletResponse();
+ HttpServletResponse originalHttpServletResponse = servletChannel.getServletContextResponse().getServletApiResponse();
return (servletRequest == originalHttpServletRequest && servletResponse == originalHttpServletResponse);
}
diff --git a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/DebugListener.java b/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/DebugListener.java
index 20d93f2e031..c999ad13e9d 100644
--- a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/DebugListener.java
+++ b/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/DebugListener.java
@@ -162,18 +162,16 @@ public class DebugListener extends AbstractLifeCycle implements ServletContextLi
return n;
}
- protected String findRequestName(ServletRequest request)
+ protected String findRequestName(ServletContextRequest request)
{
if (request == null)
return null;
- HttpServletRequest r = (HttpServletRequest)request;
- String n = (String)request.getAttribute(_attr);
- if (n == null)
- {
- n = String.format("%s@%x", r.getRequestURI(), request.hashCode());
- request.setAttribute(_attr, n);
- }
- return n;
+ return request.getId();
+ }
+
+ protected String findRequestName(ServletRequest request)
+ {
+ return findRequestName(ServletContextRequest.getServletContextRequest(request));
}
protected void log(String format, Object... arg)
@@ -225,7 +223,7 @@ public class DebugListener extends AbstractLifeCycle implements ServletContextLi
String rname = findRequestName(ace.getAsyncContext().getRequest());
ServletContextRequest request = ServletContextRequest.getServletContextRequest(ace.getAsyncContext().getRequest());
- Response response = request.getResponse();
+ Response response = request.getServletContextResponse();
String headers = _showHeaders ? ("\n" + response.getHeaders().toString()) : "";
log("! ctx=%s r=%s onComplete %s %d%s", cname, rname, ace.getServletRequestState(), response.getStatus(), headers);
@@ -280,8 +278,8 @@ public class DebugListener extends AbstractLifeCycle implements ServletContextLi
else
{
ServletContextRequest request = ServletContextRequest.getServletContextRequest(r);
- String headers = _showHeaders ? ("\n" + request.getResponse().getHeaders().toString()) : "";
- log("<< %s ctx=%s r=%s async=false %d%s", d, cname, rname, request.getResponse().getStatus(), headers);
+ String headers = _showHeaders ? ("\n" + request.getServletContextResponse().getHeaders().toString()) : "";
+ log("<< %s ctx=%s r=%s async=false %d%s", d, cname, rname, request.getServletContextResponse().getStatus(), headers);
}
}
};
@@ -296,7 +294,7 @@ public class DebugListener extends AbstractLifeCycle implements ServletContextLi
log("> ctx=%s", cname);
else
{
- String rname = findRequestName(request.getServletApiRequest());
+ String rname = findRequestName(request);
if (_renameThread)
{
@@ -316,7 +314,7 @@ public class DebugListener extends AbstractLifeCycle implements ServletContextLi
log("< ctx=%s", cname);
else
{
- String rname = findRequestName(request.getServletApiRequest());
+ String rname = findRequestName(request);
log("< ctx=%s r=%s", cname, rname);
if (_renameThread)
diff --git a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/DefaultServlet.java b/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/DefaultServlet.java
index 1a1995f17e4..73e880a889f 100644
--- a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/DefaultServlet.java
+++ b/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/DefaultServlet.java
@@ -458,7 +458,7 @@ public class DefaultServlet extends HttpServlet
else if (isPathInfoOnly())
encodedPathInContext = URIUtil.encodePath(req.getPathInfo());
else if (req instanceof ServletApiRequest apiRequest)
- encodedPathInContext = Context.getPathInContext(req.getContextPath(), apiRequest.getServletContextRequest().getHttpURI().getCanonicalPath());
+ encodedPathInContext = Context.getPathInContext(req.getContextPath(), apiRequest.getRequest().getHttpURI().getCanonicalPath());
else
encodedPathInContext = Context.getPathInContext(req.getContextPath(), URIUtil.canonicalPath(req.getRequestURI()));
@@ -878,12 +878,7 @@ public class DefaultServlet extends HttpServlet
public ServletContextResponse getServletContextResponse()
{
- if (_response instanceof ServletApiResponse)
- {
- ServletApiResponse apiResponse = (ServletApiResponse)_response;
- return apiResponse.getResponse();
- }
- return null;
+ return ServletContextResponse.getServletContextResponse(_response);
}
@Override
@@ -1003,6 +998,12 @@ public class DefaultServlet extends HttpServlet
{
return null;
}
+
+ @Override
+ public String toString()
+ {
+ return "%s@%x{%s,%s}".formatted(this.getClass().getSimpleName(), hashCode(), this._coreRequest, _response);
+ }
}
private class ServletResourceService extends ResourceService implements ResourceService.WelcomeFactory
diff --git a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/Dispatcher.java b/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/Dispatcher.java
index 4d43b9f9d3f..d1bc1702c1f 100644
--- a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/Dispatcher.java
+++ b/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/Dispatcher.java
@@ -104,7 +104,7 @@ public class Dispatcher implements RequestDispatcher
HttpServletResponse httpResponse = (response instanceof HttpServletResponse) ? (HttpServletResponse)response : new ServletResponseHttpWrapper(response);
ServletContextRequest servletContextRequest = ServletContextRequest.getServletContextRequest(request);
- servletContextRequest.getResponse().resetForForward();
+ servletContextRequest.getServletContextResponse().resetForForward();
_mappedServlet.handle(_servletHandler, _decodedPathInContext, new ForwardRequest(httpRequest), httpResponse);
// If we are not async and not closed already, then close via the possibly wrapped response.
diff --git a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/ErrorHandler.java b/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/ErrorHandler.java
index 107e2e1f314..93dc82a1c59 100644
--- a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/ErrorHandler.java
+++ b/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/ErrorHandler.java
@@ -91,7 +91,7 @@ public class ErrorHandler implements Request.Handler
ServletContextRequest servletContextRequest = Request.as(request, ServletContextRequest.class);
HttpServletRequest httpServletRequest = servletContextRequest.getServletApiRequest();
HttpServletResponse httpServletResponse = servletContextRequest.getHttpServletResponse();
- ServletContextHandler contextHandler = servletContextRequest.getContext().getServletContextHandler();
+ ServletContextHandler contextHandler = servletContextRequest.getServletContext().getServletContextHandler();
String cacheControl = getCacheControl();
if (cacheControl != null)
response.getHeaders().put(HttpHeader.CACHE_CONTROL.asString(), cacheControl);
@@ -164,7 +164,7 @@ public class ErrorHandler implements Request.Handler
for (String mimeType : acceptable)
{
generateAcceptableResponse(baseRequest, request, response, code, message, mimeType);
- if (response.isCommitted() || baseRequest.getResponse().isWritingOrStreaming())
+ if (response.isCommitted() || baseRequest.getServletContextResponse().isWritingOrStreaming())
break;
}
}
@@ -300,7 +300,7 @@ public class ErrorHandler implements Request.Handler
// TODO error page may cause a BufferOverflow. In which case we try
// TODO again with stacks disabled. If it still overflows, it is
// TODO written without a body.
- ByteBuffer buffer = baseRequest.getResponse().getHttpOutput().getByteBuffer();
+ ByteBuffer buffer = baseRequest.getServletContextResponse().getHttpOutput().getByteBuffer();
ByteBufferOutputStream out = new ByteBufferOutputStream(buffer);
PrintWriter writer = new PrintWriter(new OutputStreamWriter(out, charset));
@@ -334,7 +334,7 @@ public class ErrorHandler implements Request.Handler
LOG.warn("Error page too large: {} {} {}", code, message, request, e);
else
LOG.warn("Error page too large: {} {} {}", code, message, request);
- baseRequest.getResponse().resetContent();
+ baseRequest.getServletContextResponse().resetContent();
if (!_disableStacks)
{
LOG.info("Disabling showsStacks for {}", this);
@@ -395,7 +395,7 @@ public class ErrorHandler implements Request.Handler
if (showStacks && !_disableStacks)
writeErrorPageStacks(request, writer);
- ((ServletApiRequest)request).getServletContextRequest().getServletChannel().getHttpConfiguration()
+ ((ServletApiRequest)request).getServletRequestInfo().getServletChannel().getHttpConfiguration()
.writePoweredBy(writer, "
", "
\n");
}
diff --git a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/HttpInput.java b/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/HttpInput.java
index 531291982af..4d095125700 100644
--- a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/HttpInput.java
+++ b/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/HttpInput.java
@@ -52,7 +52,7 @@ public class HttpInput extends ServletInputStream implements Runnable
public HttpInput(ServletChannel channel)
{
_servletChannel = channel;
- _channelState = _servletChannel.getState();
+ _channelState = _servletChannel.getServletRequestState();
_asyncContentProducer = new AsyncContentProducer(_servletChannel, _lock);
_blockingContentProducer = new BlockingContentProducer(_asyncContentProducer);
_contentProducer = _blockingContentProducer;
@@ -349,7 +349,7 @@ public class HttpInput extends ServletInputStream implements Runnable
if (LOG.isDebugEnabled())
LOG.debug("running error={} {}", error, this);
// TODO is this necessary to add here?
- _servletChannel.getResponse().getHeaders().add(HttpFields.CONNECTION_CLOSE);
+ _servletChannel.getServletContextResponse().getHeaders().add(HttpFields.CONNECTION_CLOSE);
_readListener.onError(error);
}
else if (chunk.isLast() && !chunk.hasRemaining())
diff --git a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/HttpOutput.java b/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/HttpOutput.java
index 3d1298c5d6c..b5d3548fb9a 100644
--- a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/HttpOutput.java
+++ b/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/HttpOutput.java
@@ -35,17 +35,14 @@ import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.Content;
import org.eclipse.jetty.io.EofException;
import org.eclipse.jetty.io.RetainableByteBuffer;
-import org.eclipse.jetty.server.ConnectionMetaData;
import org.eclipse.jetty.server.HttpConfiguration;
-import org.eclipse.jetty.server.Response;
+import org.eclipse.jetty.util.Blocker;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.ExceptionUtil;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.IteratingCallback;
import org.eclipse.jetty.util.NanoTime;
-import org.eclipse.jetty.util.SharedBlockingCallback;
-import org.eclipse.jetty.util.SharedBlockingCallback.Blocker;
import org.eclipse.jetty.util.thread.AutoLock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -127,12 +124,9 @@ public class HttpOutput extends ServletOutputStream implements Runnable
private static final Logger LOG = LoggerFactory.getLogger(HttpOutput.class);
private static final ThreadLocal _encoder = new ThreadLocal<>();
- private final ConnectionMetaData _connectionMetaData;
private final ServletChannel _servletChannel;
- private final Response _response;
- private final ByteBufferPool _bufferPool;
private final ServletRequestState _channelState;
- private final SharedBlockingCallback _writeBlocker;
+ private final Blocker.Shared _writeBlocker;
private ApiState _apiState = ApiState.BLOCKING;
private State _state = State.OPEN;
private boolean _softClose = false;
@@ -146,15 +140,11 @@ public class HttpOutput extends ServletOutputStream implements Runnable
private volatile Throwable _onError;
private Callback _closedCallback;
- public HttpOutput(Response response, ServletChannel channel)
+ public HttpOutput(ServletChannel channel)
{
- _response = response;
_servletChannel = channel;
- _connectionMetaData = _response.getRequest().getConnectionMetaData();
- _bufferPool = _response.getRequest().getComponents().getByteBufferPool();
-
- _channelState = _servletChannel.getState();
- _writeBlocker = new WriteBlocker(_servletChannel);
+ _channelState = _servletChannel.getServletRequestState();
+ _writeBlocker = new Blocker.Shared();
HttpConfiguration config = _servletChannel.getHttpConfiguration();
_bufferSize = config.getOutputBufferSize();
_commitSize = config.getOutputAggregationSize();
@@ -164,11 +154,6 @@ public class HttpOutput extends ServletOutputStream implements Runnable
_commitSize = _bufferSize;
}
}
-
- public Response getResponse()
- {
- return _response;
- }
public boolean isWritten()
{
@@ -188,14 +173,9 @@ public class HttpOutput extends ServletOutputStream implements Runnable
}
}
- protected Blocker acquireWriteBlockingCallback() throws IOException
- {
- return _writeBlocker.acquire();
- }
-
private void channelWrite(ByteBuffer content, boolean complete) throws IOException
{
- try (Blocker blocker = _writeBlocker.acquire())
+ try (Blocker.Callback blocker = _writeBlocker.callback())
{
channelWrite(content, complete, blocker);
blocker.block();
@@ -206,13 +186,13 @@ public class HttpOutput extends ServletOutputStream implements Runnable
{
if (_firstByteNanoTime == -1)
{
- long minDataRate = _connectionMetaData.getHttpConfiguration().getMinResponseDataRate();
+ long minDataRate = _servletChannel.getConnectionMetaData().getHttpConfiguration().getMinResponseDataRate();
if (minDataRate > 0)
_firstByteNanoTime = NanoTime.now();
else
_firstByteNanoTime = Long.MAX_VALUE;
}
- _response.write(last, content, callback);
+ _servletChannel.getResponse().write(last, content, callback);
}
private void onWriteComplete(boolean last, Throwable failure)
@@ -353,7 +333,7 @@ public class HttpOutput extends ServletOutputStream implements Runnable
case PENDING: // an async write is pending and may complete at any time
// If this is not the last write, then we must abort
- if (!_servletChannel.getResponse().isContentComplete(_written))
+ if (_servletChannel.getServletContextResponse().isContentIncomplete(_written))
error = new CancellationException("Completed whilst write pending");
break;
@@ -369,7 +349,6 @@ public class HttpOutput extends ServletOutputStream implements Runnable
if (error != null)
{
_servletChannel.abort(error);
- _writeBlocker.fail(error);
_state = State.CLOSED;
}
else
@@ -463,7 +442,7 @@ public class HttpOutput extends ServletOutputStream implements Runnable
public void close() throws IOException
{
ByteBuffer content = null;
- Blocker blocker = null;
+ Blocker.Callback blocker = null;
try (AutoLock l = _channelState.lock())
{
if (_onError != null)
@@ -489,7 +468,7 @@ public class HttpOutput extends ServletOutputStream implements Runnable
case BLOCKING:
case BLOCKED:
// block until CLOSED state reached.
- blocker = _writeBlocker.acquire();
+ blocker = _writeBlocker.callback();
_closedCallback = Callback.combine(_closedCallback, blocker);
break;
@@ -506,7 +485,7 @@ public class HttpOutput extends ServletOutputStream implements Runnable
// Output is idle blocking state, but we still do an async close
_apiState = ApiState.BLOCKED;
_state = State.CLOSING;
- blocker = _writeBlocker.acquire();
+ blocker = _writeBlocker.callback();
content = _aggregate != null && _aggregate.hasRemaining() ? _aggregate.getByteBuffer() : BufferUtil.EMPTY_BUFFER;
break;
@@ -516,7 +495,7 @@ public class HttpOutput extends ServletOutputStream implements Runnable
// then trigger a close from onWriteComplete
_state = State.CLOSE;
// and block until it is complete
- blocker = _writeBlocker.acquire();
+ blocker = _writeBlocker.callback();
_closedCallback = Callback.combine(_closedCallback, blocker);
break;
@@ -550,9 +529,9 @@ public class HttpOutput extends ServletOutputStream implements Runnable
return;
// Just wait for some other close to finish.
- try (Blocker b = blocker)
+ try (Blocker.Callback cb = blocker)
{
- b.block();
+ cb.block();
}
}
else
@@ -565,7 +544,7 @@ public class HttpOutput extends ServletOutputStream implements Runnable
else
{
// Do a blocking close
- try (Blocker b = blocker)
+ try (Blocker.Callback b = blocker)
{
channelWrite(content, true, blocker);
b.block();
@@ -590,9 +569,10 @@ public class HttpOutput extends ServletOutputStream implements Runnable
private RetainableByteBuffer acquireBuffer()
{
- boolean useOutputDirectByteBuffers = _connectionMetaData.getHttpConfiguration().isUseOutputDirectByteBuffers();
+ boolean useOutputDirectByteBuffers = _servletChannel.getConnectionMetaData().getHttpConfiguration().isUseOutputDirectByteBuffers();
+ ByteBufferPool pool = _servletChannel.getRequest().getComponents().getByteBufferPool();
if (_aggregate == null)
- _aggregate = _bufferPool.acquire(getBufferSize(), useOutputDirectByteBuffers);
+ _aggregate = pool.acquire(getBufferSize(), useOutputDirectByteBuffers);
return _aggregate;
}
@@ -724,7 +704,7 @@ public class HttpOutput extends ServletOutputStream implements Runnable
checkWritable();
long written = _written + len;
int space = maximizeAggregateSpace();
- last = _servletChannel.getResponse().isAllContentWritten(written);
+ last = _servletChannel.getServletContextResponse().isAllContentWritten(written);
// Write will be aggregated if:
// + it is smaller than the commitSize
// + is not the last one, or is last but will fit in an already allocated aggregate buffer.
@@ -858,7 +838,7 @@ public class HttpOutput extends ServletOutputStream implements Runnable
{
checkWritable();
long written = _written + len;
- last = _servletChannel.getResponse().isAllContentWritten(written);
+ last = _servletChannel.getServletContextResponse().isAllContentWritten(written);
flush = last || len > 0 || (_aggregate != null && _aggregate.hasRemaining());
if (last && _state == State.OPEN)
@@ -938,7 +918,7 @@ public class HttpOutput extends ServletOutputStream implements Runnable
checkWritable();
long written = _written + 1;
int space = maximizeAggregateSpace();
- last = _servletChannel.getResponse().isAllContentWritten(written);
+ last = _servletChannel.getServletContextResponse().isAllContentWritten(written);
flush = last || space == 1;
if (last && _state == State.OPEN)
@@ -1012,7 +992,7 @@ public class HttpOutput extends ServletOutputStream implements Runnable
s = String.valueOf(s);
- String charset = _servletChannel.getResponse().getCharacterEncoding(false);
+ String charset = _servletChannel.getServletContextResponse().getCharacterEncoding(false);
CharsetEncoder encoder = _encoder.get();
if (encoder == null || !encoder.charset().name().equalsIgnoreCase(charset))
{
@@ -1025,8 +1005,8 @@ public class HttpOutput extends ServletOutputStream implements Runnable
{
encoder.reset();
}
-
- RetainableByteBuffer out = _bufferPool.acquire((int)(1 + (s.length() + 2) * encoder.averageBytesPerChar()), false);
+ ByteBufferPool pool = _servletChannel.getRequest().getComponents().getByteBufferPool();
+ RetainableByteBuffer out = pool.acquire((int)(1 + (s.length() + 2) * encoder.averageBytesPerChar()), false);
try
{
CharBuffer in = CharBuffer.wrap(s);
@@ -1062,7 +1042,7 @@ public class HttpOutput extends ServletOutputStream implements Runnable
if (result.isOverflow())
{
BufferUtil.flipToFlush(byteBuffer, 0);
- RetainableByteBuffer bigger = _bufferPool.acquire(out.capacity() + s.length() + 2, out.isDirect());
+ RetainableByteBuffer bigger = pool.acquire(out.capacity() + s.length() + 2, out.isDirect());
BufferUtil.flipToFill(bigger.getByteBuffer());
bigger.getByteBuffer().put(byteBuffer);
out.release();
@@ -1107,7 +1087,7 @@ public class HttpOutput extends ServletOutputStream implements Runnable
*/
public void sendContent(InputStream in) throws IOException
{
- try (Blocker blocker = _writeBlocker.acquire())
+ try (Blocker.Callback blocker = _writeBlocker.callback())
{
new InputStreamWritingCB(in, blocker).iterate();
blocker.block();
@@ -1122,7 +1102,7 @@ public class HttpOutput extends ServletOutputStream implements Runnable
*/
public void sendContent(ReadableByteChannel in) throws IOException
{
- try (Blocker blocker = _writeBlocker.acquire())
+ try (Blocker.Callback blocker = _writeBlocker.callback())
{
new ReadableByteChannelWritingCB(in, blocker).iterate();
blocker.block();
@@ -1256,7 +1236,7 @@ public class HttpOutput extends ServletOutputStream implements Runnable
{
if (_firstByteNanoTime == -1 || _firstByteNanoTime == Long.MAX_VALUE)
return;
- long minDataRate = _connectionMetaData.getHttpConfiguration().getMinResponseDataRate();
+ long minDataRate = _servletChannel.getConnectionMetaData().getHttpConfiguration().getMinResponseDataRate();
_flushed += bytes;
long minFlushed = minDataRate * NanoTime.millisSince(_firstByteNanoTime) / TimeUnit.SECONDS.toMillis(1);
if (LOG.isDebugEnabled())
@@ -1276,7 +1256,7 @@ public class HttpOutput extends ServletOutputStream implements Runnable
_state = State.OPEN;
_apiState = ApiState.BLOCKING;
_softClose = true; // Stay closed until next request
- HttpConfiguration config = _connectionMetaData.getHttpConfiguration();
+ HttpConfiguration config = _servletChannel.getConnectionMetaData().getHttpConfiguration();
_bufferSize = config.getOutputBufferSize();
_commitSize = config.getOutputAggregationSize();
if (_commitSize > _bufferSize)
@@ -1304,7 +1284,7 @@ public class HttpOutput extends ServletOutputStream implements Runnable
@Override
public void setWriteListener(WriteListener writeListener)
{
- if (!_servletChannel.getState().isAsync())
+ if (!_servletChannel.getServletRequestState().isAsync())
throw new IllegalStateException("!ASYNC: " + stateString());
boolean wake;
try (AutoLock l = _channelState.lock())
@@ -1313,7 +1293,7 @@ public class HttpOutput extends ServletOutputStream implements Runnable
throw new IllegalStateException("!OPEN" + stateString());
_apiState = ApiState.READY;
_writeListener = writeListener;
- wake = _servletChannel.getState().onWritePossible();
+ wake = _servletChannel.getServletRequestState().onWritePossible();
}
if (wake)
_servletChannel.execute(_servletChannel::handle);
@@ -1626,7 +1606,8 @@ public class HttpOutput extends ServletOutputStream implements Runnable
super(callback, true);
_in = in;
// Reading from InputStream requires byte[], don't use direct buffers.
- _buffer = _bufferPool.acquire(getBufferSize(), false);
+ ByteBufferPool pool = _servletChannel.getRequest().getComponents().getByteBufferPool();
+ _buffer = pool.acquire(getBufferSize(), false);
}
@Override
@@ -1701,8 +1682,9 @@ public class HttpOutput extends ServletOutputStream implements Runnable
{
super(callback, true);
_in = in;
- boolean useOutputDirectByteBuffers = _connectionMetaData.getHttpConfiguration().isUseOutputDirectByteBuffers();
- _buffer = _bufferPool.acquire(getBufferSize(), useOutputDirectByteBuffers);
+ boolean useOutputDirectByteBuffers = _servletChannel.getConnectionMetaData().getHttpConfiguration().isUseOutputDirectByteBuffers();
+ ByteBufferPool pool = _servletChannel.getRequest().getComponents().getByteBufferPool();
+ _buffer = pool.acquire(getBufferSize(), useOutputDirectByteBuffers);
}
@Override
@@ -1753,16 +1735,6 @@ public class HttpOutput extends ServletOutputStream implements Runnable
}
}
- private static class WriteBlocker extends SharedBlockingCallback
- {
- private final ServletChannel _channel;
-
- private WriteBlocker(ServletChannel channel)
- {
- _channel = channel;
- }
- }
-
private class WriteCompleteCB implements Callback
{
@Override
diff --git a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/PushBuilderImpl.java b/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/PushBuilderImpl.java
index 1a3de77dc74..7d8eba15712 100644
--- a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/PushBuilderImpl.java
+++ b/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/PushBuilderImpl.java
@@ -114,7 +114,7 @@ class PushBuilderImpl implements PushBuilder
}
if (!pushPath.startsWith("/"))
- pushPath = URIUtil.addPaths(_request.getContext().getContextPath(), pushPath);
+ pushPath = URIUtil.addPaths(_request.getServletContext().getContextPath(), pushPath);
String pushParam = null;
if (_sessionId != null)
diff --git a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/ServletApiRequest.java b/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/ServletApiRequest.java
index b12dfe156eb..d1e1d1ab8ad 100644
--- a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/ServletApiRequest.java
+++ b/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/ServletApiRequest.java
@@ -56,6 +56,7 @@ import jakarta.servlet.http.HttpSession;
import jakarta.servlet.http.HttpUpgradeHandler;
import jakarta.servlet.http.Part;
import jakarta.servlet.http.PushBuilder;
+import org.eclipse.jetty.ee10.servlet.ServletContextHandler.ServletRequestInfo;
import org.eclipse.jetty.http.BadMessageException;
import org.eclipse.jetty.http.CookieCache;
import org.eclipse.jetty.http.CookieCompliance;
@@ -77,9 +78,11 @@ import org.eclipse.jetty.server.ConnectionMetaData;
import org.eclipse.jetty.server.FormFields;
import org.eclipse.jetty.server.HttpCookieUtils;
import org.eclipse.jetty.server.Request;
+import org.eclipse.jetty.server.Response;
import org.eclipse.jetty.server.Session;
import org.eclipse.jetty.session.AbstractSessionManager;
import org.eclipse.jetty.session.ManagedSession;
+import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.Fields;
import org.eclipse.jetty.util.HostPort;
import org.eclipse.jetty.util.IO;
@@ -89,16 +92,15 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * The Jetty low level implementation of the ee10 {@link HttpServletRequest} object.
- *
- *
- * This provides the bridges from Servlet {@link HttpServletRequest} to the Jetty Core {@link Request} concepts (provided by the {@link ServletContextRequest})
- *
+ * The Jetty implementation of the ee10 {@link HttpServletRequest} object.
+ * This provides the bridge from Servlet {@link HttpServletRequest} to the Jetty Core {@link Request}
+ * via the {@link ServletContextRequest}.
*/
public class ServletApiRequest implements HttpServletRequest
{
private static final Logger LOG = LoggerFactory.getLogger(ServletApiRequest.class);
- private final ServletContextRequest _request;
+ private final ServletContextRequest _servletContextRequest;
+ private final ServletChannel _servletChannel;
//TODO review which fields should be in ServletContextRequest
private AsyncContextState _async;
private String _characterEncoding;
@@ -110,30 +112,18 @@ public class ServletApiRequest implements HttpServletRequest
private Fields _contentParameters;
private Fields _parameters;
private Fields _queryParameters;
- private String _method;
private ServletMultiPartFormData.Parts _parts;
private boolean _asyncSupported = true;
protected ServletApiRequest(ServletContextRequest servletContextRequest)
{
- _request = servletContextRequest;
- }
-
- public Fields getQueryParams()
- {
- extractQueryParameters();
- return _queryParameters;
- }
-
- public Fields getContentParams()
- {
- extractContentParameters();
- return _contentParameters;
+ _servletContextRequest = servletContextRequest;
+ _servletChannel = _servletContextRequest.getServletChannel();
}
public AuthenticationState getAuthentication()
{
- return AuthenticationState.getAuthenticationState(getServletContextRequest());
+ return AuthenticationState.getAuthenticationState(getRequest());
}
private AuthenticationState getUndeferredAuthentication()
@@ -141,11 +131,11 @@ public class ServletApiRequest implements HttpServletRequest
AuthenticationState authenticationState = getAuthentication();
if (authenticationState instanceof AuthenticationState.Deferred deferred)
{
- AuthenticationState undeferred = deferred.authenticate(getServletContextRequest());
+ AuthenticationState undeferred = deferred.authenticate(getRequest());
if (undeferred != null && undeferred != authenticationState)
{
authenticationState = undeferred;
- AuthenticationState.setAuthenticationState(getServletContextRequest(), authenticationState);
+ AuthenticationState.setAuthenticationState(getRequest(), authenticationState);
}
}
return authenticationState;
@@ -154,45 +144,55 @@ public class ServletApiRequest implements HttpServletRequest
@Override
public String getMethod()
{
- if (_method == null)
- return getServletContextRequest().getMethod();
- else
- return _method;
+ return getRequest().getMethod();
}
- //TODO shouldn't really be public?
- public void setMethod(String method)
+ /**
+ * @return The {@link ServletRequestInfo} view of the {@link ServletContextRequest} as wrapped
+ * by the {@link ServletContextHandler}.
+ * @see #getRequest()
+ */
+ public ServletRequestInfo getServletRequestInfo()
{
- _method = method;
+ return _servletContextRequest;
}
- public ServletContextRequest getServletContextRequest()
+ /**
+ * @return The core {@link Request} associated with the servlet API request. This may differ
+ * from {@link ServletContextRequest} as wrapped by the {@link ServletContextHandler} as it
+ * may have been further wrapped before being passed
+ * to {@link ServletChannel#associate(Request, Response, Callback)}.
+ * @see #getServletRequestInfo()
+ * @see ServletChannel#associate(Request, Response, Callback)
+ */
+ public Request getRequest()
{
- return _request;
+ ServletChannel servletChannel = _servletChannel;
+ return servletChannel == null ? _servletContextRequest : servletChannel.getRequest();
}
public HttpFields getFields()
{
- return _request.getHeaders();
+ return getRequest().getHeaders();
}
@Override
public String getRequestId()
{
- return _request.getConnectionMetaData().getId() + "#" + _request.getId();
+ return getRequest().getConnectionMetaData().getId() + "#" + getRequest().getId();
}
@Override
public String getProtocolRequestId()
{
- return _request.getId();
+ return getRequest().getId();
}
@Override
public ServletConnection getServletConnection()
{
// TODO cache the results
- final ConnectionMetaData connectionMetaData = _request.getConnectionMetaData();
+ final ConnectionMetaData connectionMetaData = getRequest().getConnectionMetaData();
return new ServletConnection()
{
@Override
@@ -236,15 +236,15 @@ public class ServletApiRequest implements HttpServletRequest
@Override
public Cookie[] getCookies()
{
- List httpCookies = Request.getCookies(getServletContextRequest());
+ List httpCookies = Request.getCookies(getRequest());
if (httpCookies.isEmpty())
return null;
if (httpCookies instanceof ServletCookieList servletCookieList)
return servletCookieList.getServletCookies();
- ServletCookieList servletCookieList = new ServletCookieList(httpCookies, getServletContextRequest().getConnectionMetaData().getHttpConfiguration().getRequestCookieCompliance());
- _request.setAttribute(Request.COOKIE_ATTRIBUTE, servletCookieList);
- if (_request.getComponents().getCache().getAttribute(Request.CACHE_ATTRIBUTE) instanceof CookieCache cookieCache)
+ ServletCookieList servletCookieList = new ServletCookieList(httpCookies, getRequest().getConnectionMetaData().getHttpConfiguration().getRequestCookieCompliance());
+ getRequest().setAttribute(Request.COOKIE_ATTRIBUTE, servletCookieList);
+ if (getRequest().getComponents().getCache().getAttribute(Request.CACHE_ATTRIBUTE) instanceof CookieCache cookieCache)
cookieCache.replaceCookieList(servletCookieList);
return servletCookieList.getServletCookies();
}
@@ -279,7 +279,7 @@ public class ServletApiRequest implements HttpServletRequest
@Override
public Enumeration getHeaderNames()
{
- return getFields().getFieldNames();
+ return Collections.enumeration(getFields().getFieldNamesCollection());
}
@Override
@@ -292,28 +292,28 @@ public class ServletApiRequest implements HttpServletRequest
@Override
public String getPathInfo()
{
- return _request._matchedPath.getPathInfo();
+ return getServletRequestInfo().getMatchedResource().getMatchedPath().getPathInfo();
}
@Override
public String getPathTranslated()
{
String pathInfo = getPathInfo();
- if (pathInfo == null || _request.getContext() == null)
+ if (pathInfo == null || getServletRequestInfo().getServletContext() == null)
return null;
- return _request.getContext().getServletContext().getRealPath(pathInfo);
+ return getServletRequestInfo().getServletContext().getServletContext().getRealPath(pathInfo);
}
@Override
public String getContextPath()
{
- return _request.getContext().getServletContextHandler().getRequestContextPath();
+ return getServletRequestInfo().getServletContext().getServletContextHandler().getRequestContextPath();
}
@Override
public String getQueryString()
{
- return _request.getHttpURI().getQuery();
+ return getRequest().getHttpURI().getQuery();
}
@Override
@@ -329,7 +329,7 @@ public class ServletApiRequest implements HttpServletRequest
public boolean isUserInRole(String role)
{
//obtain any substituted role name from the destination servlet
- String linkedRole = _request._mappedServlet.getServletHolder().getUserRoleLink(role);
+ String linkedRole = getServletRequestInfo().getMatchedResource().getResource().getServletHolder().getUserRoleLink(role);
AuthenticationState authenticationState = getUndeferredAuthentication();
if (authenticationState instanceof AuthenticationState.Succeeded succeededAuthentication)
@@ -354,33 +354,34 @@ public class ServletApiRequest implements HttpServletRequest
@Override
public String getRequestedSessionId()
{
- AbstractSessionManager.RequestedSession requestedSession = _request.getRequestedSession();
+ AbstractSessionManager.RequestedSession requestedSession = getServletRequestInfo().getRequestedSession();
return requestedSession == null ? null : requestedSession.sessionId();
}
@Override
public String getRequestURI()
{
- HttpURI uri = _request.getHttpURI();
+ HttpURI uri = getRequest().getHttpURI();
return uri == null ? null : uri.getPath();
}
@Override
public StringBuffer getRequestURL()
{
- return new StringBuffer(HttpURI.build(_request.getHttpURI()).query(null).asString());
+ // Use the ServletContextRequest here as even if changed in the Request, it must match the servletPath and pathInfo
+ return new StringBuffer(HttpURI.build(getRequest().getHttpURI()).query(null).asString());
}
@Override
public String getServletPath()
{
- return _request._matchedPath.getPathMatch();
+ return getServletRequestInfo().getMatchedResource().getMatchedPath().getPathMatch();
}
@Override
public HttpSession getSession(boolean create)
{
- Session session = _request.getSession(create);
+ Session session = getRequest().getSession(create);
if (session == null)
return null;
if (session.isNew() && getAuthentication() instanceof AuthenticationState.Succeeded)
@@ -397,11 +398,11 @@ public class ServletApiRequest implements HttpServletRequest
@Override
public String changeSessionId()
{
- Session session = _request.getSession(false);
+ Session session = getRequest().getSession(false);
if (session == null)
throw new IllegalStateException("No session");
- session.renewId(_request, _request.getResponse());
+ session.renewId(getRequest(), _servletChannel.getResponse());
if (getRemoteUser() != null)
session.setAttribute(ManagedSession.SESSION_CREATED_SECURE, Boolean.TRUE);
@@ -412,21 +413,21 @@ public class ServletApiRequest implements HttpServletRequest
@Override
public boolean isRequestedSessionIdValid()
{
- AbstractSessionManager.RequestedSession requestedSession = _request.getRequestedSession();
+ AbstractSessionManager.RequestedSession requestedSession = getServletRequestInfo().getRequestedSession();
return requestedSession != null && requestedSession.sessionId() != null && !requestedSession.sessionIdFromCookie();
}
@Override
public boolean isRequestedSessionIdFromCookie()
{
- AbstractSessionManager.RequestedSession requestedSession = _request.getRequestedSession();
+ AbstractSessionManager.RequestedSession requestedSession = getServletRequestInfo().getRequestedSession();
return requestedSession != null && requestedSession.sessionId() != null && requestedSession.sessionIdFromCookie();
}
@Override
public boolean isRequestedSessionIdFromURL()
{
- AbstractSessionManager.RequestedSession requestedSession = _request.getRequestedSession();
+ AbstractSessionManager.RequestedSession requestedSession = getServletRequestInfo().getRequestedSession();
return requestedSession != null && requestedSession.sessionId() != null && !requestedSession.sessionIdFromCookie();
}
@@ -462,8 +463,9 @@ public class ServletApiRequest implements HttpServletRequest
{
try
{
+ ServletRequestInfo servletRequestInfo = getServletRequestInfo();
AuthenticationState.Succeeded succeededAuthentication = AuthenticationState.login(
- username, password, getServletContextRequest(), getServletContextRequest().getResponse());
+ username, password, getRequest(), servletRequestInfo.getServletChannel().getServletContextResponse());
if (succeededAuthentication == null)
throw new QuietException.Exception("Authentication failed for username '" + username + "'");
@@ -477,7 +479,8 @@ public class ServletApiRequest implements HttpServletRequest
@Override
public void logout() throws ServletException
{
- if (!AuthenticationState.logout(getServletContextRequest(), getServletContextRequest().getResponse()))
+ ServletRequestInfo servletRequestInfo = getServletRequestInfo();
+ if (!AuthenticationState.logout(getRequest(), servletRequestInfo.getServletChannel().getServletContextResponse()))
throw new ServletException("logout failed");
}
@@ -494,7 +497,7 @@ public class ServletApiRequest implements HttpServletRequest
if (config == null)
throw new IllegalStateException("No multipart config for servlet");
- ServletContextHandler contextHandler = _request.getContext().getServletContextHandler();
+ ServletContextHandler contextHandler = getServletRequestInfo().getServletContext().getServletContextHandler();
int maxFormContentSize = contextHandler.getMaxFormContentSize();
int maxFormKeys = contextHandler.getMaxFormKeys();
@@ -574,10 +577,10 @@ public class ServletApiRequest implements HttpServletRequest
@Override
public PushBuilder newPushBuilder()
{
- if (!_request.getConnectionMetaData().isPushSupported())
+ if (!getRequest().getConnectionMetaData().isPushSupported())
return null;
- HttpFields.Mutable pushHeaders = HttpFields.build(_request.getHeaders(), EnumSet.of(
+ HttpFields.Mutable pushHeaders = HttpFields.build(getRequest().getHeaders(), EnumSet.of(
HttpHeader.IF_MATCH,
HttpHeader.IF_RANGE,
HttpHeader.IF_UNMODIFIED_SINCE,
@@ -594,7 +597,7 @@ public class ServletApiRequest implements HttpServletRequest
pushHeaders.put(HttpHeader.REFERER, referrer);
// Any Set-Cookie in the response should be present in the push.
- HttpFields.Mutable responseHeaders = _request.getResponse().getHeaders();
+ HttpFields.Mutable responseHeaders = _servletChannel.getResponse().getHeaders();
List setCookies = new ArrayList<>(responseHeaders.getValuesList(HttpHeader.SET_COOKIE));
setCookies.addAll(responseHeaders.getValuesList(HttpHeader.SET_COOKIE2));
String cookies = pushHeaders.get(HttpHeader.COOKIE);
@@ -642,7 +645,7 @@ public class ServletApiRequest implements HttpServletRequest
sessionId = getRequestedSessionId();
}
- return new PushBuilderImpl(_request, pushHeaders, sessionId);
+ return new PushBuilderImpl(ServletContextRequest.getServletContextRequest(this), pushHeaders, sessionId);
}
@Override
@@ -659,17 +662,17 @@ public class ServletApiRequest implements HttpServletRequest
case AsyncContext.ASYNC_PATH_INFO -> getPathInfo();
case AsyncContext.ASYNC_QUERY_STRING -> getQueryString();
case AsyncContext.ASYNC_MAPPING -> getHttpServletMapping();
- default -> _request.getAttribute(name);
+ default -> getRequest().getAttribute(name);
};
}
- return _request.getAttribute(name);
+ return getRequest().getAttribute(name);
}
@Override
public Enumeration getAttributeNames()
{
- Set set = _request.getAttributeNameSet();
+ Set set = getRequest().getAttributeNameSet();
if (_async != null)
{
set = new HashSet<>(set);
@@ -689,8 +692,8 @@ public class ServletApiRequest implements HttpServletRequest
{
if (_characterEncoding == null)
{
- if (_request.getContext() != null)
- _characterEncoding = _request.getContext().getServletContext().getRequestCharacterEncoding();
+ if (getRequest().getContext() != null)
+ _characterEncoding = getServletRequestInfo().getServletContext().getServletContext().getRequestCharacterEncoding();
if (_characterEncoding == null)
{
@@ -765,10 +768,10 @@ public class ServletApiRequest implements HttpServletRequest
throw new IllegalStateException("READER");
_inputState = ServletContextRequest.INPUT_STREAM;
- if (_request.getServletChannel().isExpecting100Continue())
- _request.getServletChannel().continue100(_request.getHttpInput().available());
+ if (getServletRequestInfo().getServletChannel().isExpecting100Continue())
+ getServletRequestInfo().getServletChannel().continue100(getServletRequestInfo().getHttpInput().available());
- return _request.getHttpInput();
+ return getServletRequestInfo().getHttpInput();
}
@Override
@@ -798,20 +801,6 @@ public class ServletApiRequest implements HttpServletRequest
return Collections.unmodifiableMap(getParameters().toStringArrayMap());
}
- public Fields getContentParameters()
- {
- getParameters(); // ensure extracted
- return _contentParameters;
- }
-
- public void setContentParameters(Fields params)
- {
- if (params == null || params.getSize() == 0)
- _contentParameters = ServletContextRequest.NO_PARAMS;
- else
- _contentParameters = params;
- }
-
private Fields getParameters()
{
extractContentParameters();
@@ -855,13 +844,14 @@ public class ServletApiRequest implements HttpServletRequest
{
String baseType = HttpField.valueParameters(getContentType(), null);
if (MimeTypes.Type.FORM_ENCODED.is(baseType) &&
- _request.getConnectionMetaData().getHttpConfiguration().isFormEncodedMethod(getMethod()))
+ getRequest().getConnectionMetaData().getHttpConfiguration().isFormEncodedMethod(getMethod()))
{
try
{
- int maxKeys = _request.getServletRequestState().getContextHandler().getMaxFormKeys();
- int maxContentSize = _request.getServletRequestState().getContextHandler().getMaxFormContentSize();
- _contentParameters = FormFields.from(getServletContextRequest(), maxKeys, maxContentSize).get();
+ ServletContextHandler contextHandler = getServletRequestInfo().getServletContextHandler();
+ int maxKeys = contextHandler.getMaxFormKeys();
+ int maxContentSize = contextHandler.getMaxFormContentSize();
+ _contentParameters = FormFields.from(getRequest(), maxKeys, maxContentSize).get();
}
catch (IllegalStateException | IllegalArgumentException | ExecutionException |
InterruptedException e)
@@ -889,7 +879,7 @@ public class ServletApiRequest implements HttpServletRequest
{
try
{
- _contentParameters = FormFields.get(getServletContextRequest()).get();
+ _contentParameters = FormFields.get(getRequest()).get();
}
catch (IllegalStateException | IllegalArgumentException | ExecutionException |
InterruptedException e)
@@ -918,14 +908,14 @@ public class ServletApiRequest implements HttpServletRequest
// and may have already been extracted by mergeQueryParameters().
if (_queryParameters == null)
{
- HttpURI httpURI = _request.getHttpURI();
+ HttpURI httpURI = getRequest().getHttpURI();
if (httpURI == null || StringUtil.isEmpty(httpURI.getQuery()))
_queryParameters = ServletContextRequest.NO_PARAMS;
else
{
try
{
- _queryParameters = Request.extractQueryParameters(_request, _request.getQueryEncoding());
+ _queryParameters = Request.extractQueryParameters(getRequest(), getServletRequestInfo().getQueryEncoding());
}
catch (IllegalStateException | IllegalArgumentException e)
{
@@ -939,19 +929,19 @@ public class ServletApiRequest implements HttpServletRequest
@Override
public String getProtocol()
{
- return _request.getConnectionMetaData().getProtocol();
+ return getRequest().getConnectionMetaData().getProtocol();
}
@Override
public String getScheme()
{
- return _request.getHttpURI().getScheme();
+ return getRequest().getHttpURI().getScheme();
}
@Override
public String getServerName()
{
- HttpURI uri = _request.getHttpURI();
+ HttpURI uri = getRequest().getHttpURI();
if ((uri != null) && StringUtil.isNotBlank(uri.getAuthority()))
return formatAddrOrHost(uri.getHost());
else
@@ -960,13 +950,13 @@ public class ServletApiRequest implements HttpServletRequest
private String formatAddrOrHost(String name)
{
- ServletChannel servletChannel = _request.getServletChannel();
+ ServletChannel servletChannel = _servletChannel;
return servletChannel == null ? HostPort.normalizeHost(name) : servletChannel.formatAddrOrHost(name);
}
private String findServerName()
{
- ServletChannel servletChannel = _request.getServletChannel();
+ ServletChannel servletChannel = _servletChannel;
if (servletChannel != null)
{
HostPort serverAuthority = servletChannel.getServerAuthority();
@@ -985,9 +975,9 @@ public class ServletApiRequest implements HttpServletRequest
@Override
public int getServerPort()
{
- int port = -1;
+ int port;
- HttpURI uri = _request.getHttpURI();
+ HttpURI uri = getRequest().getHttpURI();
if ((uri != null) && StringUtil.isNotBlank(uri.getAuthority()))
port = uri.getPort();
else
@@ -1003,7 +993,7 @@ public class ServletApiRequest implements HttpServletRequest
private int findServerPort()
{
- ServletChannel servletChannel = _request.getServletChannel();
+ ServletChannel servletChannel = getServletRequestInfo().getServletChannel();
if (servletChannel != null)
{
HostPort serverAuthority = servletChannel.getServerAuthority();
@@ -1043,9 +1033,9 @@ public class ServletApiRequest implements HttpServletRequest
}
};
}
- else if (_request.getServletChannel().isExpecting100Continue())
+ else if (getServletRequestInfo().getServletChannel().isExpecting100Continue())
{
- _request.getServletChannel().continue100(_request.getHttpInput().available());
+ getServletRequestInfo().getServletChannel().continue100(getServletRequestInfo().getHttpInput().available());
}
_inputState = ServletContextRequest.INPUT_READER;
return _reader;
@@ -1054,28 +1044,28 @@ public class ServletApiRequest implements HttpServletRequest
@Override
public String getRemoteAddr()
{
- return Request.getRemoteAddr(_request);
+ return Request.getRemoteAddr(getRequest());
}
@Override
public String getRemoteHost()
{
// TODO: review.
- return Request.getRemoteAddr(_request);
+ return Request.getRemoteAddr(getRequest());
}
@Override
public void setAttribute(String name, Object attribute)
{
- Object oldValue = _request.setAttribute(name, attribute);
+ Object oldValue = getRequest().setAttribute(name, attribute);
if ("org.eclipse.jetty.server.Request.queryEncoding".equals(name))
- _request.setQueryEncoding(attribute == null ? null : attribute.toString());
+ getServletRequestInfo().setQueryEncoding(attribute == null ? null : attribute.toString());
- if (!_request.getRequestAttributeListeners().isEmpty())
+ if (!getServletRequestInfo().getRequestAttributeListeners().isEmpty())
{
- final ServletRequestAttributeEvent event = new ServletRequestAttributeEvent(_request.getContext().getServletContext(), this, name, oldValue == null ? attribute : oldValue);
- for (ServletRequestAttributeListener l : _request.getRequestAttributeListeners())
+ final ServletRequestAttributeEvent event = new ServletRequestAttributeEvent(getServletRequestInfo().getServletContext().getServletContext(), this, name, oldValue == null ? attribute : oldValue);
+ for (ServletRequestAttributeListener l : getServletRequestInfo().getRequestAttributeListeners())
{
if (oldValue == null)
l.attributeAdded(event);
@@ -1090,12 +1080,12 @@ public class ServletApiRequest implements HttpServletRequest
@Override
public void removeAttribute(String name)
{
- Object oldValue = _request.removeAttribute(name);
+ Object oldValue = getRequest().removeAttribute(name);
- if (oldValue != null && !_request.getRequestAttributeListeners().isEmpty())
+ if (oldValue != null && !getServletRequestInfo().getRequestAttributeListeners().isEmpty())
{
- final ServletRequestAttributeEvent event = new ServletRequestAttributeEvent(_request.getContext().getServletContext(), this, name, oldValue);
- for (ServletRequestAttributeListener listener : _request.getRequestAttributeListeners())
+ final ServletRequestAttributeEvent event = new ServletRequestAttributeEvent(getServletRequestInfo().getServletContext().getServletContext(), this, name, oldValue);
+ for (ServletRequestAttributeListener listener : getServletRequestInfo().getRequestAttributeListeners())
{
listener.attributeRemoved(event);
}
@@ -1105,32 +1095,32 @@ public class ServletApiRequest implements HttpServletRequest
@Override
public Locale getLocale()
{
- return Request.getLocales(_request).get(0);
+ return Request.getLocales(getRequest()).get(0);
}
@Override
public Enumeration getLocales()
{
- return Collections.enumeration(Request.getLocales(_request));
+ return Collections.enumeration(Request.getLocales(getRequest()));
}
@Override
public boolean isSecure()
{
- return _request.getConnectionMetaData().isSecure();
+ return getRequest().getConnectionMetaData().isSecure();
}
@Override
public RequestDispatcher getRequestDispatcher(String path)
{
- ServletContextHandler.ServletScopedContext context = _request.getContext();
+ ServletContextHandler.ServletScopedContext context = getServletRequestInfo().getServletContext();
if (path == null || context == null)
return null;
// handle relative path
if (!path.startsWith("/"))
{
- String relTo = _request.getDecodedPathInContext();
+ String relTo = getServletRequestInfo().getDecodedPathInContext();
int slash = relTo.lastIndexOf("/");
if (slash > 1)
relTo = relTo.substring(0, slash + 1);
@@ -1145,13 +1135,13 @@ public class ServletApiRequest implements HttpServletRequest
@Override
public int getRemotePort()
{
- return Request.getRemotePort(_request);
+ return Request.getRemotePort(getRequest());
}
@Override
public String getLocalName()
{
- ServletChannel servletChannel = _request.getServletChannel();
+ ServletChannel servletChannel = getServletRequestInfo().getServletChannel();
if (servletChannel != null)
{
String localName = servletChannel.getLocalName();
@@ -1164,19 +1154,19 @@ public class ServletApiRequest implements HttpServletRequest
@Override
public String getLocalAddr()
{
- return Request.getLocalAddr(_request);
+ return Request.getLocalAddr(getRequest());
}
@Override
public int getLocalPort()
{
- return Request.getLocalPort(_request);
+ return Request.getLocalPort(getRequest());
}
@Override
public ServletContext getServletContext()
{
- return _request.getServletChannel().getServletContext();
+ return getServletRequestInfo().getServletChannel().getServletContextApi();
}
@Override
@@ -1184,10 +1174,11 @@ public class ServletApiRequest implements HttpServletRequest
{
if (!isAsyncSupported())
throw new IllegalStateException("Async Not Supported");
- ServletRequestState state = _request.getState();
+ ServletRequestState state = getServletRequestInfo().getState();
if (_async == null)
_async = new AsyncContextState(state);
- AsyncContextEvent event = new AsyncContextEvent(_request.getContext(), _async, state, this, _request.getResponse().getHttpServletResponse());
+ ServletRequestInfo servletRequestInfo = getServletRequestInfo();
+ AsyncContextEvent event = new AsyncContextEvent(getServletRequestInfo().getServletContext(), _async, state, this, servletRequestInfo.getServletChannel().getServletContextResponse().getServletApiResponse());
state.startAsync(event);
return _async;
}
@@ -1197,10 +1188,10 @@ public class ServletApiRequest implements HttpServletRequest
{
if (!isAsyncSupported())
throw new IllegalStateException("Async Not Supported");
- ServletRequestState state = _request.getState();
+ ServletRequestState state = getServletRequestInfo().getState();
if (_async == null)
_async = new AsyncContextState(state);
- AsyncContextEvent event = new AsyncContextEvent(_request.getContext(), _async, state, servletRequest, servletResponse);
+ AsyncContextEvent event = new AsyncContextEvent(getServletRequestInfo().getServletContext(), _async, state, servletRequest, servletResponse);
state.startAsync(event);
return _async;
}
@@ -1208,13 +1199,13 @@ public class ServletApiRequest implements HttpServletRequest
@Override
public HttpServletMapping getHttpServletMapping()
{
- return _request._mappedServlet.getServletPathMapping(_request.getDecodedPathInContext());
+ return getServletRequestInfo().getMatchedResource().getResource().getServletPathMapping(getServletRequestInfo().getDecodedPathInContext());
}
@Override
public boolean isAsyncStarted()
{
- return _request.getState().isAsyncStarted();
+ return getServletRequestInfo().getState().isAsyncStarted();
}
@Override
@@ -1231,7 +1222,7 @@ public class ServletApiRequest implements HttpServletRequest
@Override
public AsyncContext getAsyncContext()
{
- ServletRequestState state = _request.getServletChannel().getState();
+ ServletRequestState state = getServletRequestInfo().getServletChannel().getServletRequestState();
if (_async == null || !state.isAsyncStarted())
throw new IllegalStateException(state.getStatusString());
@@ -1247,7 +1238,7 @@ public class ServletApiRequest implements HttpServletRequest
@Override
public Map getTrailerFields()
{
- HttpFields trailers = _request.getTrailers();
+ HttpFields trailers = getRequest().getTrailers();
if (trailers == null)
return Map.of();
Map trailersMap = new HashMap<>();
diff --git a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/ServletApiResponse.java b/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/ServletApiResponse.java
index d7798dd431d..8211dca565f 100644
--- a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/ServletApiResponse.java
+++ b/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/ServletApiResponse.java
@@ -15,7 +15,6 @@ package org.eclipse.jetty.ee10.servlet;
import java.io.IOException;
import java.io.PrintWriter;
-import java.nio.channels.IllegalSelectorException;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
@@ -27,30 +26,29 @@ import java.util.function.Supplier;
import jakarta.servlet.ServletOutputStream;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletResponse;
+import org.eclipse.jetty.ee10.servlet.ServletContextHandler.ServletRequestInfo;
+import org.eclipse.jetty.ee10.servlet.ServletContextHandler.ServletResponseInfo;
import org.eclipse.jetty.ee10.servlet.writer.EncodingHttpWriter;
import org.eclipse.jetty.ee10.servlet.writer.Iso88591HttpWriter;
import org.eclipse.jetty.ee10.servlet.writer.ResponseWriter;
import org.eclipse.jetty.ee10.servlet.writer.Utf8HttpWriter;
import org.eclipse.jetty.http.HttpCookie;
import org.eclipse.jetty.http.HttpFields;
-import org.eclipse.jetty.http.HttpGenerator;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.http.HttpVersion;
-import org.eclipse.jetty.http.MimeTypes;
-import org.eclipse.jetty.io.RuntimeIOException;
+import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Response;
import org.eclipse.jetty.session.ManagedSession;
import org.eclipse.jetty.session.SessionManager;
import org.eclipse.jetty.util.Blocker;
+import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.StringUtil;
/**
- * The Jetty low level implementation of the ee10 {@link HttpServletResponse} object.
- *
- *
- * This provides the bridges from Servlet {@link HttpServletResponse} to the Jetty Core {@link Response} concepts (provided by the {@link ServletContextResponse})
- *
+ * The Jetty implementation of the ee10 {@link HttpServletResponse} object.
+ * This provides the bridge from the Servlet {@link HttpServletResponse} to the Jetty Core {@link Response}
+ * via the {@link ServletContextResponse}.
*/
public class ServletApiResponse implements HttpServletResponse
{
@@ -62,16 +60,45 @@ public class ServletApiResponse implements HttpServletResponse
ServletContextResponse.EncodingFrom.SET_LOCALE
);
- private final ServletContextResponse _response;
+ private final ServletChannel _servletChannel;
+ private final ServletContextHandler.ServletRequestInfo _servletRequestInfo;
+ private final ServletResponseInfo _servletResponseInfo;
- protected ServletApiResponse(ServletContextResponse response)
+ protected ServletApiResponse(ServletContextResponse servletContextResponse)
{
- _response = response;
+ _servletChannel = servletContextResponse.getServletContextRequest().getServletChannel();
+ _servletRequestInfo = servletContextResponse.getServletContextRequest();
+ _servletResponseInfo = servletContextResponse;
}
- public ServletContextResponse getResponse()
+ public ServletChannel getServletChannel()
{
- return _response;
+ return _servletChannel;
+ }
+
+ public ServletRequestInfo getServletRequestInfo()
+ {
+ return _servletRequestInfo;
+ }
+
+ /**
+ * @return The {@link ServletResponseInfo} for the request as provided by
+ * {@link ServletContextResponse} when wrapped by the {@link ServletContextHandler}.
+ */
+ public ServletResponseInfo getServletResponseInfo()
+ {
+ return _servletResponseInfo;
+ }
+
+ /**
+ * @return The core {@link Response} associated with the API response.
+ * This may differ from the {@link ServletContextResponse} as wrapped by the
+ * {@link ServletContextHandler} as it may have subsequently been wrapped before
+ * being passed to {@link ServletChannel#associate(Request, Response, Callback)}.
+ */
+ public Response getResponse()
+ {
+ return getServletChannel().getResponse();
}
@Override
@@ -85,22 +112,23 @@ public class ServletApiResponse implements HttpServletResponse
public void addCookie(HttpCookie cookie)
{
- Response.addCookie(_response, cookie);
+ Response.addCookie(getResponse(), cookie);
}
@Override
public boolean containsHeader(String name)
{
- return _response.getHeaders().contains(name);
+ return getResponse().getHeaders().contains(name);
}
@Override
public String encodeURL(String url)
{
- SessionManager sessionManager = _response.getServletContextRequest().getServletChannel().getContextHandler().getSessionHandler();
+ SessionManager sessionManager = getServletChannel().getServletContextHandler().getSessionHandler();
if (sessionManager == null)
return url;
- return sessionManager.encodeURI(_response.getServletContextRequest(), url, getResponse().getServletContextRequest().getServletApiRequest().isRequestedSessionIdFromCookie());
+ return sessionManager.encodeURI(getServletChannel().getRequest(), url,
+ getServletChannel().getServletContextRequest().getServletApiRequest().isRequestedSessionIdFromCookie());
}
@Override
@@ -114,14 +142,14 @@ public class ServletApiResponse implements HttpServletResponse
{
switch (sc)
{
- case -1 -> _response.getServletContextRequest().getServletChannel().abort(new IOException(msg));
+ case -1 -> getServletChannel().abort(new IOException(msg));
case HttpStatus.PROCESSING_102, HttpStatus.EARLY_HINT_103 ->
{
if (!isCommitted())
{
try (Blocker.Callback blocker = Blocker.callback())
{
- CompletableFuture completable = _response.writeInterim(sc, _response.getHeaders().asImmutable());
+ CompletableFuture completable = getServletChannel().getServletContextResponse().writeInterim(sc, getResponse().getHeaders().asImmutable());
blocker.completeWith(completable);
blocker.block();
}
@@ -131,7 +159,7 @@ public class ServletApiResponse implements HttpServletResponse
{
if (isCommitted())
throw new IllegalStateException("Committed");
- _response.getState().sendError(sc, msg);
+ getServletRequestInfo().getServletRequestState().sendError(sc, msg);
}
}
}
@@ -160,7 +188,7 @@ public class ServletApiResponse implements HttpServletResponse
resetBuffer();
try (Blocker.Callback callback = Blocker.callback())
{
- Response.sendRedirect(_response.getServletContextRequest(), _response, callback, code, location, false);
+ Response.sendRedirect(getServletRequestInfo().getRequest(), getResponse(), callback, code, location, false);
callback.block();
}
}
@@ -168,25 +196,25 @@ public class ServletApiResponse implements HttpServletResponse
@Override
public void setDateHeader(String name, long date)
{
- _response.getHeaders().putDate(name, date);
+ getResponse().getHeaders().putDate(name, date);
}
@Override
public void addDateHeader(String name, long date)
{
- _response.getHeaders().addDateField(name, date);
+ getResponse().getHeaders().addDateField(name, date);
}
@Override
public void setHeader(String name, String value)
{
- _response.getHeaders().put(name, value);
+ getResponse().getHeaders().put(name, value);
}
@Override
public void addHeader(String name, String value)
{
- _response.getHeaders().add(name, value);
+ getResponse().getHeaders().add(name, value);
}
@Override
@@ -194,7 +222,7 @@ public class ServletApiResponse implements HttpServletResponse
{
// TODO do we need int versions?
if (!isCommitted())
- _response.getHeaders().put(name, value);
+ getResponse().getHeaders().put(name, value);
}
@Override
@@ -202,136 +230,99 @@ public class ServletApiResponse implements HttpServletResponse
{
// TODO do we need a native version?
if (!isCommitted())
- _response.getHeaders().add(name, Integer.toString(value));
+ getResponse().getHeaders().add(name, Integer.toString(value));
}
@Override
public void setStatus(int sc)
{
- _response.setStatus(sc);
+ getResponse().setStatus(sc);
}
@Override
public int getStatus()
{
- return _response.getStatus();
+ return getResponse().getStatus();
}
@Override
public String getHeader(String name)
{
- return _response.getHeaders().get(name);
+ return getResponse().getHeaders().get(name);
}
@Override
public Collection getHeaders(String name)
{
- return _response.getHeaders().getValuesList(name);
+ return getResponse().getHeaders().getValuesList(name);
}
@Override
public Collection getHeaderNames()
{
- return _response.getHeaders().getFieldNamesCollection();
+ return getResponse().getHeaders().getFieldNamesCollection();
}
@Override
public String getCharacterEncoding()
{
- return _response.getCharacterEncoding(false);
+ return getServletResponseInfo().getCharacterEncoding(false);
}
@Override
public String getContentType()
{
- return _response.getContentType();
+ return getServletResponseInfo().getContentType();
}
@Override
public ServletOutputStream getOutputStream() throws IOException
{
- if (_response.getOutputType() == ServletContextResponse.OutputType.WRITER)
+ if (getServletResponseInfo().getOutputType() == ServletContextResponse.OutputType.WRITER)
throw new IllegalStateException("WRITER");
- _response.setOutputType(ServletContextResponse.OutputType.STREAM);
- return _response.getHttpOutput();
+ getServletResponseInfo().setOutputType(ServletContextResponse.OutputType.STREAM);
+ return getServletChannel().getHttpOutput();
}
@Override
public PrintWriter getWriter() throws IOException
{
- if (_response.getOutputType() == ServletContextResponse.OutputType.STREAM)
+ if (getServletResponseInfo().getOutputType() == ServletContextResponse.OutputType.STREAM)
throw new IllegalStateException("STREAM");
- if (_response.getOutputType() == ServletContextResponse.OutputType.NONE)
+ ResponseWriter writer = getServletResponseInfo().getWriter();
+ if (getServletResponseInfo().getOutputType() == ServletContextResponse.OutputType.NONE)
{
- String encoding = _response.getCharacterEncoding(true);
+ String encoding = getServletResponseInfo().getCharacterEncoding(true);
Locale locale = getLocale();
- if (_response.getWriter() != null && _response.getWriter().isFor(locale, encoding))
- _response.getWriter().reopen();
+ if (writer != null && writer.isFor(locale, encoding))
+ writer.reopen();
else
{
if (StringUtil.__ISO_8859_1.equalsIgnoreCase(encoding))
- _response.setWriter(new ResponseWriter(new Iso88591HttpWriter(_response.getHttpOutput()), locale, encoding));
+ getServletResponseInfo().setWriter(writer = new ResponseWriter(new Iso88591HttpWriter(getServletChannel().getHttpOutput()), locale, encoding));
else if (StringUtil.__UTF8.equalsIgnoreCase(encoding))
- _response.setWriter(new ResponseWriter(new Utf8HttpWriter(_response.getHttpOutput()), locale, encoding));
+ getServletResponseInfo().setWriter(writer = new ResponseWriter(new Utf8HttpWriter(getServletChannel().getHttpOutput()), locale, encoding));
else
- _response.setWriter(new ResponseWriter(new EncodingHttpWriter(_response.getHttpOutput(), encoding), locale, encoding));
+ getServletResponseInfo().setWriter(writer = new ResponseWriter(new EncodingHttpWriter(getServletChannel().getHttpOutput(), encoding), locale, encoding));
}
// Set the output type at the end, because setCharacterEncoding() checks for it.
- _response.setOutputType(ServletContextResponse.OutputType.WRITER);
+ getServletResponseInfo().setOutputType(ServletContextResponse.OutputType.WRITER);
}
- return _response.getWriter();
+ return writer;
}
@Override
public void setCharacterEncoding(String encoding)
{
- _response.setCharacterEncoding(encoding, ServletContextResponse.EncodingFrom.SET_CHARACTER_ENCODING);
+ getServletResponseInfo().setCharacterEncoding(encoding, ServletContextResponse.EncodingFrom.SET_CHARACTER_ENCODING);
}
@Override
public void setContentLength(int len)
{
- // Protect from setting after committed as default handling
- // of a servlet HEAD request ALWAYS sets _content length, even
- // if the getHandling committed the response!
- if (isCommitted())
- return;
-
- if (len > 0)
- {
- long written = _response.getHttpOutput().getWritten();
- if (written > len)
- throw new IllegalArgumentException("setContentLength(" + len + ") when already written " + written);
-
- _response.setContentLength(len);
- _response.getHeaders().put(HttpHeader.CONTENT_LENGTH, len);
- if (_response.isAllContentWritten(written))
- {
- try
- {
- _response.closeOutput();
- }
- catch (IOException e)
- {
- throw new RuntimeIOException(e);
- }
- }
- }
- else if (len == 0)
- {
- long written = _response.getHttpOutput().getWritten();
- if (written > 0)
- throw new IllegalArgumentException("setContentLength(0) when already written " + written);
- _response.setContentLength(len);
- _response.getHeaders().put(HttpFields.CONTENT_LENGTH_0);
- }
- else
- {
- _response.setContentLength(len);
- _response.getHeaders().remove(HttpHeader.CONTENT_LENGTH);
- }
+ setContentLengthLong(len);
}
@Override
@@ -342,8 +333,13 @@ public class ServletApiResponse implements HttpServletResponse
// if the getHandling committed the response!
if (isCommitted())
return;
- _response.setContentLength(len);
- _response.getHeaders().put(HttpHeader.CONTENT_LENGTH, len);
+
+ if (len > 0)
+ getResponse().getHeaders().put(HttpHeader.CONTENT_LENGTH, len);
+ else if (len == 0)
+ getResponse().getHeaders().put(HttpFields.CONTENT_LENGTH_0);
+ else
+ getResponse().getHeaders().remove(HttpHeader.CONTENT_LENGTH);
}
@Override
@@ -354,70 +350,20 @@ public class ServletApiResponse implements HttpServletResponse
if (contentType == null)
{
- if (_response.isWriting() && _response.getCharacterEncoding() != null)
- throw new IllegalSelectorException();
+ if (getServletResponseInfo().isWriting() && getServletResponseInfo().getCharacterEncoding() != null)
+ throw new IllegalStateException();
- if (_response.getLocale() == null)
- _response.setCharacterEncoding(null);
- _response.setMimeType(null);
- _response.setContentType(null);
- _response.getHeaders().remove(HttpHeader.CONTENT_TYPE);
+ getResponse().getHeaders().remove(HttpHeader.CONTENT_TYPE);
}
else
{
- _response.setContentType(contentType);
- _response.setMimeType(MimeTypes.CACHE.get(contentType));
-
- String charset = MimeTypes.getCharsetFromContentType(contentType);
- if (charset == null && _response.getMimeType() != null && _response.getMimeType().isCharsetAssumed())
- charset = _response.getMimeType().getCharsetString();
-
- if (charset == null)
- {
- switch (_response.getEncodingFrom())
- {
- case NOT_SET:
- break;
- case DEFAULT:
- case INFERRED:
- case SET_CONTENT_TYPE:
- case SET_LOCALE:
- case SET_CHARACTER_ENCODING:
- {
- _response.setContentType(contentType + ";charset=" + _response.getCharacterEncoding());
- _response.setMimeType(MimeTypes.CACHE.get(_response.getContentType()));
- break;
- }
- default:
- throw new IllegalStateException(_response.getEncodingFrom().toString());
- }
- }
- else if (_response.isWriting() && !charset.equalsIgnoreCase(_response.getCharacterEncoding()))
- {
- // too late to change the character encoding;
- _response.setContentType(MimeTypes.getContentTypeWithoutCharset(_response.getContentType()));
- if (_response.getCharacterEncoding() != null && (_response.getMimeType() == null || !_response.getMimeType().isCharsetAssumed()))
- _response.setContentType(_response.getContentType() + ";charset=" + _response.getCharacterEncoding());
- _response.setMimeType(MimeTypes.CACHE.get(_response.getContentType()));
- }
- else
- {
- _response.setRawCharacterEncoding(charset, ServletContextResponse.EncodingFrom.SET_CONTENT_TYPE);
- }
-
- if (HttpGenerator.__STRICT || _response.getMimeType() == null)
- _response.getHeaders().put(HttpHeader.CONTENT_TYPE, _response.getContentType());
- else
- {
- _response.setContentType(_response.getMimeType().asString());
- _response.getHeaders().put(_response.getMimeType().getContentTypeField());
- }
+ getResponse().getHeaders().put(HttpHeader.CONTENT_TYPE, contentType);
}
}
public long getContentCount()
{
- return _response.getHttpOutput().getWritten();
+ return getServletChannel().getHttpOutput().getWritten();
}
@Override
@@ -429,20 +375,20 @@ public class ServletApiResponse implements HttpServletResponse
throw new IllegalStateException("cannot set buffer size after response has " + getContentCount() + " bytes already written");
if (size < MIN_BUFFER_SIZE)
size = MIN_BUFFER_SIZE;
- _response.getHttpOutput().setBufferSize(size);
+ getServletChannel().getHttpOutput().setBufferSize(size);
}
@Override
public int getBufferSize()
{
- return _response.getHttpOutput().getBufferSize();
+ return getServletChannel().getHttpOutput().getBufferSize();
}
@Override
public void flushBuffer() throws IOException
{
- if (!_response.getHttpOutput().isClosed())
- _response.getHttpOutput().flush();
+ if (!getServletChannel().getHttpOutput().isClosed())
+ getServletChannel().getHttpOutput().flush();
}
@Override
@@ -450,17 +396,17 @@ public class ServletApiResponse implements HttpServletResponse
{
if (isCommitted())
throw new IllegalStateException("Committed");
- _response.getHttpOutput().resetBuffer();
- _response.getHttpOutput().reopen();
+ getServletChannel().getHttpOutput().resetBuffer();
+ getServletChannel().getHttpOutput().reopen();
}
@Override
public boolean isCommitted()
{
// If we are in sendError state, we pretend to be committed
- if (_response.getServletContextRequest().getServletChannel().isSendError())
+ if (getServletChannel().isSendError())
return true;
- return _response.getServletContextRequest().getServletChannel().isCommitted();
+ return getServletChannel().isCommitted();
}
@Override
@@ -469,14 +415,13 @@ public class ServletApiResponse implements HttpServletResponse
if (isCommitted())
throw new IllegalStateException("Committed");
- _response.reset();
+ getResponse().reset();
-
- ServletApiRequest servletApiRequest = _response.getServletContextRequest().getServletApiRequest();
- ManagedSession session = servletApiRequest.getServletContextRequest().getManagedSession();
+ ServletApiRequest servletApiRequest = getServletChannel().getServletContextRequest().getServletApiRequest();
+ ManagedSession session = servletApiRequest.getServletRequestInfo().getManagedSession();
if (session != null && session.isNew())
{
- SessionManager sessionManager = servletApiRequest.getServletContextRequest().getSessionManager();
+ SessionManager sessionManager = servletApiRequest.getServletRequestInfo().getSessionManager();
if (sessionManager != null)
{
HttpCookie cookie = sessionManager.getSessionCookie(session, servletApiRequest.getServletConnection().isSecure());
@@ -494,41 +439,41 @@ public class ServletApiResponse implements HttpServletResponse
if (locale == null)
{
- _response.setLocale(null);
- _response.getHeaders().remove(HttpHeader.CONTENT_LANGUAGE);
- if (_response.getEncodingFrom() == ServletContextResponse.EncodingFrom.SET_LOCALE)
- _response.setCharacterEncoding(null, ServletContextResponse.EncodingFrom.NOT_SET);
+ getServletResponseInfo().setLocale(null);
+ getResponse().getHeaders().remove(HttpHeader.CONTENT_LANGUAGE);
+ if (getServletResponseInfo().getEncodingFrom() == ServletContextResponse.EncodingFrom.SET_LOCALE)
+ getServletResponseInfo().setCharacterEncoding(null, ServletContextResponse.EncodingFrom.NOT_SET);
}
else
{
- _response.setLocale(locale);
- _response.getHeaders().put(HttpHeader.CONTENT_LANGUAGE, StringUtil.replace(locale.toString(), '_', '-'));
+ getServletResponseInfo().setLocale(locale);
+ getResponse().getHeaders().put(HttpHeader.CONTENT_LANGUAGE, StringUtil.replace(locale.toString(), '_', '-'));
- if (_response.getOutputType() != ServletContextResponse.OutputType.NONE)
+ if (getServletResponseInfo().getOutputType() != ServletContextResponse.OutputType.NONE)
return;
- ServletContextHandler.ServletScopedContext context = _response.getServletContextRequest().getServletChannel().getContext();
+ ServletContextHandler.ServletScopedContext context = getServletChannel().getContext();
if (context == null)
return;
String charset = context.getServletContextHandler().getLocaleEncoding(locale);
- if (!StringUtil.isEmpty(charset) && LOCALE_OVERRIDE.contains(_response.getEncodingFrom()))
- _response.setCharacterEncoding(charset, ServletContextResponse.EncodingFrom.SET_LOCALE);
+ if (!StringUtil.isEmpty(charset) && LOCALE_OVERRIDE.contains(getServletResponseInfo().getEncodingFrom()))
+ getServletResponseInfo().setCharacterEncoding(charset, ServletContextResponse.EncodingFrom.SET_LOCALE);
}
}
@Override
public Locale getLocale()
{
- if (_response.getLocale() == null)
+ if (getServletResponseInfo().getLocale() == null)
return Locale.getDefault();
- return _response.getLocale();
+ return getServletResponseInfo().getLocale();
}
@Override
public Supplier