Package com.networknt.aws.lambda
Class LightLambdaExchange
java.lang.Object
com.networknt.aws.lambda.LightLambdaExchange
Shared object among middleware threads containing information on the request/response event.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAttachment key class to attach data to the exchange. -
Constructor Summary
ConstructorsConstructorDescriptionLightLambdaExchange(com.amazonaws.services.lambda.runtime.Context context, Chain chain) -
Method Summary
Modifier and TypeMethodDescription<T extends MiddlewareHandler>
voidaddAttachment(LightLambdaExchange.Attachable<T> key, Object o) Adds an attachment to the exchange.voidgetAttachment(LightLambdaExchange.Attachable<?> attachable) Get attachment object for given key.com.amazonaws.services.lambda.runtime.Contextcom.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEventgetFinalizedRequest(boolean fromListener) Terminates the request portion of the exchange and invokes the exchangeRequestCompleteListeners.com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEventgetFinalizedResponse(boolean fromListener) Terminates the response portion of the exchange and invokes the exchangeResponseCompleteListeners.com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEventcom.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEventcom.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEventReturns the response object or an exception object if there was a failure.intgetState()intbooleanCheck to see if the exchange has any error state at all.booleanChecks to see if the exchange is complete.booleanbooleanChecks to see if the exchange is in the 'request in progress' state.booleanChecks to see if the exchange has the response portion complete.booleanChecks to see if the exchange is in the response in progress state.voidsetInitialRequest(com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent request) Sets the request object of the exchange.voidsetInitialResponse(com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent response) Sets the response object of the exchange.toString()voidupdateExchangeStatus(com.networknt.status.Status status) Update the exchange.
-
Constructor Details
-
LightLambdaExchange
-
-
Method Details
-
executeChain
public void executeChain() -
setInitialResponse
public void setInitialResponse(com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent response) Sets the response object of the exchange.- Parameters:
response- -
-
setInitialRequest
public void setInitialRequest(com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent request) Sets the request object of the exchange.- Parameters:
request- -
-
getResponse
public com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent getResponse()Returns the response object or an exception object if there was a failure.- Returns:
- - return formatted response event.
-
getContext
public com.amazonaws.services.lambda.runtime.Context getContext() -
getRequest
public com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent getRequest() -
getReadOnlyRequest
public com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent getReadOnlyRequest() -
getStatusCode
public int getStatusCode() -
getFinalizedRequest
public com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent getFinalizedRequest(boolean fromListener) Terminates the request portion of the exchange and invokes the exchangeRequestCompleteListeners. You cannot finalize a request that has already been finalized.- Parameters:
fromListener- - if the call is from a listener, do not invoke listeners again.- Returns:
- - returns the complete and final request event.
-
getFinalizedResponse
public com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent getFinalizedResponse(boolean fromListener) Terminates the response portion of the exchange and invokes the exchangeResponseCompleteListeners. You cannot finalize a response that has already been finalized.- Parameters:
fromListener- - if the call is from a listener, do not invoke listeners again.- Returns:
- - returns the complete and final response event.
-
updateExchangeStatus
public void updateExchangeStatus(com.networknt.status.Status status) Update the exchange. This happens automatically after each middleware execution, but it can be invoked manually by user logic.Once an exchange is marked as failed, no longer handle updates.
- Parameters:
status- - status to update the exchange with.
-
hasFailedState
public boolean hasFailedState()Check to see if the exchange has any error state at all.- Returns:
- - returns true if the exchange has a failure state.
-
isRequestInProgress
public boolean isRequestInProgress()Checks to see if the exchange is in the 'request in progress' state. The exchange is in the request state when the request chain is ready and has not finished executing.- Returns:
- - returns true if the exchange is handing the request.
-
isRequestComplete
public boolean isRequestComplete() -
isResponseInProgress
public boolean isResponseInProgress()Checks to see if the exchange is in the response in progress state. The exchange is in the response state when the request chain is complete, and the response chain is ready and has not finished executing.- Returns:
- - return true if the exchange is handling the response.
-
isResponseComplete
public boolean isResponseComplete()Checks to see if the exchange has the response portion complete.- Returns:
- - true if the response is complete.
-
isExchangeComplete
public boolean isExchangeComplete()Checks to see if the exchange is complete.- Returns:
- - true if the exchange is complete.
-
getState
public int getState()- Returns:
- int state
-
addExchangeFailedListener
-
addResponseCompleteListener
-
addRequestCompleteListener
-
addAttachment
public <T extends MiddlewareHandler> void addAttachment(LightLambdaExchange.Attachable<T> key, Object o) Adds an attachment to the exchange.- Type Parameters:
T- - Middleware key type.- Parameters:
key- - Attachable key.o- - object value.
-
getAttachment
Get attachment object for given key.- Parameters:
attachable- - middleware key- Returns:
- - returns the object for the provided key. Can return null if it does not exist.
-
getAttachments
-
toString
-