Class ConvertingResponseMessage<R>
java.lang.Object
org.axonframework.messaging.responsetypes.ConvertingResponseMessage<R>
- Type Parameters:
R- the type of response expected
- All Implemented Interfaces:
Serializable,Message<R>,ResultMessage<R>,QueryResponseMessage<R>
Implementation of a QueryResponseMessage that is aware of the requested response type and performs a just-in-time
conversion to ensure the response is formatted as requested.
The conversion is generally used to accommodate response types that aren't compatible with serialization, such as
OptionalResponseType.
- Since:
- 4.3
- Author:
- Allard Buijze
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionConvertingResponseMessage(ResponseType<R> expectedResponseType, QueryResponseMessage<?> responseMessage) Initialize a response message, usingexpectedResponseTypeto convert the payload from theresponseMessage, if necessary. -
Method Summary
Modifier and TypeMethodDescriptionandMetaData(Map<String, ?> additionalMetaData) Returns a copy of this QueryResponseMessage with its MetaData merged with givenmetaData.Returns the identifier of this message.Returns the meta data for this message.Returns the payload of this message.Returns the type of the payload.booleanIndicates whether the ResultMessage represents unsuccessful execution.Returns the Exception in case of exceptional result message or an emptyOptionalin case of successful execution.<T> SerializedObject<T> serializeExceptionResult(Serializer serializer, Class<T> expectedRepresentation) Serializes the exception result.<R1> SerializedObject<R1> serializeMetaData(Serializer serializer, Class<R1> expectedRepresentation) Serialize the meta data of this message to theexpectedRepresentationusing givenserializer.<S> SerializedObject<S> serializePayload(Serializer serializer, Class<S> expectedRepresentation) Serialize the payload of this message to theexpectedRepresentationusing givenserializer.withMetaData(Map<String, ?> metaData) Returns a copy of this QueryResponseMessage with the givenmetaData.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.axonframework.messaging.ResultMessage
exceptionDetails, exceptionResult
-
Constructor Details
-
ConvertingResponseMessage
public ConvertingResponseMessage(ResponseType<R> expectedResponseType, QueryResponseMessage<?> responseMessage) Initialize a response message, usingexpectedResponseTypeto convert the payload from theresponseMessage, if necessary.- Parameters:
expectedResponseType- an instance describing the expected response typeresponseMessage- the message containing the actual response from the handler
-
-
Method Details
-
serializePayload
public <S> SerializedObject<S> serializePayload(Serializer serializer, Class<S> expectedRepresentation) Description copied from interface:MessageSerialize the payload of this message to theexpectedRepresentationusing givenserializer. This method should return the same SerializedObject instance when invoked multiple times using the same serializer.- Specified by:
serializePayloadin interfaceMessage<R>- Specified by:
serializePayloadin interfaceResultMessage<R>- Type Parameters:
S- The type of the serialized data- Parameters:
serializer- The serializer to serialize payload withexpectedRepresentation- The type of data to serialize to- Returns:
- a SerializedObject containing the serialized representation of the message's payload
-
serializeExceptionResult
public <T> SerializedObject<T> serializeExceptionResult(Serializer serializer, Class<T> expectedRepresentation) Description copied from interface:ResultMessageSerializes the exception result. Will create aRemoteExceptionDescriptionfrom theOptionalexception in this ResultMessage instead of serializing the original exception.- Specified by:
serializeExceptionResultin interfaceResultMessage<R>- Type Parameters:
T- the generic type representing the expected format- Parameters:
serializer- theSerializerused to serialize the exceptionexpectedRepresentation- aClassrepresenting the expected format- Returns:
- the serialized exception as a
SerializedObject
-
serializeMetaData
public <R1> SerializedObject<R1> serializeMetaData(Serializer serializer, Class<R1> expectedRepresentation) Description copied from interface:MessageSerialize the meta data of this message to theexpectedRepresentationusing givenserializer. This method should return the same SerializedObject instance when invoked multiple times using the same serializer.- Specified by:
serializeMetaDatain interfaceMessage<R>- Type Parameters:
R1- The type of the serialized data- Parameters:
serializer- The serializer to serialize meta data withexpectedRepresentation- The type of data to serialize to- Returns:
- a SerializedObject containing the serialized representation of the message's meta data
-
isExceptional
public boolean isExceptional()Description copied from interface:ResultMessageIndicates whether the ResultMessage represents unsuccessful execution.- Specified by:
isExceptionalin interfaceResultMessage<R>- Returns:
trueif execution was unsuccessful,falseotherwise
-
optionalExceptionResult
Description copied from interface:ResultMessageReturns the Exception in case of exceptional result message or an emptyOptionalin case of successful execution.- Specified by:
optionalExceptionResultin interfaceResultMessage<R>- Returns:
- an
Optionalcontaining exception result or an empty Optional in case of a successful execution
-
getIdentifier
Description copied from interface:MessageReturns the identifier of this message. Two messages with the same identifiers should be interpreted as different representations of the same conceptual message. In such case, the meta-data may be different for both representations. The payload may be identical.- Specified by:
getIdentifierin interfaceMessage<R>- Returns:
- the unique identifier of this message
-
getMetaData
Description copied from interface:MessageReturns the meta data for this message. This meta data is a collection of key-value pairs, where the key is a String, and the value is a serializable object.- Specified by:
getMetaDatain interfaceMessage<R>- Returns:
- the meta data for this message
-
getPayload
Description copied from interface:MessageReturns the payload of this message. The payload is the application-specific information.- Specified by:
getPayloadin interfaceMessage<R>- Returns:
- the payload of this message
-
getPayloadType
Description copied from interface:MessageReturns the type of the payload. Is semantically equal togetPayload().getClass(), but allows implementations to optimize by using lazy loading or deserialization.- Specified by:
getPayloadTypein interfaceMessage<R>- Returns:
- the type of payload.
-
withMetaData
Description copied from interface:QueryResponseMessageReturns a copy of this QueryResponseMessage with the givenmetaData. The payload remains unchanged.- Specified by:
withMetaDatain interfaceMessage<R>- Specified by:
withMetaDatain interfaceQueryResponseMessage<R>- Specified by:
withMetaDatain interfaceResultMessage<R>- Parameters:
metaData- The new MetaData for the QueryResponseMessage- Returns:
- a copy of this message with the given MetaData
-
andMetaData
Description copied from interface:QueryResponseMessageReturns a copy of this QueryResponseMessage with its MetaData merged with givenmetaData. The payload remains unchanged.- Specified by:
andMetaDatain interfaceMessage<R>- Specified by:
andMetaDatain interfaceQueryResponseMessage<R>- Specified by:
andMetaDatain interfaceResultMessage<R>- Parameters:
additionalMetaData- The MetaData to merge into the QueryResponseMessage- Returns:
- a copy of this message with the given additional MetaData
-