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:com.ge.predix.integration.test.PrivilegeManagementAccessControlServiceIT.java

public void testCreateBatchSubjectsWithMalformedJSON() {
    try {//from  ww w  . j ava 2  s.c  om
        String badSubject = "{\"subject\":{\"name\" : \"good-subject-brittany\"},"
                + "{\"subject\": bad-subject-sarah\"}";
        MultiValueMap<String, String> headers = new HttpHeaders();
        headers.add("Content-type", "application/json");
        headers.add(PolicyHelper.PREDIX_ZONE_ID, this.acsZone1Name);
        HttpEntity<String> httpEntity = new HttpEntity<String>(badSubject, headers);
        this.acsAdminRestTemplate.postForEntity(this.acsUrl + PrivilegeHelper.ACS_SUBJECT_API_PATH, httpEntity,
                Subject[].class);
    } catch (HttpClientErrorException e) {
        Assert.assertEquals(e.getStatusCode(), HttpStatus.BAD_REQUEST);
        return;
    }
    this.acsAdminRestTemplate.exchange(
            this.acsUrl + PrivilegeHelper.ACS_SUBJECT_API_PATH + "/bad-subject-sarah", HttpMethod.DELETE,
            new HttpEntity<>(this.zone1Headers), ResponseEntity.class);
    this.acsAdminRestTemplate.exchange(
            this.acsUrl + PrivilegeHelper.ACS_SUBJECT_API_PATH + "/good-subject-brittany", HttpMethod.DELETE,
            new HttpEntity<>(this.zone1Headers), ResponseEntity.class);
    Assert.fail("testCreateBatchSubjectsWithMalformedJSON should have failed!");
}

From source file:org.unidle.social.ConnectionRepositoryImpl.java

@Override
@Transactional(readOnly = true)/* w w w .j ava2 s . c o m*/
public MultiValueMap<String, Connection<?>> findAllConnections() {

    final MultiValueMap<String, Connection<?>> connections = new LinkedMultiValueMap<>();

    final List<UserConnection> userConnections = userConnectionRepository.findAll(user);
    for (final UserConnection userConnection : userConnections) {

        final Connection<?> connection = Functions.toConnection(connectionFactoryLocator, textEncryptor)
                .apply(userConnection);

        connections.add(userConnection.getProviderId(), connection);
    }

    return connections;
}

From source file:com.github.hateoas.forms.spring.xhtml.XhtmlResourceMessageConverter.java

private Object readRequestBody(Class<?> clazz, InputStream inputStream, Charset charset) throws IOException {

    String body = StreamUtils.copyToString(inputStream, charset);

    String[] pairs = StringUtils.tokenizeToStringArray(body, "&");

    MultiValueMap<String, String> formValues = new LinkedMultiValueMap<String, String>(pairs.length);

    for (String pair : pairs) {
        int idx = pair.indexOf('=');
        if (idx == -1) {
            formValues.add(URLDecoder.decode(pair, charset.name()), null);
        } else {// w  w w.  ja v a2  s. c o  m
            String name = URLDecoder.decode(pair.substring(0, idx), charset.name());
            String value = URLDecoder.decode(pair.substring(idx + 1), charset.name());
            formValues.add(name, value);
        }
    }

    return recursivelyCreateObject(clazz, formValues, "");
}

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

/**
 * Upload (POST) multiple files on a url.
 *
 * The request header contains a given user name, the body of the request contains
 * a given object of type P.//from  ww w  .j a v a2s  .co  m
 *
 * @param <T> The body type of the response.
 * @param clazz The type of the return value.
 * @param fileNames A collection of all files to upload
 * @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 Collection<String> fileNames,
        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);
    }

    List<FileSystemResource> files = new LinkedList<FileSystemResource>();
    for (String f : fileNames) {
        files.add(new FileSystemResource(f));
    }
    form.add("files", files);
    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:com.gooddata.dataload.processes.ProcessService.java

private DataloadProcess postProcess(DataloadProcess process, File processData, URI postUri) {
    File tempFile = createTempFile("process", ".zip");

    try (FileOutputStream output = new FileOutputStream(tempFile)) {
        ZipHelper.zip(processData, output);
    } catch (IOException e) {
        throw new GoodDataException("Unable to zip process data", e);
    }/*from   w w w .j  a  v  a  2 s .c  om*/

    Object processToSend;
    HttpMethod method = HttpMethod.POST;
    if (tempFile.length() > MAX_MULTIPART_SIZE) {
        try {
            process.setPath(dataStoreService.getUri(tempFile.getName()).getPath());
            dataStoreService.upload(tempFile.getName(), new FileInputStream(tempFile));
            processToSend = process;
            if (DataloadProcess.TEMPLATE.matches(postUri.toString())) {
                method = HttpMethod.PUT;
            }
        } catch (FileNotFoundException e) {
            throw new GoodDataException("Unable to access zipped process data at " + tempFile.getAbsolutePath(),
                    e);
        }
    } else {
        final MultiValueMap<String, Object> parts = new LinkedMultiValueMap<>(2);
        parts.add("process", process);
        final HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MEDIA_TYPE_ZIP);
        parts.add("data", new HttpEntity<>(new FileSystemResource(tempFile), headers));
        processToSend = parts;
    }

    try {
        final ResponseEntity<DataloadProcess> response = restTemplate.exchange(postUri, method,
                new HttpEntity<>(processToSend), DataloadProcess.class);
        if (response == null) {
            throw new GoodDataException("Unable to post dataload process. No response returned from API.");
        }
        return response.getBody();
    } catch (GoodDataException | RestClientException e) {
        throw new GoodDataException("Unable to post dataload process.", e);
    } finally {
        deleteTempFile(tempFile);
    }
}

From source file:org.cloudfoundry.client.lib.rest.CloudControllerClientV1.java

private HttpEntity<MultiValueMap<String, ?>> generatePartialResourceRequest(
        UploadApplicationPayload application, CloudResources knownRemoteResources) throws IOException {
    MultiValueMap<String, Object> body = new LinkedMultiValueMap<String, Object>(2);
    if (application.getNumEntries() > 0) {
        //If the entire app contents are cached, send nothing
        body.add("application", application);
    }/*  ww w .j a  v  a  2 s  .c  o m*/
    ObjectMapper mapper = new ObjectMapper();
    String knownRemoteResourcesPayload = mapper.writeValueAsString(knownRemoteResources);
    body.add("resources", knownRemoteResourcesPayload);
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.MULTIPART_FORM_DATA);
    return new HttpEntity<MultiValueMap<String, ?>>(body, headers);
}

From source file:com.naver.template.social.connect.DaoConnectionRepository.java

public MultiValueMap<String, Connection<?>> findAllConnections() {
    //List<Connection<?>> resultList = jdbcTemplate.query(selectFromUserConnection() + " where userId = ? order by providerId, rank", connectionMapper, userId);
    List<Connection<?>> resultList = userConnectionDAO.selectAllConnections(userId);
    MultiValueMap<String, Connection<?>> connections = new LinkedMultiValueMap<String, Connection<?>>();
    Set<String> registeredProviderIds = connectionFactoryLocator.registeredProviderIds();
    for (String registeredProviderId : registeredProviderIds) {
        connections.put(registeredProviderId, Collections.<Connection<?>>emptyList());
    }/*from w  w w . ja  va2 s.  c o m*/
    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;
}

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

/**
 * Find all connections the current user has across all providers
 *//*w  w w. j av  a  2  s.  c o m*/
@Override
public MultiValueMap<String, Connection<?>> findAllConnections() {
    List<Connection<?>> resultList = connService.getConnections(this.userId);

    MultiValueMap<String, Connection<?>> connections = new LinkedMultiValueMap<String, Connection<?>>();
    Set<String> registeredProviderIds = this.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;
}