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:com.miserablemind.api.consumer.tradeking.api.impl.WatchlistTemplate.java

@Override
public String[] addSymbolsToList(String watchlistName, String[] tickers) {
    URI url = this.buildUri(String.format(URL_WATCHLIST_LIST_EDIT, watchlistName));
    MultiValueMap<String, Object> requestObject = new LinkedMultiValueMap<>();
    requestObject.add("symbols", this.buildCommaSeparatedParameterValue(tickers));

    ResponseEntity<TKAllWatchListsResponse> response = this.getRestTemplate().postForEntity(url, requestObject,
            TKAllWatchListsResponse.class);

    if (response.getBody().getError() != null)
        throw new ApiException(TradeKingServiceProvider.PROVIDER_ID, response.getBody().getError());

    return response.getBody().getWatchLists();
}

From source file:org.trustedanalytics.h2oscoringengine.publisher.restapi.validation.HostValidationRuleTest.java

@Test
public void validate_multipleHostKeysInData_exceptionThrown() {
    //given//from   w  ww . ja v  a  2  s. co m
    MultiValueMap<String, String> requestWithMultipleHostKeys = new LinkedMultiValueMap<>();
    requestWithMultipleHostKeys.add(HostValidationRule.HOST_KEY, "http://example.com");
    requestWithMultipleHostKeys.add(HostValidationRule.HOST_KEY, "http://example.com");
    HostValidationRule rule = new HostValidationRule(new FormDataValidator());

    //then
    thrown.expect(ValidationException.class);

    //when
    rule.validate(requestWithMultipleHostKeys);
}

From source file:org.trustedanalytics.h2oscoringengine.publisher.steps.AppBitsUploadingStepTest.java

private HttpEntity<MultiValueMap<String, Object>> createTestAppBitsRequest() throws IOException {
    HttpEntity<String> resourcesPart = new HttpEntity<String>("[]");
    HttpEntity<ByteArrayResource> dataPart = new HttpEntity<>(
            new ByteArrayResource(Files.readAllBytes(testAppBitsPath)), HttpCommunication.zipHeaders());

    MultiValueMap<String, Object> multiPartRequest = new LinkedMultiValueMap<>();
    multiPartRequest.add("resources", resourcesPart);
    multiPartRequest.add("application", dataPart);

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.MULTIPART_FORM_DATA);

    return new HttpEntity<>(multiPartRequest, headers);
}

From source file:com.miserablemind.api.consumer.tradeking.api.impl.WatchlistTemplate.java

@Override
public String[] addList(String watchlistName, String[] tickers) {

    Assert.notNull(tickers);//from   w w  w . j av a  2  s . c o m

    URI url = this.buildUri(URL_WATCHLIST_LIST);
    MultiValueMap<String, Object> requestObject = new LinkedMultiValueMap<>();
    requestObject.add("id", watchlistName);
    requestObject.add("symbols", this.buildCommaSeparatedParameterValue(tickers));

    ResponseEntity<TKAllWatchListsResponse> response = this.getRestTemplate().postForEntity(url, requestObject,
            TKAllWatchListsResponse.class);

    if (response.getBody().getError() != null)
        throw new ApiException(TradeKingServiceProvider.PROVIDER_ID, response.getBody().getError());

    return response.getBody().getWatchLists();
}

From source file:com.fns.grivet.service.NamedQueryServiceSelectTest.java

@Test
public void testGetQueryNotFound() throws IOException {
    Assertions.assertThrows(IllegalArgumentException.class, () -> {
        MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
        params.add("createdTime", LocalDateTime.now().plusDays(1).toString());
        namedQueryService.get("getAttributesCreatedBefore", params);
    });//from   w w  w .jav  a  2  s  .  com
}

From source file:org.mitre.openid.connect.client.DefaultUserInfoFetcher.java

@Override
public UserInfo loadUserInfo(OIDCAuthenticationToken token) {

    ServerConfiguration serverConfiguration = token.getServerConfiguration();

    if (serverConfiguration == null) {
        logger.warn("No server configuration found.");
        return null;
    }/* ww  w  .  ja  v  a  2 s. c  o m*/

    if (Strings.isNullOrEmpty(serverConfiguration.getUserInfoUri())) {
        logger.warn("No userinfo endpoint, not fetching.");
        return null;
    }

    // if we got this far, try to actually get the userinfo
    HttpClient httpClient = new SystemDefaultHttpClient();

    HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(httpClient);

    RestTemplate restTemplate = new RestTemplate(factory);

    MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
    form.add("access_token", token.getAccessTokenValue());

    try {
        String userInfoString = restTemplate.postForObject(serverConfiguration.getUserInfoUri(), form,
                String.class);

        JsonObject userInfoJson = new JsonParser().parse(userInfoString).getAsJsonObject();

        UserInfo userInfo = DefaultUserInfo.fromJson(userInfoJson);

        return userInfo;
    } catch (Exception e) {
        logger.warn("Error fetching userinfo", e);
        return null;
    }

}

From source file:com.fns.grivet.service.NamedQueryServiceSelectTest.java

@Test
public void testCreateThenGetHappyPath() throws IOException {
    Resource r = resolver.getResource("classpath:TestSelectQuery.json");
    String json = IOUtils.toString(r.getInputStream(), Charset.defaultCharset());
    NamedQuery namedQuery = objectMapper.readValue(json, NamedQuery.class);
    namedQueryService.create(namedQuery);

    MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
    params.add("createdTime", LocalDateTime.now().plusDays(1).toString());
    String result = namedQueryService.get("getAttributesCreatedBefore", params);
    String[] expected = { "bigint", "varchar", "decimal", "datetime", "int", "text", "json", "boolean" };
    List<String> actual = JsonPath.given(result).getList("name");
    Assertions.assertTrue(actual.containsAll(Arrays.asList(expected)));
}

From source file:com.fns.grivet.service.NamedQueryServiceSelectTest.java

@Test
public void testCreateThenGetIncorrectParamsSupplied() throws IOException {
    Assertions.assertThrows(IllegalArgumentException.class, () -> {
        Resource r = resolver.getResource("classpath:TestSelectQuery.json");
        String json = IOUtils.toString(r.getInputStream(), Charset.defaultCharset());
        NamedQuery namedQuery = objectMapper.readValue(json, NamedQuery.class);
        namedQueryService.create(namedQuery);

        MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
        params.add("timedCreated", LocalDateTime.now().plusDays(1).toString());
        namedQueryService.get("getAttributesCreatedBefore", params);
    });//from ww  w  .  ja v  a2 s .c o m
}

From source file:org.messic.android.controllers.LoginController.java

public void login(final Activity context, final boolean remember, final String username, final String password,
        final ProgressDialog pd) throws Exception {
    Network.nukeNetwork();// w w w. j  av  a 2 s.  co  m

    final String baseURL = Configuration.getBaseUrl() + "/messiclogin";
    MultiValueMap<String, Object> formData = new LinkedMultiValueMap<String, Object>();
    formData.add("j_username", username);
    formData.add("j_password", password);
    try {
        RestJSONClient.post(baseURL, formData, MDMLogin.class, new RestJSONClient.RestListener<MDMLogin>() {
            public void response(MDMLogin response) {
                MessicPreferences mp = new MessicPreferences(context);
                mp.setRemember(remember, username, password);
                Configuration.setToken(response.getMessic_token());

                pd.dismiss();
                Intent ssa = new Intent(context, BaseActivity.class);
                context.startActivity(ssa);
            }

            public void fail(Exception e) {
                Log.e("Login", e.getMessage(), e);
                context.runOnUiThread(new Runnable() {
                    public void run() {
                        pd.dismiss();
                        Toast.makeText(context, "Error", Toast.LENGTH_LONG).show();
                    }
                });

            }
        });
    } catch (Exception e) {
        pd.dismiss();
        Log.e("login", e.getMessage(), e);
        throw e;
    }
}

From source file:org.cloudfoundry.identity.uaa.login.test.TestClient.java

public String getOAuthAccessToken(String username, String password, String grantType, String scope) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Authorization", getBasicAuthHeaderValue(username, password));

    MultiValueMap<String, String> postParameters = new LinkedMultiValueMap<String, String>();
    postParameters.add("grant_type", grantType);
    postParameters.add("client_id", username);
    postParameters.add("scope", scope);

    HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>(
            postParameters, headers);//from   w ww . j a v  a  2 s .  co m

    ResponseEntity<Map> exchange = restTemplate.exchange(baseUrl + "/oauth/token", HttpMethod.POST,
            requestEntity, Map.class);

    return exchange.getBody().get("access_token").toString();
}