@@ -144,32 +144,39 @@ public static <T, R> Function<ServerRequest, ServerRequest> modifyRequestBody(Cl
144144 }).orElse (request );
145145 }
146146
147- @ SuppressWarnings ({"unchecked" , "rawtypes" })
148- public static <T , R > BiFunction <ServerRequest , ServerResponse , ServerResponse > modifyResponseBody (Class <T > inClass , Class < R > outClass ,
149- String newContentType , RewriteResponseFunction <T , R > rewriteFunction ) {
147+ @ SuppressWarnings ({ "unchecked" , "rawtypes" })
148+ public static <T , R > BiFunction <ServerRequest , ServerResponse , ServerResponse > modifyResponseBody (Class <T > inClass ,
149+ Class < R > outClass , String newContentType , RewriteResponseFunction <T , R > rewriteFunction ) {
150150 return (request , response ) -> {
151151 Object o = request .attributes ().get (MvcUtils .CLIENT_RESPONSE_INPUT_STREAM_ATTR );
152152 if (o instanceof InputStream inputStream ) {
153153 try {
154154 List <HttpMessageConverter <?>> converters = request .messageConverters ();
155- Optional <HttpMessageConverter <?>> inConverter = converters .stream ().filter (c -> c .canRead (inClass , response .headers ().getContentType ())).findFirst ();
155+ Optional <HttpMessageConverter <?>> inConverter = converters .stream ()
156+ .filter (c -> c .canRead (inClass , response .headers ().getContentType ()))
157+ .findFirst ();
156158 if (inConverter .isEmpty ()) {
157- //TODO: throw exception?
159+ // TODO: throw exception?
158160 return response ;
159161 }
160162 HttpMessageConverter <?> inputConverter = inConverter .get ();
161- T input = (T ) inputConverter .read ((Class )inClass , new SimpleInputMessage (inputStream , response .headers ()));
163+ T input = (T ) inputConverter .read ((Class ) inClass ,
164+ new SimpleInputMessage (inputStream , response .headers ()));
162165 R output = rewriteFunction .apply (request , response , input );
163166
164- Optional <HttpMessageConverter <?>> outConverter = converters .stream ().filter (c -> c .canWrite (outClass , null )).findFirst ();
167+ Optional <HttpMessageConverter <?>> outConverter = converters .stream ()
168+ .filter (c -> c .canWrite (outClass , null ))
169+ .findFirst ();
165170 if (outConverter .isEmpty ()) {
166- //TODO: throw exception?
171+ // TODO: throw exception?
167172 return response ;
168173 }
169174 HttpMessageConverter <R > byteConverter = (HttpMessageConverter <R >) outConverter .get ();
170175 ByteArrayHttpOutputMessage outputMessage = new ByteArrayHttpOutputMessage (response .headers ());
171176 byteConverter .write (output , null , outputMessage );
172- request .attributes ().put (MvcUtils .CLIENT_RESPONSE_INPUT_STREAM_ATTR , new ByteArrayInputStream (outputMessage .body .toByteArray ()));
177+ request .attributes ()
178+ .put (MvcUtils .CLIENT_RESPONSE_INPUT_STREAM_ATTR ,
179+ new ByteArrayInputStream (outputMessage .body .toByteArray ()));
173180 if (StringUtils .hasText (newContentType )) {
174181 response .headers ().setContentType (MediaType .parseMediaType (newContentType ));
175182 }
@@ -184,7 +191,9 @@ public static <T, R> BiFunction<ServerRequest, ServerResponse, ServerResponse> m
184191 }
185192
186193 private final static class SimpleInputMessage implements HttpInputMessage {
194+
187195 private final InputStream inputStream ;
196+
188197 private final HttpHeaders headers ;
189198
190199 private SimpleInputMessage (InputStream inputStream , HttpHeaders headers ) {
@@ -201,6 +210,7 @@ public InputStream getBody() throws IOException {
201210 public HttpHeaders getHeaders () {
202211 return this .headers ;
203212 }
213+
204214 }
205215
206216 private final static class ByteArrayHttpOutputMessage implements HttpOutputMessage {
@@ -235,7 +245,9 @@ public interface RewriteFunction<T, R> extends BiFunction<ServerRequest, T, R> {
235245 }
236246
237247 public interface RewriteResponseFunction <T , R > {
248+
238249 R apply (ServerRequest request , ServerResponse response , T t );
250+
239251 }
240252
241253 private static class ByteArrayServletInputStream extends ServletInputStream {
0 commit comments