Example usage for org.springframework.util CollectionUtils arrayToList

List of usage examples for org.springframework.util CollectionUtils arrayToList

Introduction

In this page you can find the example usage for org.springframework.util CollectionUtils arrayToList.

Prototype

@SuppressWarnings("rawtypes")
public static List arrayToList(@Nullable Object source) 

Source Link

Document

Convert the supplied array into a List.

Usage

From source file:org.springframework.cloud.stream.app.http.source.DefaultMixedCaseContentTypeHttpHeaderMapper.java

/**
 * Map from the integration MessageHeaders to an HttpHeaders instance.
 * Depending on which type of adapter is using this mapper, the HttpHeaders might be
 * for an HTTP request (outbound adapter) or for an HTTP response (inbound adapter).
 *///from w ww.ja  v  a 2  s  .  co m
@Override
public void fromHeaders(MessageHeaders headers, HttpHeaders target) {
    if (logger.isDebugEnabled()) {
        logger.debug(MessageFormat.format("outboundHeaderNames={0}",
                CollectionUtils.arrayToList(this.outboundHeaderNames)));
    }
    for (Entry<String, Object> entry : headers.entrySet()) {
        String name = entry.getKey();
        String lowerName = name.toLowerCase();
        if (this.shouldMapOutboundHeader(lowerName)) {
            Object value = entry.getValue();
            if (value != null) {
                if (!HTTP_REQUEST_HEADER_NAMES_LOWER.contains(lowerName)
                        && !HTTP_RESPONSE_HEADER_NAMES_LOWER.contains(lowerName)
                        && !MessageHeaders.CONTENT_TYPE.equalsIgnoreCase(name)) {
                    // prefix the user-defined header names if not already prefixed

                    name = StringUtils.startsWithIgnoreCase(name, this.userDefinedHeaderPrefix) ? name
                            : this.userDefinedHeaderPrefix + name;
                }
                if (logger.isDebugEnabled()) {
                    logger.debug(MessageFormat.format("setting headerName=[{0}], value={1}", name, value));
                }
                this.setHttpHeader(target, name, value);
            }
        }
    }
}

From source file:org.springframework.cloud.stream.app.http.source.DefaultMixedCaseContentTypeHttpHeaderMapper.java

/**
 * Map from an HttpHeaders instance to integration MessageHeaders.
 * Depending on which type of adapter is using this mapper, the HttpHeaders might be
 * from an HTTP request (inbound adapter) or from an HTTP response (outbound adapter).
 *///from w w  w.  j a v a  2  s.c  o  m
@Override
public Map<String, Object> toHeaders(HttpHeaders source) {
    if (logger.isDebugEnabled()) {
        logger.debug(MessageFormat.format("inboundHeaderNames={0}",
                CollectionUtils.arrayToList(this.inboundHeaderNames)));
    }
    Map<String, Object> target = new HashMap<String, Object>();
    Set<String> headerNames = source.keySet();
    for (String name : headerNames) {
        String lowerName = name.toLowerCase();
        if (this.shouldMapInboundHeader(lowerName)) {
            if (!HTTP_REQUEST_HEADER_NAMES_LOWER.contains(lowerName)
                    && !HTTP_RESPONSE_HEADER_NAMES_LOWER.contains(lowerName)) {
                String prefixedName = StringUtils.startsWithIgnoreCase(name, this.userDefinedHeaderPrefix)
                        ? name
                        : this.userDefinedHeaderPrefix + name;
                Object value = source.containsKey(prefixedName) ? this.getHttpHeader(source, prefixedName)
                        : this.getHttpHeader(source, name);
                if (value != null) {
                    if (logger.isDebugEnabled()) {
                        logger.debug(MessageFormat.format("setting headerName=[{0}], value={1}", name, value));
                    }
                    this.setMessageHeader(target, name, value);
                }
            } else {
                Object value = this.getHttpHeader(source, name);
                if (value != null) {
                    if (logger.isDebugEnabled()) {
                        logger.debug(MessageFormat.format("setting headerName=[{0}], value={1}", name, value));
                    }
                    if (CONTENT_TYPE.equalsIgnoreCase(name)) {
                        name = MessageHeaders.CONTENT_TYPE;
                    }
                    this.setMessageHeader(target, name, value);
                }
            }
        }
    }
    return target;
}

From source file:org.springframework.data.mongodb.core.convert.MappingMongoConverter.java

/**
 * Returns given object as {@link Collection}. Will return the {@link Collection} as is if the source is a
 * {@link Collection} already, will convert an array into a {@link Collection} or simply create a single element
 * collection for everything else.//w w  w  .  ja v  a 2  s .  c  o  m
 * 
 * @param source
 * @return
 */
private static Collection<?> asCollection(Object source) {

    if (source instanceof Collection) {
        return (Collection<?>) source;
    }

    return source.getClass().isArray() ? CollectionUtils.arrayToList(source) : Collections.singleton(source);
}

From source file:org.springframework.data.solr.core.convert.MappingSolrConverter.java

private static Collection<?> asCollection(Object source) {
    if (source instanceof Collection) {
        return (Collection<?>) source;
    }// w w  w  . ja  v a 2s . c  o m

    return source.getClass().isArray() ? CollectionUtils.arrayToList(source) : Collections.singleton(source);
}

From source file:org.springframework.integration.http.support.DefaultHttpHeaderMapper.java

/**
 * Map from the integration MessageHeaders to an HttpHeaders instance.
 * Depending on which type of adapter is using this mapper, the HttpHeaders might be
 * for an HTTP request (outbound adapter) or for an HTTP response (inbound adapter).
 *///w  w w.  j  av  a2  s.co  m
public void fromHeaders(MessageHeaders headers, HttpHeaders target) {
    if (logger.isDebugEnabled()) {
        logger.debug(MessageFormat.format("outboundHeaderNames={0}",
                CollectionUtils.arrayToList(outboundHeaderNames)));
    }
    Set<String> headerNames = headers.keySet();
    for (String name : headerNames) {
        if (this.shouldMapOutboundHeader(name)) {
            Object value = headers.get(name);
            if (value != null) {
                if (!this.containsElementIgnoreCase(HTTP_REQUEST_HEADER_NAMES, name)
                        && !this.containsElementIgnoreCase(HTTP_RESPONSE_HEADER_NAMES, name)) {
                    // prefix the user-defined header names if not already prefixed

                    name = StringUtils.startsWithIgnoreCase(name, this.userDefinedHeaderPrefix) ? name
                            : this.userDefinedHeaderPrefix + name;
                }
                if (logger.isDebugEnabled()) {
                    logger.debug(MessageFormat.format("setting headerName=[{0}], value={1}", name, value));
                }
                this.setHttpHeader(target, name, value);
            }
        }
    }
}

From source file:org.springframework.integration.http.support.DefaultHttpHeaderMapper.java

/**
 * Map from an HttpHeaders instance to integration MessageHeaders.
 * Depending on which type of adapter is using this mapper, the HttpHeaders might be
 * from an HTTP request (inbound adapter) or from an HTTP response (outbound adapter).
 *///from  w w w .ja va 2s  .  com
public Map<String, Object> toHeaders(HttpHeaders source) {
    if (logger.isDebugEnabled()) {
        logger.debug(MessageFormat.format("inboundHeaderNames={0}",
                CollectionUtils.arrayToList(inboundHeaderNames)));
    }
    Map<String, Object> target = new HashMap<String, Object>();
    Set<String> headerNames = source.keySet();
    for (String name : headerNames) {
        if (this.shouldMapInboundHeader(name)) {
            if (!ObjectUtils.containsElement(HTTP_REQUEST_HEADER_NAMES, name)
                    && !ObjectUtils.containsElement(HTTP_RESPONSE_HEADER_NAMES, name)) {
                String prefixedName = StringUtils.startsWithIgnoreCase(name, this.userDefinedHeaderPrefix)
                        ? name
                        : this.userDefinedHeaderPrefix + name;
                Object value = source.containsKey(prefixedName) ? this.getHttpHeader(source, prefixedName)
                        : this.getHttpHeader(source, name);
                if (value != null) {
                    if (logger.isDebugEnabled()) {
                        logger.debug(MessageFormat.format("setting headerName=[{0}], value={1}", name, value));
                    }
                    this.setMessageHeader(target, name, value);
                }
            } else {
                Object value = this.getHttpHeader(source, name);
                if (value != null) {
                    if (logger.isDebugEnabled()) {
                        logger.debug(MessageFormat.format("setting headerName=[{0}], value={1}", name, value));
                    }
                    this.setMessageHeader(target, name, value);
                }
            }
        }
    }
    return target;
}

From source file:org.springframework.integration.xml.selector.XmlValidatingMessageSelector.java

@SuppressWarnings("unchecked")
public boolean accept(Message<?> message) {
    SAXParseException[] validationExceptions = null;
    try {/*from   ww w .  ja  va2s.  c o  m*/
        validationExceptions = this.xmlValidator.validate(this.converter.convertToSource(message.getPayload()));
    } catch (Exception e) {
        throw new MessageHandlingException(message, e);
    }
    boolean validationSuccess = ObjectUtils.isEmpty(validationExceptions);
    if (!validationSuccess) {
        if (this.throwExceptionOnRejection) {
            throw new MessageRejectedException(message, "Message was rejected due to XML Validation errors",
                    new AggregatedXmlMessageValidationException(
                            CollectionUtils.arrayToList(validationExceptions)));
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Message was rejected due to XML Validation errors");
        }
    }
    return validationSuccess;
}