Package org.springframework.amqp.core

Examples of org.springframework.amqp.core.Message


       
        MessageProperties messageProperties = new MessageProperties();
       
        MessageConverter converter = new XStreamConverter();
        ((XStreamConverter) converter).setEncoding("UTF-8");
        Message amqpMessage = converter.toMessage(testObject, messageProperties);
        Assert.assertEquals("{\"amqp.spring.converter.XStreamConverterTest_-TestObject\":{\"value\":\"TESTING\"}}", new String(amqpMessage.getBody()));

        Object newObject = converter.fromMessage(amqpMessage);
        Assert.assertEquals(testObject, newObject);
        Assert.assertEquals("UTF-8", ((XStreamConverter) converter).getEncoding());
    }
View Full Code Here


        converter.setFallbackConverter(new StringConverter());
       
        MessageProperties messageProperties = new MessageProperties();
        messageProperties.setContentType("application/xml");
       
        Message amqpMessage = converter.toMessage(testObject, messageProperties);
        Assert.assertEquals("TESTING", new String(amqpMessage.getBody()));
       
        Object newObject = converter.fromMessage(amqpMessage);
        Assert.assertEquals("TESTING", newObject);
    }
View Full Code Here

        converter.setFallbackConverter(new StringConverter());
       
        MessageProperties messageProperties = new MessageProperties();
        messageProperties.setContentType("application/json");
       
        Message amqpMessage = converter.toMessage(testObject, messageProperties);
        Assert.assertEquals("{\"amqp.spring.converter.ContentTypeConverterFactoryTest_-TestObject\":{\"value\":\"TESTING\"}}", new String(amqpMessage.getBody()));
       
        Object newObject = converter.fromMessage(amqpMessage);
        Assert.assertEquals(testObject, newObject);
    }
View Full Code Here

        testObject.setValue("TESTING");
       
        MessageProperties messageProperties = new MessageProperties();
       
        MessageConverter converter = new StringConverter();
        Message amqpMessage = converter.toMessage(testObject, messageProperties);
        Object newObject = converter.fromMessage(amqpMessage);
       
        Assert.assertEquals("TESTING", newObject);
    }
View Full Code Here

                                                                        new DefaultAMQPMessageConverter(serializer));

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        EventMessageWriter outputStream = new EventMessageWriter(new DataOutputStream(baos), serializer);
        outputStream.writeEventMessage(new GenericEventMessage<String>("Event"));
        testSubject.onMessage(new Message(baos.toByteArray(), new MessageProperties()));

        verify(cluster).publish(argThat(new TypeSafeMatcher<EventMessage>() {
            @Override
            public boolean matchesSafely(EventMessage item) {
                return "Event".equals(item.getPayload());
View Full Code Here

        EventMessageWriter outputStream = new EventMessageWriter(new DataOutputStream(baos), serializer);
        outputStream.writeEventMessage(new GenericEventMessage<String>("Event"));
        byte[] body = baos.toByteArray();
        body = new String(body, Charset.forName("UTF-8")).replace("string", "strong")
                                                         .getBytes(Charset.forName("UTF-8"));
        testSubject.onMessage(new Message(body, new MessageProperties()));

        verify(cluster, never()).publish(any(EventMessage.class));
    }
View Full Code Here

    }

    @Test
    public void testMessageItemType() {
        final AmqpTemplate amqpTemplate = mock(AmqpTemplate.class);
        final Message message = mock(Message.class);

        when(amqpTemplate.receive()).thenReturn(message);

        final AmqpItemReader<Message> amqpItemReader = new AmqpItemReader<Message>(amqpTemplate);
        amqpItemReader.setItemType(Message.class);
View Full Code Here

           
            messageProperties.setContentType(MessageProperties.CONTENT_TYPE_JSON);
            messageProperties.setContentEncoding(this.encoding);
            messageProperties.setContentLength(body != null ? body.length : 0);
            classMapper.fromClass(object.getClass(), messageProperties);
            return new Message(body, messageProperties);
        } catch (XMLStreamException ex) {
            String typeId = (String) messageProperties.getHeaders().get(DefaultClassMapper.DEFAULT_CLASSID_FIELD_NAME);
            LOG.error("XMLStreamException trying to marshal message of type {}", typeId, ex);
            throw new MessageConversionException("Could not marshal message of type "+typeId, ex);
        } catch (XStreamException ex) {
View Full Code Here

           
            String msgContentType = this.contentType == null ? DEFAULT_CONTENT_TYPE : this.contentType;
            messageProperties.setContentType(msgContentType);
            messageProperties.setContentEncoding(this.encoding);
            messageProperties.setContentLength(body != null ? body.length : 0);
            return new Message(body, messageProperties);
        } catch (UnsupportedEncodingException ex) {
            LOG.error("Cannot encode strings as {}", this.encoding, ex);
            throw new MessageConversionException("Cannot encode strings as "+this.encoding, ex);
        }
    }
View Full Code Here

            String routingKey = routingKeyHeader != null ? routingKeyHeader : endpoint.routingKey;

            try {
                if(exchange.getPattern().isOutCapable()) {
                    LOG.debug("Synchronous send and request for exchange {}", exchange.getExchangeId());
                    Message amqpResponse = endpoint.getAmqpTemplate().sendAndReceive(endpoint.exchangeName, routingKey, inMessage.toAMQPMessage(msgConverter));
                    SpringAMQPMessage camelResponse = SpringAMQPMessage.fromAMQPMessage(msgConverter, amqpResponse);

                    Boolean isExceptionCaught = (Boolean)camelResponse.getHeader(SpringAMQPMessage.IS_EXCEPTION_CAUGHT);
                    if (isExceptionCaught != null && isExceptionCaught.equals(Boolean.TRUE)) {
                        Object caughtObject = camelResponse.getBody();
View Full Code Here

TOP

Related Classes of org.springframework.amqp.core.Message

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.