Example usage for org.springframework.http MediaType APPLICATION_FORM_URLENCODED

List of usage examples for org.springframework.http MediaType APPLICATION_FORM_URLENCODED

Introduction

In this page you can find the example usage for org.springframework.http MediaType APPLICATION_FORM_URLENCODED.

Prototype

MediaType APPLICATION_FORM_URLENCODED

To view the source code for org.springframework.http MediaType APPLICATION_FORM_URLENCODED.

Click Source Link

Document

Public constant media type for application/x-www-form-urlencoded .

Usage

From source file:edu.infsci2560.LoginHelper.java

public static ResponseEntity<String> login(TestRestTemplate template, String route, String userName,
        String password) {/*from w  w  w  .  j a  v a 2s . c o  m*/
    HttpHeaders headers = getHeaders(template, route);
    headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
    form.set("username", userName);
    form.set("password", password);
    ResponseEntity<String> entity = template.exchange(route, HttpMethod.POST,
            new HttpEntity<MultiValueMap<String, String>>(form, headers), String.class);
    return entity;

}

From source file:org.intermine.app.net.request.PostRequest.java

@Override
public HttpHeaders getHeaders() {
    HttpHeaders headers = super.getHeaders();
    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);

    return headers;
}

From source file:org.jnrain.mobile.accounts.kbs.KBSLogoutRequest.java

@Override
public SimpleReturnCode loadDataFromNetwork() throws Exception {
    MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
    // request body intentionally empty

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    HttpEntity<MultiValueMap<String, String>> req = new HttpEntity<MultiValueMap<String, String>>(params,
            headers);//w ww  .java  2s .  c  o  m

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

From source file:org.jnrain.mobile.accounts.kbs.KBSCheckIDRequest.java

@Override
public KBSRegisterResult loadDataFromNetwork() throws Exception {
    MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
    params.set("id", _uid);

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    HttpEntity<MultiValueMap<String, String>> req = new HttpEntity<MultiValueMap<String, String>>(params,
            headers);//from ww  w  .ja  v  a2 s .co  m

    return getRestTemplate().postForObject("http://bbs.jnrain.com/rainstyle/apicheckid.php", req,
            KBSRegisterResult.class);
}

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

public AutologinRequestConverter() {
    setSupportedMediaTypes(Arrays.asList(MediaType.APPLICATION_FORM_URLENCODED));
}

From source file:guru.nidi.ramltester.FormTest.java

@Test
public void formTest() throws Exception {
    assertNoViolations(test(aggregator, form,
            post("/form").contentType(MediaType.APPLICATION_FORM_URLENCODED).param("param", "a+b"),
            jsonResponse(200, "", null)));
}

From source file:org.jnrain.mobile.accounts.kbs.KBSLoginRequest.java

@Override
public SimpleReturnCode loadDataFromNetwork() throws Exception {
    MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
    params.set("uid", _uid);
    params.set("psw", _password);

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    HttpEntity<MultiValueMap<String, String>> req = new HttpEntity<MultiValueMap<String, String>>(params,
            headers);//from   ww  w  . ja v a 2 s .  c o m

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

From source file:org.messic.android.util.RestJSONClient.java

/**
 * Rest POST petition to the server at the url param, sending all the post parameters defiend at formData. This post
 * return an object (json marshalling) of class defined at clazz parameter. You should register a
 * {@link RestListener} in order to obtain the returned object, this is because the petition is done in an async
 * process.//  w ww.  j  a v  a2  s  . c o m
 * 
 * @param url {@link string} URL to attack
 * @param formData {@link MultiValueMap}<?,?/> map of parameters to send
 * @param clazz Class<T/> class that you will marshall to a json object
 * @param rl {@link RestListener} listener to push the object returned
 */
public static <T> void post(final String url, MultiValueMap<?, ?> formData, final Class<T> clazz,
        final RestListener<T> rl) {
    final RestTemplate restTemplate = new RestTemplate();
    restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());

    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
    // Sending multipart/form-data
    requestHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    // Populate the MultiValueMap being serialized and headers in an HttpEntity object to use for the request
    final HttpEntity<MultiValueMap<?, ?>> requestEntity = new HttpEntity<MultiValueMap<?, ?>>(formData,
            requestHeaders);

    AsyncTask<Void, Void, Void> at = new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            try {
                ResponseEntity<T> response = restTemplate.exchange(url, HttpMethod.POST, requestEntity, clazz);
                rl.response(response.getBody());
            } catch (Exception e) {
                rl.fail(e);
            }
            return null;
        }

    };

    at.execute();
}

From source file:nl.flotsam.calendar.web.UriHttpMessageConverter.java

public UriHttpMessageConverter() {
    super(MediaType.TEXT_PLAIN, MediaType.APPLICATION_FORM_URLENCODED);
}

From source file:guru.nidi.ramltester.FormTest.java

@Test
public void undefinedParam() throws Exception {
    assertOneRequestViolationThat(//from ww w.j a  v a  2 s  . co m
            test(aggregator, form,
                    post("/form").contentType(MediaType.APPLICATION_FORM_URLENCODED).param("hula", "a+b"),
                    jsonResponse(200, "", null)),
            equalTo("Form parameter 'hula' on action(POST /form) is not defined"));
}