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() 

Source Link

Document

Create a new LinkedMultiValueMap that wraps a LinkedHashMap .

Usage

From source file:org.qcri.micromappers.config.social.CustomConnectController.java

/**
 * Process a connect form submission by commencing the process of establishing a connection to the provider on behalf of the member.
 * For OAuth1, fetches a new request token from the provider, temporarily stores it in the session, then redirects the member to the provider's site for authorization.
 * For OAuth2, redirects the user to the provider's site for authorization.
 * @param providerId the provider ID to connect to
 * @param request the request//from ww  w .  jav  a2  s.  co  m
 * @return a RedirectView to the provider's authorization page or to the connection status page if there is an error
 */
@RequestMapping(value = "/{providerId}", method = RequestMethod.POST)
public RedirectView connect(@PathVariable String providerId, NativeWebRequest request) {
    ConnectionFactory<?> connectionFactory = connectionFactoryLocator.getConnectionFactory(providerId);
    MultiValueMap<String, String> parameters = new LinkedMultiValueMap<String, String>();
    preConnect(connectionFactory, parameters, request);
    try {
        return new RedirectView(connectSupport.buildOAuthUrl(connectionFactory, request, parameters));
    } catch (Exception e) {
        sessionStrategy.setAttribute(request, PROVIDER_ERROR_ATTRIBUTE, e);
        return connectionStatusRedirect(providerId, request);
    }
}

From source file:org.sakaiproject.rubrics.logic.RubricsServiceImpl.java

private String cloneRubricToSite(String rubricId, String toSite) {
    try {/*  w w w.  ja v  a  2  s.c o  m*/
        String url = serverConfigurationService.getServerUrl() + RBCS_SERVICE_URL_PREFIX + "rubrics/clone";
        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
        headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        headers.add("Authorization",
                String.format("Bearer %s", generateJsonWebToken(RubricsConstants.RBCS_TOOL, toSite)));
        headers.add("x-copy-source", rubricId);
        headers.add("site", toSite);
        MultiValueMap<String, String> body = new LinkedMultiValueMap<String, String>();
        HttpEntity<?> requestEntity = new HttpEntity<>(body, headers);
        ResponseEntity<Rubric> rubricEntity = restTemplate.exchange(url, HttpMethod.POST, requestEntity,
                Rubric.class);
        Rubric rub = rubricEntity.getBody();
        return String.valueOf(rub.getId());
    } catch (Exception e) {
        log.error("Exception when cloning rubric {} to site {} : {}", rubricId, toSite, e.getMessage());
    }
    return null;
}

From source file:org.slc.sli.api.security.saml.SamlHelper.java

/**
 *
 * @param samlAssertion// w ww . j a v a2s  . c  o  m
 * @return
 */
public LinkedMultiValueMap<String, String> extractAttributesFromResponse(Assertion samlAssertion) {
    LinkedMultiValueMap<String, String> attributes = new LinkedMultiValueMap<String, String>();

    AttributeStatement attributeStatement = samlAssertion.getAttributeStatements().get(0);

    for (org.opensaml.saml2.core.Attribute attribute : attributeStatement.getAttributes()) {
        String samlAttributeName = attribute.getName();
        List<XMLObject> valueObjects = attribute.getAttributeValues();
        for (XMLObject valueXmlObject : valueObjects) {
            attributes.add(samlAttributeName, valueXmlObject.getDOM().getTextContent());
        }
    }
    return attributes;
}

From source file:org.springframework.boot.context.embedded.ServletContextInitializerBeans.java

ServletContextInitializerBeans(ListableBeanFactory beanFactory) {
    this.initializers = new LinkedMultiValueMap<Class<?>, ServletContextInitializer>();
    addServletContextInitializerBeans(beanFactory);
    addAdaptableBeans(beanFactory);/*from   w w  w . java  2  s .  c o  m*/
    List<ServletContextInitializer> sortedInitializers = new ArrayList<ServletContextInitializer>();
    for (Map.Entry<?, List<ServletContextInitializer>> entry : this.initializers.entrySet()) {
        AnnotationAwareOrderComparator.sort(entry.getValue());
        sortedInitializers.addAll(entry.getValue());
    }
    this.sortedList = Collections.unmodifiableList(sortedInitializers);
}

From source file:org.springframework.boot.web.servlet.ServletContextInitializerBeans.java

public ServletContextInitializerBeans(ListableBeanFactory beanFactory) {
    this.initializers = new LinkedMultiValueMap<Class<?>, ServletContextInitializer>();
    addServletContextInitializerBeans(beanFactory);
    addAdaptableBeans(beanFactory);//  ww w  .j  a  v a  2  s .  co  m
    List<ServletContextInitializer> sortedInitializers = new ArrayList<ServletContextInitializer>();
    for (Map.Entry<?, List<ServletContextInitializer>> entry : this.initializers.entrySet()) {
        AnnotationAwareOrderComparator.sort(entry.getValue());
        sortedInitializers.addAll(entry.getValue());
    }
    this.sortedList = Collections.unmodifiableList(sortedInitializers);
}

From source file:org.springframework.cloud.netflix.ribbon.apache.RibbonApacheHttpRequestTests.java

@Test
public void testNullEntity() throws Exception {
    String uri = "http://example.com";
    LinkedMultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
    headers.add("my-header", "my-value");
    headers.add(HttpEncoding.CONTENT_LENGTH, "5192");
    LinkedMultiValueMap<String, String> params = new LinkedMultiValueMap<>();
    params.add("myparam", "myparamval");
    RibbonApacheHttpRequest httpRequest = new RibbonApacheHttpRequest(new RibbonCommandContext("example", "GET",
            uri, false, headers, params, null, new ArrayList<RibbonRequestCustomizer>()));

    HttpUriRequest request = httpRequest.toRequest(RequestConfig.custom().build());

    assertThat("request is wrong type", request, is(not(instanceOf(HttpEntityEnclosingRequest.class))));
    assertThat("uri is wrong", request.getURI().toString(), startsWith(uri));
    assertThat("my-header is missing", request.getFirstHeader("my-header"), is(notNullValue()));
    assertThat("my-header is wrong", request.getFirstHeader("my-header").getValue(), is(equalTo("my-value")));
    assertThat("Content-Length is wrong", request.getFirstHeader(HttpEncoding.CONTENT_LENGTH).getValue(),
            is(equalTo("5192")));
    assertThat("myparam is missing", request.getURI().getQuery(), is(equalTo("myparam=myparamval")));

}

From source file:org.springframework.cloud.netflix.ribbon.apache.RibbonApacheHttpRequestTests.java

void testEntity(String entityValue, ByteArrayInputStream requestEntity, boolean addContentLengthHeader,
        String method) throws IOException {
    String lengthString = String.valueOf(entityValue.length());
    Long length = null;//from  w  ww  .  j  a  v  a  2 s  .c o  m
    URI uri = URI.create("http://example.com");
    LinkedMultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
    if (addContentLengthHeader) {
        headers.add("Content-Length", lengthString);
        length = (long) entityValue.length();
    }

    RibbonRequestCustomizer requestCustomizer = new RibbonRequestCustomizer<RequestBuilder>() {
        @Override
        public boolean accepts(Class builderClass) {
            return builderClass == RequestBuilder.class;
        }

        @Override
        public void customize(RequestBuilder builder) {
            builder.addHeader("from-customizer", "foo");
        }
    };
    RibbonCommandContext context = new RibbonCommandContext("example", method, uri.toString(), false, headers,
            new LinkedMultiValueMap<String, String>(), requestEntity,
            Collections.singletonList(requestCustomizer));
    context.setContentLength(length);
    RibbonApacheHttpRequest httpRequest = new RibbonApacheHttpRequest(context);

    HttpUriRequest request = httpRequest.toRequest(RequestConfig.custom().build());

    assertThat("request is wrong type", request, is(instanceOf(HttpEntityEnclosingRequest.class)));
    assertThat("uri is wrong", request.getURI().toString(), startsWith(uri.toString()));
    if (addContentLengthHeader) {
        assertThat("Content-Length is missing", request.getFirstHeader("Content-Length"), is(notNullValue()));
        assertThat("Content-Length is wrong", request.getFirstHeader("Content-Length").getValue(),
                is(equalTo(lengthString)));
    }
    assertThat("from-customizer is missing", request.getFirstHeader("from-customizer"), is(notNullValue()));
    assertThat("from-customizer is wrong", request.getFirstHeader("from-customizer").getValue(),
            is(equalTo("foo")));

    HttpEntityEnclosingRequest entityRequest = (HttpEntityEnclosingRequest) request;
    assertThat("entity is missing", entityRequest.getEntity(), is(notNullValue()));
    HttpEntity entity = entityRequest.getEntity();
    assertThat("contentLength is wrong", entity.getContentLength(), is(equalTo((long) entityValue.length())));
    assertThat("content is missing", entity.getContent(), is(notNullValue()));
    String string = StreamUtils.copyToString(entity.getContent(), Charset.forName("UTF-8"));
    assertThat("content is wrong", string, is(equalTo(entityValue)));
}

From source file:org.springframework.cloud.netflix.zuul.filters.ProxyRequestHelper.java

public MultiValueMap<String, String> buildZuulRequestQueryParams(HttpServletRequest request) {

    Map<String, List<String>> map = HTTPRequestUtils.getInstance().getQueryParams();

    MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
    if (map == null)
        return params;

    for (String key : map.keySet()) {

        for (String value : map.get(key)) {
            params.add(key, value);/*from   w w w  .j  ava 2 s.c o  m*/
        }
    }
    return params;
}

From source file:org.springframework.cloud.netflix.zuul.filters.ProxyRequestHelper.java

public MultiValueMap<String, String> buildZuulRequestHeaders(HttpServletRequest request) {

    RequestContext context = RequestContext.getCurrentContext();

    MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
    Enumeration<?> headerNames = request.getHeaderNames();
    if (headerNames != null) {
        while (headerNames.hasMoreElements()) {
            String name = (String) headerNames.nextElement();
            String value = request.getHeader(name);
            if (isIncludedHeader(name))
                headers.set(name, value);
        }//from   w  w  w.  j av  a  2  s .  c o m
    }
    Map<String, String> zuulRequestHeaders = context.getZuulRequestHeaders();

    for (String header : zuulRequestHeaders.keySet()) {
        headers.set(header, zuulRequestHeaders.get(header));
    }

    headers.set("accept-encoding", "deflate, gzip");

    return headers;
}

From source file:org.springframework.cloud.netflix.zuul.filters.route.SimpleHostRoutingFilter.java

private MultiValueMap<String, String> revertHeaders(Header[] headers) {
    MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
    for (Header header : headers) {
        String name = header.getName();
        if (!map.containsKey(name)) {
            map.put(name, new ArrayList<String>());
        }//from  w w w  .  j  ava 2 s  .c  o  m
        map.get(name).add(header.getValue());
    }
    return map;
}