org.apache.activemq.artemis.core.protocol.proton.converter.message.EncodedMessage

Here are the examples of the java api class org.apache.activemq.artemis.core.protocol.proton.converter.message.EncodedMessage taken from open source projects.

1. ProtonMessageConverter#inboundJMSType()

View license
/**
    * Just create the JMS Part of the inbound (for testing)
    *
    * @param messageSource
    * @return
    * @throws Exception                    https://issues.jboss.org/browse/ENTMQ-1560
    */
public ServerJMSMessage inboundJMSType(EncodedMessage messageSource) throws Exception {
    EncodedMessage encodedMessageSource = messageSource;
    ServerJMSMessage transformedMessage = null;
    InboundTransformer transformer = inboundTransformer;
    while (transformer != null) {
        try {
            transformedMessage = (ServerJMSMessage) transformer.transform(encodedMessageSource);
            break;
        } catch (Exception e) {
            ActiveMQClientLogger.LOGGER.debug("Transform of message using [{}] transformer, failed" + inboundTransformer.getTransformerName());
            ActiveMQClientLogger.LOGGER.trace("Transformation error:", e);
            transformer = transformer.getFallbackTransformer();
        }
    }
    if (transformedMessage == null) {
        throw new IOException("Failed to transform incoming delivery, skipping.");
    }
    transformedMessage.encode();
    return transformedMessage;
}

2. ProtonSessionIntegrationCallback#serverSend()

View license
@Override
public void serverSend(final Receiver receiver, final Delivery delivery, String address, int messageFormat, ByteBuf messageEncoded) throws Exception {
    EncodedMessage encodedMessage = new EncodedMessage(messageFormat, messageEncoded.array(), messageEncoded.arrayOffset(), messageEncoded.writerIndex());
    ServerMessage message = manager.getConverter().inbound(encodedMessage);
    //use the address on the receiver if not null, if null let's hope it was set correctly on the message
    if (address != null) {
        message.setAddress(new SimpleString(address));
    }
    recoverContext();
    try {
        serverSession.send(message, false);
        manager.getServer().getStorageManager().afterCompleteOperations(new IOCallback() {

            @Override
            public void done() {
                synchronized (connection.getLock()) {
                    delivery.settle();
                    connection.flush();
                }
            }

            @Override
            public void onError(int errorCode, String errorMessage) {
                synchronized (connection.getLock()) {
                    receiver.setCondition(new ErrorCondition(AmqpError.ILLEGAL_STATE, errorCode + ":" + errorMessage));
                    connection.flush();
                }
            }
        });
    } finally {
        resetContext();
    }
}

3. TestConversions#testSimpleConversionBytes()

View license
@Test
public void testSimpleConversionBytes() throws Exception {
    Map<String, Object> mapprop = createPropertiesMap();
    ApplicationProperties properties = new ApplicationProperties(mapprop);
    MessageImpl message = (MessageImpl) Message.Factory.create();
    message.setApplicationProperties(properties);
    byte[] bodyBytes = new byte[4];
    for (int i = 0; i < bodyBytes.length; i++) {
        bodyBytes[i] = (byte) 0xff;
    }
    message.setBody(new Data(new Binary(bodyBytes)));
    EncodedMessage encodedMessage = encodeMessage(message);
    ProtonMessageConverter converter = new ProtonMessageConverter(new SimpleIDGenerator(0));
    ServerJMSBytesMessage serverMessage = (ServerJMSBytesMessage) converter.inboundJMSType(encodedMessage);
    verifyProperties(serverMessage);
    assertEquals(bodyBytes.length, serverMessage.getBodyLength());
    byte[] newBodyBytes = new byte[4];
    serverMessage.readBytes(newBodyBytes);
    Assert.assertArrayEquals(bodyBytes, newBodyBytes);
    Object obj = converter.outbound((ServerMessage) serverMessage.getInnerMessage(), 0);
    System.out.println("output = " + obj);
}

4. TestConversions#testSimpleConversionMap()

View license
@Test
public void testSimpleConversionMap() throws Exception {
    Map<String, Object> mapprop = createPropertiesMap();
    ApplicationProperties properties = new ApplicationProperties(mapprop);
    MessageImpl message = (MessageImpl) Message.Factory.create();
    message.setApplicationProperties(properties);
    Map<String, Object> mapValues = new HashMap<>();
    mapValues.put("somestr", "value");
    mapValues.put("someint", Integer.valueOf(1));
    message.setBody(new AmqpValue(mapValues));
    EncodedMessage encodedMessage = encodeMessage(message);
    ProtonMessageConverter converter = new ProtonMessageConverter(new SimpleIDGenerator(0));
    ServerJMSMapMessage serverMessage = (ServerJMSMapMessage) converter.inboundJMSType(encodedMessage);
    verifyProperties(serverMessage);
    Assert.assertEquals(1, serverMessage.getInt("someint"));
    Assert.assertEquals("value", serverMessage.getString("somestr"));
    Object obj = converter.outbound((ServerMessage) serverMessage.getInnerMessage(), 0);
    reEncodeMsg(obj);
    MessageImpl outMessage = (MessageImpl) obj;
    AmqpValue value = (AmqpValue) outMessage.getBody();
    Map mapoutput = (Map) value.getValue();
    assertEquals(Integer.valueOf(1), mapoutput.get("someint"));
    System.out.println("output = " + obj);
}

5. TestConversions#testSimpleConversionStream()

View license
@Test
public void testSimpleConversionStream() throws Exception {
    Map<String, Object> mapprop = createPropertiesMap();
    ApplicationProperties properties = new ApplicationProperties(mapprop);
    MessageImpl message = (MessageImpl) Message.Factory.create();
    message.setApplicationProperties(properties);
    List<Object> objects = new LinkedList<>();
    objects.add(new Integer(10));
    objects.add("10");
    message.setBody(new AmqpSequence(objects));
    EncodedMessage encodedMessage = encodeMessage(message);
    ProtonMessageConverter converter = new ProtonMessageConverter(new SimpleIDGenerator(0));
    ServerJMSStreamMessage serverMessage = (ServerJMSStreamMessage) converter.inboundJMSType(encodedMessage);
    simulatePersistence(serverMessage);
    verifyProperties(serverMessage);
    serverMessage.reset();
    assertEquals(10, serverMessage.readInt());
    assertEquals("10", serverMessage.readString());
    Object obj = converter.outbound((ServerMessage) serverMessage.getInnerMessage(), 0);
    reEncodeMsg(obj);
    MessageImpl outMessage = (MessageImpl) obj;
    List list = ((AmqpSequence) outMessage.getBody()).getValue();
    Assert.assertEquals(Integer.valueOf(10), list.get(0));
    Assert.assertEquals("10", list.get(1));
}

6. TestConversions#testSimpleConversionText()

View license
@Test
public void testSimpleConversionText() throws Exception {
    Map<String, Object> mapprop = createPropertiesMap();
    ApplicationProperties properties = new ApplicationProperties(mapprop);
    MessageImpl message = (MessageImpl) Message.Factory.create();
    message.setApplicationProperties(properties);
    String text = "someText";
    message.setBody(new AmqpValue(text));
    EncodedMessage encodedMessage = encodeMessage(message);
    ProtonMessageConverter converter = new ProtonMessageConverter(new SimpleIDGenerator(0));
    ServerJMSTextMessage serverMessage = (ServerJMSTextMessage) converter.inboundJMSType(encodedMessage);
    simulatePersistence(serverMessage);
    verifyProperties(serverMessage);
    Assert.assertEquals(text, serverMessage.getText());
    Object obj = converter.outbound((ServerMessage) serverMessage.getInnerMessage(), 0);
    reEncodeMsg(obj);
    MessageImpl outMessage = (MessageImpl) obj;
    AmqpValue value = (AmqpValue) outMessage.getBody();
    String textValue = (String) value.getValue();
    Assert.assertEquals(text, textValue);
    System.out.println("output = " + obj);
}