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
MockServerHttpConnection
implementation.
-
-
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.Serializable
exportState()
Exports the state of the currentHttpRequest
andHttpResponse
.HttpRequest
getClientRequest()
Obtains the actual client sentHttpRequest
for theServerHttpConnection
.HttpRequest
getRequest()
Obtains theHttpRequest
to be serviced.HttpResponse
getResponse()
Obtains theHttpResponse
.HttpServerLocation
getServerLocation()
Obtains theHttpServerLocation
.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
response(MockHttpResponse response)
Callback with theMockHttpResponse
.MockHttpResponse
send(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:MockServerHttpConnection
Sends theHttpResponse
.- Specified by:
send
in interfaceMockServerHttpConnection
- Parameters:
escalation
- OptionalEscalation
. Should benull
for successful processing.- Returns:
MockHttpResponse
.
-
response
public void response(MockHttpResponse response)
Description copied from interface:MockHttpRequestCallback
Callback with theMockHttpResponse
.- Specified by:
response
in interfaceMockHttpRequestCallback
- Parameters:
response
-MockHttpResponse
.
-
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
.
-
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.
-
getServerLocation
public HttpServerLocation getServerLocation()
Description copied from interface:ServerHttpConnection
Obtains theHttpServerLocation
.- Specified by:
getServerLocation
in interfaceServerHttpConnection
- Returns:
HttpServerLocation
.
-
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
-
-