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.apress.prospringintegration.web.MultipartHttpClient.java

public static void main(String[] args) {
    RestTemplate template = new RestTemplate();
    String uri = "http://localhost:8080/http-adapter-1.0.0/inboundMultipartAdapter.html";
    Resource picture = new ClassPathResource("com/apress/prospringintegration/web/test.png");
    MultiValueMap map = new LinkedMultiValueMap();
    map.add("name", "John Smith");
    map.add("picture", picture);
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(new MediaType("multipart", "form-data"));
    HttpEntity request = new HttpEntity(map, headers);
    ResponseEntity<?> httpResponse = template.exchange(uri, HttpMethod.POST, request, null);
    System.out.println("Status: " + httpResponse.getStatusCode().name());
}

From source file:com.iflytek.rest.demo.UserServiceTest.java

public static void requestRestApi(String access_token) {
    RestTemplate restTemplate = new RestTemplate();
    MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
    form.add("method", "user.get");
    form.add("version", "1.0.0");
    form.add("locale", "zh_CN");
    form.add("format", "json");
    form.add("appkey", "Hb0YhmOo"); //-Dexcludes.appkey=Hb0YhmOo
    form.add("access_token", access_token);

    form.add("id", "10001");
    String result = restTemplate.postForObject("http://localhost:8090/api", form, String.class);
    System.out.println(result);//from   w w w.  jav  a  2 s  . com
}

From source file:com.iflytek.rest.demo.UserServiceTest.java

public static String requestAccessToken() {
    RestTemplate restTemplate = new RestTemplate();
    MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
    form.add("client_id", "Hb0YhmOo");
    form.add("client_secret", "R7odNVS0KPtgXJ1TKQbHAxFP6EHdSW5d");
    form.add("grant_type", "client_credentials"); //?password & client_credentials

    //grant_typeclient_credentials????username & password?
    form.add("username", "admin_test_333");
    form.add("password", "passw0rd");

    String result = restTemplate.postForObject(OAUTH_SERVER_URL, form, String.class);
    System.out.println(result);/*from w  w  w.  jav a 2  s . com*/
    String access_token = JSON.parseObject(result).getString("access_token");
    return access_token;
}

From source file:cz.cvut.jirutjak.fastimport.droid.oauth2.AccessTokenUtils.java

public static MultiValueMap<String, String> createAccessTokenRequestForm(String authCode,
        OAuth2ResourceDetails resource) {
    MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
    form.add("code", authCode);
    form.add("client_id", resource.getClientId());
    form.add("client_secret", resource.getClientSecret());
    form.add("redirect_uri", resource.getRedirectUri());
    form.add("grant_type", GRANT_TYPE);

    return form;/*from w w w. jav a2  s.c  o m*/
}

From source file:cn.org.once.cstack.utils.RestUtils.java

@SuppressWarnings("rawtypes")
public static String sendPostCommand(String url, String volume) {

    RestTemplate restTemplate = new RestTemplate();
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    headers.add("Accept", "text/plain");
    MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
    params.add("Binds", volume);
    @SuppressWarnings("unchecked")
    HttpEntity request = new HttpEntity(params, headers);
    ResponseEntity<String> response = restTemplate.postForEntity(url, request, String.class);
    return response.toString();
}

From source file:org.craftercms.commons.rest.RestClientUtils.java

/**
 * Adds a param value to a params map. If value is null, nothing is done.
 *
 * @param key    the param key//  w ww. j a va  2s. c  o  m
 * @param value  the param value
 * @param params the params map
 */
public static void addValue(String key, Object value, MultiValueMap<String, String> params) {
    if (value != null) {
        params.add(key, value.toString());
    }
}

From source file:de.zib.gndms.stuff.misc.LanguageAlgebra.java

public static MultiValueMap<String, String> getMultiValueMapFromMap(Map<String, String> map) {
    MultiValueMap<String, String> multiMap = new LinkedMultiValueMap<String, String>(map.size());

    for (String k : map.keySet()) {
        multiMap.add(k, map.get(k));
    }/*  w ww . ja  v a2s  . c  o  m*/

    return multiMap;
}

From source file:org.craftercms.commons.rest.RestClientUtils.java

/**
 * Adds a collection of param values to a params map. If the collection is null, nothing is done.
 *
 * @param key    the param key//from  w  w w .j  a  v a  2s.c  om
 * @param values the collection of param values
 * @param params the params map
 */
public static void addValues(String key, Collection<String> values, MultiValueMap<String, String> params) {
    if (values != null) {
        for (String value : values) {
            params.add(key, value);
        }
    }
}

From source file:org.craftercms.commons.rest.RestClientUtils.java

/**
 * Adds an array of param values to a params map. If the array is null, nothing is done.
 *
 * @param key    the param key//  w w w  .  j  a  va 2 s. c  om
 * @param values the array of param values
 * @param params the params map
 */
public static void addValues(String key, String[] values, MultiValueMap<String, String> params) {
    if (values != null) {
        for (String value : values) {
            params.add(key, value);
        }
    }
}

From source file:com.mycompany.trader.TradingConnect.java

private static void loginAndSaveJsessionIdCookie(final String user, final String password,
        final HttpHeaders headersToUpdate) {

    String url = "http://localhost:" + port + "/blueprint-trading-services/login.html";

    new RestTemplate().execute(url, HttpMethod.POST, new RequestCallback() {
        @Override/*from   w w w  .j a  v a  2s.  c o m*/
        public void doWithRequest(ClientHttpRequest request) throws IOException {
            MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
            map.add("username", user);
            map.add("password", password);
            new FormHttpMessageConverter().write(map, MediaType.APPLICATION_FORM_URLENCODED, request);
        }
    }, new ResponseExtractor<Object>() {
        @Override
        public Object extractData(ClientHttpResponse response) throws IOException {
            headersToUpdate.add("Cookie", response.getHeaders().getFirst("Set-Cookie"));
            return null;
        }
    });
}