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>

public class ConvertingResponseMessage<R> extends Object implements 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 Details

    • ConvertingResponseMessage

      public ConvertingResponseMessage(ResponseType<R> expectedResponseType, QueryResponseMessage<?> responseMessage)
      Initialize a response message, using expectedResponseType to convert the payload from the responseMessage, if necessary.
      Parameters:
      expectedResponseType - an instance describing the expected response type
      responseMessage - 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: Message
      Serialize the payload of this message to the expectedRepresentation using given serializer. This method should return the same SerializedObject instance when invoked multiple times using the same serializer.
      Specified by:
      serializePayload in interface Message<R>
      Specified by:
      serializePayload in interface ResultMessage<R>
      Type Parameters:
      S - The type of the serialized data
      Parameters:
      serializer - The serializer to serialize payload with
      expectedRepresentation - 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: ResultMessage
      Serializes the exception result. Will create a RemoteExceptionDescription from the Optional exception in this ResultMessage instead of serializing the original exception.
      Specified by:
      serializeExceptionResult in interface ResultMessage<R>
      Type Parameters:
      T - the generic type representing the expected format
      Parameters:
      serializer - the Serializer used to serialize the exception
      expectedRepresentation - a Class representing 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: Message
      Serialize the meta data of this message to the expectedRepresentation using given serializer. This method should return the same SerializedObject instance when invoked multiple times using the same serializer.
      Specified by:
      serializeMetaData in interface Message<R>
      Type Parameters:
      R1 - The type of the serialized data
      Parameters:
      serializer - The serializer to serialize meta data with
      expectedRepresentation - 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: ResultMessage
      Indicates whether the ResultMessage represents unsuccessful execution.
      Specified by:
      isExceptional in interface ResultMessage<R>
      Returns:
      true if execution was unsuccessful, false otherwise
    • optionalExceptionResult

      public Optional<Throwable> optionalExceptionResult()
      Description copied from interface: ResultMessage
      Returns the Exception in case of exceptional result message or an empty Optional in case of successful execution.
      Specified by:
      optionalExceptionResult in interface ResultMessage<R>
      Returns:
      an Optional containing exception result or an empty Optional in case of a successful execution
    • getIdentifier

      public String getIdentifier()
      Description copied from interface: Message
      Returns 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:
      getIdentifier in interface Message<R>
      Returns:
      the unique identifier of this message
    • getMetaData

      public MetaData getMetaData()
      Description copied from interface: Message
      Returns 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:
      getMetaData in interface Message<R>
      Returns:
      the meta data for this message
    • getPayload

      public R getPayload()
      Description copied from interface: Message
      Returns the payload of this message. The payload is the application-specific information.
      Specified by:
      getPayload in interface Message<R>
      Returns:
      the payload of this message
    • getPayloadType

      public Class<R> getPayloadType()
      Description copied from interface: Message
      Returns the type of the payload.

      Is semantically equal to getPayload().getClass(), but allows implementations to optimize by using lazy loading or deserialization.

      Specified by:
      getPayloadType in interface Message<R>
      Returns:
      the type of payload.
    • withMetaData

      public QueryResponseMessage<R> withMetaData(@Nonnull Map<String,?> metaData)
      Description copied from interface: QueryResponseMessage
      Returns a copy of this QueryResponseMessage with the given metaData. The payload remains unchanged.
      Specified by:
      withMetaData in interface Message<R>
      Specified by:
      withMetaData in interface QueryResponseMessage<R>
      Specified by:
      withMetaData in interface ResultMessage<R>
      Parameters:
      metaData - The new MetaData for the QueryResponseMessage
      Returns:
      a copy of this message with the given MetaData
    • andMetaData

      public QueryResponseMessage<R> andMetaData(@Nonnull Map<String,?> additionalMetaData)
      Description copied from interface: QueryResponseMessage
      Returns a copy of this QueryResponseMessage with its MetaData merged with given metaData. The payload remains unchanged.
      Specified by:
      andMetaData in interface Message<R>
      Specified by:
      andMetaData in interface QueryResponseMessage<R>
      Specified by:
      andMetaData in interface ResultMessage<R>
      Parameters:
      additionalMetaData - The MetaData to merge into the QueryResponseMessage
      Returns:
      a copy of this message with the given additional MetaData