Example usage for org.springframework.util LinkedMultiValueMap LinkedMultiValueMap

List of usage examples for org.springframework.util LinkedMultiValueMap LinkedMultiValueMap

Introduction

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

Prototype

public LinkedMultiValueMap() 

Source Link

Document

Create a new LinkedMultiValueMap that wraps a LinkedHashMap .

Usage

From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.UploadDataFile.java

/**
 * Method, where data file information is pushed to server in order to create data file record.
 * All heavy lifting is made here./*from   w  w  w.j a  v a2  s.c o  m*/
 *
 * @param dataFileContents must be three params in order - experiment id, description, path to file
 * @return URI of uploaded file
 */
@Override
protected URI doInBackground(String... dataFileContents) {
    SharedPreferences credentials = getCredentials();
    String username = credentials.getString("username", null);
    String password = credentials.getString("password", null);
    String url = credentials.getString("url", null) + Values.SERVICE_DATAFILE;

    setState(RUNNING, R.string.working_ws_upload_data_file);
    HttpAuthentication authHeader = new HttpBasicAuthentication(username, password);
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.setAuthorization(authHeader);
    requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML));

    SSLSimpleClientHttpRequestFactory factory = new SSLSimpleClientHttpRequestFactory();
    //so files wont buffer in memory
    factory.setBufferRequestBody(false);
    // Create a new RestTemplate instance
    RestTemplate restTemplate = new RestTemplate(factory);
    restTemplate.getMessageConverters().add(new StringHttpMessageConverter());
    restTemplate.getMessageConverters().add(new FormHttpMessageConverter());

    try {
        Log.d(TAG, url);
        FileSystemResource toBeUploadedFile = new FileSystemResource(dataFileContents[2]);
        MultiValueMap<String, Object> form = new LinkedMultiValueMap<String, Object>();
        form.add("experimentId", dataFileContents[0]);
        form.add("description", dataFileContents[1]);
        form.add("file", toBeUploadedFile);

        HttpEntity<Object> entity = new HttpEntity<Object>(form, requestHeaders);
        // Make the network request
        return restTemplate.postForLocation(url, entity);
    } catch (Exception e) {
        Log.e(TAG, e.getLocalizedMessage(), e);
        setState(ERROR, e);
    } finally {
        setState(DONE);
    }
    return null;
}

From source file:com.svds.resttest.model.GenericCountOutputNGTest.java

/**
 * Test of getRequestParams method, of class GenericCountOutput.
 *//*from  w w  w  .  j  ava2 s. c o  m*/
@Test
public void testGetRequestParams() {
    System.out.println("getRequestParams");
    MultiValueMap<String, String> requestParams = new LinkedMultiValueMap<>();
    GenericCountOutput instance = new GenericCountOutput();
    instance.setRequestParams(requestParams);
    assertEquals(instance.getRequestParams(), requestParams);
}

From source file:fr.itldev.koya.services.impl.KoyaContentServiceImpl.java

private Document upload(User user, NodeRef parent, Object o) throws AlfrescoServiceException {
    MultiValueMap<String, Object> parts = new LinkedMultiValueMap<>();
    parts.add("filedata", o);
    parts.add("destination", parent.toString());
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.MULTIPART_FORM_DATA);
    HttpEntity<MultiValueMap<String, Object>> request = new HttpEntity<>(parts, headers);
    AlfrescoUploadReturn upReturn = fromJSON(new TypeReference<AlfrescoUploadReturn>() {
    }, user.getRestTemplate().postForObject(getAlfrescoServerUrl() + REST_POST_UPLOAD, request, String.class));

    return (Document) getSecuredItem(user, upReturn.getNodeRef());

}

From source file:org.zaizi.AuthServerApplicationTests.java

@Test
public void loginSucceeds() {
    ResponseEntity<String> response = template.getForEntity("http://localhost:" + port + contextPath + "/login",
            String.class);
    String csrf = getCsrf(response.getBody());
    MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
    form.set("username", "admin");
    form.set("password", "ulibraxi");
    form.set("_csrf", csrf);
    HttpHeaders headers = new HttpHeaders();
    headers.put("COOKIE", response.getHeaders().get("Set-Cookie"));
    RequestEntity<MultiValueMap<String, String>> request = new RequestEntity<MultiValueMap<String, String>>(
            form, headers, HttpMethod.POST, URI.create("http://localhost:" + port + contextPath + "/login"));
    ResponseEntity<Void> location = template.exchange(request, Void.class);
    assertEquals("http://localhost:" + port + contextPath + "/", location.getHeaders().getFirst("Location"));
}

From source file:com.ggk.hrms.authentication.CustomTokenServices.java

private Map<String, Object> checkToken(String accessToken) {
    MultiValueMap<String, String> formData = new LinkedMultiValueMap<String, String>();
    formData.add("token", accessToken);
    HttpHeaders headers = new HttpHeaders();
    headers.set("Authorization", getAuthorizationHeader(clientId, clientSecret));
    String accessTokenUrl = new StringBuilder(checkTokenEndpointUrl).append("?access_token=")
            .append(accessToken).toString();
    return postForMap(accessTokenUrl, formData, headers);
}

From source file:com.golonzovsky.oauth2.google.security.GoogleTokenServices.java

private Map<String, Object> checkToken(String accessToken) {
    MultiValueMap<String, String> formData = new LinkedMultiValueMap<>();
    formData.add("token", accessToken);
    HttpHeaders headers = new HttpHeaders();
    headers.set("Authorization", getAuthorizationHeader(clientId, clientSecret));
    String accessTokenUrl = checkTokenEndpointUrl + "?access_token=" + accessToken;
    return postForMap(accessTokenUrl, formData, headers);
}

From source file:com.example.ProxyAuthorizationServerTokenServices.java

private MultiValueMap<String, String> createForm(String refreshToken, TokenRequest tokenRequest) {
    MultiValueMap<String, String> form = new LinkedMultiValueMap<>();
    form.set(OAuth2Utils.GRANT_TYPE, "refresh_token");
    form.set("refresh_token", refreshToken);
    if (!tokenRequest.getScope().isEmpty()) {
        form.set(OAuth2Utils.SCOPE, OAuth2Utils.formatParameterList(tokenRequest.getScope()));
    }//  w  ww  . j a v a2 s  .  c  om
    return form;
}

From source file:com.svds.resttest.model.GenericResultsOutputNGTest.java

/**
 * Test of getRequestParams method, of class GenericResultsOutput.
 *///from   w  w  w.java 2  s  .  c  o m
@Test
public void testGetRequestParams() {
    System.out.println("getRequestParams");
    MultiValueMap<String, String> requestParams = new LinkedMultiValueMap<>();
    GenericResultsOutput instance = new GenericResultsOutput();
    instance.setRequestParams(requestParams);
    assertEquals(instance.getRequestParams(), requestParams);
}

From source file:io.syndesis.runtime.APITokenRule.java

@Override
protected void after() {
    MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
    map.set("refresh_token", refreshToken);
    map.set("client_id", "admin-cli");
    HttpHeaders headers = new HttpHeaders();
    headers.set("Authorization", "Bearer " + accessToken);
    ResponseEntity<JsonNode> json = restTemplate.postForEntity("http://localhost:" + keycloakPort
            + "/auth/realms/" + keycloakRealm + "/protocol/" + keycloakProtocol + "/logout", map,
            JsonNode.class);
    assertThat(json.getStatusCode()).as("logout status code").isEqualTo(HttpStatus.NO_CONTENT);
}

From source file:io.github.davejoyce.dao.composite.social.connect.jpa.JpaConnectionRepository.java

/**
 * {@inheritDoc}//from   ww  w  .j a v a  2  s .  c o m
 */
public MultiValueMap<String, Connection<?>> findAllConnections() {
    TypedQuery<AppUserSocialConnection> query = entityManager
            .createQuery(QUERY_FIND_ALL_CONNECTIONS, AppUserSocialConnection.class)
            .setParameter("userId", userId);
    List<Connection<?>> resultList = appUserSocialConnectionsToConnections(query.getResultList());
    MultiValueMap<String, Connection<?>> connections = new LinkedMultiValueMap<String, Connection<?>>();
    Set<String> registeredProviderIds = connectionFactoryLocator.registeredProviderIds();
    for (String registeredProviderId : registeredProviderIds) {
        connections.put(registeredProviderId, Collections.<Connection<?>>emptyList());
    }
    for (Connection<?> connection : resultList) {
        String providerId = connection.getKey().getProviderId();
        if (connections.get(providerId).size() == 0) {
            connections.put(providerId, new LinkedList<Connection<?>>());
        }
        connections.add(providerId, connection);
    }
    return connections;
}