Java Code Examples for org.springframework.util.MimeTypeUtils#generateMultipartBoundary()

The following examples show how to use org.springframework.util.MimeTypeUtils#generateMultipartBoundary() . 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: RequestPartIntegrationTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test  // SPR-13319
public void standardMultipartResolverWithEncodedFileName() throws Exception {
	byte[] boundary = MimeTypeUtils.generateMultipartBoundary();
	String boundaryText = new String(boundary, "US-ASCII");
	Map<String, String> params = Collections.singletonMap("boundary", boundaryText);

	String content =
			"--" + boundaryText + "\n" +
			"Content-Disposition: form-data; name=\"file\"; filename*=\"utf-8''%C3%A9l%C3%A8ve.txt\"\n" +
			"Content-Type: text/plain\n" +
			"Content-Length: 7\n" +
			"\n" +
			"content\n" +
			"--" + boundaryText + "--";

	RequestEntity<byte[]> requestEntity =
			RequestEntity.post(new URI(baseUrl + "/standard-resolver/spr13319"))
					.contentType(new MediaType(MediaType.MULTIPART_FORM_DATA, params))
					.body(content.getBytes(StandardCharsets.US_ASCII));

	ByteArrayHttpMessageConverter converter = new ByteArrayHttpMessageConverter();
	converter.setSupportedMediaTypes(Collections.singletonList(MediaType.MULTIPART_FORM_DATA));
	this.restTemplate.setMessageConverters(Collections.singletonList(converter));

	ResponseEntity<Void> responseEntity = restTemplate.exchange(requestEntity, Void.class);
	assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
}
 
Example 2
Source File: RequestPartIntegrationTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test  // SPR-13319
public void standardMultipartResolverWithEncodedFileName() throws Exception {
	byte[] boundary = MimeTypeUtils.generateMultipartBoundary();
	String boundaryText = new String(boundary, "US-ASCII");
	Map<String, String> params = Collections.singletonMap("boundary", boundaryText);

	String content =
			"--" + boundaryText + "\n" +
			"Content-Disposition: form-data; name=\"file\"; filename*=\"utf-8''%C3%A9l%C3%A8ve.txt\"\n" +
			"Content-Type: text/plain\n" +
			"Content-Length: 7\n" +
			"\n" +
			"content\n" +
			"--" + boundaryText + "--";

	RequestEntity<byte[]> requestEntity =
			RequestEntity.post(new URI(baseUrl + "/standard-resolver/spr13319"))
					.contentType(new MediaType(MediaType.MULTIPART_FORM_DATA, params))
					.body(content.getBytes(StandardCharsets.US_ASCII));

	ByteArrayHttpMessageConverter converter = new ByteArrayHttpMessageConverter();
	converter.setSupportedMediaTypes(Collections.singletonList(MediaType.MULTIPART_FORM_DATA));
	this.restTemplate.setMessageConverters(Collections.singletonList(converter));

	ResponseEntity<Void> responseEntity = restTemplate.exchange(requestEntity, Void.class);
	assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
}
 
Example 3
Source File: RequestPartIntegrationTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test  // SPR-13319
public void standardMultipartResolverWithEncodedFileName() throws Exception {
	byte[] boundary = MimeTypeUtils.generateMultipartBoundary();
	String boundaryText = new String(boundary, "US-ASCII");
	Map<String, String> params = Collections.singletonMap("boundary", boundaryText);

	String content =
			"--" + boundaryText + "\n" +
			"Content-Disposition: form-data; name=\"file\"; filename*=\"utf-8''%C3%A9l%C3%A8ve.txt\"\n" +
			"Content-Type: text/plain\n" +
			"Content-Length: 7\n" +
			"\n" +
			"content\n" +
			"--" + boundaryText + "--";

	RequestEntity<byte[]> requestEntity =
			RequestEntity.post(new URI(baseUrl + "/standard-resolver/spr13319"))
					.contentType(new MediaType(MediaType.MULTIPART_FORM_DATA, params))
					.body(content.getBytes(Charset.forName("us-ascii")));

	ByteArrayHttpMessageConverter converter = new ByteArrayHttpMessageConverter();
	converter.setSupportedMediaTypes(Collections.singletonList(MediaType.MULTIPART_FORM_DATA));
	this.restTemplate.setMessageConverters(Collections.singletonList(converter));

	ResponseEntity<Void> responseEntity = restTemplate.exchange(requestEntity, Void.class);
	assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
}
 
Example 4
Source File: FormHttpMessageConverter.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Generate a multipart boundary.
 * <p>This implementation delegates to
 * {@link MimeTypeUtils#generateMultipartBoundary()}.
 */
protected byte[] generateMultipartBoundary() {
	return MimeTypeUtils.generateMultipartBoundary();
}
 
Example 5
Source File: MultipartHttpMessageWriter.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Generate a multipart boundary.
 * <p>By default delegates to {@link MimeTypeUtils#generateMultipartBoundary()}.
 */
protected byte[] generateMultipartBoundary() {
	return MimeTypeUtils.generateMultipartBoundary();
}
 
Example 6
Source File: FormHttpMessageConverter.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Generate a multipart boundary.
 * <p>This implementation delegates to
 * {@link MimeTypeUtils#generateMultipartBoundary()}.
 */
protected byte[] generateMultipartBoundary() {
	return MimeTypeUtils.generateMultipartBoundary();
}
 
Example 7
Source File: MultipartHttpMessageWriter.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Generate a multipart boundary.
 * <p>By default delegates to {@link MimeTypeUtils#generateMultipartBoundary()}.
 */
protected byte[] generateMultipartBoundary() {
	return MimeTypeUtils.generateMultipartBoundary();
}
 
Example 8
Source File: FormHttpMessageConverter.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Generate a multipart boundary.
 * <p>This implementation delegates to
 * {@link MimeTypeUtils#generateMultipartBoundary()}.
 */
protected byte[] generateMultipartBoundary() {
	return MimeTypeUtils.generateMultipartBoundary();
}
 
Example 9
Source File: FormHttpMessageConverter.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Generate a multipart boundary.
 * <p>This implementation delegates to
 * {@link MimeTypeUtils#generateMultipartBoundary()}.
 */
protected byte[] generateMultipartBoundary() {
	return MimeTypeUtils.generateMultipartBoundary();
}
 
Example 10
Source File: FormHttpMessageConverter.java    From onetwo with Apache License 2.0 2 votes vote down vote up
/**
 * Generate a multipart boundary.
 * <p>This implementation delegates to
 * {@link MimeTypeUtils#generateMultipartBoundary()}.
 */
protected byte[] generateMultipartBoundary() {
	return MimeTypeUtils.generateMultipartBoundary();
}