Example usage for org.springframework.messaging.support MessageBuilder build

List of usage examples for org.springframework.messaging.support MessageBuilder build

Introduction

In this page you can find the example usage for org.springframework.messaging.support MessageBuilder build.

Prototype

@SuppressWarnings("unchecked")
    public Message<T> build() 

Source Link

Usage

From source file:io.pivotal.poc.dispatcher.MessageDispatcher.java

private String sendMessage(String topic, Object body, HttpHeaders requestHeaders) {
    MessageChannel channel = resolver.resolveDestination(topic + ".input");
    MessageBuilder<?> builder = MessageBuilder.withPayload(body);
    builder.setHeader(MessageHeaders.CONTENT_TYPE, requestHeaders.getContentType());
    for (Map.Entry<String, List<String>> entry : requestHeaders.entrySet()) {
        String headerName = entry.getKey();
        if (requestHeadersToMap.contains(headerName)) {
            builder.setHeaderIfAbsent(headerName,
                    StringUtils.collectionToCommaDelimitedString(entry.getValue()));
        }//from  ww  w .j  av  a 2  s.  c om
    }
    Message<?> message = builder.build();
    channel.send(message);
    return message.getHeaders().getId().toString();
}

From source file:org.springframework.messaging.converter.AbstractMessageConverter.java

@Override
@Nullable//from   w w w.ja v  a  2s  .  c o  m
public final Message<?> toMessage(Object payload, @Nullable MessageHeaders headers,
        @Nullable Object conversionHint) {
    if (!canConvertTo(payload, headers)) {
        return null;
    }

    Object payloadToUse = convertToInternal(payload, headers, conversionHint);
    if (payloadToUse == null) {
        return null;
    }

    MimeType mimeType = getDefaultContentType(payloadToUse);
    if (headers != null) {
        MessageHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(headers,
                MessageHeaderAccessor.class);
        if (accessor != null && accessor.isMutable()) {
            if (mimeType != null) {
                accessor.setHeaderIfAbsent(MessageHeaders.CONTENT_TYPE, mimeType);
            }
            return MessageBuilder.createMessage(payloadToUse, accessor.getMessageHeaders());
        }
    }

    MessageBuilder<?> builder = MessageBuilder.withPayload(payloadToUse);
    if (headers != null) {
        builder.copyHeaders(headers);
    }
    if (mimeType != null) {
        builder.setHeaderIfAbsent(MessageHeaders.CONTENT_TYPE, mimeType);
    }
    return builder.build();
}

From source file:org.springframework.messaging.support.converter.AbstractMessageConverter.java

@Override
public final Message<?> toMessage(Object payload, MessageHeaders headers) {
    if (!canConvertTo(payload, headers)) {
        return null;
    }/*from   www  .ja  va2 s  . c  om*/
    payload = convertToInternal(payload, headers);
    MessageBuilder<?> builder = MessageBuilder.withPayload(payload);
    if (headers != null) {
        builder.copyHeaders(headers);
    }
    MimeType mimeType = getDefaultContentType(payload);
    if (mimeType != null) {
        builder.setHeaderIfAbsent(MessageHeaders.CONTENT_TYPE, mimeType);
    }
    return builder.build();
}