Example usage for org.springframework.util LinkedMultiValueMap LinkedMultiValueMap

List of usage examples for org.springframework.util LinkedMultiValueMap LinkedMultiValueMap

Introduction

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

Prototype

public LinkedMultiValueMap(Map<K, List<V>> otherMap) 

Source Link

Document

Copy constructor: Create a new LinkedMultiValueMap with the same mappings as the specified Map.

Usage

From source file:io.neba.core.mvc.MultipartSlingHttpServletRequest.java

@Override
public MultiValueMap<String, MultipartFile> getMultiFileMap() {
    RequestParameterMap requestParameterMap = getRequestParameterMap();
    MultiValueMap<String, MultipartFile> fileMap = new LinkedMultiValueMap<String, MultipartFile>(
            requestParameterMap.size());
    for (Entry<String, RequestParameter[]> entry : requestParameterMap.entrySet()) {
        RequestParameter[] params = entry.getValue();
        if (params != null && params.length > 0) {
            List<MultipartFile> files = new ArrayList<MultipartFile>(params.length);
            for (RequestParameter parameter : params) {
                if (!parameter.isFormField()) {
                    files.add(new SlingMultipartFile(entry.getKey(), parameter));
                }//w  ww .j a va2 s  .c om
            }
            if (!files.isEmpty()) {
                fileMap.put(entry.getKey(), files);
            }
        }
    }
    return fileMap;
}

From source file:jails.http.converter.FormHttpMessageConverter.java

public MultiValueMap<String, String> read(Class<? extends MultiValueMap<String, ?>> clazz,
        HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {

    MediaType contentType = inputMessage.getHeaders().getContentType();
    Charset charset = contentType.getCharSet() != null ? contentType.getCharSet() : this.charset;
    String body = FileCopyUtils.copyToString(new InputStreamReader(inputMessage.getBody(), charset));

    String[] pairs = StringUtils.tokenizeToStringArray(body, "&");

    MultiValueMap<String, String> result = new LinkedMultiValueMap<String, String>(pairs.length);

    for (String pair : pairs) {
        int idx = pair.indexOf('=');
        if (idx == -1) {
            result.add(URLDecoder.decode(pair, charset.name()), null);
        } else {//w w  w  .ja  v  a 2 s  .co m
            String name = URLDecoder.decode(pair.substring(0, idx), charset.name());
            String value = URLDecoder.decode(pair.substring(idx + 1), charset.name());
            result.add(name, value);
        }
    }
    return result;
}

From source file:org.zalando.boot.etcd.EtcdClient.java

/**
 * Sets the value of the node with the given key in etcd. Any previously
 * existing key-value pair is returned as prevNode in the etcd response.
 * /*from w w w  . j a  v a  2  s . c  o m*/
 * @param key
 *            the node's key
 * @param value
 *            the node's value
 * @return the response from etcd with the node
 * @throws EtcdException
 *             in case etcd returned an error
 */
public EtcdResponse put(final String key, final String value) throws EtcdException {
    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(KEYSPACE);
    builder.pathSegment(key);

    MultiValueMap<String, String> payload = new LinkedMultiValueMap<>(1);
    payload.set("value", value);

    return execute(builder, HttpMethod.PUT, payload, EtcdResponse.class);
}

From source file:com.github.hateoas.forms.spring.xhtml.XhtmlResourceMessageConverter.java

private Object readRequestBody(Class<?> clazz, InputStream inputStream, Charset charset) throws IOException {

    String body = StreamUtils.copyToString(inputStream, charset);

    String[] pairs = StringUtils.tokenizeToStringArray(body, "&");

    MultiValueMap<String, String> formValues = new LinkedMultiValueMap<String, String>(pairs.length);

    for (String pair : pairs) {
        int idx = pair.indexOf('=');
        if (idx == -1) {
            formValues.add(URLDecoder.decode(pair, charset.name()), null);
        } else {/*from   w  w  w . j  a va  2 s.  c  o m*/
            String name = URLDecoder.decode(pair.substring(0, idx), charset.name());
            String value = URLDecoder.decode(pair.substring(idx + 1), charset.name());
            formValues.add(name, value);
        }
    }

    return recursivelyCreateObject(clazz, formValues, "");
}

From source file:com.vedri.mtp.frontend.support.stomp.DefaultSubscriptionRegistry.java

private MultiValueMap<String, String> filterSubscriptions(MultiValueMap<String, String> allMatches,
        Message<?> message) {/* ww  w  . j a  v a2s . c  om*/

    if (!this.selectorHeaderInUse) {
        return allMatches;
    }
    EvaluationContext context = null;
    MultiValueMap<String, String> result = new LinkedMultiValueMap<String, String>(allMatches.size());
    for (String sessionId : allMatches.keySet()) {
        for (String subId : allMatches.get(sessionId)) {
            SessionSubscriptionInfo info = this.subscriptionRegistry.getSubscriptions(sessionId);
            if (info == null) {
                continue;
            }
            Subscription sub = info.getSubscription(subId);
            if (sub == null) {
                continue;
            }
            Expression expression = sub.getSelectorExpression();
            if (expression == null) {
                result.add(sessionId, subId);
                continue;
            }
            if (context == null) {
                context = new StandardEvaluationContext(message);
                context.getPropertyAccessors().add(new SimpMessageHeaderPropertyAccessor());
            }
            try {
                if (expression.getValue(context, boolean.class)) {
                    result.add(sessionId, subId);
                }
            } catch (SpelEvaluationException ex) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Failed to evaluate selector: " + ex.getMessage());
                }
            } catch (Throwable ex) {
                logger.debug("Failed to evaluate selector", ex);
            }
        }
    }
    return result;
}

From source file:org.zalando.boot.etcd.EtcdClient.java

/**
 * Sets the value of the node with the given key in etcd.
 * /*from   www.  ja  v a2 s .com*/
 * @param key
 *            the node's key
 * @param value
 *            the node's value
 * @param ttl
 *            the node's time-to-live or <code>-1</code> to unset existing
 *            ttl
 * @return the response from etcd with the node
 * @throws EtcdException
 *             in case etcd returned an error
 */
public EtcdResponse put(String key, String value, int ttl) throws EtcdException {
    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(KEYSPACE);
    builder.pathSegment(key);
    builder.queryParam("ttl", ttl == -1 ? "" : ttl);

    MultiValueMap<String, String> payload = new LinkedMultiValueMap<>(1);
    payload.set("value", value);

    return execute(builder, HttpMethod.PUT, payload, EtcdResponse.class);
}

From source file:com.httpMessageConvert.FormHttpMessageConverter.java

public Object read(Class<? extends Object> clazz, HttpInputMessage inputMessage)
        throws IOException, HttpMessageNotReadableException {

    MediaType contentType = inputMessage.getHeaders().getContentType();
    Charset charset = contentType.getCharSet() != null ? contentType.getCharSet() : this.charset;
    String body = StreamUtils.copyToString(inputMessage.getBody(), charset);

    String[] pairs = StringUtils.tokenizeToStringArray(body, "&");

    MultiValueMap<String, String> result = new LinkedMultiValueMap<String, String>(pairs.length);

    for (String pair : pairs) {
        int idx = pair.indexOf('=');
        if (idx == -1) {
            result.add(URLDecoder.decode(pair, charset.name()), null);
        } else {//from  w  w w.ja  v  a2 s .c om
            String name = URLDecoder.decode(pair.substring(0, idx), charset.name());
            String value = URLDecoder.decode(pair.substring(idx + 1), charset.name());
            result.add(name, value);
        }
    }

    Map<String, String> map = result.toSingleValueMap();
    String json = JSONObject.toJSONString(map);
    JavaType javaType = getJavaType(clazz, null);
    ObjectMapper objectMapper = new ObjectMapper();
    return objectMapper.readValue(json, javaType);
}

From source file:org.zalando.boot.etcd.EtcdClient.java

/**
 * Creates a new node with the given key-value pair under the node with the
 * given key./*  w ww .j a  va  2s  .co m*/
 * 
 * @param key
 *            the directory node's key
 * @param value
 *            the value of the created node
 * @return the response from etcd with the node
 * @throws EtcdException
 *             in case etcd returned an error
 */
public EtcdResponse create(final String key, final String value) throws EtcdException {
    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(KEYSPACE);
    builder.pathSegment(key);

    MultiValueMap<String, String> payload = new LinkedMultiValueMap<>(1);
    payload.set("value", value);

    return execute(builder, HttpMethod.POST, payload, EtcdResponse.class);
}

From source file:org.zalando.boot.etcd.EtcdClient.java

/**
 * Atomically creates or updates a key-value pair in etcd.
 * /*from  w  w  w .  j  ava2  s  .  co  m*/
 * @param key
 *            the key
 * @param value
 *            the value
 * @param prevExist
 *            <code>true</code> if the existing node should be updated,
 *            <code>false</code> of the node should be created
 * @return the response from etcd with the node
 * @throws EtcdException
 *             in case etcd returned an error
 */
public EtcdResponse compareAndSwap(final String key, final String value, boolean prevExist)
        throws EtcdException {
    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(KEYSPACE);
    builder.pathSegment(key);
    builder.queryParam("prevExist", prevExist);

    MultiValueMap<String, String> payload = new LinkedMultiValueMap<>(1);
    payload.set("value", value);

    return execute(builder, HttpMethod.PUT, payload, EtcdResponse.class);
}

From source file:org.zalando.boot.etcd.EtcdClient.java

/**
 * Atomically creates or updates a key-value pair in etcd.
 * /*from  w ww .ja  v  a  2 s .c o  m*/
 * @param key
 *            the key
 * @param value
 *            the value
 * @param ttl
 *            the time-to-live
 * @param prevExist
 *            <code>true</code> if the existing node should be updated,
 *            <code>false</code> of the node should be created
 * @return the response from etcd with the node
 * @throws EtcdException
 *             in case etcd returned an error
 */
public EtcdResponse compareAndSwap(final String key, final String value, int ttl, boolean prevExist)
        throws EtcdException {
    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(KEYSPACE);
    builder.pathSegment(key);
    builder.queryParam("ttl", ttl == -1 ? "" : ttl);
    builder.queryParam("prevExist", prevExist);

    MultiValueMap<String, String> payload = new LinkedMultiValueMap<>(1);
    payload.set("value", value);

    return execute(builder, HttpMethod.PUT, payload, EtcdResponse.class);
}