Tabnine Logo
MessageProperties.getContentEncoding
Code IndexAdd Tabnine to your IDE (free)

How to use
getContentEncoding
method
in
org.springframework.amqp.core.MessageProperties

Best Java code snippets using org.springframework.amqp.core.MessageProperties.getContentEncoding (Showing top 20 results out of 315)

origin: spring-projects/spring-integration

  headers.put(AmqpHeaders.CLUSTER_ID, clusterId);
String contentEncoding = amqpMessageProperties.getContentEncoding();
if (StringUtils.hasText(contentEncoding)) {
  headers.put(AmqpHeaders.CONTENT_ENCODING, contentEncoding);
origin: spring-projects/spring-integration

message1 -> {
  MessageProperties messageProperties = message1.getMessageProperties();
  String contentEncoding = messageProperties.getContentEncoding();
  long contentLength = messageProperties.getContentLength();
  String contentType = messageProperties.getContentType();
origin: spring-projects/spring-integration

assertEquals("test.contentEncoding", amqpProperties.getContentEncoding());
assertEquals(99L, amqpProperties.getContentLength());
assertEquals("test.contentType", amqpProperties.getContentType());
origin: spring-projects/spring-amqp

public MessageBuilderSupport<T> setContentEncodingIfAbsent(String contentEncoding) {
  if (this.properties.getContentEncoding() == null) {
    this.properties.setContentEncoding(contentEncoding);
  }
  return this;
}
origin: spring-projects/spring-amqp

private Object asString(Message message, MessageProperties properties) {
  String encoding = properties.getContentEncoding();
  if (encoding == null) {
    encoding = this.defaultCharset;
  }
  try {
    return new String(message.getBody(), encoding);
  }
  catch (UnsupportedEncodingException e) {
    throw new MessageConversionException("failed to convert text-based Message content", e);
  }
}
origin: spring-projects/spring-amqp

@Override
public Message postProcessMessage(Message message) throws AmqpException {
  String encoding = message.getMessageProperties().getContentEncoding();
  if (encoding == null) {
    return message;
  }
  else {
    int colonAt = encoding.indexOf(':');
    if (colonAt > 0) {
      encoding = encoding.substring(0, colonAt);
    }
    MessagePostProcessor decompressor = this.decompressors.get(encoding);
    if (decompressor != null) {
      return decompressor.postProcessMessage(message);
    }
    else {
      return message;
    }
  }
}
origin: com.bluelock/camel-spring-amqp

  @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);
    }
  }
}
origin: Bluelock/camel-spring-amqp

  @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);
    }
  }
}
origin: spring-projects/spring-amqp

@Override
public Message postProcessMessage(Message message) throws AmqpException {
  ByteArrayOutputStream zipped = new ByteArrayOutputStream();
  try {
    OutputStream zipper = getCompressorStream(zipped);
    FileCopyUtils.copy(new ByteArrayInputStream(message.getBody()), zipper);
    MessageProperties messageProperties = message.getMessageProperties();
    String currentEncoding = messageProperties.getContentEncoding();
    messageProperties
        .setContentEncoding(getEncoding() + (currentEncoding == null ? "" : ":" + currentEncoding));
    if (this.autoDecompress) {
      messageProperties.setHeader(MessageProperties.SPRING_AUTO_DECOMPRESS, true);
    }
    byte[] compressed = zipped.toByteArray();
    if (this.logger.isTraceEnabled()) {
      this.logger.trace("Compressed " + message.getBody().length + " to " + compressed.length);
    }
    return new Message(compressed, messageProperties);
  }
  catch (IOException e) {
    throw new AmqpIOException(e);
  }
}
origin: Bluelock/camel-spring-amqp

public static SpringAMQPMessage setBasicPropertiesToHeaders(SpringAMQPMessage msg, Message amqpMessage) {
  msg.getHeaders().put(MESSAGE_ID, amqpMessage.getMessageProperties().getMessageId());
  byte[] correlationId = amqpMessage.getMessageProperties().getCorrelationId();
  msg.getHeaders().put(CORRELATION_ID, correlationId == null ? null : new String(correlationId));
  msg.getHeaders().put(CONTENT_ENCODING, amqpMessage.getMessageProperties().getContentEncoding());
  msg.getHeaders().put(CONTENT_TYPE, amqpMessage.getMessageProperties().getContentType());
  msg.getHeaders().put(EXPIRATION, amqpMessage.getMessageProperties().getExpiration());
  msg.getHeaders().put(PRIORITY, amqpMessage.getMessageProperties().getPriority());
  msg.getHeaders().put(REPLY_TO, amqpMessage.getMessageProperties().getReplyTo());
  msg.getHeaders().put(DELIVERY_MODE, MessageDeliveryMode.toInt(amqpMessage.getMessageProperties().getDeliveryMode()));
  msg.getHeaders().put(TYPE, amqpMessage.getMessageProperties().getType());
  return msg;
}

origin: com.bluelock/camel-spring-amqp

public static SpringAMQPMessage setBasicPropertiesToHeaders(SpringAMQPMessage msg, Message amqpMessage) {
  msg.getHeaders().put(MESSAGE_ID, amqpMessage.getMessageProperties().getMessageId());
  byte[] correlationId = amqpMessage.getMessageProperties().getCorrelationId();
  msg.getHeaders().put(CORRELATION_ID, correlationId == null ? null : new String(correlationId));
  msg.getHeaders().put(CONTENT_ENCODING, amqpMessage.getMessageProperties().getContentEncoding());
  msg.getHeaders().put(CONTENT_TYPE, amqpMessage.getMessageProperties().getContentType());
  msg.getHeaders().put(EXPIRATION, amqpMessage.getMessageProperties().getExpiration());
  msg.getHeaders().put(PRIORITY, amqpMessage.getMessageProperties().getPriority());
  msg.getHeaders().put(REPLY_TO, amqpMessage.getMessageProperties().getReplyTo());
  msg.getHeaders().put(DELIVERY_MODE, MessageDeliveryMode.toInt(amqpMessage.getMessageProperties().getDeliveryMode()));
  msg.getHeaders().put(TYPE, amqpMessage.getMessageProperties().getType());
  return msg;
}

origin: spring-projects/spring-amqp

@Test
public void stringToMessage() throws Exception {
  SimpleMessageConverter converter = new SimpleMessageConverter();
  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);
}
origin: spring-projects/spring-amqp

@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);
}
origin: spring-projects/spring-amqp

@Test
public void testSimpleBatchGZippedWithEncoding() throws Exception {
  BatchingStrategy batchingStrategy = new SimpleBatchingStrategy(2, Integer.MAX_VALUE, 30000);
  BatchingRabbitTemplate template = new BatchingRabbitTemplate(batchingStrategy, this.scheduler);
  template.setConnectionFactory(this.connectionFactory);
  template.setBeforePublishPostProcessors(new GZipPostProcessor());
  MessageProperties props = new MessageProperties();
  props.setContentEncoding("foo");
  Message message = new Message("foo".getBytes(), props);
  template.send("", ROUTE, message);
  message = new Message("bar".getBytes(), props);
  template.send("", ROUTE, message);
  message = receive(template);
  assertEquals("gzip:foo", message.getMessageProperties().getContentEncoding());
  GUnzipPostProcessor unzipper = new GUnzipPostProcessor();
  message = unzipper.postProcessMessage(message);
  assertEquals("\u0000\u0000\u0000\u0003foo\u0000\u0000\u0000\u0003bar", new String(message.getBody()));
}
origin: spring-projects/spring-amqp

@Test
public void testSimpleBatchGZippedConfiguredUnzipper() throws Exception {
  BatchingStrategy batchingStrategy = new SimpleBatchingStrategy(2, Integer.MAX_VALUE, 30000);
  BatchingRabbitTemplate template = new BatchingRabbitTemplate(batchingStrategy, this.scheduler);
  template.setConnectionFactory(this.connectionFactory);
  GZipPostProcessor gZipPostProcessor = new GZipPostProcessor();
  gZipPostProcessor.setLevel(Deflater.BEST_COMPRESSION);
  assertEquals(Deflater.BEST_COMPRESSION, getStreamLevel(gZipPostProcessor));
  template.setBeforePublishPostProcessors(gZipPostProcessor);
  template.setAfterReceivePostProcessors(new GUnzipPostProcessor());
  MessageProperties props = new MessageProperties();
  Message message = new Message("foo".getBytes(), props);
  template.send("", ROUTE, message);
  message = new Message("bar".getBytes(), props);
  template.send("", ROUTE, message);
  message = receive(template);
  assertNull(message.getMessageProperties().getContentEncoding());
  assertEquals("\u0000\u0000\u0000\u0003foo\u0000\u0000\u0000\u0003bar", new String(message.getBody()));
}
origin: spring-projects/spring-amqp

@Test
public void testSimpleBatchGZipped() throws Exception {
  BatchingStrategy batchingStrategy = new SimpleBatchingStrategy(2, Integer.MAX_VALUE, 30000);
  BatchingRabbitTemplate template = new BatchingRabbitTemplate(batchingStrategy, this.scheduler);
  template.setConnectionFactory(this.connectionFactory);
  GZipPostProcessor gZipPostProcessor = new GZipPostProcessor();
  assertEquals(Deflater.BEST_SPEED, getStreamLevel(gZipPostProcessor));
  template.setBeforePublishPostProcessors(gZipPostProcessor);
  MessageProperties props = new MessageProperties();
  Message message = new Message("foo".getBytes(), props);
  template.send("", ROUTE, message);
  message = new Message("bar".getBytes(), props);
  template.send("", ROUTE, message);
  message = receive(template);
  assertEquals("gzip", message.getMessageProperties().getContentEncoding());
  GUnzipPostProcessor unzipper = new GUnzipPostProcessor();
  message = unzipper.postProcessMessage(message);
  assertEquals("\u0000\u0000\u0000\u0003foo\u0000\u0000\u0000\u0003bar", new String(message.getBody()));
}
origin: spring-projects/spring-amqp

@Test
public void testSimpleBatchZippedBestCompression() throws Exception {
  BatchingStrategy batchingStrategy = new SimpleBatchingStrategy(2, Integer.MAX_VALUE, 30000);
  BatchingRabbitTemplate template = new BatchingRabbitTemplate(batchingStrategy, this.scheduler);
  template.setConnectionFactory(this.connectionFactory);
  ZipPostProcessor zipPostProcessor = new ZipPostProcessor();
  zipPostProcessor.setLevel(Deflater.BEST_COMPRESSION);
  assertEquals(Deflater.BEST_COMPRESSION, getStreamLevel(zipPostProcessor));
  template.setBeforePublishPostProcessors(zipPostProcessor);
  MessageProperties props = new MessageProperties();
  Message message = new Message("foo".getBytes(), props);
  template.send("", ROUTE, message);
  message = new Message("bar".getBytes(), props);
  template.send("", ROUTE, message);
  message = receive(template);
  assertEquals("zip", message.getMessageProperties().getContentEncoding());
  UnzipPostProcessor unzipper = new UnzipPostProcessor();
  message = unzipper.postProcessMessage(message);
  assertEquals("\u0000\u0000\u0000\u0003foo\u0000\u0000\u0000\u0003bar", new String(message.getBody()));
}
origin: spring-projects/spring-amqp

@Test
public void testSimpleBatchZippedWithEncoding() throws Exception {
  BatchingStrategy batchingStrategy = new SimpleBatchingStrategy(2, Integer.MAX_VALUE, 30000);
  BatchingRabbitTemplate template = new BatchingRabbitTemplate(batchingStrategy, this.scheduler);
  template.setConnectionFactory(this.connectionFactory);
  ZipPostProcessor zipPostProcessor = new ZipPostProcessor();
  assertEquals(Deflater.BEST_SPEED, getStreamLevel(zipPostProcessor));
  template.setBeforePublishPostProcessors(zipPostProcessor);
  MessageProperties props = new MessageProperties();
  props.setContentEncoding("foo");
  Message message = new Message("foo".getBytes(), props);
  template.send("", ROUTE, message);
  message = new Message("bar".getBytes(), props);
  template.send("", ROUTE, message);
  message = receive(template);
  assertEquals("zip:foo", message.getMessageProperties().getContentEncoding());
  UnzipPostProcessor unzipper = new UnzipPostProcessor();
  message = unzipper.postProcessMessage(message);
  assertEquals("\u0000\u0000\u0000\u0003foo\u0000\u0000\u0000\u0003bar", new String(message.getBody()));
}
origin: spring-projects/spring-amqp

private void assertLower(MessageProperties properties) {
  assertEquals("appId", properties.getAppId());
  assertEquals("clusterId", properties.getClusterId());
  assertEquals("contentEncoding", properties.getContentEncoding());
  assertEquals(MessageProperties.CONTENT_TYPE_TEXT_PLAIN, properties.getContentType());
  assertEquals(1, properties.getContentLength());
  assertEquals("correlationId", properties.getCorrelationId());
  assertEquals(MessageDeliveryMode.NON_PERSISTENT, properties.getDeliveryMode());
  assertEquals(2, properties.getDeliveryTag());
  assertEquals("expiration", properties.getExpiration());
  assertEquals("bar", properties.getHeaders().get("foo"));
  assertEquals("fiz", properties.getHeaders().get("qux"));
  assertEquals("fuz", properties.getHeaders().get("baz"));
  assertEquals(Integer.valueOf(3), properties.getMessageCount());
  assertEquals("messageId", properties.getMessageId());
  assertEquals(Integer.valueOf(4), properties.getPriority());
  assertEquals("receivedExchange", properties.getReceivedExchange());
  assertEquals("receivedRoutingKey", properties.getReceivedRoutingKey());
  assertTrue(properties.getRedelivered());
  assertTrue(properties.getTimestamp().getTime() > 0);
  assertEquals("type", properties.getType());
  assertEquals("userId", properties.getUserId());
}
origin: spring-projects/spring-amqp

private void assertUpper(MessageProperties properties) {
  assertEquals("APPID", properties.getAppId());
  assertEquals("CLUSTERID", properties.getClusterId());
  assertEquals("CONTENTENCODING", properties.getContentEncoding());
  assertEquals(MessageProperties.CONTENT_TYPE_BYTES, properties.getContentType());
  assertEquals(10, properties.getContentLength());
  assertEquals("CORRELATIONID", properties.getCorrelationId());
  assertEquals(MessageDeliveryMode.PERSISTENT, properties.getDeliveryMode());
  assertEquals(20, properties.getDeliveryTag());
  assertEquals("EXPIRATION", properties.getExpiration());
  assertEquals("BAR", properties.getHeaders().get("foo"));
  assertEquals("FIZ", properties.getHeaders().get("qux"));
  assertEquals("FUZ", properties.getHeaders().get("baz"));
  assertEquals(Integer.valueOf(30), properties.getMessageCount());
  assertEquals("MESSAGEID", properties.getMessageId());
  assertEquals(Integer.valueOf(40), properties.getPriority());
  assertEquals("RECEIVEDEXCHANGE", properties.getReceivedExchange());
  assertEquals("RECEIVEDROUTINGKEY", properties.getReceivedRoutingKey());
  assertFalse(properties.getRedelivered());
  assertTrue(properties.getTimestamp().getTime() == 0);
  assertEquals("TYPE", properties.getType());
  assertEquals("USERID", properties.getUserId());
}
org.springframework.amqp.coreMessagePropertiesgetContentEncoding

Popular methods of MessageProperties

  • getDeliveryTag
  • <init>
  • setHeader
  • getHeaders
  • setExpiration
  • setContentType
  • getReplyTo
  • getCorrelationId
  • getMessageId
  • getReceivedRoutingKey
  • setCorrelationId
  • setDeliveryMode
  • setCorrelationId,
  • setDeliveryMode,
  • setReplyTo,
  • getConsumerQueue,
  • getReceivedExchange,
  • getContentType,
  • getExpiration,
  • setContentEncoding,
  • setMessageId,
  • getAppId

Popular in Java

  • Reactive rest calls using spring rest template
  • scheduleAtFixedRate (Timer)
  • getResourceAsStream (ClassLoader)
  • setContentView (Activity)
  • Table (com.google.common.collect)
    A collection that associates an ordered pair of keys, called a row key and a column key, with a sing
  • File (java.io)
    An "abstract" representation of a file system entity identified by a pathname. The pathname may be a
  • Stack (java.util)
    Stack is a Last-In/First-Out(LIFO) data structure which represents a stack of objects. It enables u
  • UUID (java.util)
    UUID is an immutable representation of a 128-bit universally unique identifier (UUID). There are mul
  • ServletException (javax.servlet)
    Defines a general exception a servlet can throw when it encounters difficulty.
  • HttpServlet (javax.servlet.http)
    Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site. A sub
  • PhpStorm for WordPress
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now