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.jnrain.mobile.network.NewPostRequest.java

@Override
public SimpleReturnCode loadDataFromNetwork() throws Exception {
    MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
    params.set("Content", _content);
    params.set("board", _brd);
    params.set("signature", Integer.toString(_signid));
    params.set("subject", _title);

    if (_is_new_thread) {
        params.set("ID", "");
        params.set("groupID", "");
        params.set("reID", "0");
    } else {//  w w w  .ja  v  a 2s.  c o m
        params.set("ID", Long.toString(_tid));
        params.set("groupID", Long.toString(_tid));
        params.set("reID", Long.toString(_reid));
    }

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    HttpEntity<MultiValueMap<String, String>> req = new HttpEntity<MultiValueMap<String, String>>(params,
            headers);

    return getRestTemplate().postForObject(
            /* "http://rhymin.jnrain.com/api/post/new/", */
            "http://bbs.jnrain.com/rainstyle/apipost.php", req, SimpleReturnCode.class);
}

From source file:de.codecentric.batch.test.metrics.BatchMetricsExporterIntegrationTest.java

@Test
public void testRunJob() throws InterruptedException {
    MultiValueMap<String, Object> requestMap = new LinkedMultiValueMap<>();
    requestMap.add("jobParameters", "run=2");
    Long executionId = restTemplate.postForObject(
            "http://localhost:" + port + "/batch/operations/jobs/simpleBatchMetricsJob", requestMap,
            Long.class);
    while (!restTemplate
            .getForObject("http://localhost:" + port + "/batch/operations/jobs/executions/{executionId}",
                    String.class, executionId)
            .equals("COMPLETED")) {
        Thread.sleep(1000);//from   w ww  . j av  a  2s . c  o m
    }
    String log = restTemplate.getForObject(
            "http://localhost:" + port + "/batch/operations/jobs/executions/{executionId}/log", String.class,
            executionId);
    assertThat(log.length() > 20, is(true));
    JobExecution jobExecution = jobExplorer.getJobExecution(executionId);
    assertThat(jobExecution.getStatus(), is(BatchStatus.COMPLETED));
    String jobExecutionString = restTemplate.getForObject(
            "http://localhost:" + port + "/batch/monitoring/jobs/executions/{executionId}", String.class,
            executionId);
    assertThat(jobExecutionString.contains("COMPLETED"), is(true));
    Metric<?> metric = metricReader
            .findOne("gauge.batch.simpleBatchMetricsJob.simpleBatchMetricsStep.processor");
    assertThat(metric, is(notNullValue()));
    assertThat((Double) metric.getValue(), is(notNullValue()));
    assertThat((Double) metric.getValue(), is(7.0));
}

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:eu.cloudwave.wp5.monitoring.rest.FeedbackHandlerMonitoringClient.java

/**
 * Sends monitoring data (i.e. the call trace) and its attached metrics to the Feedback Handler.
 * // w ww. j  a va2  s  .com
 * @param executions
 *          the {@link RunningProcedureExecution}'s (i.e. the call trace)
 * @return <code>true</code> if the data has been successfully sent to the Feedback Handler, <code>false</code>
 *         otherwise
 */
public boolean postData(final RunningProcedureExecution rootProcedureExecution) {
    final MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
    headers.add(Headers.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
    headers.add(Headers.ACCESS_TOKEN, accessToken());
    headers.add(Headers.APPLICATION_ID, applicationId());
    final HttpEntity<MetricContainingProcedureExecutionDto> httpEntity = new HttpEntity<MetricContainingProcedureExecutionDto>(
            rootProcedureExecution, headers);
    final ResponseEntity<Boolean> result = new RestTemplate().exchange(url(), HttpMethod.POST, httpEntity,
            Boolean.class);
    return result.getBody();
}

From source file:fr.keemto.web.LoginWebIT.java

@Test
public void shouldAuthenticateUserWithValidCredentials() {

    MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
    params.add(USERNAME_PARAM, VALID_USERNAME);
    params.add(PASSWORD_PARAM, "test");

    LoginStatus status = template.postForObject(URL, params, LoginStatus.class);

    assertThat(status.isLoggedIn(), is(true));
    assertThat(status.getUsername(), equalTo(VALID_USERNAME));
}

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

private MultiValueMap<String, String> toParams(String targetType, long id) {
    MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
    params.set("target_type", targetType);
    params.set("target_id", String.valueOf(id));
    return params;
}

From source file:lcn.module.oltp.web.common.base.MultipartResolver.java

/**
 * multipart?  parsing? ./*from   w  w w . j av  a2 s .co m*/
 */
@SuppressWarnings("unchecked")
@Override
protected MultipartParsingResult parseFileItems(List fileItems, String encoding) {

    //? 3.0  
    MultiValueMap<String, MultipartFile> multipartFiles = new LinkedMultiValueMap<String, MultipartFile>();
    //   Map<String, String[]> multipartParameters = new HashMap<String, String[]>();

    //   Map multipartFiles = new HashMap();
    Map multipartParameters = new HashMap();

    // Extract multipart files and multipart parameters.
    for (Iterator it = fileItems.iterator(); it.hasNext();) {
        FileItem fileItem = (FileItem) it.next();

        if (fileItem.isFormField()) {

            String value = null;
            if (encoding != null) {
                try {
                    value = fileItem.getString(encoding);
                } catch (UnsupportedEncodingException ex) {
                    if (logger.isWarnEnabled()) {
                        logger.warn("Could not decode multipart item '" + fileItem.getFieldName()
                                + "' with encoding '" + encoding + "': using platform default");
                    }
                    value = fileItem.getString();
                }
            } else {
                value = fileItem.getString();
            }
            String[] curParam = (String[]) multipartParameters.get(fileItem.getFieldName());
            if (curParam == null) {
                // simple form field
                multipartParameters.put(fileItem.getFieldName(), new String[] { value });
            } else {
                // array of simple form fields
                String[] newParam = StringUtils.addStringToArray(curParam, value);
                multipartParameters.put(fileItem.getFieldName(), newParam);
            }
        } else {

            if (fileItem.getSize() > 0) {
                // multipart file field
                CommonsMultipartFile file = new CommonsMultipartFile(fileItem);

                //? 3.0 ? API? 
                List<MultipartFile> fileList = new ArrayList<MultipartFile>();
                fileList.add(file);

                if (multipartFiles.put(fileItem.getName(), fileList) != null) { // CHANGED!!
                    throw new MultipartException("Multiple files for field name [" + file.getName()
                            + "] found - not supported by MultipartResolver");
                }
                if (logger.isDebugEnabled()) {
                    logger.debug("Found multipart file [" + file.getName() + "] of size " + file.getSize()
                            + " bytes with original filename [" + file.getOriginalFilename() + "], stored "
                            + file.getStorageDescription());
                }
            }

        }
    }
    return new MultipartParsingResult((MultiValueMap<String, MultipartFile>) multipartFiles,
            (Map<String, String[]>) multipartParameters, multipartParameters);

    //   return new MultipartParsingResult(multipartFiles, multipartParameters);
}

From source file:org.trustedanalytics.h2oscoringengine.publisher.restapi.validation.HostValidationRuleTest.java

@Test
public void validate_emptyHostKeyInData_exceptionThrown() {
    //given//  ww w.  ja  v a 2 s.  c  o  m
    MultiValueMap<String, String> requestWithEmptyHostKey = new LinkedMultiValueMap<>();
    requestWithEmptyHostKey.add(HostValidationRule.HOST_KEY, "");
    HostValidationRule rule = new HostValidationRule(new FormDataValidator());

    //then
    thrown.expect(ValidationException.class);

    //when
    rule.validate(requestWithEmptyHostKey);
}

From source file:comsat.sample.ui.SampleGroovyTemplateApplicationTests.java

@Test
public void testCreate() throws Exception {
    MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
    map.set("text", "FOO text");
    map.set("summary", "FOO");
    URI location = new TestRestTemplate().postForLocation("http://localhost:" + this.port, map);
    assertTrue("Wrong location:\n" + location, location.toString().contains("localhost:" + this.port));
}

From source file:ee.jaaaar.dreamestate.core.StreamingMultipartResolver.java

@Override
public MultipartHttpServletRequest resolveMultipart(HttpServletRequest request) throws MultipartException {

    // Create a new file upload handler
    ServletFileUpload upload = new ServletFileUpload();
    upload.setFileSizeMax(maxUploadSize);

    String encoding = determineEncoding(request);

    Map<String, String[]> multipartParameters = new HashMap<String, String[]>();

    MultiValueMap<String, MultipartFile> multipartFiles = new LinkedMultiValueMap<String, MultipartFile>();

    // Parse the request
    try {/*w  w  w .j a v a  2  s .  c  o  m*/
        FileItemIterator iter = upload.getItemIterator(request);
        while (iter.hasNext()) {
            FileItemStream item = iter.next();

            String name = item.getFieldName();
            InputStream stream = item.openStream();
            if (item.isFormField()) {

                String value = Streams.asString(stream, encoding);

                String[] curParam = (String[]) multipartParameters.get(name);
                if (curParam == null) {
                    // simple form field
                    multipartParameters.put(name, new String[] { value });
                } else {
                    // array of simple form fields
                    String[] newParam = StringUtils.addStringToArray(curParam, value);
                    multipartParameters.put(name, newParam);
                }
            } else {
                // Process the input stream
                MultipartFile file = new StreamingMultipartFile(item);
                multipartFiles.add(name, file);
            }
        }
    } catch (IOException e) {
        throw new MultipartException("something went wrong here", e);
    } catch (FileUploadException e) {
        throw new MultipartException("something went wrong here", e);
    }

    return new DefaultMultipartHttpServletRequest(request, multipartFiles, multipartParameters);
}