Class JmsResponseBuilder

java.lang.Object
com.trafficparrot.sdk.messaging.JmsResponseBuilder
Direct Known Subclasses:
JmsResponseBuilder

public class JmsResponseBuilder extends Object
Builds the JmsResponse a JmsResponseTransformer returns, from a destination and a body:

 return new JmsResponseBuilder()
         .like(response)
         .withDestination(new Destination("other.queue", response.destination.type))
         .build();
 
The response it builds names no transformer, as a transformer's result must, and has no JMS properties, no delay and the default destination lookup. To keep the mapping's, use the JmsResponse constructor that takes them.
  • Constructor Details

    • JmsResponseBuilder

      public JmsResponseBuilder()
      Creates a builder with no destination and no body.
  • Method Details

    • like

      public JmsResponseBuilder like(JmsResponse response)
      Takes the destination, body and body type of a response. A body the response reads from a file is taken as its content. Nothing else is taken: its JMS properties, delay and destination lookup are not carried over.
      Parameters:
      response - the response to take them from, usually the mapping's
      Returns:
      this builder
    • withText

      public JmsResponseBuilder withText(String text)
      Sets a text body, sent as a text message.
      Parameters:
      text - the body, which may hold Handlebars expressions
      Returns:
      this builder
    • withBytes

      public JmsResponseBuilder withBytes(byte[] bytes)
      Sets a binary body, sent as a bytes message.
      Parameters:
      bytes - the body
      Returns:
      this builder
    • withObject

      public JmsResponseBuilder withObject(Object object) throws com.fasterxml.jackson.core.JsonProcessingException
      Sets a Java object as the body, held as its JSON with the object's class as the body type.
      Parameters:
      object - the object to send
      Returns:
      this builder
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException - if the object cannot be written as JSON
    • withDestination

      public JmsResponseBuilder withDestination(Destination destination)
      Sets the queue or topic the response is sent to when the request names no reply-to destination.
      Parameters:
      destination - the destination
      Returns:
      this builder
    • build

      public JmsResponse build()
      Builds the response.
      Returns:
      a response with the destination and body set so far, which names no transformer