From 8f534ebfa767cee814b8bec8e4626aed6c99b7ee Mon Sep 17 00:00:00 2001 From: spencergibb Date: Fri, 28 Mar 2025 15:13:58 -0400 Subject: [PATCH] polishing modifyresponsebody.adoc --- .../filters/modifyresponsebody.adoc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/modules/ROOT/pages/spring-cloud-gateway-server-mvc/filters/modifyresponsebody.adoc b/docs/modules/ROOT/pages/spring-cloud-gateway-server-mvc/filters/modifyresponsebody.adoc index b7bd7163..da97b6e6 100644 --- a/docs/modules/ROOT/pages/spring-cloud-gateway-server-mvc/filters/modifyresponsebody.adoc +++ b/docs/modules/ROOT/pages/spring-cloud-gateway-server-mvc/filters/modifyresponsebody.adoc @@ -5,20 +5,29 @@ You can use the `ModifyResponseBody` filter to modify the response body before i NOTE: This filter can be configured only by using the Java DSL. -The following listing shows how to modify a response body filter: +The following listing shows how to modify a response body filter: +.GatewaySampleApplication.java [source,java] ---- +import static org.springframework.cloud.gateway.server.mvc.filter.AfterFilterFunctions.modifyResponseBody; +import static org.springframework.cloud.gateway.server.mvc.filter.BeforeFilterFunctions.uri; +import static org.springframework.cloud.gateway.server.mvc.handler.GatewayRouterFunctions.route; +import static org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctions.http; + @Bean public RouterFunction gatewayRouterFunctionsModifyResponseBodySimple() { return route("modify_response_body") .GET("/anything/modifyresponsebody", http()) - .before(new HttpbinUriResolver()) + .before(uri("https://example.org")) .after(modifyResponseBody(String.class, String.class, null, (request, response, s) -> s.replace("fooval", "FOOVAL"))) .build(); } ---- + +The sample above does not change the content type or do anything dynamic. Below, the sample changes the content type and dynamically modifies the content. + .GatewaySampleApplication.java [source,java] ----