Example usage for org.springframework.util MultiValueMap set

List of usage examples for org.springframework.util MultiValueMap set

Introduction

In this page you can find the example usage for org.springframework.util MultiValueMap set.

Prototype

void set(K key, @Nullable V value);

Source Link

Document

Set the given single value under the given key.

Usage

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

@Test
public void testCreateValidation() throws Exception {
    MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
    map.set("text", "");
    map.set("summary", "");
    ResponseEntity<String> entity = new TestRestTemplate().postForEntity("http://localhost:" + this.port, map,
            String.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
    assertTrue("Wrong body ('required' validation error doesn't match):\n" + entity.getBody(),
            entity.getBody().contains("is required"));
}

From source file:com.miserablemind.api.consumer.tradeking.api.impl.StreamingTemplate.java

@Override
public Stream quotesAndTradesStream(final List<StreamListener> listeners, String[] quotes) {
    String quotesString = this.buildCommaSeparatedParameterValue(quotes);
    Stream stream = new ThreadedStreamConsumer() {
        protected StreamReader getStreamReader() throws StreamCreationException {
            MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>(1);
            parameters.set("symbols", String.valueOf(quotesString));
            return createStream(HttpMethod.POST, URL_STREAM_QUOTES_TRADES, parameters, listeners);
        }/* ww w . j a  va2s. c  o  m*/
    };
    stream.open();
    return stream;
}

From source file:com.ginema.ApplicationTests.java

@Test
public void loginSucceeds() {
    ResponseEntity<String> response = template.getForEntity("http://localhost:" + port + "/ginema-server/login",
            String.class);
    String csrf = getCsrf(response.getBody());
    MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
    form.set("username", "user");
    form.set("password", "password");
    form.set("_csrf", csrf);
    HttpHeaders headers = new HttpHeaders();
    headers.put("COOKIE", response.getHeaders().get("Set-Cookie"));
    RequestEntity<MultiValueMap<String, String>> request = new RequestEntity<MultiValueMap<String, String>>(
            form, headers, HttpMethod.POST, URI.create("http://localhost:" + port + "/ginema-server/login"));
    ResponseEntity<Void> location = template.exchange(request, Void.class);
    assertEquals("http://localhost:" + port + "/ginema-server/", location.getHeaders().getFirst("Location"));
}

From source file:com.example.ProxyAuthorizationServerTokenServices.java

private MultiValueMap<String, String> createForm(String refreshToken, TokenRequest tokenRequest) {
    MultiValueMap<String, String> form = new LinkedMultiValueMap<>();
    form.set(OAuth2Utils.GRANT_TYPE, "refresh_token");
    form.set("refresh_token", refreshToken);
    if (!tokenRequest.getScope().isEmpty()) {
        form.set(OAuth2Utils.SCOPE, OAuth2Utils.formatParameterList(tokenRequest.getScope()));
    }//from   w ww.  j  av  a  2s . co  m
    return form;
}

From source file:com.naver.template.social.SocialPostBO.java

public void postToFacebook(String userId) {
    Facebook facebook = simpleSocialConnectionFactory.getFacebook(userId);

    String imageUrl = "http://cfile9.uf.tistory.com/image/1771223E4E3EAE20032F8B";
    String linkUrl = "";
    String linkName = "?";
    String caption = "lovepin.it";
    String description = "? blah blah";
    String actions = "[{ name: 'Get the LOVEPIN App', link: 'http://lovepin.it/apps' }]";

    MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
    map.set("picture", imageUrl);
    map.set("link", linkUrl);
    map.set("name", linkName);
    map.set("caption", caption);
    map.set("description", description);
    map.set("actions", actions);

    String providerUserId = simpleSocialConnectionFactory.getConnectionRepository(userId)
            .getPrimaryConnection(Facebook.class).getKey().getProviderUserId();

    try {//from  w ww .  j  a va2s  .  c  om
        facebook.post(providerUserId, "feed", map);
    } catch (NotAuthorizedException ex) {
        //
    } catch (OperationNotPermittedException ex) {
        //
    } catch (ApiException ex) {
        //
    } catch (ResourceAccessException ex) {
        //
    }
}

From source file:org.craftercms.engine.http.impl.AlfrescoHttpProxy.java

@Override
protected String createTargetQueryString(HttpServletRequest request) {
    String queryString = request.getQueryString();
    String alfTicket = getCurrentTicket(request);

    if (queryString == null) {
        queryString = "";
    }//from  ww  w .  j  av  a2 s  .c  o m

    if (alfTicket != null) {
        MultiValueMap<String, String> queryParams = HttpUtils.getParamsFromQueryString(queryString);
        queryParams.set("alf_ticket", alfTicket);

        try {
            queryString = HttpUtils.getQueryStringFromParams(queryParams, "UTF-8");
            //queryString = URLDecoder.decode(queryString, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            logger.error("Unable to encode params " + queryParams + " into a query string", e);
        }
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug("'" + alfrescoTicketCookieName + "' cookie not specified. Proxy request will be "
                    + "generated without it");
        }

        if (StringUtils.isNotEmpty(queryString)) {
            queryString = "?" + queryString;
        }
    }

    return queryString;
}

From source file:org.cloudfoundry.identity.uaa.login.integration.AutologinContollerIntegrationTests.java

@Test
public void testGetCodeWithFormEncodedRequest() {
    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    MultiValueMap<String, String> request = new LinkedMultiValueMap<String, String>();
    request.set("username", testAccounts.getUserName());
    request.set("password", testAccounts.getPassword());
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> entity = serverRunning.getRestTemplate().exchange(serverRunning.getUrl("/autologin"),
            HttpMethod.POST, new HttpEntity<MultiValueMap>(request, headers), Map.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
    @SuppressWarnings("unchecked")
    Map<String, Object> result = (Map<String, Object>) entity.getBody();
    assertNotNull(result.get("code"));
}

From source file:com.interop.webapp.WebAppTests.java

@Test
public void testLogin() throws Exception {
    HttpHeaders headers = getHeaders();//from  w  w  w.  ja v a 2  s  .co  m
    headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
    form.set("username", "user");
    form.set("password", "user");
    ResponseEntity<String> entity = new TestRestTemplate().exchange("http://localhost:" + this.port + "/login",
            HttpMethod.POST, new HttpEntity<MultiValueMap<String, String>>(form, headers), String.class);
    assertEquals(HttpStatus.FOUND, entity.getStatusCode());
    assertTrue("Wrong location:\n" + entity.getHeaders(),
            entity.getHeaders().getLocation().toString().endsWith(port + "/"));
    assertNotNull("Missing cookie:\n" + entity.getHeaders(), entity.getHeaders().get("Set-Cookie"));
}

From source file:org.cloudfoundry.identity.uaa.login.AutologinRequestConverter.java

@Override
protected void writeInternal(AutologinRequest t, HttpOutputMessage outputMessage)
        throws IOException, HttpMessageNotWritableException {
    MultiValueMap<String, String> map = new LinkedMaskingMultiValueMap<String, String>("password");
    if (t.getUsername() != null) {
        map.set("username", t.getUsername());
    }//from  w  w w  . jav a 2  s  . co m
    if (t.getPassword() != null) {
        map.set("password", t.getPassword());
    }
    converter.write(map, MediaType.APPLICATION_FORM_URLENCODED, outputMessage);
}

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 2 s  . co 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);
}