Class MessageBodyType

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

public class MessageBodyType extends Object
Describes the body type of a messaging request or response.

This is the canonical location for MessageBodyType. The deprecated MessageBodyType remains available for backward compatibility.

  • Field Details

    • TEXT

      public static final MessageBodyType TEXT
      A text body: the response's text is the body.
    • BYTES

      public static final MessageBodyType BYTES
      A binary body held as Base64: the response's text is the Base64 of the bytes to send.
    • PRINTABLE_CHARACTERS

      public static final MessageBodyType PRINTABLE_CHARACTERS
      A binary body held in the printable-characters encoding, which keeps the ASCII characters in it readable: the response's text is that encoding of the bytes to send.
    • UNKNOWN_BODY_TYPE

      public static final MessageBodyType UNKNOWN_BODY_TYPE
      Stands in where a body type is not known or does not apply. Not a type to give a response.
    • value

      public final String value
      The body type as a mapping file writes it: TEXT, BYTES, PRINTABLE_CHARACTERS, proto/<message type>, protoBase64Bytes/<message type>, javaProto/<Java class>, javaProto/<Java class>:<message type>, or the name of a Java class for a Java object body.
  • Constructor Details

    • MessageBodyType

      public MessageBodyType(String value)
      Creates a body type from its text in a mapping file. Use the constants for the fixed types and the static methods for the others.
      Parameters:
      value - the body type as a mapping file writes it, as value describes
  • Method Details

    • protoMessageType

      public static MessageBodyType protoMessageType(String typeName)
      The type of a body that is a protobuf message.
      Parameters:
      typeName - the protobuf message type's name
      Returns:
      the body type proto/<typeName>
    • anyJavaProtoMessageType

      public static MessageBodyType anyJavaProtoMessageType()
      The body type javaProto/*, which stands for a protobuf message of any type with a Java class.
      Returns:
      the body type
    • anyJavaClassType

      public static MessageBodyType anyJavaClassType()
      The body type java.lang.Object, which stands for a Java object of any class.
      Returns:
      the body type
    • javaProtoMessageType

      public static MessageBodyType javaProtoMessageType(String javaAndProtoTypeName)
      The type of a body that is a protobuf message with a Java class, when the class and the message type have one name.
      Parameters:
      javaAndProtoTypeName - the name the Java class and the protobuf message type share
      Returns:
      the body type javaProto/<javaAndProtoTypeName>
    • javaProtoMessageType

      public static MessageBodyType javaProtoMessageType(String javaTypeName, String protoTypeName)
      The type of a body that is a protobuf message with a Java class.
      Parameters:
      javaTypeName - the Java class's name
      protoTypeName - the protobuf message type's name
      Returns:
      the body type javaProto/<javaTypeName>:<protoTypeName>, or javaProto/<javaTypeName> when the two names are the same
    • javaClassType

      public static MessageBodyType javaClassType(Object object)
      The type of a body that is this Java object.
      Parameters:
      object - the object
      Returns:
      a body type that names the object's class, or for a dynamic proxy its invocation handler's class
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • protoMessageType

      public String protoMessageType()
      The protobuf message type of a proto/ body type.
      Returns:
      value without its proto/ prefix; the whole value for any other body type
    • protoBase64BytesMessageType

      public String protoBase64BytesMessageType()
      The protobuf message type of a protoBase64Bytes/ body type.
      Returns:
      value without its protoBase64Bytes/ prefix; the whole value for any other body type
    • javaProtoJavaType

      public String javaProtoJavaType()
      NOTE: this is encoded as either: - javaProto/com.example.JavaType:com.example.ProtoType - javaProto/com.example.ProtoAndJavaType
      Returns:
      the Java class name of a javaProto/ body type
    • javaProtoMessageType

      public String javaProtoMessageType()
      NOTE: this is encoded as either: - javaProto/com.example.JavaType:com.example.ProtoType - javaProto/com.example.ProtoAndJavaType
      Returns:
      the protobuf message type name of a javaProto/ body type
    • isProtoMessageType

      public boolean isProtoMessageType()
      Whether this is a proto/ body type.
      Returns:
      true if value starts with proto/
    • isProtoBase64BytesMessageType

      public boolean isProtoBase64BytesMessageType()
      Whether this is a protoBase64Bytes/ body type.
      Returns:
      true if value starts with protoBase64Bytes/
    • isJavaProtoMessageType

      public boolean isJavaProtoMessageType()
      Whether this is a javaProto/ body type.
      Returns:
      true if value starts with javaProto/
    • canRepresent

      public boolean canRepresent(MessageBodyType bodyType)
      Whether a body of this type can stand for a body of another type.
      Parameters:
      bodyType - the other body type
      Returns:
      true if the two are equal, or each is one of TEXT, BYTES and PRINTABLE_CHARACTERS
    • isJavaObject

      public boolean isJavaObject()
      Whether the body is a Java object.
      Returns:
      true if value is none of the other forms and names a class on Traffic Parrot's classpath
    • javaClass

      public Class<?> javaClass()
      The class of a Java object body.
      Returns:
      the class value names
      Throws:
      IllegalStateException - if no such class is on Traffic Parrot's classpath