Search in sources :

Example 6 with ServerJMSTextMessage

use of org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSTextMessage in project activemq-artemis by apache.

the class JMSMappingOutboundTransformerTest method testConvertCompressedTextMessageCreatesDataSectionBody.

@Test
public void testConvertCompressedTextMessageCreatesDataSectionBody() throws Exception {
    String contentString = "myTextMessageContent";
    ServerJMSTextMessage outbound = createTextMessage(contentString, true);
    outbound.encode();
    Message amqp = AMQPConverter.getInstance().fromCore(outbound.getInnerMessage()).getProtonMessage();
    assertNotNull(amqp.getBody());
    assertTrue(amqp.getBody() instanceof AmqpValue);
    AmqpValue value = (AmqpValue) amqp.getBody();
    assertEquals(contentString, value.getValue());
}
Also used : CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) ServerJMSTextMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSTextMessage) ServerJMSObjectMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSObjectMessage) Message(org.apache.qpid.proton.message.Message) ServerJMSMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMessage) ServerJMSStreamMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSStreamMessage) ServerJMSBytesMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSBytesMessage) ServerJMSMapMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMapMessage) ServerJMSTextMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSTextMessage) AmqpValue(org.apache.qpid.proton.amqp.messaging.AmqpValue) Test(org.junit.Test)

Example 7 with ServerJMSTextMessage

use of org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSTextMessage in project activemq-artemis by apache.

the class JMSMappingOutboundTransformerTest method testConvertTextMessageToAmqpMessageWithNoBody.

// ----- TextMessage type tests -------------------------------------------//
@Test
public void testConvertTextMessageToAmqpMessageWithNoBody() throws Exception {
    ServerJMSTextMessage outbound = createTextMessage();
    outbound.encode();
    Message amqp = AMQPConverter.getInstance().fromCore(outbound.getInnerMessage()).getProtonMessage();
    assertNotNull(amqp.getBody());
    assertTrue(amqp.getBody() instanceof AmqpValue);
    assertNull(((AmqpValue) amqp.getBody()).getValue());
}
Also used : CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) ServerJMSTextMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSTextMessage) ServerJMSObjectMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSObjectMessage) Message(org.apache.qpid.proton.message.Message) ServerJMSMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMessage) ServerJMSStreamMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSStreamMessage) ServerJMSBytesMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSBytesMessage) ServerJMSMapMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMapMessage) ServerJMSTextMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSTextMessage) AmqpValue(org.apache.qpid.proton.amqp.messaging.AmqpValue) Test(org.junit.Test)

Example 8 with ServerJMSTextMessage

use of org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSTextMessage in project activemq-artemis by apache.

the class JMSMappingOutboundTransformerTest method testConvertTextMessageContentNotStoredCreatesAmqpValueStringBody.

@Test
public void testConvertTextMessageContentNotStoredCreatesAmqpValueStringBody() throws Exception {
    String contentString = "myTextMessageContent";
    ServerJMSTextMessage outbound = createTextMessage(contentString);
    outbound.encode();
    Message amqp = AMQPConverter.getInstance().fromCore(outbound.getInnerMessage()).getProtonMessage();
    assertNotNull(amqp.getBody());
    assertTrue(amqp.getBody() instanceof AmqpValue);
    assertEquals(contentString, ((AmqpValue) amqp.getBody()).getValue());
}
Also used : CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) ServerJMSTextMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSTextMessage) ServerJMSObjectMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSObjectMessage) Message(org.apache.qpid.proton.message.Message) ServerJMSMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMessage) ServerJMSStreamMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSStreamMessage) ServerJMSBytesMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSBytesMessage) ServerJMSMapMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMapMessage) ServerJMSTextMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSTextMessage) AmqpValue(org.apache.qpid.proton.amqp.messaging.AmqpValue) Test(org.junit.Test)

Example 9 with ServerJMSTextMessage

use of org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSTextMessage in project activemq-artemis by apache.

the class CoreAmqpConverter method convertBody.

private static Section convertBody(ServerJMSMessage message, Map<Symbol, Object> maMap, Properties properties) throws JMSException {
    Section body = null;
    if (message instanceof ServerJMSBytesMessage) {
        Binary payload = getBinaryFromMessageBody((ServerJMSBytesMessage) message);
        maMap.put(AMQPMessageSupport.JMS_MSG_TYPE, AMQPMessageSupport.JMS_BYTES_MESSAGE);
        if (payload == null) {
            payload = EMPTY_BINARY;
        } else {
            body = new AmqpValue(payload);
        }
    } else if (message instanceof ServerJMSTextMessage) {
        body = new AmqpValue(((TextMessage) message).getText());
        maMap.put(AMQPMessageSupport.JMS_MSG_TYPE, AMQPMessageSupport.JMS_TEXT_MESSAGE);
    } else if (message instanceof ServerJMSMapMessage) {
        body = new AmqpValue(getMapFromMessageBody((ServerJMSMapMessage) message));
        maMap.put(AMQPMessageSupport.JMS_MSG_TYPE, AMQPMessageSupport.JMS_MAP_MESSAGE);
    } else if (message instanceof ServerJMSStreamMessage) {
        maMap.put(AMQPMessageSupport.JMS_MSG_TYPE, AMQPMessageSupport.JMS_STREAM_MESSAGE);
        ArrayList<Object> list = new ArrayList<>();
        final ServerJMSStreamMessage m = (ServerJMSStreamMessage) message;
        try {
            while (true) {
                list.add(m.readObject());
            }
        } catch (MessageEOFException e) {
        }
        body = new AmqpSequence(list);
    } else if (message instanceof ServerJMSObjectMessage) {
        properties.setContentType(AMQPMessageSupport.SERIALIZED_JAVA_OBJECT_CONTENT_TYPE);
        maMap.put(AMQPMessageSupport.JMS_MSG_TYPE, AMQPMessageSupport.JMS_OBJECT_MESSAGE);
        Binary payload = getBinaryFromMessageBody((ServerJMSObjectMessage) message);
        if (payload == null) {
            payload = EMPTY_BINARY;
        }
        body = new Data(payload);
        // we are sending it.
        if (!message.propertyExists(JMS_AMQP_CONTENT_TYPE)) {
            message.setStringProperty(JMS_AMQP_CONTENT_TYPE, SERIALIZED_JAVA_OBJECT_CONTENT_TYPE.toString());
        }
    } else if (message instanceof ServerJMSMessage) {
        maMap.put(AMQPMessageSupport.JMS_MSG_TYPE, AMQPMessageSupport.JMS_MESSAGE);
        // If this is not an AMQP message that was converted then the original encoding
        // will be unknown so we check for special cases of messages with special data
        // encoded into the server message body.
        ICoreMessage internalMessage = message.getInnerMessage();
        int readerIndex = internalMessage.getBodyBuffer().readerIndex();
        try {
            Object s = internalMessage.getBodyBuffer().readNullableSimpleString();
            if (s != null) {
                body = new AmqpValue(s.toString());
            }
        } catch (Throwable ignored) {
            logger.debug("Exception ignored during conversion", ignored.getMessage(), ignored);
            body = new AmqpValue("Conversion to AMQP error!");
        } finally {
            internalMessage.getBodyBuffer().readerIndex(readerIndex);
        }
    }
    return body;
}
Also used : MessageEOFException(javax.jms.MessageEOFException) ArrayList(java.util.ArrayList) ServerJMSObjectMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSObjectMessage) ServerJMSStreamMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSStreamMessage) Data(org.apache.qpid.proton.amqp.messaging.Data) Section(org.apache.qpid.proton.amqp.messaging.Section) AmqpSequence(org.apache.qpid.proton.amqp.messaging.AmqpSequence) AmqpValue(org.apache.qpid.proton.amqp.messaging.AmqpValue) ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) ServerJMSBytesMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSBytesMessage) ServerJMSTextMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSTextMessage) ServerJMSMapMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMapMessage) Binary(org.apache.qpid.proton.amqp.Binary) ServerJMSMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMessage)

Example 10 with ServerJMSTextMessage

use of org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSTextMessage in project activemq-artemis by apache.

the class JMSMappingInboundTransformerTest method testTransformMessageWithAmqpValueStringCreatesTextMessage.

@Test
public void testTransformMessageWithAmqpValueStringCreatesTextMessage() throws Exception {
    String contentString = "myTextMessageContent";
    Message message = Message.Factory.create();
    message.setBody(new AmqpValue(contentString));
    ServerJMSTextMessage jmsMessage = (ServerJMSTextMessage) ServerJMSMessage.wrapCoreMessage(new AMQPMessage(message).toCore());
    jmsMessage.decode();
    assertTrue("Expected TextMessage", jmsMessage instanceof TextMessage);
    assertEquals("Unexpected message class type", ServerJMSTextMessage.class, jmsMessage.getClass());
    TextMessage textMessage = (TextMessage) jmsMessage;
    assertNotNull(textMessage.getText());
    assertEquals(contentString, textMessage.getText());
}
Also used : ServerJMSTextMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSTextMessage) AMQPMessage(org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage) ServerJMSObjectMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSObjectMessage) Message(org.apache.qpid.proton.message.Message) TextMessage(javax.jms.TextMessage) ServerJMSMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMessage) ServerJMSStreamMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSStreamMessage) ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) ServerJMSBytesMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSBytesMessage) ServerJMSMapMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMapMessage) ServerJMSTextMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSTextMessage) AMQPMessage(org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage) AmqpValue(org.apache.qpid.proton.amqp.messaging.AmqpValue) ServerJMSTextMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSTextMessage) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Aggregations

ServerJMSTextMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSTextMessage)10 ServerJMSBytesMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSBytesMessage)8 ServerJMSMapMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMapMessage)8 ServerJMSMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMessage)8 ServerJMSObjectMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSObjectMessage)8 ServerJMSStreamMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSStreamMessage)8 AmqpValue (org.apache.qpid.proton.amqp.messaging.AmqpValue)7 Message (org.apache.qpid.proton.message.Message)7 CoreMessage (org.apache.activemq.artemis.core.message.impl.CoreMessage)6 Test (org.junit.Test)6 ICoreMessage (org.apache.activemq.artemis.api.core.ICoreMessage)3 AMQPMessage (org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage)2 Symbol (org.apache.qpid.proton.amqp.Symbol)2 MessageAnnotations (org.apache.qpid.proton.amqp.messaging.MessageAnnotations)2 ArrayList (java.util.ArrayList)1 MessageEOFException (javax.jms.MessageEOFException)1 TextMessage (javax.jms.TextMessage)1 Binary (org.apache.qpid.proton.amqp.Binary)1 AmqpSequence (org.apache.qpid.proton.amqp.messaging.AmqpSequence)1 ApplicationProperties (org.apache.qpid.proton.amqp.messaging.ApplicationProperties)1