@Test void shouldPropagateJsonProcessingException() throws Exception { ObjectMapper mapper = mock(ObjectMapper.class); when(mapper.writeValueAsBytes(any())).thenThrow(mock(JsonProcessingException.class)); try { AdviceUtils.setHttpResponse(responseEntity, webExchange, mapper).block(); fail("A RuntimeException should have been thrown"); } catch (RuntimeException e) { assertThat((JsonProcessingException)e.getCause(), isA(JsonProcessingException.class)); } }
public static Mono<Void> setHttpResponse(final ResponseEntity<Problem> entity, final ServerWebExchange exchange, final ObjectMapper mapper) { final ServerHttpResponse response = exchange.getResponse(); response.setStatusCode(entity.getStatusCode()); response.getHeaders().addAll(entity.getHeaders()); try { final DataBuffer buffer = response.bufferFactory() .wrap(mapper.writeValueAsBytes(entity.getBody())); return response.writeWith(Mono.just(buffer)) .doOnError(error -> DataBufferUtils.release(buffer)); } catch (final JsonProcessingException ex) { return Mono.error(ex); } }
AdviceUtils { public static Mono<Void> setHttpResponse(final ResponseEntity<Problem> entity, final ServerWebExchange exchange, final ObjectMapper mapper) { final ServerHttpResponse response = exchange.getResponse(); response.setStatusCode(entity.getStatusCode()); response.getHeaders().addAll(entity.getHeaders()); try { final DataBuffer buffer = response.bufferFactory() .wrap(mapper.writeValueAsBytes(entity.getBody())); return response.writeWith(Mono.just(buffer)) .doOnError(error -> DataBufferUtils.release(buffer)); } catch (final JsonProcessingException ex) { return Mono.error(ex); } } }
AdviceUtils { public static Mono<Void> setHttpResponse(final ResponseEntity<Problem> entity, final ServerWebExchange exchange, final ObjectMapper mapper) { final ServerHttpResponse response = exchange.getResponse(); response.setStatusCode(entity.getStatusCode()); response.getHeaders().addAll(entity.getHeaders()); try { final DataBuffer buffer = response.bufferFactory() .wrap(mapper.writeValueAsBytes(entity.getBody())); return response.writeWith(Mono.just(buffer)) .doOnError(error -> DataBufferUtils.release(buffer)); } catch (final JsonProcessingException ex) { return Mono.error(ex); } } private  AdviceUtils(); }
AdviceUtils { public static Mono<Void> setHttpResponse(final ResponseEntity<Problem> entity, final ServerWebExchange exchange, final ObjectMapper mapper) { final ServerHttpResponse response = exchange.getResponse(); response.setStatusCode(entity.getStatusCode()); response.getHeaders().addAll(entity.getHeaders()); try { final DataBuffer buffer = response.bufferFactory() .wrap(mapper.writeValueAsBytes(entity.getBody())); return response.writeWith(Mono.just(buffer)) .doOnError(error -> DataBufferUtils.release(buffer)); } catch (final JsonProcessingException ex) { return Mono.error(ex); } } private  AdviceUtils(); static Mono<Void> setHttpResponse(final ResponseEntity<Problem> entity, final ServerWebExchange exchange,
            final ObjectMapper mapper); }
AdviceUtils { public static Mono<Void> setHttpResponse(final ResponseEntity<Problem> entity, final ServerWebExchange exchange, final ObjectMapper mapper) { final ServerHttpResponse response = exchange.getResponse(); response.setStatusCode(entity.getStatusCode()); response.getHeaders().addAll(entity.getHeaders()); try { final DataBuffer buffer = response.bufferFactory() .wrap(mapper.writeValueAsBytes(entity.getBody())); return response.writeWith(Mono.just(buffer)) .doOnError(error -> DataBufferUtils.release(buffer)); } catch (final JsonProcessingException ex) { return Mono.error(ex); } } private  AdviceUtils(); static Mono<Void> setHttpResponse(final ResponseEntity<Problem> entity, final ServerWebExchange exchange,
            final ObjectMapper mapper);  }