Example usage for org.springframework.messaging.simp.stomp StompHeaders getContentType

List of usage examples for org.springframework.messaging.simp.stomp StompHeaders getContentType

Introduction

In this page you can find the example usage for org.springframework.messaging.simp.stomp StompHeaders getContentType.

Prototype

@Nullable
public MimeType getContentType() 

Source Link

Document

Return the content-type header value.

Usage

From source file:org.springframework.integration.stomp.support.StompHeaderMapper.java

private void setStompHeader(StompHeaders target, String name, Object value) {
    if (StompHeaders.CONTENT_LENGTH.equals(name)) {
        if (value instanceof Number) {
            target.setContentLength(((Number) value).longValue());
        } else if (value instanceof String) {
            target.setContentLength(Long.parseLong((String) value));
        } else {// w  ww.j a  v a  2  s.  c om
            Class<?> clazz = (value != null) ? value.getClass() : null;
            throw new IllegalArgumentException(
                    "Expected Number or String value for 'content-length' header value, but received: "
                            + clazz);
        }
    } else if (StompHeaders.CONTENT_TYPE.equals(name) || MessageHeaders.CONTENT_TYPE.equals(name)) {
        MimeType contentType = target.getContentType();
        if (contentType == null || StompHeaders.CONTENT_TYPE.equals(name)) {
            if (value instanceof MediaType) {
                target.setContentType((MediaType) value);
            } else if (value instanceof String) {
                target.setContentType(MediaType.parseMediaType((String) value));
            } else {
                Class<?> clazz = (value != null) ? value.getClass() : null;
                throw new IllegalArgumentException(
                        "Expected MediaType or String value for 'content-type' header value, but received: "
                                + clazz);
            }
        }
    } else if (StompHeaders.DESTINATION.equals(name) || IntegrationStompHeaders.DESTINATION.equals(name)) {
        if (value instanceof String) {
            target.setDestination((String) value);
        } else {
            Class<?> clazz = (value != null) ? value.getClass() : null;
            throw new IllegalArgumentException(
                    "Expected String value for 'destination' header value, but received: " + clazz);
        }
    } else if (StompHeaders.RECEIPT.equals(name) || IntegrationStompHeaders.RECEIPT.equals(name)) {
        if (value instanceof String) {
            target.setReceipt((String) value);
        } else {
            Class<?> clazz = (value != null) ? value.getClass() : null;
            throw new IllegalArgumentException(
                    "Expected String value for 'receipt' header value, but received: " + clazz);
        }
    } else {
        if (value instanceof String) {
            target.set(name, (String) value);
        } else {
            Class<?> clazz = (value != null) ? value.getClass() : null;
            throw new IllegalArgumentException(
                    "Expected String value for any generic STOMP header value, but received: " + clazz);
        }
    }
}

From source file:org.springframework.integration.stomp.support.StompHeaderMapper.java

@Override
public Map<String, Object> toHeaders(StompHeaders source) {
    Map<String, Object> target = new HashMap<String, Object>();
    for (String name : source.keySet()) {
        if (shouldMapHeader(name, this.inboundHeaderNames)) {
            if (StompHeaders.CONTENT_TYPE.equals(name)) {
                target.put(MessageHeaders.CONTENT_TYPE, source.getContentType());
            } else {
                String key = name;
                if (IntegrationStompHeaders.HEADERS.contains(name)) {
                    key = IntegrationStompHeaders.PREFIX + name;
                }//  w  ww  .ja va2 s.co m
                target.put(key, source.getFirst(name));
            }
        }
    }
    return target;
}