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:de.loercher.localpress.integration.GeoAndRatingITest.java

@Test
public void testAddArticle() {
    String nowString = "2015-10-12T08:00+02:00[Europe/Berlin]";
    ZonedDateTime now = new DateTimeConverter().fromString(nowString);

    AddArticleEntityDTO geoDTO = new AddArticleEntityDTO(nowString);
    Instant instant = now.toInstant();
    Instant fir = Instant.now();

    MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
    headers.add("UserID", "ulf");

    HttpEntity<AddArticleEntityDTO> request = new HttpEntity<>(geoDTO, headers);

    RestTemplate template = new RestTemplate();
    ResponseEntity<Map> result = template.postForEntity("http://52.29.77.191:8080/localpress/feedback", request,
            Map.class);

    Instant afterRating = Instant.now();

    GeoBaseEntity.EntityBuilder builder = new GeoBaseEntity.EntityBuilder();
    GeoBaseEntity entity = builder.author("ulf")
            .coordinates(Arrays.asList(new Coordinate[] { new Coordinate(50.1, 8.4) }))
            .timestamp(now.toEpochSecond()).content("abc.de").title("mein titel").user("ulf").build();

    HttpEntity<GeoBaseEntity> second = new HttpEntity<>(entity, headers);
    System.out.println(result.getBody().get("articleID"));

    template.put("http://euve33985.vserver.de:8080/geo/" + result.getBody().get("articleID"), second);

    Instant afterGeoPut = Instant.now();

    result = template.getForEntity("http://euve33985.vserver.de:8080/geo/" + result.getBody().get("articleID"),
            Map.class);

    Instant afterGeoGet = Instant.now();

    assertEquals("User ID has changed over time!", "ulf", result.getBody().get("user"));
    assertEquals("Content URL has changed over time!", "abc.de", result.getBody().get("content"));

    DateTimeConverter conv = new DateTimeConverter();

    Duration first = Duration.between(fir, afterRating);
    Duration sec = Duration.between(afterRating, afterGeoPut);
    Duration third = Duration.between(afterGeoPut, afterGeoGet);

    System.out.println("Begin: " + conv.toString(now));
    System.out.println("Time until POST to rating: " + new Double(first.toMillis()) / 1000);
    System.out.println("Time until PUT to geo: " + new Double(sec.toMillis()) / 1000);
    System.out.println("Time until GET to geo: " + new Double(third.toMillis()) / 1000);
}

From source file:de.codecentric.batch.test.JobParametersIncrementerIntegrationTest.java

@Test
public void testRunJob() throws InterruptedException {
    MultiValueMap<String, Object> requestMap = new LinkedMultiValueMap<>();
    requestMap.add("jobParameters", "param1=value1");
    Long executionId = restTemplate.postForObject(
            "http://localhost:" + port + "/batch/operations/jobs/incrementerJob", requestMap, Long.class);
    while (!restTemplate
            .getForObject("http://localhost:" + port + "/batch/operations/jobs/executions/{executionId}",
                    String.class, executionId)
            .equals("COMPLETED")) {
        Thread.sleep(1000);// w w w . j a va2  s.  co  m
    }
    JobExecution jobExecution = jobExplorer.getJobExecution(executionId);
    assertThat(jobExecution.getStatus(), is(BatchStatus.COMPLETED));
    assertThat(jobExecution.getJobParameters().getLong("run.id"), is(1l));
    assertThat(jobExecution.getJobParameters().getString("param1"), is("value1"));
    executionId = restTemplate.postForObject(
            "http://localhost:" + port + "/batch/operations/jobs/incrementerJob", "", Long.class);
    while (!restTemplate
            .getForObject("http://localhost:" + port + "/batch/operations/jobs/executions/{executionId}",
                    String.class, executionId)
            .equals("COMPLETED")) {
        Thread.sleep(1000);
    }
    jobExecution = jobExplorer.getJobExecution(executionId);
    assertThat(jobExecution.getStatus(), is(BatchStatus.COMPLETED));
    assertThat(jobExecution.getJobParameters().getLong("run.id"), is(2l));
    requestMap = new LinkedMultiValueMap<>();
    requestMap.add("jobParameters", "param1=value1,param2=value2");
    executionId = restTemplate.postForObject(
            "http://localhost:" + port + "/batch/operations/jobs/incrementerJob", requestMap, Long.class);
    while (!restTemplate
            .getForObject("http://localhost:" + port + "/batch/operations/jobs/executions/{executionId}",
                    String.class, executionId)
            .equals("COMPLETED")) {
        Thread.sleep(1000);
    }
    jobExecution = jobExplorer.getJobExecution(executionId);
    assertThat(jobExecution.getStatus(), is(BatchStatus.COMPLETED));
    assertThat(jobExecution.getJobParameters().getLong("run.id"), is(3l));
    assertThat(jobExecution.getJobParameters().getString("param1"), is("value1"));
    assertThat(jobExecution.getJobParameters().getString("param2"), is("value2"));
}

From source file:com.onedrive.api.resource.support.UploadSession.java

public UploadSession uploadFragment(long startIndex, long endIndex, long totalSize, byte[] data) {
    Assert.notNull(uploadUrl, "UploadSession instance invalid. The uploadUrl is not defined.");
    Assert.notNull(data, "The data is required.");
    MultiValueMap<String, String> headers = new LinkedMultiValueMap<String, String>();
    headers.add("Content-Range", "bytes " + startIndex + "-" + endIndex + "/" + totalSize);
    ResponseEntity<UploadSession> response = getOneDrive().getRestTemplate().exchange(uploadUri(),
            HttpMethod.PUT, new HttpEntity<ByteArrayResource>(new ByteArrayResource(data), headers),
            UploadSession.class);
    UploadSession session = response.getBody();
    session.setUploadUrl(uploadUrl);// w  w w  .j a va 2  s.  co  m
    session.complete = response.getStatusCode().equals(HttpStatus.CREATED)
            || response.getStatusCode().equals(HttpStatus.OK);
    return session;
}

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

protected static MultiValueMap<String, JsonNode> convertValuesToJsonNodes(
        MultiValueMap<String, String> queryParameters) {
    MultiValueMap<String, JsonNode> parameters = new LinkedMultiValueMap<>();
    final Set<Entry<String, List<String>>> entrySet = queryParameters.entrySet();
    for (Entry<String, List<String>> entry : entrySet) {
        for (String value : entry.getValue()) {
            final String key = entry.getKey().toLowerCase();
            parameters.add(key, getJsonNodeFrom(value));
        }// ww  w . j a  v a  2s .c o m
    }
    return parameters;
}

From source file:client.ServiceRequester.java

public HttpEntity<byte[]> createRequestHeaders(BufferedImage image) {
    byte[] imageBytes = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
    MultiValueMap<String, String> headers = new LinkedMultiValueMap<String, String>();

    headers.add("imageType", String.valueOf(image.getType()));
    headers.add("imageWidth", String.valueOf(image.getWidth()));
    headers.add("imageHeight", String.valueOf(image.getHeight()));

    return new HttpEntity<byte[]>(imageBytes, 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: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 {//  w  w w  .j a  v  a  2 s.co  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.rst.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 = new StringBuilder(checkTokenEndpointUrl).append("?access_token=")
            .append(accessToken).toString();
    return postForMap(accessTokenUrl, formData, headers);
}

From source file:org.cloudfoundry.identity.uaa.integration.NativeApplicationIntegrationTests.java

/**
 * tests that a client secret is required.
 *//*from w w w  . j av  a2s.  c o  m*/
@Test
public void testSecretRequired() throws Exception {
    MultiValueMap<String, String> formData = new LinkedMultiValueMap<String, String>();
    formData.add("grant_type", "password");
    formData.add("username", resource.getUsername());
    formData.add("password", resource.getPassword());
    formData.add("scope", "cloud_controller.read");
    HttpHeaders headers = new HttpHeaders();
    headers.set("Authorization", "Basic " + new String(Base64.encode("no-such-client:".getBytes("UTF-8"))));
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
    ResponseEntity<String> response = serverRunning.postForString("/oauth/token", formData, headers);
    assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());
}

From source file:org.trustedanalytics.h2oscoringengine.publisher.steps.AppBitsUploadingStep.java

/**
 * Prepares request to CF// w w w  .j  a v a2s.com
 * <a href="https://apidocs.cloudfoundry.org/225/apps/uploads_the_bits_for_an_app.html">endpoint
 * </a>
 * 
 * @param dataPath
 * @return prepared request
 * @throws IOException
 */
private HttpEntity<MultiValueMap<String, Object>> prepareMutlipartRequest(Path dataPath) throws IOException {
    HttpEntity<String> resourcesPart = prepareResourcesRequestPart();
    HttpEntity<ByteArrayResource> dataPart = prepareDataRequestPart(dataPath);

    MultiValueMap<String, Object> multiPartRequest = new LinkedMultiValueMap<>();
    multiPartRequest.add("resources", resourcesPart);
    multiPartRequest.add("application", dataPart);

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

    return new HttpEntity<>(multiPartRequest, headers);

}