Package org.springframework.amqp.core

Examples of org.springframework.amqp.core.MessageProperties


        converter.getConverters().put("application/json", new XStreamConverter());
        converter.getConverters().put("application/xml", new StringConverter());
        converter.setDefaultContentType("application/json");
        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);
View Full Code Here


        converter.getConverters().put("application/json", new XStreamConverter());
        converter.getConverters().put("application/xml", new StringConverter());
        converter.setDefaultContentType("application/json");
        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);
View Full Code Here

    @Test
    public void testConversion() throws Exception {
        TestObject testObject = new TestObject();
        testObject.setValue("TESTING");
       
        MessageProperties messageProperties = new MessageProperties();
       
        MessageConverter converter = new StringConverter();
        Message amqpMessage = converter.toMessage(testObject, messageProperties);
        Object newObject = converter.fromMessage(amqpMessage);
       
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

        }
    }

    @Override
    public Object fromMessage(Message message) throws MessageConversionException {
        MessageProperties messageProperties = message.getMessageProperties();
        if(messageProperties == null)
            throw new MessageConversionException("Cannot decode a message with no properties!");

        byte[] body = message.getBody();
        if(body == null)
            return null;

        String messageEncoding = messageProperties.getContentEncoding();
        if(messageEncoding == null)
            messageEncoding = getEncoding();

        String contentType = messageProperties.getContentType();
        if(! MessageProperties.CONTENT_TYPE_JSON.equalsIgnoreCase(contentType))
            throw new MessageConversionException("Cannot understand a message of type "+contentType);

        try {
            ByteArrayInputStream inStream = new ByteArrayInputStream(body);
            StaxReader reader = new StaxReader(new QNameMap(), this.inputFactory.createXMLStreamReader(inStream, messageEncoding));
            return this.objectMapper.unmarshal(reader);
        } catch (XMLStreamException ex) {
            String typeId = (String) messageProperties.getHeaders().get(DefaultClassMapper.DEFAULT_CLASSID_FIELD_NAME);
            LOG.error("XMLStreamException trying to unmarshal message of type {}", typeId, ex);
            throw new MessageConversionException("Could not unmarshal message of type "+typeId, ex);
        } catch (XStreamException ex) {
            //For some reason messages appear to be getting eaten at this stage... very nasty when you try to troubleshoot.
            String typeId = (String) messageProperties.getHeaders().get(DefaultClassMapper.DEFAULT_CLASSID_FIELD_NAME);
            LOG.error("XStreamException trying to unmarshal message of type {}", typeId, ex);
            throw new MessageConversionException("Could not unmarshal message of type "+typeId, ex);
        }
    }
View Full Code Here

        return converter.toMessage(object, messageProperties);
    }

    @Override
    public Object fromMessage(Message message) throws MessageConversionException {
        MessageProperties messageProperties = message.getMessageProperties();
        String contentType = messageProperties.getContentType();
        if(messageProperties == null)
            throw new MessageConversionException("Cannot decode a message with no properties!");
       
        MessageConverter converter = converters.get(contentType);
        if(converter == null) //Try to fall back
View Full Code Here

        }
    }

    @Override
    public Object fromMessage(Message message) throws MessageConversionException {
        MessageProperties messageProperties = message.getMessageProperties();
        if(messageProperties == null)
            throw new MessageConversionException("Cannot decode a message with no properties!");

        byte[] body = message.getBody();
        if(body == null)
            return null;

        String messageEncoding = messageProperties.getContentEncoding();
        if(messageEncoding == null)
            messageEncoding = this.encoding;

        String messageContentType = messageProperties.getContentType();
        if(this.contentType != null && ! this.contentType.equalsIgnoreCase(messageContentType))
            throw new MessageConversionException("Cannot understand a message of type "+messageContentType);

        try {
            return new String(body, messageEncoding);
View Full Code Here

       
        return ExchangePattern.valueOf(exchangePatternName);
    }

    public Message toAMQPMessage(MessageConverter msgConverter) {
        MessageProperties properties = new MessageProperties();
        properties.setMessageId(this.getMessageId());
       
        Message amqpMessage;
        if(this.getBody() != null) {
            amqpMessage = msgConverter.toMessage(this.getBody(), properties);
           
View Full Code Here

        }
    }

    @Override
    public Object fromMessage(Message message) throws MessageConversionException {
        MessageProperties messageProperties = message.getMessageProperties();
        if(messageProperties == null)
            throw new MessageConversionException("Cannot decode a message with no properties!");

        byte[] body = message.getBody();
        if(body == null)
            return null;

        String messageEncoding = messageProperties.getContentEncoding();
        if(messageEncoding == null)
            messageEncoding = this.encoding;

        String messageContentType = messageProperties.getContentType();
        if(this.contentType != null && ! this.contentType.equalsIgnoreCase(messageContentType))
            throw new MessageConversionException("Cannot understand a message of type "+messageContentType);

        try {
            return new String(body, messageEncoding);
View Full Code Here

TOP

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

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.