Class ServletCoreRequest
- All Implemented Interfaces:
Content.Source, Request, Attributes
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.
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface Attributes
Attributes.Layer, Attributes.Lazy, Attributes.Mapped, Attributes.SyntheticNested classes/interfaces inherited from interface Content.Source
Content.Source.FactoryNested classes/interfaces inherited from interface Request
Request.AttributesWrapper, Request.AuthenticationState, Request.Handler, Request.ServeAs, Request.Wrapper -
Field Summary
Fields inherited from interface Attributes
NULLFields inherited from interface Request
COOKIE_ATTRIBUTE, DEFAULT_LOCALES, LOG -
Method Summary
Modifier and TypeMethodDescriptionvoidaddFailureListener(Consumer<Throwable> onFailure) Adds a listener for asynchronous fatal failures.voidaddHttpStreamWrapper(Function<HttpStream, HttpStream> wrapper) Add aHttpStream.Wrapperto the currentHttpStream.voidaddIdleTimeoutListener(Predicate<TimeoutException> onIdleTimeout) Adds a listener for idle timeouts.voidClear all attribute namesbooleanConsume any available content.voidDemands to invoke the given demand callback parameter when a chunk of content is available.voidFails this content source with alastfailure chunk, failing and discarding accumulated content chunks that were not yet read.getAttribute(String name) Get an attributeGet the immutable set of attribute names.longGet the nanoTime at which the request arrived to a connector, obtained viaSystem.nanoTime().Get theContextassociated with thisRequest.longGet the nanoTime at which the request headers were parsed, obtained viaSystem.nanoTime().getId()an ID unique within the lifetime scope of theConnectionMetaData.getId()).jakarta.servlet.http.HttpServletRequestgetSession(boolean create) Get aSessionassociated with the request.booleanisSecure()read()Reads a chunk of content.removeAttribute(String name) Remove an attributesetAttribute(String name, Object attribute) Set an attributewrap(jakarta.servlet.http.HttpServletRequest httpServletRequest) Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Attributes
asAttributeMap, equals, hashCodeMethods inherited from interface Content.Source
fail, getLength, rewind
-
Method Details
-
wrap
-
getHeaders
- Specified by:
getHeadersin interfaceRequest- Returns:
- the HTTP headers of this
Request
-
getHttpURI
- Specified by:
getHttpURIin interfaceRequest- Returns:
- the HTTP URI of this
Request - See Also:
-
getId
Description copied from interface:Requestan ID unique within the lifetime scope of theConnectionMetaData.getId()). This may be a protocol ID (e.g. HTTP/2 stream ID) or it may be unrelated to the protocol. -
getMethod
-
getServletRequest
public jakarta.servlet.http.HttpServletRequest getServletRequest() -
isSecure
-
removeAttribute
Description copied from interface:AttributesRemove an attribute- Specified by:
removeAttributein interfaceAttributes- Parameters:
name- the attribute to remove- Returns:
- the value of the attribute if removed, else
null
-
setAttribute
Description copied from interface:AttributesSet an attribute- Specified by:
setAttributein interfaceAttributes- Parameters:
name- the attribute to setattribute- 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
Description copied from interface:AttributesGet an attribute- Specified by:
getAttributein interfaceAttributes- Parameters:
name- the attribute to get- Returns:
- the value of the attribute, or
nullif no such attribute exists
-
getAttributeNameSet
Description copied from interface:AttributesGet the immutable set of attribute names.- Specified by:
getAttributeNameSetin interfaceAttributes- Returns:
- Set of attribute names, or an empty set if there are no attributes.
-
clearAttributes
public void clearAttributes()Description copied from interface:AttributesClear all attribute names- Specified by:
clearAttributesin interfaceAttributes
-
fail
Description copied from interface:Content.SourceFails this content source with a
lastfailure 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.Chunkinstance with a non nullContent.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:
failin interfaceContent.Source- Parameters:
failure- the cause of the failure- See Also:
-
getComponents
- Specified by:
getComponentsin interfaceRequest- Returns:
- the
Componentsto be used with thisRequest.
-
getConnectionMetaData
- Specified by:
getConnectionMetaDatain interfaceRequest- Returns:
- the
ConnectionMetaDataassociated to thisRequest
-
getContext
Description copied from interface:RequestGet theContextassociated with thisRequest.Note that a
Requestshould always have an associatedContextsince if theRequestis not being handled by aContextHandlerthen theContextfromServer.getContext()will be used.- Specified by:
getContextin interfaceRequest- Returns:
- the
Contextassociated with thisRequest. Nevernull. - See Also:
-
demand
Description copied from interface:RequestDemands 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
Runnablecallback and a call to this method. Invocations of the passedRunnableare serialized and a callback fordemandcall is not invoked until any previousdemandcallback has returned. Thus theRunnableshould 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 returnnull.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
IllegalStateExceptionto be thrown.If the invocation of the demand callback throws an exception, then
Content.Source.fail(Throwable)is called.- Specified by:
demandin interfaceContent.Source- Specified by:
demandin interfaceRequest- Parameters:
demandCallback- the demand callback to invoke when there is a content chunk available.- See Also:
-
getTrailers
- Specified by:
getTrailersin interfaceRequest- Returns:
- the HTTP trailers of this
Request, ornullif they are not present
-
getBeginNanoTime
public long getBeginNanoTime()Description copied from interface:RequestGet the nanoTime at which the request arrived to a connector, obtained via
System.nanoTime(). This method can be used when measuring latencies.- Specified by:
getBeginNanoTimein interfaceRequest- Returns:
- The nanoTime at which the request was received/created in nanoseconds
-
getHeadersNanoTime
public long getHeadersNanoTime()Description copied from interface:RequestGet the nanoTime at which the request headers were parsed, obtained via
System.nanoTime(). This method can be used when measuring latencies.- Specified by:
getHeadersNanoTimein interfaceRequest- Returns:
- The nanoTime at which the request was ready in nanoseconds
-
read
Description copied from interface:RequestReads 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.Chunkinstance with non nullContent.Chunk.getFailure(), to signal that there was a failure trying to produce a chunk of content, or that the content production has beenfailedexternally - a
Content.Chunkinstance, containing the chunk of content.
Once a read returns an
Content.Chunkinstance with non-nullContent.Chunk.getFailure()then if the failure islastfurther reads will continue to return the same failure chunk instance, otherwise furtherread()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 returnedContent.Chunk.Additionally, prior to the ultimate call to
Retainable.release(), the reader code may make additional calls toRetainable.retain(), that must ultimately be matched by a correspondent number of calls toRetainable.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 callbackare 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.Chunkmay be aTrailersinstance, in case of request content trailers.- Specified by:
readin interfaceContent.Source- Specified by:
readin interfaceRequest- Returns:
- a chunk of content, possibly a failure instance, or
null - See Also:
-
consumeAvailable
public boolean consumeAvailable()Description copied from interface:RequestConsume any available content. This bypasses any request wrappers to process the content inRequest.read()and reads directly from theHttpStream. This reads until there is no content currently available, or it reaches EOF. TheHttpConfiguration.setMaxUnconsumedRequestContentReads(int)configuration can be used to configure how many reads will be attempted by this method.- Specified by:
consumeAvailablein interfaceRequest- Returns:
- true if the content was fully consumed.
-
addIdleTimeoutListener
Description copied from interface:RequestAdds a listener for idle timeouts.
The listener is a predicate function that should return
trueto indicate that the idle timeout should be handled by the container as a fatal failure (seeRequest.addFailureListener(Consumer)); orfalseto 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)orResponse.write(boolean, ByteBuffer, Callback)operations.Listeners are processed in the same order they are added, and the first that returns
truestops the processing of subsequent listeners, which are therefore not invoked.- Specified by:
addIdleTimeoutListenerin interfaceRequest- Parameters:
onIdleTimeout- the idle timeout listener as a predicate function- See Also:
-
addFailureListener
Description copied from interface:RequestAdds a listener for asynchronous fatal failures.
When a listener is called, the effects of the failure have already taken place:
- Pending
Request.demand(Runnable)have been woken up. - Calls to
Request.read()will return theThrowablefailure. - Pending and new
Response.write(boolean, ByteBuffer, Callback)calls will be failed by callingCallback.failed(Throwable)on the callback passed toResponse.write(boolean, ByteBuffer, Callback).
Listeners are processed in the same order they are added.
- Specified by:
addFailureListenerin interfaceRequest- Parameters:
onFailure- the failure listener as a consumer function- See Also:
- Pending
-
getTunnelSupport
- Specified by:
getTunnelSupportin interfaceRequest
-
addHttpStreamWrapper
Description copied from interface:RequestAdd aHttpStream.Wrapperto the currentHttpStream.- Specified by:
addHttpStreamWrapperin interfaceRequest- Parameters:
wrapper- A function that wraps the passed stream.- See Also:
-
getSession
Description copied from interface:RequestGet a
Sessionassociated with the request. Sessions may not be supported by a given configuration, in which casenullwill be returned.- Specified by:
getSessionin interfaceRequest- Parameters:
create- True if the session should be created for the request.- Returns:
- The session associated with the request or
null.
-