Package org.springframework.amqp.support.converter

Examples of org.springframework.amqp.support.converter.MessageConversionException


            messageProperties.setContentEncoding(this.encoding);
            messageProperties.setContentLength(body.length);
            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


    @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);
        } catch (UnsupportedEncodingException ex) {
            LOG.error("Cannot dencode strings as {}", this.encoding, ex);
            throw new MessageConversionException("Cannot dencode strings as "+this.encoding, ex);
        }
    }
View Full Code Here

            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) {
            //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 marshal message of type {}", typeId, ex);
            throw new MessageConversionException("Could not marshal message of type "+typeId, ex);
        }
    }
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

    assertEquals("foo", new String(rejected.getBody()));
    assertNotNull(failed.get());

    container.stop();

    Exception e = new ListenerExecutionFailedException("foo", new MessageConversionException("bar"));
    try {
      eh.handleError(e);
      fail("expected exception");
    }
    catch (AmqpRejectAndDontRequeueException aradre) {
      assertSame(e, aradre.getCause());
    }
    e = new ListenerExecutionFailedException("foo", new MessageConversionException("bar",
        new AmqpRejectAndDontRequeueException("baz")));
    eh.handleError(e);
  }
View Full Code Here

    messagingTemplate.setAmqpMessageConverter(new SimpleMessageConverter() {

      @Override
      protected org.springframework.amqp.core.Message createMessage(Object object,
          MessageProperties messageProperties) throws MessageConversionException {
        throw new MessageConversionException("Test exception");
      }
    });

    thrown.expect(org.springframework.messaging.converter.MessageConversionException.class);
    thrown.expectMessage(new StringContains("Test exception"));
View Full Code Here

      return this.handlerMethod.invoke(message, amqpMessage, channel);
    }
    catch (org.springframework.messaging.converter.MessageConversionException ex) {
      throw new ListenerExecutionFailedException(createMessagingErrorMessage("Listener method could not " +
          "be invoked with the incoming message"),
          new MessageConversionException("Cannot handle message", ex));
    }
    catch (MessagingException ex) {
      throw new ListenerExecutionFailedException(createMessagingErrorMessage("Listener method could not " +
          "be invoked with the incoming message"), ex);
    }
View Full Code Here

        return converter.toMessage(result, new MessageProperties());
      }
    }
    else {
      if (!(result instanceof org.springframework.amqp.core.Message)) {
        throw new MessageConversionException("No MessageConverter specified - cannot handle message ["
            + result + "]");
      }
      return (org.springframework.amqp.core.Message) result;
    }
  }
View Full Code Here

    if (converter != null && !(result instanceof Message)) {
      return converter.toMessage(result, new MessageProperties());
    }
    else {
      if (!(result instanceof Message)) {
        throw new MessageConversionException("No MessageConverter specified - cannot handle message ["
            + result + "]");
      }
      return (Message) result;
    }
  }
View Full Code Here

TOP

Related Classes of org.springframework.amqp.support.converter.MessageConversionException

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.