public StompFrame convertMessage(StompProtocolConverter converter, ActiveMQMessage message)
      throws IOException, JMSException {
    StompFrame command = new StompFrame();
    command.setAction(Stomp.Responses.MESSAGE);
    Map<String, String> headers = new HashMap<>(25);
    command.setHeaders(headers);

    Helper.copyStandardHeadersFromMessageToFrame(converter, message, command, this);

    if (message.getDataStructureType() == ActiveMQTextMessage.DATA_STRUCTURE_TYPE) {

      if (!message.isCompressed() && message.getContent() != null) {
        ByteSequence msgContent = message.getContent();
        if (msgContent.getLength() > 4) {
          byte[] content = new byte[msgContent.getLength() - 4];
          System.arraycopy(msgContent.data, 4, content, 0, content.length);
          command.setContent(content);
        }
      } else {
        ActiveMQTextMessage msg = (ActiveMQTextMessage) message.copy();
        String messageText = msg.getText();
        if (messageText != null) {
          command.setContent(msg.getText().getBytes("UTF-8"));
        }
      }

    } else if (message.getDataStructureType() == ActiveMQBytesMessage.DATA_STRUCTURE_TYPE) {

      ActiveMQBytesMessage msg = (ActiveMQBytesMessage) message.copy();
      msg.setReadOnlyBody(true);
      byte[] data = new byte[(int) msg.getBodyLength()];
      msg.readBytes(data);

      headers.put(Stomp.Headers.CONTENT_LENGTH, Integer.toString(data.length));
      command.setContent(data);
    }

    return command;
  }
  @Override
  public StompFrame convertMessage(ProtocolConverter converter, ActiveMQMessage message)
      throws IOException, JMSException {

    StompFrame command = new StompFrame();
    command.setAction(Responses.MESSAGE);
    Map<String, String> headers = new HashMap<String, String>(25);
    command.setHeaders(headers);

    copyStandardHeadersFromMessageToFrame(converter, message, command, this);

    String transformation = headers.get(Headers.TRANSFORMATION);

    if (message.getDataStructureType() == ActiveMQObjectMessage.DATA_STRUCTURE_TYPE) {

      if (Transformations.JMS_XML.equals(transformation)) {
        headers.put(Headers.TRANSFORMATION, Transformations.JMS_OBJECT_XML.toString());
      } else if (Transformations.JMS_JSON.equals(transformation)) {
        headers.put(Headers.TRANSFORMATION, Transformations.JMS_OBJECT_JSON.toString());
      }

      if (!headers.containsKey(Headers.TRANSFORMATION)) {
        headers.put(Headers.TRANSFORMATION, Transformations.JMS_OBJECT_XML.toString());
      }

      ActiveMQObjectMessage msg = (ActiveMQObjectMessage) message.copy();
      command.setContent(
          marshall(msg.getObject(), headers.get(Headers.TRANSFORMATION)).getBytes("UTF-8"));

    } else if (message.getDataStructureType() == ActiveMQMapMessage.DATA_STRUCTURE_TYPE) {

      if (Transformations.JMS_XML.equals(transformation)) {
        headers.put(Headers.TRANSFORMATION, Transformations.JMS_MAP_XML.toString());
      } else if (Transformations.JMS_JSON.equals(transformation)) {
        headers.put(Headers.TRANSFORMATION, Transformations.JMS_MAP_JSON.toString());
      }

      if (!headers.containsKey(Headers.TRANSFORMATION)) {
        headers.put(Headers.TRANSFORMATION, Transformations.JMS_MAP_XML.toString());
      }

      ActiveMQMapMessage msg = (ActiveMQMapMessage) message.copy();
      command.setContent(
          marshall((Serializable) msg.getContentMap(), headers.get(Headers.TRANSFORMATION))
              .getBytes("UTF-8"));

    } else if (message.getDataStructureType() == ActiveMQMessage.DATA_STRUCTURE_TYPE
        && AdvisorySupport.ADIVSORY_MESSAGE_TYPE.equals(message.getType())) {

      if (Transformations.JMS_XML.equals(transformation)) {
        headers.put(Headers.TRANSFORMATION, Transformations.JMS_ADVISORY_XML.toString());
      } else if (Transformations.JMS_JSON.equals(transformation)) {
        headers.put(Headers.TRANSFORMATION, Transformations.JMS_ADVISORY_JSON.toString());
      }

      if (!headers.containsKey(Headers.TRANSFORMATION)) {
        headers.put(Headers.TRANSFORMATION, Transformations.JMS_ADVISORY_JSON.toString());
      }

      String body =
          marshallAdvisory(message.getDataStructure(), headers.get(Headers.TRANSFORMATION));
      command.setContent(body.getBytes("UTF-8"));

    } else {
      command = super.convertMessage(converter, message);
    }

    return command;
  }