use of cn.taketoday.http.server.ServletServerHttpResponse in project today-infrastructure by TAKETODAY.
the class ReactiveTypeHandlerTests method testEmitterContentType.
private void testEmitterContentType(String expected) throws Exception {
ServletServerHttpResponse message = new ServletServerHttpResponse(this.servletResponse);
ResponseBodyEmitter emitter = handleValue(Flux.empty(), Flux.class, ResolvableType.fromClass(String.class));
emitter.extendResponse(webRequest);
assertThat(message.getHeaders().getContentType().toString()).isEqualTo(expected);
resetRequest();
}
use of cn.taketoday.http.server.ServletServerHttpResponse in project today-framework by TAKETODAY.
the class ReactiveTypeHandlerTests method writeStreamJson.
@Test
public void writeStreamJson() throws Exception {
this.servletRequest.addHeader("Accept", "application/x-ndjson");
Sinks.Many<Bar> sink = Sinks.many().unicast().onBackpressureBuffer();
ResponseBodyEmitter emitter = handleValue(sink.asFlux(), Flux.class, ResolvableType.fromClass(Bar.class));
EmitterHandler emitterHandler = new EmitterHandler();
emitter.initialize(emitterHandler);
ServletServerHttpResponse message = new ServletServerHttpResponse(this.servletResponse);
emitter.extendResponse(message);
Bar bar1 = new Bar("foo");
Bar bar2 = new Bar("bar");
sink.tryEmitNext(bar1);
sink.tryEmitNext(bar2);
sink.tryEmitComplete();
assertThat(message.getHeaders().getContentType().toString()).isEqualTo("application/x-ndjson");
assertThat(emitterHandler.getValues()).isEqualTo(Arrays.asList(bar1, "\n", bar2, "\n"));
}
use of cn.taketoday.http.server.ServletServerHttpResponse in project today-framework by TAKETODAY.
the class ObjectToStringHttpMessageConverterTests method setup.
@BeforeEach
public void setup() {
ConversionService conversionService = new DefaultConversionService();
this.converter = new ObjectToStringHttpMessageConverter(conversionService);
this.servletResponse = new MockHttpServletResponse();
this.response = new ServletServerHttpResponse(this.servletResponse);
}
use of cn.taketoday.http.server.ServletServerHttpResponse in project today-framework by TAKETODAY.
the class RequestResponseBodyAdviceChainTests method setup.
@BeforeEach
public void setup() {
this.body = "body";
this.contentType = MediaType.TEXT_PLAIN;
this.paramType = new MethodParameter(ReflectionUtils.getMethod(this.getClass(), "handle", String.class), 0);
this.returnType = new MethodParameter(ReflectionUtils.getMethod(this.getClass(), "handle", String.class), -1);
MockHttpServletRequest servletRequest = new MockHttpServletRequest();
this.request = new ServletServerHttpRequest(servletRequest);
MockHttpServletResponse servletResponse = new MockHttpServletResponse();
this.response = new ServletServerHttpResponse(servletResponse);
this.requestContext = new ServletRequestContext(null, servletRequest, servletResponse);
}
use of cn.taketoday.http.server.ServletServerHttpResponse in project today-framework by TAKETODAY.
the class ReactiveTypeHandlerTests method testEmitterContentType.
private void testEmitterContentType(String expected) throws Exception {
ServletServerHttpResponse message = new ServletServerHttpResponse(this.servletResponse);
ResponseBodyEmitter emitter = handleValue(Flux.empty(), Flux.class, ResolvableType.fromClass(String.class));
emitter.extendResponse(message);
assertThat(message.getHeaders().getContentType().toString()).isEqualTo(expected);
resetRequest();
}
Aggregations