Java Code Examples for org.springframework.http.MediaType#getParameter()

The following examples show how to use org.springframework.http.MediaType#getParameter() . 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: AbstractMockWebServerTestCase.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private MockResponse multipartRequest(RecordedRequest request) {
	MediaType mediaType = MediaType.parseMediaType(request.getHeader("Content-Type"));
	assertTrue(mediaType.isCompatibleWith(MediaType.MULTIPART_FORM_DATA));
	String boundary = mediaType.getParameter("boundary");
	Buffer body = request.getBody();
	try {
		assertPart(body, "form-data", boundary, "name 1", "text/plain", "value 1");
		assertPart(body, "form-data", boundary, "name 2", "text/plain", "value 2+1");
		assertPart(body, "form-data", boundary, "name 2", "text/plain", "value 2+2");
		assertFilePart(body, "form-data", boundary, "logo", "logo.jpg", "image/jpeg");
	}
	catch (EOFException ex) {
		throw new IllegalStateException(ex);
	}
	return new MockResponse().setResponseCode(200);
}
 
Example 2
Source File: AbstractMockWebServerTestCase.java    From java-technology-stack with MIT License 6 votes vote down vote up
private MockResponse multipartRequest(RecordedRequest request) {
	MediaType mediaType = MediaType.parseMediaType(request.getHeader("Content-Type"));
	assertTrue(mediaType.isCompatibleWith(MediaType.MULTIPART_FORM_DATA));
	String boundary = mediaType.getParameter("boundary");
	Buffer body = request.getBody();
	try {
		assertPart(body, "form-data", boundary, "name 1", "text/plain", "value 1");
		assertPart(body, "form-data", boundary, "name 2", "text/plain", "value 2+1");
		assertPart(body, "form-data", boundary, "name 2", "text/plain", "value 2+2");
		assertFilePart(body, "form-data", boundary, "logo", "logo.jpg", "image/jpeg");
	}
	catch (EOFException ex) {
		throw new IllegalStateException(ex);
	}
	return new MockResponse().setResponseCode(200);
}
 
Example 3
Source File: ProducesRequestCondition.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private boolean matchParameters(MediaType acceptedMediaType) {
	for (String name : getMediaType().getParameters().keySet()) {
		String s1 = getMediaType().getParameter(name);
		String s2 = acceptedMediaType.getParameter(name);
		if (StringUtils.hasText(s1) && StringUtils.hasText(s2) && !s1.equalsIgnoreCase(s2)) {
			return false;
		}
	}
	return true;
}
 
Example 4
Source File: ProducesRequestCondition.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private boolean matchParameters(MediaType acceptedMediaType) {
	for (String name : getMediaType().getParameters().keySet()) {
		String s1 = getMediaType().getParameter(name);
		String s2 = acceptedMediaType.getParameter(name);
		if (StringUtils.hasText(s1) && StringUtils.hasText(s2) && !s1.equalsIgnoreCase(s2)) {
			return false;
		}
	}
	return true;
}
 
Example 5
Source File: EncoderHttpMessageWriter.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private boolean matchParameters(MediaType streamingMediaType, MediaType mediaType) {
	for (String name : streamingMediaType.getParameters().keySet()) {
		String s1 = streamingMediaType.getParameter(name);
		String s2 = mediaType.getParameter(name);
		if (StringUtils.hasText(s1) && StringUtils.hasText(s2) && !s1.equalsIgnoreCase(s2)) {
			return false;
		}
	}
	return true;
}