Search in sources :

Example 16 with MultiValueMap

use of org.springframework.util.MultiValueMap in project spring-security-oauth by spring-projects.

the class HttpTestUtils method postForString.

public ResponseEntity<String> postForString(String path, MultiValueMap<String, String> formData) {
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
    return client.exchange(getUrl(path), HttpMethod.POST, new HttpEntity<MultiValueMap<String, String>>(formData, headers), String.class);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) MultiValueMap(org.springframework.util.MultiValueMap)

Example 17 with MultiValueMap

use of org.springframework.util.MultiValueMap in project geode by apache.

the class ClientHttpRequestJUnitTest method testCreateRequestEntityForPut.

@Test
@SuppressWarnings("unchecked")
public void testCreateRequestEntityForPut() throws Exception {
    final Link expectedLink = new Link("put", toUri("http://host.domain.com:8080/app/libraries/{name}/books/{isbn}"), HttpMethod.PUT);
    final ClientHttpRequest request = new ClientHttpRequest(expectedLink);
    assertEquals(expectedLink, request.getLink());
    final MultiValueMap<String, Object> expectedRequestParameters = new LinkedMultiValueMap<String, Object>(4);
    expectedRequestParameters.add("year", "1979");
    request.addHeaderValues(HttpHeader.ACCEPT.getName(), MediaType.TEXT_XML_VALUE);
    request.addHeaderValues(HttpHeader.CONTENT_TYPE.getName(), MediaType.APPLICATION_FORM_URLENCODED_VALUE);
    request.addParameterValues("year", expectedRequestParameters.getFirst("year"));
    final HttpEntity<MultiValueMap<String, Object>> requestEntity = (HttpEntity<MultiValueMap<String, Object>>) request.createRequestEntity();
    assertNotNull(requestEntity);
    assertNotNull(requestEntity.getHeaders());
    assertEquals(Collections.singletonList(MediaType.TEXT_XML), requestEntity.getHeaders().getAccept());
    assertEquals(MediaType.APPLICATION_FORM_URLENCODED, requestEntity.getHeaders().getContentType());
    assertEquals(expectedRequestParameters, requestEntity.getBody());
}
Also used : HttpEntity(org.springframework.http.HttpEntity) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) Link(org.apache.geode.management.internal.web.domain.Link) MultiValueMap(org.springframework.util.MultiValueMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 18 with MultiValueMap

use of org.springframework.util.MultiValueMap in project uPortal by Jasig.

the class DefaultTinCanAPIProvider method sendRequest.

/**
     * Send a request to the LRS.
     *
     * @param pathFragment the URL. Should be relative to the xAPI API root
     * @param method the HTTP method
     * @param getParams the set of GET params
     * @param postData the post data.
     * @param returnType the type of object to expect in the response
     * @param <T> The type of object to expect in the response
     * @return The response object.
     */
protected <T> ResponseEntity<T> sendRequest(String pathFragment, HttpMethod method, List<? extends NameValuePair> getParams, Object postData, Class<T> returnType) {
    HttpHeaders headers = new HttpHeaders();
    headers.add(XAPI_VERSION_HEADER, XAPI_VERSION_VALUE);
    // make multipart data is handled correctly.
    if (postData instanceof MultiValueMap) {
        headers.setContentType(MediaType.MULTIPART_FORM_DATA);
    }
    URI fullURI = buildRequestURI(pathFragment, getParams);
    HttpEntity<?> entity = new HttpEntity<>(postData, headers);
    ResponseEntity<T> response = restTemplate.exchange(fullURI, method, entity, returnType);
    return response;
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) URI(java.net.URI) MultiValueMap(org.springframework.util.MultiValueMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap)

Example 19 with MultiValueMap

use of org.springframework.util.MultiValueMap in project h2o-2 by h2oai.

the class h2oService method ParseCSVFile.

public String ParseCSVFile(String key, String framename) throws org.json.JSONException {
    //http://localhost:54321/2/Parse2.query?source_key=nfs://tmp/etsy_images/image_deep_features_csv
    String h2oUrlImportEndPoint = H2O_HOST_URL + H2O_PARSE_URL + key;
    log.debug("@@@ Calling endpoint {}", h2oUrlImportEndPoint);
    MultiValueMap<String, String> parameters = new LinkedMultiValueMap<String, String>();
    /*parser_type:CSV
        separator:44
        header:1
        header_with_hash:0
        single_quotes:0
        header_from_file:
        exclude:
        source_key:nfs://tmp/etsy_images/deep_features_csv
        destination_key:deep_features_csv.hex
        preview:
        delete_on_done:1*/
    parameters.add("parser_type", "CSV");
    parameters.add("separator", "44");
    parameters.add("header", "1");
    parameters.add("singleQuotes", "0");
    parameters.add("source_key", key);
    parameters.add("destination_key", framename);
    parameters.add("delete_on_done", "true");
    RestTemplate restTemplate = new RestTemplate();
    HttpHeaders headers = new HttpHeaders();
    headers.add("Accept", MediaType.APPLICATION_JSON_VALUE);
    HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(parameters, headers);
    ResponseEntity<String> response = restTemplate.exchange(h2oUrlImportEndPoint, HttpMethod.GET, request, String.class);
    String responseBody = response.getBody();
    /*

        {"Request2":0,
        "response_info":{"h2o":"paragsanghavi","node":"/172.16.2.46:54321","time":25,"status":"redirect",
        "redirect_url":"/2/Progress2.json?job_key=%240301ac10022e32d4ffffffff%24_96ec9394a616c1e5d4ff8a63f17b428e&destination_key=image_deep_features_csv.hex"},
        "job_key":"$0301ac10022e32d4ffffffff$_96ec9394a616c1e5d4ff8a63f17b428e",
        "destination_key":"image_deep_features_csv.hex"}
         */
    log.debug("@@@ Response json from h2o {}", responseBody);
    JSONObject jsonobject = new JSONObject(responseBody);
    String job_key = (String) jsonobject.get("job_key");
    log.debug("!!!!!! Job name {}", job_key);
    String destination_key = (String) jsonobject.get("destination_key");
    String job_status = JobStatus(job_key, destination_key);
    if (job_status != null) {
        return destination_key;
    }
    return null;
}
Also used : JSONObject(org.json.JSONObject) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) RestTemplate(org.springframework.web.client.RestTemplate) MultiValueMap(org.springframework.util.MultiValueMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap)

Example 20 with MultiValueMap

use of org.springframework.util.MultiValueMap in project pinpoint by naver.

the class HttpRemoteService method createPost.

private HttpPost createPost(String url, MultiValueMap<String, String> params) throws UnsupportedEncodingException {
    HttpPost post = new HttpPost(url);
    List<NameValuePair> nvps = new ArrayList<NameValuePair>();
    for (Map.Entry<String, List<String>> entry : params.entrySet()) {
        String key = entry.getKey();
        for (String value : entry.getValue()) {
            nvps.add(new BasicNameValuePair(key, value));
        }
    }
    post.setEntity(new UrlEncodedFormEntity(nvps));
    return post;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) MultiValueMap(org.springframework.util.MultiValueMap) Map(java.util.Map) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap)

Aggregations

MultiValueMap (org.springframework.util.MultiValueMap)46 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)33 Test (org.junit.Test)18 Map (java.util.Map)17 HttpHeaders (org.springframework.http.HttpHeaders)17 List (java.util.List)9 HttpEntity (org.springframework.http.HttpEntity)9 RestTemplate (org.springframework.web.client.RestTemplate)6 URI (java.net.URI)4 LinkedHashMap (java.util.LinkedHashMap)4 DefaultOAuth2AccessToken (org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)4 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)4 HttpRequestHandler (org.springframework.web.HttpRequestHandler)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Link (org.apache.geode.management.internal.web.domain.Link)3 UnitTest (org.apache.geode.test.junit.categories.UnitTest)3 MethodParameter (org.springframework.core.MethodParameter)3 DefaultHandshakeHandler (org.springframework.web.socket.server.support.DefaultHandshakeHandler)3 HttpSessionHandshakeInterceptor (org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor)3