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:nl.flotsam.calendar.web.UriHttpMessageConverter.java

@Override
protected void writeInternal(URI uri, HttpOutputMessage outputMessage)
        throws IOException, HttpMessageNotWritableException {
    OutputStream out = null;//from   w  w w. j  av a  2  s. c  o m
    try {
        out = outputMessage.getBody();
        if (MediaType.APPLICATION_FORM_URLENCODED == outputMessage.getHeaders().getContentType()) {
            IOUtils.write(URLEncoder.encode(uri.toASCIIString(), "UTF-8"), out, "US-ASCII");
        } else {
            IOUtils.write(uri.toASCIIString(), out, "US-ASCII");
        }
    } finally {
        IOUtils.closeQuietly(out);
    }
}

From source file:nl.avans.ivh5a1.proftaak.insurance.InsuranceControllerTest.java

/**
* Hiermee wordt getest wat er gebeurt wanneer er een leeg form wordt ingediend
* Indien dit goed gaat zal de return url hetzelfde zijn als de aanroep url
* De insuranceCode kan geen errors bevatten en is daarom ook niet meegenomen in deze test
*     *//*from w  w  w . j  a  v a  2 s .c o m*/
@Test
public void PostEmptyForm() throws Exception {
    Insurance insuranceTemp = new Insurance();
    int cOCnr = 100100;
    logger.info("--- Post empty form ----");

    mockMvc.perform(post("/insurance/create/" + cOCnr).contentType(MediaType.APPLICATION_FORM_URLENCODED)
            .sessionAttr("insurance", insuranceTemp)).andExpect(status().isOk())
            .andExpect(view().name("views/insurance/create"))

            .andExpect(model().attributeHasFieldErrors("insurance", "insuranceName"))
            .andExpect(model().attributeHasFieldErrors("insurance", "insurancePrice"))
            .andExpect(model().attributeHasFieldErrors("insurance", "description"))

            .andExpect(model().attribute("insurance", hasProperty("insuranceName", isEmptyOrNullString())))
            .andExpect(model().attribute("insurance", hasProperty("insurancePrice", closeTo(0.0, 0))))
            .andExpect(model().attribute("insurance", hasProperty("description", isEmptyOrNullString())));

}

From source file:am.ik.categolj2.app.authentication.AuthenticationHelper.java

public HttpEntity<MultiValueMap<String, Object>> createRopRequest(String username, String password) {
    MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
    params.add("username", username);
    params.add("password", password);
    params.add("grant_type", "password");
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    byte[] clientInfo = (adminClientProperties.getClientId() + ":" + adminClientProperties.getClientSecret())
            .getBytes(StandardCharsets.UTF_8);
    String basic = new String(Base64.getEncoder().encode(clientInfo), StandardCharsets.UTF_8);
    headers.set(com.google.common.net.HttpHeaders.AUTHORIZATION, "Basic " + basic);
    return new HttpEntity<>(params, headers);
}

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

@Test
public void formWithSchema() throws Exception {
    final RamlDefinition form = RamlLoaders.fromClasspath(getClass())
            .addSchemaValidator(new FormEncodedSchemaValidator()).load("form.raml");

    assertOneRequestViolationThat(/*from   w ww .j  ava 2 s.c o  m*/
            test(aggregator, form, post("/form/schema").contentType(MediaType.APPLICATION_FORM_URLENCODED),
                    jsonResponse(200, "", null)),
            equalTo("No schema allowed on action(POST /form/schema) mime-type('application/x-www-form-urlencoded')"));
}

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 {/*  www  . ja  v  a  2  s.com*/
        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:platform.filter.HttpPutDeleteFormContentFilter.java

private boolean isFormContentType(HttpServletRequest request) {
    String contentType = request.getContentType();
    if (contentType != null) {
        try {//from  w  w w  .  j  ava2  s .  c om
            MediaType mediaType = MediaType.parseMediaType(contentType);
            return (MediaType.APPLICATION_FORM_URLENCODED.includes(mediaType));
        } catch (IllegalArgumentException ex) {
            return false;
        }
    } else {
        return false;
    }
}

From source file:de.fau.amos4.test.integration.ClientEditTest.java

@Test
@WithUserDetails("datev@example.com")
public void testThatClientEditSubmitChangesPassword() throws Exception {
    BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
    Client client = new Client();
    client.setPasswordHash(encoder.encode("datev"));

    Mockito.doReturn(client).when(clientService).getClientByEmail(Matchers.<String>any());
    Assert.assertEquals(client, clientService.getClientByEmail("dfjashf"));

    mockMvc.perform(post("/client/edit/submit").with(csrf()).contentType(MediaType.APPLICATION_FORM_URLENCODED)
            .param("NewPassword", "test").param("ConfirmPassword", "test").param("OldPassword", "datev")
            .sessionAttr("client", client)).andDo(print()).andExpect(status().is3xxRedirection())
            .andExpect(view().name("redirect:/client/dashboard?m=profileChanged"));
}

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

@Test
public void testLogin() throws Exception {
    HttpHeaders headers = getHeaders();/*  w w w . j a v a  2s .c o  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:com.github.hateoas.forms.spring.xhtml.XhtmlResourceMessageConverter.java

public XhtmlResourceMessageConverter() {
    this.setSupportedMediaTypes(Arrays.asList(MediaType.TEXT_HTML, MediaType.APPLICATION_FORM_URLENCODED));
}