Package org.springframework.amqp.core

Examples of org.springframework.amqp.core.MessageProperties


  }

  @Test
  public void messageToBytes() {
    SerializerMessageConverter converter = new SerializerMessageConverter();
    Message message = new Message(new byte[] { 1, 2, 3 }, new MessageProperties());
    message.getMessageProperties().setContentType(MessageProperties.CONTENT_TYPE_BYTES);
    Object result = converter.fromMessage(message);
    assertEquals(byte[].class, result.getClass());
    byte[] resultBytes = (byte[]) result;
    assertEquals(3, resultBytes.length);
View Full Code Here


  }

  @Test
  public void messageToSerializedObject() throws Exception {
    SerializerMessageConverter converter = new SerializerMessageConverter();
    MessageProperties properties = new MessageProperties();
    properties.setContentType(MessageProperties.CONTENT_TYPE_SERIALIZED_OBJECT);
    ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
    ObjectOutputStream objectStream = new ObjectOutputStream(byteStream);
    TestBean testBean = new TestBean("foo");
    objectStream.writeObject(testBean);
    objectStream.flush();
View Full Code Here

  @Test
  public void messageToSerializedObjectNoContentType() throws Exception {
    SerializerMessageConverter converter = new SerializerMessageConverter();
    converter.setIgnoreContentType(true);
    MessageProperties properties = new MessageProperties();
    ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
    ObjectOutputStream objectStream = new ObjectOutputStream(byteStream);
    TestBean testBean = new TestBean("foo");
    objectStream.writeObject(testBean);
    objectStream.flush();
View Full Code Here

  }

  @Test
  public void stringToMessage() throws Exception {
    SerializerMessageConverter converter = new SerializerMessageConverter();
    Message message = converter.toMessage("test", new MessageProperties());
    String contentType = message.getMessageProperties().getContentType();
    String content = new String(message.getBody(),
        message.getMessageProperties().getContentEncoding());
    assertEquals("text/plain", contentType);
    assertEquals("test", content);
View Full Code Here

  }

  @Test
  public void bytesToMessage() throws Exception {
    SerializerMessageConverter converter = new SerializerMessageConverter();
    Message message = converter.toMessage(new byte[] { 1, 2, 3 }, new MessageProperties());
    String contentType = message.getMessageProperties().getContentType();
    byte[] body = message.getBody();
    assertEquals("application/octet-stream", contentType);
    assertEquals(3, body.length);
    assertEquals(1, body[0]);
View Full Code Here

  @Test
  public void serializedObjectToMessage() throws Exception {
    SerializerMessageConverter converter = new SerializerMessageConverter();
    TestBean testBean = new TestBean("foo");
    Message message = converter.toMessage(testBean, new MessageProperties());
    String contentType = message.getMessageProperties().getContentType();
    byte[] body = message.getBody();
    assertEquals("application/x-java-serialized-object", contentType);
    ByteArrayInputStream bais = new ByteArrayInputStream(body);
    Object deserializedObject = new ObjectInputStream(bais).readObject();
View Full Code Here

  @Override
  public Object fromMessage(Message message)
      throws MessageConversionException {
    Object content = null;
    MessageProperties properties = message.getMessageProperties();
    if (properties != null) {
      String contentType = properties.getContentType();
      if (contentType != null && contentType.contains("json")) {
        String encoding = properties.getContentEncoding();
        if (encoding == null) {
          encoding = getDefaultCharset();
        }
        try {
View Full Code Here

  @Test
  public void marshal() throws Exception {
    TestMarshaller marshaller = new TestMarshaller();
    MarshallingMessageConverter converter = new MarshallingMessageConverter(marshaller);
    converter.afterPropertiesSet();
    Message message = converter.toMessage("marshal test", new MessageProperties());
    String response = new String(message.getBody(), "UTF-8");
    assertEquals("MARSHAL TEST", response);
  }
View Full Code Here

    TestMarshaller marshaller = new TestMarshaller();
    MarshallingMessageConverter converter = new MarshallingMessageConverter(marshaller);
    converter.setContentType(MessageProperties.CONTENT_TYPE_XML);
    converter.afterPropertiesSet();

    Message message = converter.toMessage("marshal test", new MessageProperties());

    assertEquals("application/xml", message.getMessageProperties().getContentType());
  }
View Full Code Here

  @Test
  public void dontSetNullContentType() throws Exception {
    TestMarshaller marshaller = new TestMarshaller();
    MarshallingMessageConverter converter = new MarshallingMessageConverter(marshaller);
    converter.afterPropertiesSet();
    final String defaultContentType = new MessageProperties().getContentType();

    Message message = converter.toMessage("marshal test", new MessageProperties());

    assertEquals(defaultContentType, message.getMessageProperties().getContentType());
  }
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.