org.springframework.cloud.gateway.filter.NettyWriteResponseFilter Java Examples
The following examples show how to use
org.springframework.cloud.gateway.filter.NettyWriteResponseFilter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GatewayFilterSpecTests.java From spring-cloud-gateway with Apache License 2.0 | 6 votes |
@Test public void shouldSetModifyBodyResponseFilterWithRewriteFunction() { ConfigurableApplicationContext context = mock( ConfigurableApplicationContext.class); Route.AsyncBuilder routeBuilder = Route.async().id("123").uri("abc:123") .predicate(exchange -> true); when(context.getBean(ModifyResponseBodyGatewayFilterFactory.class)) .thenReturn(new ModifyResponseBodyGatewayFilterFactory( HandlerStrategies.withDefaults().messageReaders(), Collections.emptySet(), Collections.emptySet())); RouteLocatorBuilder.Builder routes = new RouteLocatorBuilder(context).routes(); GatewayFilterSpec spec = new GatewayFilterSpec(routeBuilder, routes); spec.modifyResponseBody(String.class, String.class, (exchange, s) -> Mono.just(s)); Route route = routeBuilder.build(); assertThat(route.getFilters()).hasSize(1); assertFilter(route.getFilters().get(0), ModifyResponseBodyGatewayFilterFactory.ModifyResponseGatewayFilter.class, NettyWriteResponseFilter.WRITE_RESPONSE_FILTER_ORDER - 1); }
Example #2
Source File: GatewayFilterSpecTests.java From spring-cloud-gateway with Apache License 2.0 | 6 votes |
@Test public void shouldSetModifyBodyResponseFilterWithRewriteFunctionAndEmptyBodySupplier() { ConfigurableApplicationContext context = mock( ConfigurableApplicationContext.class); Route.AsyncBuilder routeBuilder = Route.async().id("123").uri("abc:123") .predicate(exchange -> true); when(context.getBean(ModifyResponseBodyGatewayFilterFactory.class)) .thenReturn(new ModifyResponseBodyGatewayFilterFactory( HandlerStrategies.withDefaults().messageReaders(), Collections.emptySet(), Collections.emptySet())); RouteLocatorBuilder.Builder routes = new RouteLocatorBuilder(context).routes(); GatewayFilterSpec spec = new GatewayFilterSpec(routeBuilder, routes); spec.modifyResponseBody(String.class, String.class, (exchange, s) -> Mono.just(s == null ? "emptybody" : s)); Route route = routeBuilder.build(); assertThat(route.getFilters()).hasSize(1); assertFilter(route.getFilters().get(0), ModifyResponseBodyGatewayFilterFactory.ModifyResponseGatewayFilter.class, NettyWriteResponseFilter.WRITE_RESPONSE_FILTER_ORDER - 1); }
Example #3
Source File: GatewayFilterSpecTests.java From spring-cloud-gateway with Apache License 2.0 | 6 votes |
@Test public void shouldSetModifyBodyResponseFilterWithRewriteFunctionAndNewContentType() { ConfigurableApplicationContext context = mock( ConfigurableApplicationContext.class); Route.AsyncBuilder routeBuilder = Route.async().id("123").uri("abc:123") .predicate(exchange -> true); when(context.getBean(ModifyResponseBodyGatewayFilterFactory.class)) .thenReturn(new ModifyResponseBodyGatewayFilterFactory( HandlerStrategies.withDefaults().messageReaders(), Collections.emptySet(), Collections.emptySet())); RouteLocatorBuilder.Builder routes = new RouteLocatorBuilder(context).routes(); GatewayFilterSpec spec = new GatewayFilterSpec(routeBuilder, routes); spec.modifyResponseBody(String.class, String.class, MediaType.APPLICATION_JSON_VALUE, (exchange, s) -> Mono.just(s)); Route route = routeBuilder.build(); assertThat(route.getFilters()).hasSize(1); assertFilter(route.getFilters().get(0), ModifyResponseBodyGatewayFilterFactory.ModifyResponseGatewayFilter.class, NettyWriteResponseFilter.WRITE_RESPONSE_FILTER_ORDER - 1); }
Example #4
Source File: GatewayFilterSpecTests.java From spring-cloud-gateway with Apache License 2.0 | 6 votes |
@Test public void shouldSetModifyBodyResponseFilterWithConfigConsumer() { ConfigurableApplicationContext context = mock( ConfigurableApplicationContext.class); Route.AsyncBuilder routeBuilder = Route.async().id("123").uri("abc:123") .predicate(exchange -> true); when(context.getBean(ModifyResponseBodyGatewayFilterFactory.class)) .thenReturn(new ModifyResponseBodyGatewayFilterFactory( HandlerStrategies.withDefaults().messageReaders(), Collections.emptySet(), Collections.emptySet())); RouteLocatorBuilder.Builder routes = new RouteLocatorBuilder(context).routes(); GatewayFilterSpec spec = new GatewayFilterSpec(routeBuilder, routes); spec.modifyResponseBody( (smth) -> new ModifyResponseBodyGatewayFilterFactory.Config() .setRewriteFunction(String.class, String.class, (exchange, s) -> Mono.just(s))); Route route = routeBuilder.build(); assertThat(route.getFilters()).hasSize(1); assertFilter(route.getFilters().get(0), ModifyResponseBodyGatewayFilterFactory.ModifyResponseGatewayFilter.class, NettyWriteResponseFilter.WRITE_RESPONSE_FILTER_ORDER - 1); }
Example #5
Source File: Fix302GlobalFilter.java From WeEvent with Apache License 2.0 | 4 votes |
@Override public int getOrder() { return NettyWriteResponseFilter.WRITE_RESPONSE_FILTER_ORDER - 1; }
Example #6
Source File: GatewayAutoConfiguration.java From spring-cloud-gateway with Apache License 2.0 | 4 votes |
@Bean public NettyWriteResponseFilter nettyWriteResponseFilter( GatewayProperties properties) { return new NettyWriteResponseFilter(properties.getStreamingMediaTypes()); }
Example #7
Source File: ModifyResponseBodyGatewayFilterFactory.java From spring-cloud-gateway with Apache License 2.0 | 4 votes |
@Override public int getOrder() { return NettyWriteResponseFilter.WRITE_RESPONSE_FILTER_ORDER - 1; }
Example #8
Source File: ModifyResponseGatewayFilterFactory.java From syncope with Apache License 2.0 | 4 votes |
@Override public int getOrder() { return NettyWriteResponseFilter.WRITE_RESPONSE_FILTER_ORDER - 1; }
Example #9
Source File: BodyPropertyAddingGatewayFilterFactory.java From syncope with Apache License 2.0 | 4 votes |
@Override public int getOrder() { return NettyWriteResponseFilter.WRITE_RESPONSE_FILTER_ORDER - 1; }