Package org.rootservices.otter.dispatch
Class JsonRouteRun<U extends DefaultUser,P>
- java.lang.Object
-
- org.rootservices.otter.dispatch.JsonRouteRun<U,P>
-
- All Implemented Interfaces:
RouteRunner
public class JsonRouteRun<U extends DefaultUser,P> extends java.lang.Object implements RouteRunner
-
-
Field Summary
Fields Modifier and Type Field Description protected static org.slf4j.LoggerLOGGER
-
Constructor Summary
Constructors Constructor Description JsonRouteRun()JsonRouteRun(RestRoute<U,P> restRoute, RestResponseTranslator<P> restResponseTranslator, RestRequestTranslator<U,P> restRequestTranslator, RestBtwnRequestTranslator<U,P> restBtwnRequestTranslator, RestBtwnResponseTranslator<P> restBtwnResponseTranslator, JsonTranslator<P> jsonTranslator, java.util.Map<StatusCode,RestErrorHandler<U>> errorHandlers, RestErrorRequestTranslator<U> errorRequestTranslator, RestErrorResponseTranslator errorResponseTranslator)
-
Method Summary
Modifier and Type Method Description protected RestResponse<P>execute(Method method, RestResource<U,P> resource, RestRequest<U,P> request, RestResponse<P> response)protected voidexecuteBetween(java.util.List<RestBetween<U>> betweens, Method method, RestBtwnRequest<U> btwnRequest, RestBtwnResponse btwnResponse)protected RestReponseEither<U,P>executeResourceMethod(RestRoute<U,P> route, RestBtwnRequest<U> btwnRequest, RestBtwnResponse btwnResponse, java.util.Optional<P> entity)This executes a route's before betweens, resource method, and the after betweens.RestRoute<U,P>getRestRoute()protected java.util.Optional<Answer>handle(StatusCode statusCode, java.lang.Throwable cause, Ask ask, Answer answer)protected AnswerhandleErrors(RestResponseError<U,P> error, Ask ask, Answer answer)protected AnswerhandleServerError(java.lang.Throwable cause, Ask ask, Answer answer)protected booleanisPayloadDirty(java.util.Optional<byte[]> resourcePayload, java.util.Optional<byte[]> btwnPayload)protected java.util.Optional<P>makeEntity(java.util.Optional<byte[]> body)protected java.util.Optional<byte[]>payloadToBytes(java.util.Optional<P> payload)protected Answerprocess(Ask ask, Answer answer)Answerrun(Ask ask, Answer answer)protected voidsetResponsePayload(java.util.Optional<byte[]> payload, java.util.Optional<byte[]> afterPayload, RestResponse<P> resourceResponse, RestResponse<P> response)
-
-
-
Constructor Detail
-
JsonRouteRun
public JsonRouteRun()
-
JsonRouteRun
public JsonRouteRun(RestRoute<U,P> restRoute, RestResponseTranslator<P> restResponseTranslator, RestRequestTranslator<U,P> restRequestTranslator, RestBtwnRequestTranslator<U,P> restBtwnRequestTranslator, RestBtwnResponseTranslator<P> restBtwnResponseTranslator, JsonTranslator<P> jsonTranslator, java.util.Map<StatusCode,RestErrorHandler<U>> errorHandlers, RestErrorRequestTranslator<U> errorRequestTranslator, RestErrorResponseTranslator errorResponseTranslator)
-
-
Method Detail
-
run
public Answer run(Ask ask, Answer answer) throws HaltException
- Specified by:
runin interfaceRouteRunner- Throws:
HaltException
-
process
protected Answer process(Ask ask, Answer answer) throws HaltException
- Throws:
HaltException
-
makeEntity
protected java.util.Optional<P> makeEntity(java.util.Optional<byte[]> body) throws DeserializationException
- Throws:
DeserializationException
-
handleErrors
protected Answer handleErrors(RestResponseError<U,P> error, Ask ask, Answer answer) throws HaltException
- Throws:
HaltException
-
handle
protected java.util.Optional<Answer> handle(StatusCode statusCode, java.lang.Throwable cause, Ask ask, Answer answer)
-
handleServerError
protected Answer handleServerError(java.lang.Throwable cause, Ask ask, Answer answer) throws HaltException
- Throws:
HaltException
-
executeResourceMethod
protected RestReponseEither<U,P> executeResourceMethod(RestRoute<U,P> route, RestBtwnRequest<U> btwnRequest, RestBtwnResponse btwnResponse, java.util.Optional<P> entity)
This executes a route's before betweens, resource method, and the after betweens. If any exceptions occur it will populate the right ivar of the RestReponseEither that is returned. An Either is used for the response type in order to handle exceptions. The handlers should have access to the various request and response objects which are parameterized types. Exceptions cannot have generic typed parameters.- Parameters:
route- the route to execute.btwnRequest- the request to pass before betweens.btwnResponse- the response to pass to before betweens.entity- the payload of the request.- Returns:
- A RestReponseEither, if left is present then it executed correctly. If right is present then an error occurred and it should be handled.
-
execute
protected RestResponse<P> execute(Method method, RestResource<U,P> resource, RestRequest<U,P> request, RestResponse<P> response)
-
setResponsePayload
protected void setResponsePayload(java.util.Optional<byte[]> payload, java.util.Optional<byte[]> afterPayload, RestResponse<P> resourceResponse, RestResponse<P> response) throws DeserializationException- Throws:
DeserializationException
-
isPayloadDirty
protected boolean isPayloadDirty(java.util.Optional<byte[]> resourcePayload, java.util.Optional<byte[]> btwnPayload)
-
executeBetween
protected void executeBetween(java.util.List<RestBetween<U>> betweens, Method method, RestBtwnRequest<U> btwnRequest, RestBtwnResponse btwnResponse) throws HaltException
- Throws:
HaltException
-
payloadToBytes
protected java.util.Optional<byte[]> payloadToBytes(java.util.Optional<P> payload)
-
-