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:org.starfishrespect.myconsumption.android.ui.CreateAccountActivity.java

private int createAccount() {
    RestTemplate template = new RestTemplate();
    template.getMessageConverters().add(new FormHttpMessageConverter());
    template.getMessageConverters().add(new StringHttpMessageConverter());
    MultiValueMap<String, String> postParams = new LinkedMultiValueMap<>();
    postParams.add("password", CryptoUtils.sha256(editTextPassword.getText().toString()));
    try {//from ww w  .  j  a v a  2 s. c o  m
        String result = template.postForObject(
                SingleInstance.getServerUrl() + "users/" + editTextUsername.getText().toString(), postParams,
                String.class);
        LOGD(TAG, result);

        SimpleResponseDTO response = new ObjectMapper().readValue(result, SimpleResponseDTO.class);
        return response.getStatus();

    } catch (Exception e) {
        e.printStackTrace();
        return -1;
    }
}

From source file:com.goldengekko.meetr.itest.AuthITest.java

public static LinkedMultiValueMap<String, String> getOAuth2Request() {

    LinkedMultiValueMap<String, String> request = new LinkedMultiValueMap<String, String>();

    request.add("access_token", TOKEN);
    request.add("providerId", OAuth2Service.PROVIDER_ID_ITEST);
    request.add("providerUserId", ITestTemplate.ITEST_PROVIDER_USER_ID);
    request.add("expires_in", "60");
    request.add("appArg0", "appArg0");
    return request;
}

From source file:com.t163.http.client.T163HttpClient.java

/**
 * getBodyMap//from   w ww .  j a  v  a 2  s .c om
 * @param object
 * @return
 * @throws IllegalArgumentException
 * @throws IllegalAccessException
 */
private MultiValueMap<String, String> getBodyMap(Object object)
        throws IllegalArgumentException, IllegalAccessException {
    MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
    Field[] fields = object.getClass().getDeclaredFields();
    for (Field field : fields) {
        field.setAccessible(true);
        if (field.get(object) != null) {
            map.add(String.valueOf(field.getName()), String.valueOf(field.get(object)));
        }
    }
    return map;
}

From source file:com.faujnet.mongo.repository.MongoConnectionRepository.java

/**
 * Find the connections the current user has to the given provider users. 
 *//*  w  ww.  j  a  v a  2  s . c om*/
@Override
public MultiValueMap<String, Connection<?>> findConnectionsToUsers(
        MultiValueMap<String, String> providerUsers) {
    if (providerUsers == null || providerUsers.isEmpty()) {
        throw new IllegalArgumentException("Unable to execute find: no providerUsers provided");
    }

    List<Connection<?>> resultList = connService.getConnections(userId, providerUsers);

    MultiValueMap<String, Connection<?>> connectionsForUsers = new LinkedMultiValueMap<String, Connection<?>>();
    for (Connection<?> connection : resultList) {
        String providerId = connection.getKey().getProviderId();
        List<String> userIds = providerUsers.get(providerId);
        List<Connection<?>> connections = connectionsForUsers.get(providerId);
        if (connections == null) {
            connections = new ArrayList<Connection<?>>(userIds.size());
            for (int i = 0; i < userIds.size(); i++) {
                connections.add(null);
            }
            connectionsForUsers.put(providerId, connections);
        }
        String providerUserId = connection.getKey().getProviderUserId();
        int connectionIndex = userIds.indexOf(providerUserId);
        connections.set(connectionIndex, connection);
    }
    return connectionsForUsers;
}

From source file:org.agorava.yammer.impl.MessageServiceImpl.java

private MultiValueMap<String, String> buildParams(long olderThan, long newerThan, String threaded, int limit) {
    MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
    if (olderThan != 0) {
        params.set("older_than", String.valueOf(olderThan));
    }/*from ww w.  jav  a2s .com*/
    if (newerThan != 0) {
        params.set("newer_than", String.valueOf(newerThan));
    }
    if (threaded != null) {
        params.set("threaded", String.valueOf(threaded));
    }
    if (limit != 0) {
        params.set("limit", String.valueOf(limit));
    }
    return params;
}

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.zhm.config.MyAuthorizationCodeAccessTokenProvider.java

public String obtainAuthorizationCode(OAuth2ProtectedResourceDetails details, AccessTokenRequest request)
        throws UserRedirectRequiredException, UserApprovalRequiredException, AccessDeniedException,
        OAuth2AccessDeniedException {

    AuthorizationCodeResourceDetails resource = (AuthorizationCodeResourceDetails) details;

    HttpHeaders headers = getHeadersForAuthorizationRequest(request);
    MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
    if (request.containsKey(OAuth2Utils.USER_OAUTH_APPROVAL)) {
        form.set(OAuth2Utils.USER_OAUTH_APPROVAL, request.getFirst(OAuth2Utils.USER_OAUTH_APPROVAL));
        for (String scope : details.getScope()) {
            form.set(scopePrefix + scope, request.getFirst(OAuth2Utils.USER_OAUTH_APPROVAL));
        }/*from   ww  w. j a  va  2  s  .  co m*/
    } else {
        form.putAll(getParametersForAuthorizeRequest(resource, request));
    }
    authorizationRequestEnhancer.enhance(request, resource, form, headers);
    final AccessTokenRequest copy = request;

    final ResponseExtractor<ResponseEntity<Void>> delegate = getAuthorizationResponseExtractor();
    ResponseExtractor<ResponseEntity<Void>> extractor = new ResponseExtractor<ResponseEntity<Void>>() {
        @Override
        public ResponseEntity<Void> extractData(ClientHttpResponse response) throws IOException {
            if (response.getHeaders().containsKey("Set-Cookie")) {
                copy.setCookie(response.getHeaders().getFirst("Set-Cookie"));
            }
            return delegate.extractData(response);
        }
    };
    // Instead of using restTemplate.exchange we use an explicit response extractor here so it can be overridden by
    // subclasses
    ResponseEntity<Void> response = getRestTemplate().execute(resource.getUserAuthorizationUri(),
            HttpMethod.POST, getRequestCallback(resource, form, headers), extractor, form.toSingleValueMap());

    if (response.getStatusCode() == HttpStatus.OK) {
        // Need to re-submit with approval...
        throw getUserApprovalSignal(resource, request);
    }

    URI location = response.getHeaders().getLocation();
    String query = location.getQuery();
    Map<String, String> map = OAuth2Utils.extractMap(query);
    if (map.containsKey("state")) {
        request.setStateKey(map.get("state"));
        if (request.getPreservedState() == null) {
            String redirectUri = resource.getRedirectUri(request);
            if (redirectUri != null) {
                request.setPreservedState(redirectUri);
            } else {
                request.setPreservedState(new Object());
            }
        }
    }

    String code = map.get("code");
    if (code == null) {
        throw new UserRedirectRequiredException(location.toString(), form.toSingleValueMap());
    }
    request.set("code", code);
    return code;

}

From source file:org.n52.io.request.IoParameters.java

private IoParameters(File defaultConfig) {
    query = new LinkedMultiValueMap<>();
    query.setAll(readDefaultConfig(defaultConfig));
}

From source file:org.callistasoftware.netcare.core.spi.impl.PushNotificationServiceImpl.java

void sendApnsNotification(final String registrationId, final String message) {
    getLog().info("Preparing to send APNS message: {}", apnsCount);

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

    MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
    params.add("token", registrationId);
    params.add("message", message);

    HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(params,
            headers);/*from www. j a v a  2  s  . com*/

    String result = new RestTemplate().postForObject(apnsServiceUrl, request, String.class);

    if (result.equals("success")) {
        getLog().debug("Push notification " + apnsCount + " sent. Result: " + result);
        apnsCount++;
    } else {
        getLog().error("Push notification could not be sent. Server result:\n" + result);
    }
}