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.weibo.api.Statuses.java

/**
 * http://open.weibo.com/wiki/2/statuses/update
 * @param status/*  www  .j  a v a2s .  co m*/
 * @param visible
 * @param listId
 * @param accessToken
 * @return
 */
public Status update(String status, Visible visible, String listId, String accessToken) {
    MultiValueMap<String, Object> map = new LinkedMultiValueMap<String, Object>();
    map.add("status", status);
    if (visible != null) {
        map.add("visible", visible.getCode());
        if (visible == Visible.GROUP) {
            map.add("list_id", listId);
        }
    }
    map.add("access_token", accessToken);
    return weiboHttpClient.postForm(STATUSES_UPDATE_URL, map, Status.class);
}

From source file:com.weibo.api.Statuses.java

/**
 * http://open.weibo.com/wiki/2/statuses/upload
 * @param status/*from w  w  w  . j a v a  2s.c  o  m*/
 * @param visible
 * @param listId
 * @param pic
 * @param accessToken
 * @return
 */
public Status upload(String status, Visible visible, String listId, String pic, String accessToken) {
    MultiValueMap<String, Object> map = new LinkedMultiValueMap<String, Object>();
    map.add("status", status);
    if (visible != null) {
        map.add("visible", visible.getCode());
        if (visible == Visible.GROUP) {
            map.add("list_id", listId);
        }
    }
    map.add("pic", new ClassPathResource(pic));
    map.add("access_token", accessToken);
    return weiboHttpClient.post(STATUSES_UPLOAD_URL, map, Status.class, MediaType.MULTIPART_FORM_DATA);
}

From source file:com.weibo.api.Statuses.java

/**
 * http://open.weibo.com/wiki/2/statuses/upload_url_text
 * @deprecated TODO: need to added testcase.
 * @param status//from  www .ja  v a2  s.c o m
 * @param visible
 * @param listId
 * @param url
 * @param accessToken
 * @return
 */
public Status uploadUrlText(String status, Visible visible, String listId, String url, String accessToken) {
    MultiValueMap<String, Object> map = new LinkedMultiValueMap<String, Object>();
    map.add("status", status);
    if (visible != null) {
        map.add("visible", visible.getCode());
        if (visible == Visible.GROUP) {
            map.add("list_id", listId);
        }
    }
    map.add("url", url);
    map.add("access_token", accessToken);
    return weiboHttpClient.postForm(STATUSES_UPLOAD_URL_TEXT_URL, map, Status.class);
}

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

@Test
@OAuth2ContextConfiguration(resource = OAuth2ContextConfiguration.Implicit.class, initialize = false)
public void testUserChangesOwnPassword() throws Exception {

    MultiValueMap<String, String> parameters = new LinkedMultiValueMap<String, String>();
    parameters.set("source", "credentials");
    parameters.set("username", joe.getUserName());
    parameters.set("password", "password");
    context.getAccessTokenRequest().putAll(parameters);

    PasswordChangeRequest change = new PasswordChangeRequest();
    change.setOldPassword("password");
    change.setPassword("newpassword");

    HttpHeaders headers = new HttpHeaders();
    ResponseEntity<Void> result = client.exchange(serverRunning.getUrl(userEndpoint) + "/{id}/password",
            HttpMethod.PUT, new HttpEntity<PasswordChangeRequest>(change, headers), null, joe.getId());
    assertEquals(HttpStatus.OK, result.getStatusCode());

    // Now try logging in with the new credentials
    headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));

    String credentials = String.format("{ \"username\":\"%s\", \"password\":\"%s\" }", joe.getUserName(),
            "newpassword");

    MultiValueMap<String, String> formData = new LinkedMultiValueMap<String, String>();
    formData.add("credentials", credentials);
    result = serverRunning.postForResponse(implicitUrl(), headers, formData);

    assertNotNull(result.getHeaders().getLocation());
    assertTrue(result.getHeaders().getLocation().toString()
            .matches("https://uaa.cloudfoundry.com/redirect/vmc#access_token=.+"));
}

From source file:com.weibo.api.Statuses.java

/**
 * http://open.weibo.com/wiki/2/statuses/repost
 * @param id//from   www.j  a  v a  2 s .co  m
 * @param status
 * @param isComment
 * @param rip
 * @param accessToken
 * @return
 */
public Status repost(String id, String status, IsComment isComment, String rip, String accessToken) {
    MultiValueMap<String, Object> map = new LinkedMultiValueMap<String, Object>();
    map.add("id", id);
    if (StringUtils.isNotBlank(status)) {
        map.add("status", status);
    }
    if (isComment == null) {
        isComment = IsComment.NO;
    }
    map.add("isComment", isComment.getCode());
    if (StringUtils.isNotBlank(rip)) {
        map.add("rip", rip);
    }
    map.add("access_token", accessToken);
    return weiboHttpClient.postForm(STATUSES_REPORT_URL, map, Status.class);
}

From source file:org.openmhealth.shimmer.common.domain.RequestEntityBuilder.java

private void addToMultiValueMap(MultiValueMap<String, String> map, String key, String value) {

    checkNotNull(key);/*from  ww  w . ja v a 2s.  com*/
    checkArgument(!key.isEmpty());
    checkNotNull(value);
    checkArgument(!value.isEmpty());

    map.add(key, value);
}

From source file:com.weibo.api.OAuth2.java

/**
 * http://open.weibo.com/wiki/Oauth2/get_token_info
 * @param accessToken/*from   w ww.  j av  a 2s. com*/
 * @return
 */
public TokenInfo getTokenInfo(String accessToken) {
    MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
    map.add("access_token", accessToken);
    String result = weiboHttpClient.postForm(OAUTH2_GET_TOKEN_INFO, map, String.class);
    try {
        TokenInfo tokenInfo = weiboObjectMapper.readValue(result, TokenInfo.class);
        return tokenInfo;
    } catch (JsonParseException e) {
        log.error(ExceptionUtils.getFullStackTrace(e));
    } catch (JsonMappingException e) {
        log.error(ExceptionUtils.getFullStackTrace(e));
    } catch (IOException e) {
        log.error(ExceptionUtils.getFullStackTrace(e));
    }
    return null;
}

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

@Test
public void test_Get404Check_Success() {
    RamlRoot published = RamlVerifier.loadRamlFromFile("test-style-missing-get404.raml");
    MultiValueMap<String, HttpStatus> statusChecks = new LinkedMultiValueMap<>();
    statusChecks.add(HttpMethod.GET.name(), HttpStatus.NOT_FOUND);
    RamlVerifier verifier = new RamlVerifier(published, null, Collections.emptyList(), null, null,
            Collections.singletonList(new ResponseCodeDefinitionStyleChecker(statusChecks)));
    assertFalse("Check that raml passes rules", verifier.hasErrors());
    assertFalse("Check that implementation matches rules", verifier.hasWarnings());
}

From source file:com.artivisi.belajar.restful.ui.controller.ApplicationConfigControllerTestIT.java

@SuppressWarnings("unchecked")
@Test/* ww w . j av  a  2s. com*/
public void testUploadPakaiRestTemplate() {
    RestTemplate rest = new RestTemplate();

    String jsessionid = rest.execute(login, HttpMethod.POST, new RequestCallback() {
        @Override
        public void doWithRequest(ClientHttpRequest request) throws IOException {
            request.getBody().write(("j_username=" + username + "&j_password=" + password).getBytes());
        }
    }, new ResponseExtractor<String>() {
        @Override
        public String extractData(ClientHttpResponse response) throws IOException {
            List<String> cookies = response.getHeaders().get("Cookie");

            // assuming only one cookie with jsessionid as the only value
            if (cookies == null) {
                cookies = response.getHeaders().get("Set-Cookie");
            }

            String cookie = cookies.get(cookies.size() - 1);

            int start = cookie.indexOf('=');
            int end = cookie.indexOf(';');

            return cookie.substring(start + 1, end);
        }
    });

    MultiValueMap<String, Object> form = new LinkedMultiValueMap<String, Object>();
    form.add("foto", new FileSystemResource("src/test/resources/foto-endy.jpg"));
    form.add("Filename", "cv-endy.pdf");
    form.add("cv", new FileSystemResource("src/test/resources/resume-endy-en.pdf"));
    form.add("keterangan", "File Endy");
    Map<String, String> result = rest.postForObject(target + "/abc123/files;jsessionid=" + jsessionid, form,
            Map.class);

    assertEquals("success", result.get("cv"));
    assertEquals("success", result.get("foto"));
    assertEquals("success", result.get("keterangan"));
}

From source file:com.weibo.api.OAuth2.java

/**
 * http://open.weibo.com/wiki/OAuth2/access_token
 * @param appKey/*from   ww w  .  j ava 2  s.c  o m*/
 * @param appSecret
 * @param redirectUri
 * @param code
 * @return
 */
public AccessToken accessToken(String appKey, String appSecret, String redirectUri, String code) {
    MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
    map.add("client_id", appKey);
    map.add("client_secret", appSecret);
    map.add("grant_type", "authorization_code");
    map.add("code", code);
    map.add("redirect_uri", redirectUri);
    String result = weiboHttpClient.postForm(OAUTH2_ACCESS_TOKEN, map, String.class);
    try {
        AccessToken accessToken = weiboObjectMapper.readValue(result, AccessToken.class);
        return accessToken;
    } catch (JsonParseException e) {
        log.error(ExceptionUtils.getFullStackTrace(e));
    } catch (JsonMappingException e) {
        log.error(ExceptionUtils.getFullStackTrace(e));
    } catch (IOException e) {
        log.error(ExceptionUtils.getFullStackTrace(e));
    }
    return null;
}