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

public OAuth2AccessToken refreshAccessToken(OAuth2ProtectedResourceDetails resource,
        OAuth2RefreshToken refreshToken, AccessTokenRequest request)
        throws UserRedirectRequiredException, OAuth2AccessDeniedException {
    MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
    form.add("grant_type", "refresh_token");
    form.add("refresh_token", refreshToken.getValue());
    try {//ww w  .j  a v a 2 s  .  c o  m
        return retrieveToken(request, resource, form, getHeadersForTokenRequest(request));
    } catch (OAuth2AccessDeniedException e) {
        throw getRedirectForAuthorization((AuthorizationCodeResourceDetails) resource, request);
    }
}

From source file:com.evozon.evoportal.my_account.util.MyAccountUtil.java

public static MultiValueMap<String, Object> getPMReportsParameters(AccountModelHolder oldModel,
        AccountModelHolder newModel, User selectedUser, UserAccountOperation commandType) {
    MultiValueMap<String, Object> mapModifications = new LinkedMultiValueMap<String, Object>();

    if (!UserAccountOperation.ADD_USER.equals(commandType) && !hasPMReportsDataModified(oldModel, newModel)) {
        return mapModifications;
    }/*from   ww w.j av  a2 s.c o  m*/

    String userCNP = UserAccountOperation.USER_UPDATE.equals(commandType) ? oldModel.getDetailsModel().getCNP()
            : newModel.getDetailsModel().getCNP();
    mapModifications.add(PMReportsConstants.USER_CNP, userCNP);
    mapModifications.add(PMReportsConstants.USER_EMAIL, newModel.getDetailsModel().getEmailAddress());
    mapModifications.add(PMReportsConstants.USER_LAST_NAME, newModel.getDetailsModel().getLastName());
    mapModifications.add(PMReportsConstants.USER_FIRST_NAME, newModel.getDetailsModel().getFirstName());
    mapModifications.add(PMReportsConstants.USER_DATE_HIRED,
            convertDateToString(newModel.getFreeDaysModel().getStartDate(), DATE_FORMAT_MONTH_DAY_YEAR));

    String pmDep = findPMReportsAssociatedDepartment(newModel, selectedUser);
    if (!pmDep.isEmpty()) {
        mapModifications.add(PMReportsConstants.DEPARTMENT_NAME, pmDep);
    }

    String countryCode = null;
    EvoAddressModel primaryAddress = newModel.getPrimaryAddress();
    if (primaryAddress != null) {
        mapModifications.add(PMReportsConstants.USER_ZIP_CODE, primaryAddress.getPostalCode());
        mapModifications.add(PMReportsConstants.USER_CITY_NAME, primaryAddress.getCity());

        countryCode = primaryAddress.getCountryCode();
        if (countryCode.isEmpty()) {
            countryCode = PMReportsConstants.USER_DEFAULT_COUNTRY_CODE;
        }

        mapModifications.add(PMReportsConstants.USER_STREET_NAME, primaryAddress.getStreetName());
        mapModifications.add(PMReportsConstants.USER_STREET_NUMBER, primaryAddress.getStreetNumber());
    }
    // The 'country code' is mandatory
    mapModifications.add(PMReportsConstants.USER_COUNTRY_CODE,
            (countryCode == null) ? PMReportsConstants.USER_DEFAULT_COUNTRY_CODE : countryCode);

    mapModifications.add(PMReportsConstants.USER_MOBILE_NUMBER, newModel.getDetailsModel().getPhoneNumber());
    mapModifications.add(PMReportsConstants.USER_PLATE_NUMBER, newModel.getDetailsModel().getLicensePlate());

    return mapModifications;
}

From source file:org.openmhealth.shim.withings.WithingsShim.java

URI createWithingsRequestUri(ShimDataRequest shimDataRequest, String userid,
        WithingsDataType withingsDataType) {

    MultiValueMap<String, String> dateTimeMap = new LinkedMultiValueMap<>();
    if (withingsDataType.usesUnixEpochSecondsDate || isPartnerAccessActivityMeasure(withingsDataType)) {
        //the partner access endpoints for activity also use epoch secs

        dateTimeMap.add("startdate", String.valueOf(shimDataRequest.getStartDateTime().toEpochSecond()));
        dateTimeMap.add("enddate",
                String.valueOf(shimDataRequest.getEndDateTime().plusDays(1).toEpochSecond()));
    } else {//from   www . ja  v  a2s.c  o m
        dateTimeMap.add("startdateymd", shimDataRequest.getStartDateTime().toLocalDate().toString());
        dateTimeMap.add("enddateymd", shimDataRequest.getEndDateTime().toLocalDate().toString());

    }

    UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString(DATA_URL)
            .pathSegment(withingsDataType.getEndpoint());
    String measureParameter;
    if (isPartnerAccessActivityMeasure(withingsDataType)) {
        // partner level access allows greater detail around activity, but uses a different endpoint
        measureParameter = PARTNER_ACCESS_ACTIVITY_ENDPOINT;
    } else {
        measureParameter = withingsDataType.getMeasureParameter();
    }
    uriComponentsBuilder.queryParam("action", measureParameter).queryParam("userid", userid)
            .queryParams(dateTimeMap);

    // if it's a body measure
    if (Objects.equals(withingsDataType.getMeasureParameter(), "getmeas")) {

        /*
        The Withings API allows us to query for single body measures, which we take advantage of to reduce
        unnecessary data transfer. However, since blood pressure is represented as two separate measures,
        namely a diastolic and a systolic measure, when the measure type is blood pressure we ask for all
        measures and then filter out the ones we don't care about.
         */
        if (withingsDataType != WithingsDataType.BLOOD_PRESSURE) {

            WithingsBodyMeasureType measureType = WithingsBodyMeasureType.valueOf(withingsDataType.name());
            uriComponentsBuilder.queryParam("meastype", measureType.getMagicNumber());
        }

        uriComponentsBuilder.queryParam("category", 1); //filter out goal datapoints

    }

    UriComponents uriComponents = uriComponentsBuilder.build();
    return uriComponents.toUri();

}

From source file:de.zib.gndms.gndmc.AbstractClient.java

/**
 * Upload (POST) a file on a url./*from www .  ja  va  2  s. c  om*/
 *
 * The request header contains a given user name, the body of the request contains
 * a given object of type P.
 *
 * @param <T> The body type of the response.
 * @param clazz The type of the return value.
 * @param fileName Remote filename.
 * @param originalFileName Path to local file.
 * @param url The url of the request.
 * @param dn The user name.
 * @return The response as entity.
 */
protected final <T> ResponseEntity<T> postFile(final Class<T> clazz, final String fileName,
        final String originalFileName, final String url, final String dn) {

    GNDMSResponseHeader requestHeaders = new GNDMSResponseHeader();
    MultiValueMap<String, Object> form = new LinkedMultiValueMap<String, Object>();
    final HttpEntity requestEntity;

    if (dn != null) {
        requestHeaders.setDN(dn);
    }

    form.add("file", new FileSystemResource(originalFileName));
    requestEntity = new HttpEntity(form, requestHeaders);

    if (null == restTemplate)
        throw new NullPointerException("Please set RestTemplate in Client!");

    return restTemplate.postForEntity(url, requestEntity, clazz);
}

From source file:org.apigw.authserver.AuthorizationCodeProviderIntegrationtest.java

@Test
public void testUserDeniesConfirmation() throws Exception {
    log.debug("testUserDeniesConfirmation");
    String cookie = helper.loginAndGetConfirmationPage(CLIENT_ID, REDIRECT_URL, SCOPE);

    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
    headers.set("Cookie", cookie);

    MultiValueMap<String, String> formData = new LinkedMultiValueMap<String, String>();
    formData.add("user_oauth_approval", "false");
    ResponseEntity<Void> result = serverRunning.postForStatus("/apigw-auth-server-web/oauth/authorize", headers,
            formData);/*w  ww .ja v  a2 s. c  o  m*/
    assertEquals(HttpStatus.FOUND, result.getStatusCode());

    String location = result.getHeaders().getFirst("Location");
    assertTrue(location.startsWith(REDIRECT_URL));
    assertTrue(location.substring(location.indexOf('?')).contains("error=access_denied"));
    assertTrue(location.contains("state=gzzFqB!!!"));
}

From source file:fr.treeptik.cloudunit.cli.rest.RestUtils.java

/**
 * sendPostCommand/*from  w  w w  .  j  a v  a2s .co  m*/
 *
 * @param url
 * @param parameters
 * @return
 * @throws ClientProtocolException
 */
public Map<String, Object> sendPostForUpload(String url, Map<String, Object> parameters) {
    RestTemplate restTemplate = new RestTemplate();
    List<HttpMessageConverter<?>> mc = restTemplate.getMessageConverters();
    mc.add(new MappingJacksonHttpMessageConverter());
    restTemplate.setMessageConverters(mc);
    MultiValueMap<String, Object> postParams = new LinkedMultiValueMap<String, Object>();
    postParams.setAll(parameters);
    Map<String, Object> response = new HashMap<String, Object>();
    HttpHeaders headers = new HttpHeaders();
    headers.set("Content-Type", "multipart/form-data");
    headers.set("Accept", "application/json");
    headers.add("Cookie", "JSESSIONID=" + localContext.getCookieStore().getCookies().get(0).getValue());
    org.springframework.http.HttpEntity<Object> request = new org.springframework.http.HttpEntity<Object>(
            postParams, headers);
    ResponseEntity<?> result = restTemplate.exchange(url, HttpMethod.POST, request, String.class);
    String body = result.getBody().toString();
    MediaType contentType = result.getHeaders().getContentType();
    HttpStatus statusCode = result.getStatusCode();
    response.put("content-type", contentType);
    response.put("statusCode", statusCode);
    response.put("body", body);

    return response;

}

From source file:org.socialsignin.spring.data.dynamodb.repository.query.AbstractDynamoDBQueryCriteria.java

public AbstractDynamoDBQueryCriteria(DynamoDBEntityInformation<T, ID> dynamoDBEntityInformation) {
    this.clazz = dynamoDBEntityInformation.getJavaType();
    this.attributeConditions = new LinkedMultiValueMap<String, Condition>();
    this.propertyConditions = new LinkedMultiValueMap<String, Condition>();
    this.hashKeyPropertyName = dynamoDBEntityInformation.getHashKeyPropertyName();
    this.entityInformation = dynamoDBEntityInformation;
    this.attributeNamesByPropertyName = new HashMap<String, String>();

}

From source file:com.expedia.seiso.web.assembler.ResourceAssembler.java

/**
 * @param apiVersion/*from   w ww .j  a  va 2  s . com*/
 *            API version
 * @param repoKey
 * @return
 */
public Resource toRepoSearchList(@NonNull ApiVersion apiVersion, @NonNull String repoKey) {
    val itemClass = itemMetaLookup.getItemClass(repoKey);
    val repoInfo = repositories.getRepositoryInformationFor(itemClass);
    val queryMethods = repoInfo.getQueryMethods();

    val resource = new Resource();
    resource.addLink(repoSearchLinks(apiVersion).repoSearchListLink(Relations.SELF, itemClass));
    resource.addLink(itemLinks(apiVersion).repoLink(Relations.UP, itemClass));

    // Query method links
    for (val queryMethod : queryMethods) {
        val restResource = AnnotationUtils.getAnnotation(queryMethod, RestResource.class);
        if (restResource == null) {
            continue;
        }

        val path = restResource.path();
        if (path.isEmpty()) {
            continue;
        }

        val requestParams = new LinkedMultiValueMap<String, String>();
        val methodParams = queryMethod.getParameters();
        for (val methodParam : methodParams) {
            val paramAnn = methodParam.getAnnotation(Param.class);
            if (paramAnn != null) {
                val requestParamName = paramAnn.value();
                // FIXME Formatting the URI template variables belongs with the xxxLinks objects, not here. [WLW]
                requestParams.set(requestParamName, "{" + requestParamName + "}");
            }
        }

        val rel = "s:" + (restResource.rel().isEmpty() ? path : restResource.rel());
        val link = repoSearchLinks(apiVersion).toRepoSearchLinkTemplate(rel, itemClass, path, requestParams);
        resource.addLink(link);
    }

    return resource;
}

From source file:org.cloudfoundry.identity.uaa.login.feature.OpenIdTokenGrantsIT.java

@Test
public void testPasswordGrant() throws Exception {
    String basicDigestHeaderValue = "Basic " + new String(Base64.encodeBase64(("cf:").getBytes()));

    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
    headers.set("Authorization", basicDigestHeaderValue);

    LinkedMultiValueMap<String, String> postBody = new LinkedMultiValueMap<>();
    postBody.add("client_id", "cf");
    postBody.add("redirect_uri", "https://uaa.cloudfoundry.com/redirect/cf");
    postBody.add("response_type", "token id_token");
    postBody.add("grant_type", "password");
    postBody.add("username", user.getUserName());
    postBody.add("password", "secret");

    ResponseEntity<Map> responseEntity = restOperations.exchange(loginUrl + "/oauth/token", HttpMethod.POST,
            new HttpEntity<>(postBody, headers), Map.class);

    Assert.assertEquals(HttpStatus.OK, responseEntity.getStatusCode());

    Map<String, Object> params = responseEntity.getBody();

    Assert.assertTrue(params.get("jti") != null);
    Assert.assertEquals("bearer", params.get("token_type"));
    Assert.assertThat((Integer) params.get("expires_in"), Matchers.greaterThan(40000));

    String[] scopes = UriUtils.decode((String) params.get("scope"), "UTF-8").split(" ");
    Assert.assertThat(Arrays.asList(scopes), containsInAnyOrder("scim.userids", "password.write",
            "cloud_controller.write", "openid", "cloud_controller.read"));

    validateToken("access_token", params, scopes);
    validateToken("id_token", params, scopes);
}

From source file:sparklr.common.AbstractAuthorizationCodeProviderTests.java

@Test
public void testIllegalAttemptToApproveWithoutUsingAuthorizationRequest() throws Exception {

    HttpHeaders headers = getAuthenticatedHeaders();

    String authorizeUrl = getAuthorizeUrl("my-trusted-client", "http://anywhere.com", "read");
    authorizeUrl = authorizeUrl + "&user_oauth_approval=true";
    ResponseEntity<Void> response = http.postForStatus(authorizeUrl, headers,
            new LinkedMultiValueMap<String, String>());
    assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
}