@Test public void wrapConcurrentResult_ResponseEntity() throws Exception { this.returnValueHandlers.addHandler(new HttpEntityMethodProcessor(this.converters)); ServletInvocableHandlerMethod handlerMethod = getHandlerMethod(new ResponseEntityHandler(), "handleDeferred"); handlerMethod = handlerMethod.wrapConcurrentResult(new ResponseEntity<>("bar", HttpStatus.OK)); handlerMethod.invokeAndHandle(this.webRequest, this.mavContainer); assertEquals("bar", this.response.getContentAsString()); }
private void wrapConcurrentResult_ResponseBody(Object handler, Object result, Class<?> expectedReturnType) throws Exception { this.returnValueHandlers.addHandler(new ModelAndViewMethodReturnValueHandler()); this.returnValueHandlers.addHandler(new RequestResponseBodyMethodProcessor(this.converters)); ServletInvocableHandlerMethod handlerMethod = getHandlerMethod(handler, "handle"); handlerMethod = handlerMethod.wrapConcurrentResult(result); handlerMethod.invokeAndHandle(this.webRequest, this.mavContainer); assertEquals((result != null ? result.toString() : ""), this.response.getContentAsString()); assertEquals(expectedReturnType, handlerMethod.getReturnValueType(result).getParameterType()); }
@Test public void wrapConcurrentResult_CollectedValuesList() throws Exception { List<HttpMessageConverter<?>> converters = Collections.singletonList(new MappingJackson2HttpMessageConverter()); ResolvableType elementType = ResolvableType.forClass(List.class); ReactiveTypeHandler.CollectedValuesList result = new ReactiveTypeHandler.CollectedValuesList(elementType); result.add(Arrays.asList("foo1", "bar1")); result.add(Arrays.asList("foo2", "bar2")); ContentNegotiationManager manager = new ContentNegotiationManager(); this.returnValueHandlers.addHandler(new RequestResponseBodyMethodProcessor(converters, manager)); ServletInvocableHandlerMethod hm = getHandlerMethod(new MethodLevelResponseBodyHandler(), "handleFluxOfLists"); hm = hm.wrapConcurrentResult(result); hm.invokeAndHandle(this.webRequest, this.mavContainer); assertEquals(200, this.response.getStatus()); assertEquals("[[\"foo1\",\"bar1\"],[\"foo2\",\"bar2\"]]", this.response.getContentAsString()); }
@Test // SPR-12287 public void wrapConcurrentResult_ResponseEntityNullBody() throws Exception { this.returnValueHandlers.addHandler(new HttpEntityMethodProcessor(this.converters)); ServletInvocableHandlerMethod handlerMethod = getHandlerMethod(new ResponseEntityHandler(), "handleDeferred"); handlerMethod = handlerMethod.wrapConcurrentResult(new ResponseEntity<>(HttpStatus.OK)); handlerMethod.invokeAndHandle(this.webRequest, this.mavContainer); assertEquals(200, this.response.getStatus()); assertEquals("", this.response.getContentAsString()); }
@Test // SPR-15478 public void wrapConcurrentResult_CollectedValuesListWithResponseEntity() throws Exception { List<HttpMessageConverter<?>> converters = Collections.singletonList(new MappingJackson2HttpMessageConverter()); ResolvableType elementType = ResolvableType.forClass(Bar.class); ReactiveTypeHandler.CollectedValuesList result = new ReactiveTypeHandler.CollectedValuesList(elementType); result.add(new Bar("foo")); result.add(new Bar("bar")); ContentNegotiationManager manager = new ContentNegotiationManager(); this.returnValueHandlers.addHandler(new RequestResponseBodyMethodProcessor(converters, manager)); ServletInvocableHandlerMethod hm = getHandlerMethod(new ResponseEntityHandler(), "handleFlux"); hm = hm.wrapConcurrentResult(result); hm.invokeAndHandle(this.webRequest, this.mavContainer); assertEquals(200, this.response.getStatus()); assertEquals("[{\"value\":\"foo\"},{\"value\":\"bar\"}]", this.response.getContentAsString()); }
@Test public void wrapConcurrentResult_ResponseEntityNullReturnValue() throws Exception { this.returnValueHandlers.addHandler(new HttpEntityMethodProcessor(this.converters)); ServletInvocableHandlerMethod handlerMethod = getHandlerMethod(new ResponseEntityHandler(), "handleDeferred"); handlerMethod = handlerMethod.wrapConcurrentResult(null); handlerMethod.invokeAndHandle(this.webRequest, this.mavContainer); assertEquals(200, this.response.getStatus()); assertEquals("", this.response.getContentAsString()); }
@Test public void wrapConcurrentResult_ResponseBodyEmitter() throws Exception { this.returnValueHandlers.addHandler(new ResponseBodyEmitterReturnValueHandler(this.converters)); ServletInvocableHandlerMethod handlerMethod = getHandlerMethod(new StreamingHandler(), "handleEmitter"); handlerMethod = handlerMethod.wrapConcurrentResult(null); handlerMethod.invokeAndHandle(this.webRequest, this.mavContainer); assertEquals(200, this.response.getStatus()); assertEquals("", this.response.getContentAsString()); }
@Test public void wrapConcurrentResult_StreamingResponseBody() throws Exception { this.returnValueHandlers.addHandler(new StreamingResponseBodyReturnValueHandler()); ServletInvocableHandlerMethod handlerMethod = getHandlerMethod(new StreamingHandler(), "handleStreamBody"); handlerMethod = handlerMethod.wrapConcurrentResult(null); handlerMethod.invokeAndHandle(this.webRequest, this.mavContainer); assertEquals(200, this.response.getStatus()); assertEquals("", this.response.getContentAsString()); }
return "Resume with async result [" + formatted + "]"; }); invocableMethod = invocableMethod.wrapConcurrentResult(result);
return "Resume with async result [" + formatted + "]"; }); invocableMethod = invocableMethod.wrapConcurrentResult(result);
logger.debug("Found concurrent result value [" + result + "]"); invocableMethod = invocableMethod.wrapConcurrentResult(result);
logger.debug("Found concurrent result value [" + result + "]"); invocableMethod = invocableMethod.wrapConcurrentResult(result);