Package org.chenile.core.context
Class ChenileExchange
java.lang.Object
org.chenile.core.context.ChenileExchange
- All Implemented Interfaces:
Serializable
,WarningAware
,ChainContextContainer<ChenileExchange>
public class ChenileExchange
extends Object
implements Serializable, ChainContextContainer<ChenileExchange>, WarningAware
A bidirectional exchange that navigates between different Chenile Interceptors.
The exchange contains a body which is the incoming request along with headers.
Commands will set the response or exception in the return journey.
There can be transformers that convert the body to the type acceptable by the service.
Chenile end point modules such as chenile-http must be able to convert their end point specific incoming request (such as HttpServletRequest) into ChenileExchange
They must also be able to convert the returned response into their protocol specific response object (such as HttpServletResponse)
- Author:
- Raja Shankar Kolluru
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionAn object internally used byServiceInvoker
to invoke the API.private Object
The converted body of the incoming message.private com.fasterxml.jackson.core.type.TypeReference<?>
bodyType is populated by the Chenile Transformation framework.private ChainContext<ChenileExchange>
Internal field for the purpose of continuing the interceptor chain.private ErrorNumException
The exception thrown by the service or any of the interceptorsIncoming request headers.private int
contains the http response status codeprivate boolean
This is useful if this request is determined to be a mock request.private Locale
Calculated locale.private boolean
private LogWriter
private Method
This field just uses a cached method object for optimization purposes.private Map<String,
MultipartFile> This is used to handle multipart messages from HTTP.private OperationDefinition
This is a very important metadata to handle the request.private String
This (optional) field allows traceability to the original request.private Object
The actual response returned by the service or any interceptor.private ParameterizedTypeReference<?>
used (by chenile-proxy) to convert the response JSON to a response body.private List<ResponseMessage>
contains all errors and warningsprivate static final long
private ChenileServiceDefinition
private Object
the service which will be invoked.private String
the spring bean ID of the service being invoked.Fields inherited from interface org.chenile.base.response.WarningAware
WARNING_MESSAGES_KEY
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
private ErrorNumException
getBody()
com.fasterxml.jackson.core.type.TypeReference<?>
<T extends Annotation>
TgetExtensionByAnnotation
(Class<T> klass) <T> T
<T> T
int
boolean
boolean
void
void
setApiInvocation
(List<Object> apiInvocation) void
void
setBodyType
(com.fasterxml.jackson.core.type.TypeReference<?> bodyType) void
setChainContext
(ChainContext<ChenileExchange> chainContext) void
Call this to set exception in the exchange.void
void
setHeaders
(Map<String, Object> headers) void
setHttpResponseStatusCode
(int httpResponseStatusCode) void
setInvokeMock
(boolean invokeMock) void
void
setLocalInvocation
(boolean b) void
setLogWriter
(LogWriter logWriter) void
void
setMultiPartMap
(Map<String, MultipartFile> multiPartMap) void
setOperationDefinition
(OperationDefinition operationDefinition) void
setOriginalSourceReference
(String originalSourceReference) void
setResponse
(Object response) void
setResponseBodyType
(ParameterizedTypeReference<?> responseBodyType) void
setResponseMessages
(List<ResponseMessage> responseMessages) void
setServiceDefinition
(ChenileServiceDefinition serviceDefinition) void
setServiceReference
(Object serviceReference) void
setServiceReferenceId
(String serviceReferenceId)
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
headers
Incoming request headers. Some headers can be added as we navigate through the interception chain -
multiPartMap
This is used to handle multipart messages from HTTP. -
body
The converted body of the incoming message. This will be set to the actual payload expected by the service. It may be a JSON string to begin with before the transformation framework converts it to the desired payload type -
bodyType
private com.fasterxml.jackson.core.type.TypeReference<?> bodyTypebodyType is populated by the Chenile Transformation framework. The bodyType might vary depending on the URL of the incoming request and also some headers. A body type selector is a specialCommand<ChenileExchange>
that determines the body type depending on the context of the request. (like headers, URL , locale etc.) All incoming JSONs (and other type of strings) are converted into the body type specified here -
apiInvocation
An object internally used byServiceInvoker
to invoke the API. -
operationDefinition
This is a very important metadata to handle the request. It contains the definition of the Service and the Operation within it. All operations are performed using these data structures. For example this metadata will be used to determine the service that needs to be invoked and the method within the service. This metadata is also used to determine the interceptors that are applicable etc. ChenileServiceDefinition and OperationDefinition are expected to be set by the protocol specific end point. Example: in chenile-http the URL called will be mapped to the ChenileServiceDefinition and OperationDefinition. -
serviceDefinition
-
logWriter
-
originalSourceReference
This (optional) field allows traceability to the original request. This is populated when the entry point is invoked in a batch mode from a file watcher or a reader from a queue or topic. In this situation, no response is emitted. Hence, we need to know how this request got created in the first place.
Typical values can be:
- file1:line1:ref ID -> to indicate that this message was constructed from the file in question etc.
- mqtt:topic1:id -> to indicate that this messages was created by MQTT by reading the topic in question etc.
-
responseBodyType
used (by chenile-proxy) to convert the response JSON to a response body. -
response
The actual response returned by the service or any interceptor. (for example a caching interceptor might set the response and return) -
exception
The exception thrown by the service or any of the interceptors -
httpResponseStatusCode
private int httpResponseStatusCodecontains the http response status code -
responseMessages
contains all errors and warnings -
chainContext
Internal field for the purpose of continuing the interceptor chain. The interceptors can use this to pass control to the next in the line by calling theChainContext.doContinue()
method. Interceptors can also use theChainContext.savePoint()
to save the current point and usingChainContext.resumeFromSavedPoint(ChainContext.SavePoint)
to continue the chain from the saved point. This is useful if the rest of the interceptor chain needs to be called multiple times as part of some retry logic. -
localInvocation
private boolean localInvocation -
locale
Calculated locale. This should be populated from the incoming request as per the headers passed to it. -
invokeMock
private boolean invokeMockThis is useful if this request is determined to be a mock request. Hence a mock service may have to be invoked instead of the actual service. In case of HTTP a special header (x-chenile-mock) will be passed for mock requests. -
serviceReference
the service which will be invoked. This would be populated by theConstructServiceReference
interceptor and invoked byServiceInvoker
. By switching the serviceReference, any interceptor can change the target service that will be invoked. But please be sure to recompute the method by callingMethodUtils
-
method
This field just uses a cached method object for optimization purposes. This needs to be recalculated if the serviceReference is changed by an interceptor. -
serviceReferenceId
the spring bean ID of the service being invoked.
-
-
Constructor Details
-
ChenileExchange
public ChenileExchange() -
ChenileExchange
-
-
Method Details
-
getOriginalSourceReference
-
setOriginalSourceReference
-
getOperationDefinition
-
setOperationDefinition
-
getServiceDefinition
-
setServiceDefinition
-
getHeaders
-
getHeader
-
getHeader
-
getHeader
-
getHeader
-
setHeaders
-
setHeader
-
getBody
-
setBody
-
setResponse
-
getResponse
-
getChainContext
- Specified by:
getChainContext
in interfaceChainContextContainer<ChenileExchange>
-
setChainContext
- Specified by:
setChainContext
in interfaceChainContextContainer<ChenileExchange>
-
getBodyType
public com.fasterxml.jackson.core.type.TypeReference<?> getBodyType() -
setBodyType
public void setBodyType(com.fasterxml.jackson.core.type.TypeReference<?> bodyType) -
getApiInvocation
-
setApiInvocation
-
setLocalInvocation
public void setLocalInvocation(boolean b) -
isLocalInvocation
public boolean isLocalInvocation() -
setException
Call this to set exception in the exchange. This method has side effects! It modifies theresponseMessages
in the exchange.
If the exception is null then it removes all traces of errors so far! It empties the response messages in the exchange.
If the exception is set for the first time, then all the errors in the exception get copied as response messages in the exchange.
If the exception is already present, then the exception is not over-ridden. Instead, the response messages are added from this exception.- Parameters:
e
- the exception that needs to be set in Chenile Exchange
-
createErrorNumExceptionIfRequired
-
getException
-
getLocale
-
setLocale
-
isInvokeMock
public boolean isInvokeMock() -
setInvokeMock
public void setInvokeMock(boolean invokeMock) -
getServiceReference
-
setServiceReference
-
getServiceReferenceId
-
setServiceReferenceId
-
setMultiPartMap
-
getMultiPartMap
-
getResponseBodyType
-
setResponseBodyType
-
getMethod
-
setMethod
-
getHttpResponseStatusCode
public int getHttpResponseStatusCode() -
setHttpResponseStatusCode
public void setHttpResponseStatusCode(int httpResponseStatusCode) -
getResponseMessages
-
setResponseMessages
-
getWarningMessages
- Specified by:
getWarningMessages
in interfaceWarningAware
-
addWarningMessage
- Specified by:
addWarningMessage
in interfaceWarningAware
-
removeAllWarnings
public void removeAllWarnings()- Specified by:
removeAllWarnings
in interfaceWarningAware
-
getExtensionByAnnotation
-
getLogWriter
-
setLogWriter
-