org.springframework.messaging.Message.getPayload()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(588)

本文整理了Java中org.springframework.messaging.Message.getPayload()方法的一些代码示例,展示了Message.getPayload()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.getPayload()方法的具体详情如下:
包路径:org.springframework.messaging.Message
类名称:Message
方法名:getPayload

Message.getPayload介绍

[英]Return the message payload.
[中]返回消息有效载荷。

代码示例

代码示例来源:origin: spring-projects/spring-framework

/**
 * Encodes the given STOMP {@code message} into a {@code byte[]}.
 * @param message the message to encode
 * @return the encoded message
 */
public byte[] encode(Message<byte[]> message) {
  return encode(message.getHeaders(), message.getPayload());
}

代码示例来源:origin: spring-projects/spring-framework

private MessageBuilder(Message<T> originalMessage) {
  Assert.notNull(originalMessage, "Message must not be null");
  this.payload = originalMessage.getPayload();
  this.originalMessage = originalMessage;
  this.headerAccessor = new MessageHeaderAccessor(originalMessage);
}

代码示例来源:origin: spring-projects/spring-framework

@Override
  public void onFailure(Throwable ex) {
    if (tcpConnection != null) {
      handleTcpConnectionFailure("failed to forward " +
          accessor.getShortLogMessage(message.getPayload()), ex);
    }
    else if (logger.isErrorEnabled()) {
      logger.error("Failed to forward " + accessor.getShortLogMessage(message.getPayload()));
    }
  }
});

代码示例来源:origin: spring-projects/spring-framework

@Override
protected Object convertFromInternal(Message<?> message, Class<?> targetClass, @Nullable Object conversionHint) {
  Charset charset = getContentTypeCharset(getMimeType(message.getHeaders()));
  Object payload = message.getPayload();
  return (payload instanceof String ? payload : new String((byte[]) payload, charset));
}

代码示例来源:origin: spring-projects/spring-framework

private void logMessage(Message<?> message) {
  if (logger.isDebugEnabled()) {
    SimpMessageHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, SimpMessageHeaderAccessor.class);
    accessor = (accessor != null ? accessor : SimpMessageHeaderAccessor.wrap(message));
    logger.debug("Processing " + accessor.getShortLogMessage(message.getPayload()));
  }
}

代码示例来源:origin: spring-projects/spring-framework

public MessageExchangeBuilder andExpectMessage(String sessionId, String subscriptionId) {
  Assert.state(SimpMessageType.MESSAGE.equals(this.headers.getMessageType()), "MESSAGE type expected");
  String destination = this.headers.getDestination();
  Object payload = this.message.getPayload();
  this.expected.add(new StompMessageFrameMessageMatcher(sessionId, subscriptionId, destination, payload));
  return this;
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void toMessageUtf16() {
  MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
  MimeType contentType = new MimeType("application", "json", StandardCharsets.UTF_16BE);
  Map<String, Object> map = new HashMap<>();
  map.put(MessageHeaders.CONTENT_TYPE, contentType);
  MessageHeaders headers = new MessageHeaders(map);
  String payload = "H\u00e9llo W\u00f6rld";
  Message<?> message = converter.toMessage(payload, headers);
  assertEquals("\"" + payload + "\"", new String((byte[]) message.getPayload(), StandardCharsets.UTF_16BE));
  assertEquals(contentType, message.getHeaders().get(MessageHeaders.CONTENT_TYPE));
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void toMessageWithPayloadAndHeaders() {
  MessageHeaders headers = new MessageHeaders(Collections.<String, Object>singletonMap("foo", "bar"));
  Message<?> message = this.converter.toMessage("payload", headers);
  assertEquals("payload", message.getPayload());
  assertEquals("bar", message.getHeaders().get("foo"));
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void basic() throws InterruptedException {
  BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 128);
  String chunk = "SEND\na:alpha\n\nMessage body\0";
  List<Message<byte[]>> messages = stompDecoder.decode(toByteBuffer(chunk));
  assertEquals(1, messages.size());
  assertEquals("Message body", new String(messages.get(0).getPayload()));
  assertEquals(0, stompDecoder.getBufferSize());
  assertNull(stompDecoder.getExpectedContentLength());
}

代码示例来源:origin: spring-projects/spring-framework

@JsonView(Summary.class)
public Message<SampleResponse> replyJacksonMessageAndJsonView(Message<String> input) {
  return MessageBuilder.withPayload(createSampleResponse(input.getPayload()))
      .setHeader("foo", "bar").build();
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void convertAndSendPayload() {
  this.template.convertAndSend("myChannel", "payload");
  assertSame(this.myChannel, this.template.messageChannel);
  assertNotNull(this.template.message);
  assertSame("payload", this.template.message.getPayload());
}

代码示例来源:origin: spring-projects/spring-framework

@Test
  public void toMessageWithPayloadAndMutableHeaders() {
    MessageHeaderAccessor accessor = new MessageHeaderAccessor();
    accessor.setHeader("foo", "bar");
    accessor.setLeaveMutable(true);
    MessageHeaders headers = accessor.getMessageHeaders();

    Message<?> message = this.converter.toMessage("payload", headers);

    assertEquals("payload", message.getPayload());
    assertSame(headers, message.getHeaders());
    assertEquals("bar", message.getHeaders().get("foo"));
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void decodeFrameWithCrLfEols() {
  Message<byte[]> frame = decode("DISCONNECT\r\n\r\n\0");
  StompHeaderAccessor headers = StompHeaderAccessor.wrap(frame);
  assertEquals(StompCommand.DISCONNECT, headers.getCommand());
  assertEquals(0, headers.toNativeHeaderMap().size());
  assertEquals(0, frame.getPayload().length);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void decodeFrameWithNoHeadersAndNoBody() {
  Message<byte[]> frame = decode("DISCONNECT\n\n\0");
  StompHeaderAccessor headers = StompHeaderAccessor.wrap(frame);
  assertEquals(StompCommand.DISCONNECT, headers.getCommand());
  assertEquals(0, headers.toNativeHeaderMap().size());
  assertEquals(0, frame.getPayload().length);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void customPayloadConverter() throws JMSException {
  TextMessage jmsMsg = new StubTextMessage("1224");
  this.converter.setPayloadConverter(new TestMessageConverter());
  Message<?> msg = (Message<?>) this.converter.fromMessage(jmsMsg);
  assertEquals(1224L, msg.getPayload());
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void createFromMessage() {
  Message<String> message1 = MessageBuilder.withPayload("test")
      .setHeader("foo", "bar").build();
  Message<String> message2 = MessageBuilder.fromMessage(message1).build();
  assertEquals("test", message2.getPayload());
  assertEquals("bar", message2.getHeaders().get("foo"));
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void convertAndSendPayloadWithPostProcessorToDestination() {
  this.template.convertAndSend("somewhere", "payload", this.postProcessor);
  assertEquals("somewhere", this.template.destination);
  assertNotNull(this.template.message);
  assertEquals("expected 'id' and 'timestamp' headers only", 2, this.template.message.getHeaders().size());
  assertEquals("payload", this.template.message.getPayload());
  assertNotNull(this.postProcessor.getMessage());
  assertSame(this.template.message, this.postProcessor.getMessage());
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void convertAndSendPayloadWithPostProcessor() {
  this.template.convertAndSend("myChannel", "payload", this.postProcessor);
  assertSame(this.myChannel, this.template.messageChannel);
  assertNotNull(this.template.message);
  assertEquals("payload", this.template.message.getPayload());
  assertNotNull(this.postProcessor.getMessage());
  assertSame(this.postProcessor.getMessage(), this.template.message);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void convertAndSendWithPostProcessor() {
  Message<?> responseMessage = new GenericMessage<Object>("response");
  this.template.setDefaultDestination("home");
  this.template.setReceiveMessage(responseMessage);
  String response = this.template.convertSendAndReceive("request", String.class, this.postProcessor);
  assertEquals("home", this.template.destination);
  assertSame("request", this.template.requestMessage.getPayload());
  assertSame("response", response);
  assertSame(this.postProcessor.getMessage(), this.template.requestMessage);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void payloadConversionLazilyInvoked() throws JMSException {
  javax.jms.Message jmsMessage = mock(javax.jms.Message.class);
  MessageConverter messageConverter = mock(MessageConverter.class);
  given(messageConverter.fromMessage(jmsMessage)).willReturn("FooBar");
  MessagingMessageListenerAdapter listener = getSimpleInstance("simple", Message.class);
  listener.setMessageConverter(messageConverter);
  Message<?> message = listener.toMessagingMessage(jmsMessage);
  verify(messageConverter, never()).fromMessage(jmsMessage);
  assertEquals("FooBar", message.getPayload());
  verify(messageConverter, times(1)).fromMessage(jmsMessage);
}

相关文章