Example usage for org.springframework.util MultiValueMap add

List of usage examples for org.springframework.util MultiValueMap add

Introduction

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

Prototype

void add(K key, @Nullable V value);

Source Link

Document

Add the given single value to the current list of values for the given key.

Usage

From source file:org.jruby.rack.mock.WebUtils.java

/**
 * Parse the given string with matrix variables. An example string would look
 * like this {@code "q1=a;q1=b;q2=a,b,c"}. The resulting map would contain
 * keys {@code "q1"} and {@code "q2"} with values {@code ["a","b"]} and
 * {@code ["a","b","c"]} respectively./*from  ww w.  ja v a2  s. co  m*/
 *
 * @param matrixVariables the unparsed matrix variables string
 * @return a map with matrix variable names and values, never {@code null}
 */
public static MultiValueMap<String, String> parseMatrixVariables(String matrixVariables) {
    MultiValueMap<String, String> result = new LinkedMultiValueMap<String, String>();
    if (!StringUtils.hasText(matrixVariables)) {
        return result;
    }
    StringTokenizer pairs = new StringTokenizer(matrixVariables, ";");
    while (pairs.hasMoreTokens()) {
        String pair = pairs.nextToken();
        int index = pair.indexOf('=');
        if (index != -1) {
            String name = pair.substring(0, index);
            String rawValue = pair.substring(index + 1);
            for (String value : StringUtils.commaDelimitedListToStringArray(rawValue)) {
                result.add(name, value);
            }
        } else {
            result.add(pair, "");
        }
    }
    return result;
}

From source file:test.phoenixnap.oss.plugin.naming.RamlStyleCheckerTest.java

@Test
public void test_Get404Check_Fails() {
    RamlRoot published = RamlVerifier.loadRamlFromFile("test-style-missing-get404-fails.raml");
    MultiValueMap<String, HttpStatus> statusChecks = new LinkedMultiValueMap<>();
    HttpStatus status = HttpStatus.NOT_FOUND;
    statusChecks.add(HttpMethod.GET.name(), status);
    RamlVerifier verifier = new RamlVerifier(published, null, Collections.emptyList(), null, null,
            Collections.singletonList(new ResponseCodeDefinitionStyleChecker(statusChecks)));

    assertFalse("Check that raml passes rules", verifier.hasErrors());
    assertTrue("Check that implementation matches rules", verifier.hasWarnings());
    assertEquals("Check that implementation shuld have 1 warnings", 1, verifier.getWarnings().size());
    TestHelper//from   w  w  w.j  av a 2  s. c  om
            .verifyIssuesUnordered(verifier.getWarnings(),
                    new Issue[] {
                            new Issue(IssueSeverity.WARNING, IssueLocation.CONTRACT, IssueType.STYLE,
                                    String.format(ResponseCodeDefinitionStyleChecker.DESCRIPTION, "GET",
                                            status.name(), status.value()),
                                    "GET /base/endpointThatWillBoom") });
}

From source file:de.tudarmstadt.ukp.clarin.webanno.crowdflower.CrowdJob.java

public MultiValueMap<String, String> getIncludedCountriesMap() {
    MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
    for (String country : getIncludedCountries()) {
        map.add(jobKey + "[" + includedCountriesKey + "][]", country);
    }//from   w  w  w  . j a  va  2 s .  c om
    return map;
}

From source file:de.tudarmstadt.ukp.clarin.webanno.crowdflower.CrowdJob.java

public MultiValueMap<String, String> getExcludedCountriesMap() {
    MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
    for (String country : getExcludedCountries()) {
        map.add(jobKey + "[" + excludedCountriesKey + "][]", country);
    }//from w  w  w.  jav a  2 s.  c  om
    return map;
}

From source file:org.apigw.authserver.AuthorizationCodeProviderIntegrationtest.java

@Test
public void testUserDeniesConfirmation() throws Exception {
    log.debug("testUserDeniesConfirmation");
    String cookie = helper.loginAndGetConfirmationPage(CLIENT_ID, REDIRECT_URL, SCOPE);

    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
    headers.set("Cookie", cookie);

    MultiValueMap<String, String> formData = new LinkedMultiValueMap<String, String>();
    formData.add("user_oauth_approval", "false");
    ResponseEntity<Void> result = serverRunning.postForStatus("/apigw-auth-server-web/oauth/authorize", headers,
            formData);/* www  .jav  a2  s  .  co  m*/
    assertEquals(HttpStatus.FOUND, result.getStatusCode());

    String location = result.getHeaders().getFirst("Location");
    assertTrue(location.startsWith(REDIRECT_URL));
    assertTrue(location.substring(location.indexOf('?')).contains("error=access_denied"));
    assertTrue(location.contains("state=gzzFqB!!!"));
}

From source file:org.cloudfoundry.identity.uaa.integration.ClientAdminEndpointsIntegrationTests.java

private OAuth2AccessToken getClientCredentialsAccessToken(String scope) throws Exception {

    String clientId = testAccounts.getAdminClientId();
    String clientSecret = testAccounts.getAdminClientSecret();

    MultiValueMap<String, String> formData = new LinkedMultiValueMap<String, String>();
    formData.add("grant_type", "client_credentials");
    formData.add("client_id", clientId);
    formData.add("scope", scope);
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
    headers.set("Authorization",
            "Basic " + new String(Base64.encode(String.format("%s:%s", clientId, clientSecret).getBytes())));

    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> response = serverRunning.postForMap("/oauth/token", formData, headers);
    assertEquals(HttpStatus.OK, response.getStatusCode());

    @SuppressWarnings("unchecked")
    OAuth2AccessToken accessToken = DefaultOAuth2AccessToken.valueOf(response.getBody());
    return accessToken;

}

From source file:io.kahu.hawaii.util.logger.RequestLogBuilderTest.java

@Test
public void testFormParams() throws Exception {
    MultiValueMap<String, String> m = new LinkedMultiValueMap<String, String>();
    m.add("foo", "bar");
    m.add("foo", "baz");
    m.add("fred", "derf");
    RequestLogBuilder builder = new RequestLogBuilder(logManager, "the-type");
    builder = builder.formParams(m);//from  w  ww  .  ja v a2s.c o m
    builder.logIncoming();

    JSONObject params = new JSONObject();
    JSONArray a = new JSONArray();
    a.put("bar");
    a.put("baz");
    params.put("foo", a);
    a = new JSONArray();
    a.put("derf");
    params.put("fred", a);

    verify(logManager).logIncomingCallStart(eq("the-type"), isNull(String.class), eq(params));
}

From source file:com.taxamo.example.ec.ApplicationController.java

/**
 * This method initializes Express Checkout token with PayPal and then redirects to Taxamo checkout form.
 *
 * Please note that only Express Checkout token is provided to Taxamo - and Taxamo will use
 * provided PayPal credentials to get order details from it and render the checkout form.
 *
 *
 * @param model/*from  w  w  w . j  a  va 2 s.  c  o m*/
 * @return
 */
@RequestMapping("/express-checkout")
public String expressCheckout(Model model) {

    RestTemplate template = new RestTemplate();

    MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
    map.add("USER", ppUser);
    map.add("PWD", ppPass);
    map.add("SIGNATURE", ppSign);
    map.add("VERSION", "117");
    map.add("METHOD", "SetExpressCheckout");
    map.add("returnUrl", properties.getProperty(PropertiesConstants.STORE)
            + properties.getProperty(PropertiesConstants.CONFIRM_LINK));
    map.add("cancelUrl", properties.getProperty(PropertiesConstants.STORE)
            + properties.getProperty(PropertiesConstants.CANCEL_LINK));

    //shopping item(s)
    map.add("PAYMENTREQUEST_0_AMT", "20.00"); // total amount
    map.add("PAYMENTREQUEST_0_PAYMENTACTION", "Sale");
    map.add("PAYMENTREQUEST_0_CURRENCYCODE", "EUR");

    map.add("L_PAYMENTREQUEST_0_NAME0", "ProdName");
    map.add("L_PAYMENTREQUEST_0_DESC0", "ProdName desc");
    map.add("L_PAYMENTREQUEST_0_AMT0", "20.00");
    map.add("L_PAYMENTREQUEST_0_QTY0", "1");
    map.add("L_PAYMENTREQUEST_0_ITEMCATEGORY0", "Digital");

    List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
    messageConverters.add(new FormHttpMessageConverter());
    messageConverters.add(new StringHttpMessageConverter());
    template.setMessageConverters(messageConverters);

    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);

    HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(map,
            requestHeaders);
    ResponseEntity<String> res = template.exchange(
            URI.create(properties.get(PropertiesConstants.PAYPAL_NVP).toString()), HttpMethod.POST, request,
            String.class);

    Map<String, List<String>> params = parseQueryParams(res.getBody());

    String ack = params.get("ACK").get(0);
    if (!ack.equals("Success")) {
        model.addAttribute("error", params.get("L_LONGMESSAGE0").get(0));
        return "error";
    } else {
        String token = params.get("TOKEN").get(0);
        return "redirect:" + properties.get(PropertiesConstants.TAXAMO) + "/checkout/index.html?" + "token="
                + token + "&public_token=" + publicToken + "&cancel_url="
                + new String(
                        Base64.encodeBase64((properties.getProperty(PropertiesConstants.STORE)
                                + properties.getProperty(PropertiesConstants.CANCEL_LINK)).getBytes()))
                + "&return_url="
                + new String(Base64.encodeBase64((properties.getProperty(PropertiesConstants.STORE)
                        + properties.getProperty(PropertiesConstants.CONFIRM_LINK)).getBytes()))
                + "#/paypal_express_checkout";
    }
}

From source file:org.cloudfoundry.identity.uaa.login.feature.ImplicitGrantIT.java

private MultiValueMap<String, String> parseFragmentParams(UriComponents locationComponents) {
    MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
    String[] tuples = locationComponents.getFragment().split("&");
    for (String tuple : tuples) {
        String[] parts = tuple.split("=");
        params.add(parts[0], parts[1]);
    }/*  w  w  w .ja v  a2s.  c o m*/
    return params;
}