use of org.springframework.http.converter.StringHttpMessageConverter in project spring-framework by spring-projects.
the class RouterFunctionMapping method initMessageConverters.
/**
* Initializes a default set of {@linkplain HttpMessageConverter message converters}.
*/
private void initMessageConverters() {
List<HttpMessageConverter<?>> messageConverters = new ArrayList<>(4);
messageConverters.add(new ByteArrayHttpMessageConverter());
messageConverters.add(new StringHttpMessageConverter());
if (!shouldIgnoreXml) {
try {
messageConverters.add(new SourceHttpMessageConverter<>());
} catch (Error err) {
// Ignore when no TransformerFactory implementation is available
}
}
messageConverters.add(new AllEncompassingFormHttpMessageConverter());
this.messageConverters = messageConverters;
}
use of org.springframework.http.converter.StringHttpMessageConverter in project spring-framework by spring-projects.
the class HttpEntityMethodProcessorTests method handleReturnValueCharSequence.
// SPR-13423
@Test
public void handleReturnValueCharSequence() throws Exception {
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new ByteArrayHttpMessageConverter());
converters.add(new StringHttpMessageConverter());
Method method = getClass().getDeclaredMethod("handle");
MethodParameter returnType = new MethodParameter(method, -1);
ResponseEntity<StringBuilder> returnValue = ResponseEntity.ok(new StringBuilder("Foo"));
HttpEntityMethodProcessor processor = new HttpEntityMethodProcessor(converters);
processor.handleReturnValue(returnValue, returnType, mavContainer, webRequest);
assertThat(servletResponse.getHeader("Content-Type")).isEqualTo("text/plain;charset=ISO-8859-1");
assertThat(servletResponse.getContentAsString()).isEqualTo("Foo");
}
use of org.springframework.http.converter.StringHttpMessageConverter in project spring-framework by spring-projects.
the class DefaultServerResponseBuilderTests method bodyPublisher.
@Test
public void bodyPublisher() throws Exception {
String body = "foo";
Publisher<String> publisher = Mono.just(body);
ServerResponse response = ServerResponse.ok().body(publisher);
MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", "https://example.com");
MockHttpServletResponse mockResponse = new MockHttpServletResponse();
mockRequest.setAsyncSupported(true);
ServerResponse.Context context = () -> Collections.singletonList(new StringHttpMessageConverter());
ModelAndView mav = response.writeTo(mockRequest, mockResponse, context);
assertThat(mav).isNull();
assertThat(mockResponse.getContentAsString()).isEqualTo(body);
}
use of org.springframework.http.converter.StringHttpMessageConverter in project spring-framework by spring-projects.
the class DefaultServerResponseBuilderTests method bodyCompletionStage.
@Test
public void bodyCompletionStage() throws Exception {
String body = "foo";
CompletionStage<String> completionStage = CompletableFuture.completedFuture(body);
ServerResponse response = ServerResponse.ok().body(completionStage);
MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", "https://example.com");
MockHttpServletResponse mockResponse = new MockHttpServletResponse();
mockRequest.setAsyncSupported(true);
ServerResponse.Context context = () -> Collections.singletonList(new StringHttpMessageConverter());
ModelAndView mav = response.writeTo(mockRequest, mockResponse, context);
assertThat(mav).isNull();
assertThat(mockResponse.getContentAsString()).isEqualTo(body);
}
use of org.springframework.http.converter.StringHttpMessageConverter in project spring-framework by spring-projects.
the class ContentRequestMatchersIntegrationTests method setup.
@BeforeEach
public void setup() {
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new StringHttpMessageConverter());
converters.add(new MappingJackson2HttpMessageConverter());
this.restTemplate = new RestTemplate();
this.restTemplate.setMessageConverters(converters);
this.mockServer = MockRestServiceServer.createServer(this.restTemplate);
}
Aggregations