Java Code Examples for org.springframework.http.MediaType#APPLICATION_FORM_URLENCODED

The following examples show how to use org.springframework.http.MediaType#APPLICATION_FORM_URLENCODED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RestfulTest.java    From WeEvent with Apache License 2.0 6 votes vote down vote up
@Test
public void testPublishContentIs10K() {
    MultiValueMap<String, String> eventData = new LinkedMultiValueMap<>();
    eventData.add("topic", this.topicName);
    eventData.add("content", get10KStr());

    HttpHeaders headers = new HttpHeaders();
    MediaType type = MediaType.APPLICATION_FORM_URLENCODED;
    headers.setContentType(type);
    headers.add("Accept", MediaType.APPLICATION_JSON.toString());

    HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(eventData, headers);
    ResponseEntity<SendResult> rsp = rest.postForEntity(url + "publish", request, SendResult.class);
    log.info("publish, status: " + rsp.getStatusCode() + " body: " + rsp.getBody());
    Assert.assertEquals(200, rsp.getStatusCodeValue());
    Assert.assertNotNull(rsp.getBody());
    Assert.assertTrue(rsp.getBody().getEventId().contains("-"));
}
 
Example 2
Source File: RestfulTest.java    From WeEvent with Apache License 2.0 6 votes vote down vote up
@Test
public void testPublishContentGt10K() {
    MultiValueMap<String, String> eventData = new LinkedMultiValueMap<>();
    eventData.add("topic", this.topicName);
    eventData.add("content", get10KStr() + "s");

    HttpHeaders headers = new HttpHeaders();
    MediaType type = MediaType.APPLICATION_FORM_URLENCODED;
    headers.setContentType(type);
    headers.add("Accept", MediaType.APPLICATION_JSON.toString());

    HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(eventData, headers);
    ResponseEntity<String> rsp = rest.postForEntity(url + "publish", request, String.class);
    log.info("publish, status: " + rsp.getStatusCode() + " body: " + rsp.getBody());
    Assert.assertEquals(200, rsp.getStatusCodeValue());
    Assert.assertNotNull(rsp.getBody());
    Assert.assertTrue(rsp.getBody().contains(ErrorCode.EVENT_CONTENT_EXCEEDS_MAX_LENGTH.getCode() + ""));
}
 
Example 3
Source File: BodyExtractors.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Extractor to read form data into {@code MultiValueMap<String, String>}.
 * <p>As of 5.1 this method can also be used on the client side to read form
 * data from a server response (e.g. OAuth).
 * @return {@code BodyExtractor} for form data
 */
public static BodyExtractor<Mono<MultiValueMap<String, String>>, ReactiveHttpInputMessage> toFormData() {
	return (message, context) -> {
		ResolvableType elementType = FORM_DATA_TYPE;
		MediaType mediaType = MediaType.APPLICATION_FORM_URLENCODED;
		HttpMessageReader<MultiValueMap<String, String>> reader = findReader(elementType, mediaType, context);
		return readToMono(message, context, elementType, reader);
	};
}
 
Example 4
Source File: BodyExtractors.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Extractor to read form data into {@code MultiValueMap<String, String>}.
 * <p>As of 5.1 this method can also be used on the client side to read form
 * data from a server response (e.g. OAuth).
 * @return {@code BodyExtractor} for form data
 */
public static BodyExtractor<Mono<MultiValueMap<String, String>>, ReactiveHttpInputMessage> toFormData() {
	return (message, context) -> {
		ResolvableType elementType = FORM_DATA_TYPE;
		MediaType mediaType = MediaType.APPLICATION_FORM_URLENCODED;
		HttpMessageReader<MultiValueMap<String, String>> reader = findReader(elementType, mediaType, context);
		return readToMono(message, context, elementType, reader);
	};
}
 
Example 5
Source File: FastJsonHttpMessageConverter.java    From mcg-helper with Apache License 2.0 2 votes vote down vote up
public FastJsonHttpMessageConverter() {

        super(MediaType.APPLICATION_JSON, MediaType.APPLICATION_FORM_URLENCODED);
    }