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:guru.nidi.ramltester.FormTest.java

@Test
public void formWithoutFormParameters() throws Exception {
    assertOneRequestViolationThat(/*from   w ww . jav  a  2  s  .co m*/
            test(aggregator, form,
                    post("/form/parameterless").contentType(MediaType.APPLICATION_FORM_URLENCODED),
                    jsonResponse(200, "", null)),
            equalTo("No formParameters given on action(POST /form/parameterless) mime-type('application/x-www-form-urlencoded')"));
}

From source file:com.pluralsight.controller.test.GoalControllerTest.java

@Test
public void addGoalInvalidTest() throws Exception {
    login("prasady:mindfire");

    this.mockMvc.perform(post("/addGoal").contentType(MediaType.APPLICATION_FORM_URLENCODED)
            .param("minutes", "-1").sessionAttr("goal", new Goal())).andExpect(view().name("addGoal"));
}

From source file:de.dominikschadow.duke.encounters.controller.SearchControllerTest.java

@Test
public void quickSearchEncounter() throws Exception {
    mvc.perform(post("/search").with(csrf()).contentType(MediaType.APPLICATION_FORM_URLENCODED)
            .param("quickSearch", "JavaOne 2015")).andExpect(status().isOk())
            .andExpect(view().name("encounters")).andExpect(model().attribute("encounters", hasSize(1)));
}

From source file:springfox.documentation.spring.web.readers.parameter.ParameterTypeReader.java

private static String queryOrForm(OperationContext context) {
    if (context.consumes().contains(MediaType.APPLICATION_FORM_URLENCODED)
            && context.httpMethod() == HttpMethod.POST) {
        return "form";
    }/*from   w ww  .ja  va 2 s .  c o m*/
    return "query";
}

From source file:be.solidx.hot.utils.AbstractHttpDataDeserializer.java

@Override
public Object processRequestData(byte[] data, String contentType) {
    MediaType ct = MediaType.parseMediaType(contentType);

    if (LOGGER.isDebugEnabled())
        LOGGER.debug("Content-type: " + contentType);

    Charset charset = ct.getCharSet() == null ? Charset.forName("UTF-8") : ct.getCharSet();

    // Subtypes arre used because of possible encoding definitions
    if (ct.getSubtype().equals(MediaType.APPLICATION_OCTET_STREAM.getSubtype())) {
        return data;
    } else if (ct.getSubtype().equals(MediaType.APPLICATION_JSON.getSubtype())) {
        try {/* w ww.j  a v  a  2s .c  o  m*/
            return fromJSON(data);
        } catch (IOException e) {
            throw new RuntimeException(e.getMessage(), e.getCause());
        }
    } else if (ct.getSubtype().equals(MediaType.APPLICATION_XML.getSubtype())) {
        try {
            return toXML(data, ct.getCharSet() == null ? Charset.forName("UTF-8") : ct.getCharSet());
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e.getCause());
        }
    } else if (ct.getSubtype().equals(MediaType.APPLICATION_FORM_URLENCODED.getSubtype())) {
        String decoded;
        try {
            decoded = URLDecoder.decode(new String(data, charset), charset.toString());
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e.getCause());
        }
        return fromFormUrlEncoded(decoded);
    } else {
        return new String(data, ct.getCharSet() == null ? Charset.forName("UTF-8") : ct.getCharSet());
    }
}

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 . ja v  a 2  s  . com
    if (t.getPassword() != null) {
        map.set("password", t.getPassword());
    }
    converter.write(map, MediaType.APPLICATION_FORM_URLENCODED, outputMessage);
}

From source file:de.dominikschadow.duke.encounters.controller.EncounterControllerTest.java

@Test
public void searchEncounter() throws Exception {
    mvc.perform(post("/encounters").with(csrf()).contentType(MediaType.APPLICATION_FORM_URLENCODED)
            .param("event", "JavaOne 2015").param("location", "San Francisco").param("likelihood", "ANY")
            .param("country", "USA")).andExpect(status().isOk()).andExpect(view().name("encounters"))
            .andExpect(model().attribute("encounters", hasSize(1)));
}

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

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

    if (isPreflight) {
        // preflight request, only prereg flag is sent
        params.set("prereg", "1");
    } else {//from  ww w.  j  a  va 2s  .co  m
        // please keep this in sync with rainstyle/apiregister.php
        params.set("userid", _uid);
        params.set("password", _password);
        params.set("nickname", _nickname);
        params.set("realname", _realname);
        params.set("email", _email);
        params.set("phone", _phone);
        params.set("idnumber", _idnumber);
        params.set("gender", Integer.toString(_gender));
        params.set("captcha", _captcha);
    }

    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://bbs.jnrain.com/rainstyle/apiregister.php", req,
            KBSRegisterResult.class);
}

From source file:com.pluralsight.controller.test.GoalControllerTest.java

@Test(expected = NestedServletException.class)
public void addGoalUnAuthTest() throws Exception {
    login("sambitc:mindfire");

    this.mockMvc.perform(post("/addGoal").contentType(MediaType.APPLICATION_FORM_URLENCODED)
            .param("minutes", "30").sessionAttr("goal", new Goal()));
}

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"));
}