Class ServletCoreRequest

java.lang.Object
org.eclipse.jetty.ee10.servlet.ServletCoreRequest
All Implemented Interfaces:
Content.Source, Request, Attributes

public class ServletCoreRequest extends Object implements Request
Wrap a ServletRequest as a core Request.

Whilst similar to a Request.Wrapper, this class is not a Wrapper as callers should not be able to access Request.Wrapper.getWrapped() and bypass the ServletRequest.

The current implementation does not support any read operations.

  • Method Details

    • wrap

      public static Request wrap(jakarta.servlet.http.HttpServletRequest httpServletRequest)
    • getHeaders

      public HttpFields getHeaders()
      Specified by:
      getHeaders in interface Request
      Returns:
      the HTTP headers of this Request
    • getHttpURI

      public HttpURI getHttpURI()
      Specified by:
      getHttpURI in interface Request
      Returns:
      the HTTP URI of this Request
      See Also:
    • getId

      public String getId()
      Description copied from interface: Request
      an ID unique within the lifetime scope of the ConnectionMetaData.getId()). This may be a protocol ID (e.g. HTTP/2 stream ID) or it may be unrelated to the protocol.
      Specified by:
      getId in interface Request
      See Also:
    • getMethod

      public String getMethod()
      Specified by:
      getMethod in interface Request
      Returns:
      the HTTP method of this Request
    • getServletRequest

      public jakarta.servlet.http.HttpServletRequest getServletRequest()
    • isSecure

      public boolean isSecure()
      Specified by:
      isSecure in interface Request
    • removeAttribute

      public Object removeAttribute(String name)
      Description copied from interface: Attributes
      Remove an attribute
      Specified by:
      removeAttribute in interface Attributes
      Parameters:
      name - the attribute to remove
      Returns:
      the value of the attribute if removed, else null
    • setAttribute

      public Object setAttribute(String name, Object attribute)
      Description copied from interface: Attributes
      Set an attribute
      Specified by:
      setAttribute in interface Attributes
      Parameters:
      name - the attribute to set
      attribute - the value to set. A null value is equivalent to removing the attribute.
      Returns:
      the previous value of the attribute if set, else null
    • getAttribute

      public Object getAttribute(String name)
      Description copied from interface: Attributes
      Get an attribute
      Specified by:
      getAttribute in interface Attributes
      Parameters:
      name - the attribute to get
      Returns:
      the value of the attribute, or null if no such attribute exists
    • getAttributeNameSet

      public Set<String> getAttributeNameSet()
      Description copied from interface: Attributes
      Get the immutable set of attribute names.
      Specified by:
      getAttributeNameSet in interface Attributes
      Returns:
      Set of attribute names, or an empty set if there are no attributes.
    • clearAttributes

      public void clearAttributes()
      Description copied from interface: Attributes
      Clear all attribute names
      Specified by:
      clearAttributes in interface Attributes
    • fail

      public void fail(Throwable failure)
      Description copied from interface: Content.Source

      Fails this content source with a last failure chunk, failing and discarding accumulated content chunks that were not yet read.

      The failure may be notified to the content reader at a later time, when the content reader reads a content chunk, via a Content.Chunk instance with a non null Content.Chunk.getFailure().

      If Content.Source.read() has returned a last chunk, this is a no operation.

      Typical failure: the content being aborted by user code, or idle timeouts.

      If this method has already been called, then it is a no operation.

      Specified by:
      fail in interface Content.Source
      Parameters:
      failure - the cause of the failure
      See Also:
    • getComponents

      public Components getComponents()
      Specified by:
      getComponents in interface Request
      Returns:
      the Components to be used with this Request.
    • getConnectionMetaData

      public ConnectionMetaData getConnectionMetaData()
      Specified by:
      getConnectionMetaData in interface Request
      Returns:
      the ConnectionMetaData associated to this Request
    • getContext

      public Context getContext()
      Description copied from interface: Request
      Get the Context associated with this Request.

      Note that a Request should always have an associated Context since if the Request is not being handled by a ContextHandler then the Context from Server.getContext() will be used.

      Specified by:
      getContext in interface Request
      Returns:
      the Context associated with this Request. Never null.
      See Also:
    • demand

      public void demand(Runnable demandCallback)
      Description copied from interface: Request

      Demands to invoke the given demand callback parameter when a chunk of content is available.

      See how to use this method idiomatically.

      Implementations guarantee that calls to this method are safely reentrant so that stack overflows are avoided in the case of mutual recursion between the execution of the Runnable callback and a call to this method. Invocations of the passed Runnable are serialized and a callback for demand call is not invoked until any previous demand callback has returned. Thus the Runnable should not block waiting for a callback of a future demand call.

      The demand callback may be invoked spuriously: a subsequent call to Content.Source.read() may return null.

      Calling this method establishes a pending demand, which is fulfilled when the demand callback is invoked.

      Calling this method when there is already a pending demand results in an IllegalStateException to be thrown.

      If the invocation of the demand callback throws an exception, then Content.Source.fail(Throwable) is called.

      Specified by:
      demand in interface Content.Source
      Specified by:
      demand in interface Request
      Parameters:
      demandCallback - the demand callback to invoke when there is a content chunk available.
      See Also:
    • getTrailers

      public HttpFields getTrailers()
      Specified by:
      getTrailers in interface Request
      Returns:
      the HTTP trailers of this Request, or null if they are not present
    • getBeginNanoTime

      public long getBeginNanoTime()
      Description copied from interface: Request

      Get the nanoTime at which the request arrived to a connector, obtained via System.nanoTime(). This method can be used when measuring latencies.

      Specified by:
      getBeginNanoTime in interface Request
      Returns:
      The nanoTime at which the request was received/created in nanoseconds
    • getHeadersNanoTime

      public long getHeadersNanoTime()
      Description copied from interface: Request

      Get the nanoTime at which the request headers were parsed, obtained via System.nanoTime(). This method can be used when measuring latencies.

      Specified by:
      getHeadersNanoTime in interface Request
      Returns:
      The nanoTime at which the request was ready in nanoseconds
    • read

      public Content.Chunk read()
      Description copied from interface: Request

      Reads a chunk of content.

      See how to use this method idiomatically.

      The returned chunk could be:

      • null, to signal that there isn't a chunk of content available
      • an Content.Chunk instance with non null Content.Chunk.getFailure(), to signal that there was a failure trying to produce a chunk of content, or that the content production has been failed externally
      • a Content.Chunk instance, containing the chunk of content.

      Once a read returns an Content.Chunk instance with non-null Content.Chunk.getFailure() then if the failure is last further reads will continue to return the same failure chunk instance, otherwise further read() operations may return different non-failure chunks.

      Once a read returns a last chunk, further reads will continue to return a last chunk (although the instance may be different).

      The content reader code must ultimately arrange for a call to Retainable.release() on the returned Content.Chunk.

      Additionally, prior to the ultimate call to Retainable.release(), the reader code may make additional calls to Retainable.retain(), that must ultimately be matched by a correspondent number of calls to Retainable.release().

      Concurrent reads from different threads are not recommended, as they are inherently in a race condition.

      Reads performed outside the invocation context of a demand callback are allowed. However, reads performed with a pending demand are inherently in a race condition (the thread that reads with the thread that invokes the demand callback).

      In addition, the returned Content.Chunk may be a Trailers instance, in case of request content trailers.

      Specified by:
      read in interface Content.Source
      Specified by:
      read in interface Request
      Returns:
      a chunk of content, possibly a failure instance, or null
      See Also:
    • consumeAvailable

      public boolean consumeAvailable()
      Description copied from interface: Request
      Consume any available content. This bypasses any request wrappers to process the content in Request.read() and reads directly from the HttpStream. This reads until there is no content currently available, or it reaches EOF. The HttpConfiguration.setMaxUnconsumedRequestContentReads(int) configuration can be used to configure how many reads will be attempted by this method.
      Specified by:
      consumeAvailable in interface Request
      Returns:
      true if the content was fully consumed.
    • addIdleTimeoutListener

      public void addIdleTimeoutListener(Predicate<TimeoutException> onIdleTimeout)
      Description copied from interface: Request

      Adds a listener for idle timeouts.

      The listener is a predicate function that should return true to indicate that the idle timeout should be handled by the container as a fatal failure (see Request.addFailureListener(Consumer)); or false to ignore that specific timeout and for another timeout to occur after another idle period.

      Idle timeout listeners are only invoked if there are no pending Request.demand(Runnable) or Response.write(boolean, ByteBuffer, Callback) operations.

      Listeners are processed in the same order they are added, and the first that returns true stops the processing of subsequent listeners, which are therefore not invoked.

      Specified by:
      addIdleTimeoutListener in interface Request
      Parameters:
      onIdleTimeout - the idle timeout listener as a predicate function
      See Also:
    • addFailureListener

      public void addFailureListener(Consumer<Throwable> onFailure)
      Description copied from interface: Request

      Adds a listener for asynchronous fatal failures.

      When a listener is called, the effects of the failure have already taken place:

      Listeners are processed in the same order they are added.

      Specified by:
      addFailureListener in interface Request
      Parameters:
      onFailure - the failure listener as a consumer function
      See Also:
    • getTunnelSupport

      public TunnelSupport getTunnelSupport()
      Specified by:
      getTunnelSupport in interface Request
    • addHttpStreamWrapper

      public void addHttpStreamWrapper(Function<HttpStream,HttpStream> wrapper)
      Description copied from interface: Request
      Add a HttpStream.Wrapper to the current HttpStream.
      Specified by:
      addHttpStreamWrapper in interface Request
      Parameters:
      wrapper - A function that wraps the passed stream.
      See Also:
    • getSession

      public Session getSession(boolean create)
      Description copied from interface: Request

      Get a Session associated with the request. Sessions may not be supported by a given configuration, in which case null will be returned.

      Specified by:
      getSession in interface Request
      Parameters:
      create - True if the session should be created for the request.
      Returns:
      The session associated with the request or null.