Package net.officefloor.server.http.mock
Class MockHttpServer.MockServerHttpConnectionImpl
- java.lang.Object
-
- net.officefloor.server.http.mock.MockHttpServer.MockServerHttpConnectionImpl
-
- All Implemented Interfaces:
MockHttpRequestCallback,MockServerHttpConnection,ServerHttpConnection
- Enclosing class:
- MockHttpServer
public static class MockHttpServer.MockServerHttpConnectionImpl extends java.lang.Object implements MockServerHttpConnection, MockHttpRequestCallback
MockServerHttpConnectionimplementation.
-
-
Field Summary
-
Fields inherited from interface net.officefloor.server.http.ServerHttpConnection
DEFAULT_HTTP_ENTITY_CHARSET, HTTP_CHARSET, URI_CHARSET
-
-
Constructor Summary
Constructors Constructor Description MockServerHttpConnectionImpl(MockHttpRequestBuilder request)Instantiate.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.io.SerializableexportState()Exports the state of the currentHttpRequestandHttpResponse.HttpRequestgetClientRequest()Obtains the actual client sentHttpRequestfor theServerHttpConnection.HttpRequestgetRequest()Obtains theHttpRequestto be serviced.HttpResponsegetResponse()Obtains theHttpResponse.HttpServerLocationgetServerLocation()Obtains theHttpServerLocation.voidimportState(java.io.Serializable momento)Imports and overrides the currentHttpRequestandHttpResponsewith the input momento.booleanisSecure()Indicates if the connection is over a secure channel (e.g.voidresponse(MockHttpResponse response)Callback with theMockHttpResponse.MockHttpResponsesend(java.lang.Throwable escalation)Sends theHttpResponse.
-
-
-
Constructor Detail
-
MockServerHttpConnectionImpl
public MockServerHttpConnectionImpl(MockHttpRequestBuilder request)
Instantiate.- Parameters:
request-MockHttpRequestBuilder.
-
-
Method Detail
-
send
public MockHttpResponse send(java.lang.Throwable escalation)
Description copied from interface:MockServerHttpConnectionSends theHttpResponse.- Specified by:
sendin interfaceMockServerHttpConnection- Parameters:
escalation- OptionalEscalation. Should benullfor successful processing.- Returns:
MockHttpResponse.
-
response
public void response(MockHttpResponse response)
Description copied from interface:MockHttpRequestCallbackCallback with theMockHttpResponse.- Specified by:
responsein interfaceMockHttpRequestCallback- Parameters:
response-MockHttpResponse.
-
getRequest
public HttpRequest getRequest()
Description copied from interface:ServerHttpConnectionObtains theHttpRequestto be serviced.- Specified by:
getRequestin interfaceServerHttpConnection- Returns:
HttpRequestto be serviced.
-
getResponse
public HttpResponse getResponse()
Description copied from interface:ServerHttpConnectionObtains theHttpResponse.- Specified by:
getResponsein interfaceServerHttpConnection- Returns:
HttpResponse.
-
isSecure
public boolean isSecure()
Description copied from interface:ServerHttpConnectionIndicates if the connection is over a secure channel (e.g. utilising SSL).- Specified by:
isSecurein interfaceServerHttpConnection- Returns:
trueif connection is over a secure channel.
-
getServerLocation
public HttpServerLocation getServerLocation()
Description copied from interface:ServerHttpConnectionObtains theHttpServerLocation.- Specified by:
getServerLocationin interfaceServerHttpConnection- Returns:
HttpServerLocation.
-
exportState
public java.io.Serializable exportState() throws java.io.IOExceptionDescription copied from interface:ServerHttpConnectionExports the state of the current
HttpRequestandHttpResponse.This enables maintaining the state of the
HttpRequest/HttpResponseand later reinstating them (typically after a redirect).- Specified by:
exportStatein interfaceServerHttpConnection- Returns:
- Momento containing the current
HttpRequestandHttpResponsestate. - 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.IOExceptionDescription copied from interface:ServerHttpConnectionImports and overrides the currentHttpRequestandHttpResponsewith the input momento.- Specified by:
importStatein 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:ServerHttpConnectionObtains the actual client sent
HttpRequestfor theServerHttpConnection.As the
HttpRequestcan 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
HttpMethodis aPOSTorGET(regardless of imported state) - checking for the
AuthorizationHttpHeaderto ensure it was sent by the client for servicing theHttpRequest - checking for the JWT token
HttpRequestCookieto 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:
getClientRequestin 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
-
-