Package net.officefloor.server.http.impl
Class ProcessAwareServerHttpConnectionManagedObject<B>
- java.lang.Object
-
- net.officefloor.server.http.impl.ProcessAwareServerHttpConnectionManagedObject<B>
-
- Type Parameters:
B
- Type of underlying buffer being used.
- All Implemented Interfaces:
FlowCallback
,ContextAwareManagedObject
,ManagedObject
,ServerHttpConnection
public class ProcessAwareServerHttpConnectionManagedObject<B> extends java.lang.Object implements ServerHttpConnection, ContextAwareManagedObject, FlowCallback
ServerHttpConnection
implementation available forExternalServiceInput
.- Author:
- Daniel Sagenschneider
-
-
Field Summary
-
Fields inherited from interface net.officefloor.frame.api.function.FlowCallback
ESCALATE
-
Fields inherited from interface net.officefloor.server.http.ServerHttpConnection
DEFAULT_HTTP_ENTITY_CHARSET, HTTP_CHARSET, URI_CHARSET
-
-
Constructor Summary
Constructors Constructor Description ProcessAwareServerHttpConnectionManagedObject(HttpServerLocation serverLocation, boolean isSecure, java.util.function.Supplier<HttpMethod> methodSupplier, java.util.function.Supplier<java.lang.String> requestUriSupplier, HttpVersion version, NonMaterialisedHttpHeaders requestHeaders, ByteSequence requestEntity, HttpHeaderValue serverName, DateHttpHeaderClock dateHttpHeaderClock, boolean isIncludeStackTraceOnEscalation, HttpResponseWriter<B> writer, StreamBufferPool<B> bufferPool)
Instantiate.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.io.Serializable
exportState()
Exports the state of the currentHttpRequest
andHttpResponse
.static ExternalServiceCleanupEscalationHandler<ProcessAwareServerHttpConnectionManagedObject>
getCleanupEscalationHandler()
Obtains theExternalServiceCleanupEscalationHandler
.HttpRequest
getClientRequest()
Obtains the actual client sentHttpRequest
for theServerHttpConnection
.java.lang.Object
getObject()
Obtains the object being managed.HttpRequest
getRequest()
Obtains theHttpRequest
to be serviced.HttpResponse
getResponse()
Obtains theHttpResponse
.HttpServerLocation
getServerLocation()
Obtains theHttpServerLocation
.FlowCallback
getServiceFlowCallback()
Obtains the serviceFlowCallback
.void
importState(java.io.Serializable momento)
Imports and overrides the currentHttpRequest
andHttpResponse
with the input momento.boolean
isSecure()
Indicates if the connection is over a secure channel (e.g.void
run(java.lang.Throwable escalation)
Invoked on completion of theFlow
.void
setCleanupEscalations(CleanupEscalation[] cleanupEscalations)
Sets theCleanupEscalation
instances.void
setManagedObjectContext(ManagedObjectContext context)
Provides theManagedObjectContext
to theManagedObject
.
-
-
-
Constructor Detail
-
ProcessAwareServerHttpConnectionManagedObject
public ProcessAwareServerHttpConnectionManagedObject(HttpServerLocation serverLocation, boolean isSecure, java.util.function.Supplier<HttpMethod> methodSupplier, java.util.function.Supplier<java.lang.String> requestUriSupplier, HttpVersion version, NonMaterialisedHttpHeaders requestHeaders, ByteSequence requestEntity, HttpHeaderValue serverName, DateHttpHeaderClock dateHttpHeaderClock, boolean isIncludeStackTraceOnEscalation, HttpResponseWriter<B> writer, StreamBufferPool<B> bufferPool)
Instantiate.- Parameters:
serverLocation
-HttpServerLocation
.isSecure
- Indicates if secure.methodSupplier
-Supplier
for theHttpRequest
HttpMethod
.requestUriSupplier
-Supplier
for theHttpRequest
URI.version
-HttpVersion
for theHttpRequest
.requestHeaders
-NonMaterialisedHttpHeaders
for theHttpRequest
.requestEntity
-ByteSequence
for theHttpRequest
entity.serverName
- Name of the server. May benull
if not sendingServer
HttpHeader
.dateHttpHeaderClock
-DateHttpHeaderClock
. May benull
to not sendDate
HttpHeader
.isIncludeStackTraceOnEscalation
-true
to include theEscalation
stack trace in theHttpResponse
.writer
-HttpResponseWriter
.bufferPool
-StreamBufferPool
.
-
-
Method Detail
-
getCleanupEscalationHandler
public static ExternalServiceCleanupEscalationHandler<ProcessAwareServerHttpConnectionManagedObject> getCleanupEscalationHandler()
Obtains theExternalServiceCleanupEscalationHandler
.- Returns:
ExternalServiceCleanupEscalationHandler
.
-
getServiceFlowCallback
public FlowCallback getServiceFlowCallback()
Obtains the serviceFlowCallback
.- Returns:
FlowCallback
to use for servicing this.
-
setCleanupEscalations
public void setCleanupEscalations(CleanupEscalation[] cleanupEscalations) throws java.io.IOException
Sets theCleanupEscalation
instances.- Parameters:
cleanupEscalations
-CleanupEscalation
instances.- Throws:
java.io.IOException
- If fails to send theCleanupEscalation
details in theHttpResponse
.
-
setManagedObjectContext
public void setManagedObjectContext(ManagedObjectContext context)
Description copied from interface:ContextAwareManagedObject
Provides theManagedObjectContext
to theManagedObject
.- Specified by:
setManagedObjectContext
in interfaceContextAwareManagedObject
- Parameters:
context
-ManagedObjectContext
.
-
getObject
public java.lang.Object getObject()
Description copied from interface:ManagedObject
Obtains the object being managed.- Specified by:
getObject
in interfaceManagedObject
- Returns:
- Object being managed.
-
getServerLocation
public HttpServerLocation getServerLocation()
Description copied from interface:ServerHttpConnection
Obtains theHttpServerLocation
.- Specified by:
getServerLocation
in interfaceServerHttpConnection
- Returns:
HttpServerLocation
.
-
isSecure
public boolean isSecure()
Description copied from interface:ServerHttpConnection
Indicates if the connection is over a secure channel (e.g. utilising SSL).- Specified by:
isSecure
in interfaceServerHttpConnection
- Returns:
true
if connection is over a secure channel.
-
getRequest
public HttpRequest getRequest()
Description copied from interface:ServerHttpConnection
Obtains theHttpRequest
to be serviced.- Specified by:
getRequest
in interfaceServerHttpConnection
- Returns:
HttpRequest
to be serviced.
-
getResponse
public HttpResponse getResponse()
Description copied from interface:ServerHttpConnection
Obtains theHttpResponse
.- Specified by:
getResponse
in interfaceServerHttpConnection
- Returns:
HttpResponse
.
-
exportState
public java.io.Serializable exportState() throws java.io.IOException
Description copied from interface:ServerHttpConnection
Exports the state of the current
HttpRequest
andHttpResponse
.This enables maintaining the state of the
HttpRequest
/HttpResponse
and later reinstating them (typically after a redirect).- Specified by:
exportState
in interfaceServerHttpConnection
- Returns:
- Momento containing the current
HttpRequest
andHttpResponse
state. - Throws:
java.io.IOException
- Should the state not be able to be exported.- See Also:
ServerHttpConnection.importState(Serializable)
-
importState
public void importState(java.io.Serializable momento) throws java.lang.IllegalArgumentException, java.io.IOException
Description copied from interface:ServerHttpConnection
Imports and overrides the currentHttpRequest
andHttpResponse
with the input momento.- Specified by:
importState
in interfaceServerHttpConnection
- Parameters:
momento
- Momento exported from aServerHttpConnection
.- Throws:
java.lang.IllegalArgumentException
- Should the momento be invalid.java.io.IOException
- Should the state not be able to be imported.- See Also:
ServerHttpConnection.exportState()
-
getClientRequest
public HttpRequest getClientRequest()
Description copied from interface:ServerHttpConnection
Obtains the actual client sent
HttpRequest
for theServerHttpConnection
.As the
HttpRequest
can be overridden, this allows logic requiring to know details of the actual clientHttpRequest
. Examples of this logic are:- the POST/redirect/GET pattern that needs to know whether the client
sent
HttpMethod
is aPOST
orGET
(regardless of imported state) - checking for the
Authorization
HttpHeader
to ensure it was sent by the client for servicing theHttpRequest
- checking for the JWT token
HttpRequestCookie
to ensure it was sent by the client for servicing theHttpRequest
Note for most application logic the
ServerHttpConnection.getRequest()
should be used, as the intention is for this to contain the appropriate information for servicing theHttpRequest
.- Specified by:
getClientRequest
in interfaceServerHttpConnection
- Returns:
- Actual client
HttpRequest
. - See Also:
ServerHttpConnection.exportState()
,ServerHttpConnection.importState(Serializable)
- the POST/redirect/GET pattern that needs to know whether the client
sent
-
run
public void run(java.lang.Throwable escalation) throws java.lang.Throwable
Description copied from interface:FlowCallback
Invoked on completion of theFlow
.- Specified by:
run
in interfaceFlowCallback
- Parameters:
escalation
- PossibleThrowable
from theFlow
.null
indicates allEscalation
instances handled withinFlow
.- Throws:
java.lang.Throwable
-Escalation
within the callback logic.
-
-