Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ The following example configures an `AddRequestHeader` filter:
spring:
cloud:
gateway:
mvc:
routes:
- id: add_request_header_route
uri: https://example.org
predicates:
- Path=/red
filters:
- AddRequestHeader=X-Request-red, blue
server:
webmvc:
routes:
- id: add_request_header_route
uri: https://example.org
predicates:
- Path=/red
filters:
- AddRequestHeader=X-Request-red, blue
----

.GatewaySampleApplication.java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ The following example configures an `AddRequestHeadersIfNotPresent` filter:
spring:
cloud:
gateway:
mvc:
routes:
- id: add_request_headers_route_inp
uri: https://example.org
predicates:
- Path=/red
filters:
- AddRequestHeadersIfNotPresent=X-Request-Color-1:blue,X-Request-Color-2:green
server:
webmvc:
routes:
- id: add_request_headers_route_inp
uri: https://example.org
predicates:
- Path=/red
filters:
- AddRequestHeadersIfNotPresent=X-Request-Color-1:blue,X-Request-Color-2:green
----

.GatewaySampleApplication.java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ application.yml
spring:
cloud:
gateway:
mvc:
routes:
- id: add_request_parameter_route
uri: https://example.org
predicates:
- Path=/anything/addrequestparam
filters:
- AddRequestParameter=red, blue
server:
webmvc:
routes:
- id: add_request_parameter_route
uri: https://example.org
predicates:
- Path=/anything/addrequestparam
filters:
- AddRequestParameter=red, blue
----

.GatewaySampleApplication.java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ The following example configures an `AddResponseHeader` filter:
spring:
cloud:
gateway:
mvc:
routes:
- id: add_response_header_route
uri: https://example.org
predicates:
- Path=/anything/addresheader
filters:
- AddResponseHeader=X-Response-Red, Blue
server:
webmvc:
routes:
- id: add_response_header_route
uri: https://example.org
predicates:
- Path=/anything/addresheader
filters:
- AddResponseHeader=X-Response-Red, Blue
----

.GatewaySampleApplication.java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ The following example configures a Spring Cloud CircuitBreaker filter:
spring:
cloud:
gateway:
mvc:
routes:
- id: circuitbreakernofallback
uri: https://example.org
predicates:
- Path=/anything/circuitbreakernofallback
filters:
- CircuitBreaker=myCircuitBreaker
server:
webmvc:
routes:
- id: circuitbreakernofallback
uri: https://example.org
predicates:
- Path=/anything/circuitbreakernofallback
filters:
- CircuitBreaker=myCircuitBreaker
----
.GatewaySampleApplication.java
[source,java]
Expand Down Expand Up @@ -59,17 +60,18 @@ The following example configures such a fallback:
spring:
cloud:
gateway:
mvc:
routes:
- id: circuitbreaker_route
uri: https://example.org
predicates:
- Path=/consumingServiceEndpoint
filters:
- name: CircuitBreaker
args:
name: myCircuitBreaker
fallbackUri: forward:/inCaseOfFailureUseThis
server:
webmvc:
routes:
- id: circuitbreaker_route
uri: https://example.org
predicates:
- Path=/consumingServiceEndpoint
filters:
- name: CircuitBreaker
args:
name: myCircuitBreaker
fallbackUri: forward:/inCaseOfFailureUseThis
----

The following listing does the same thing in Java:
Expand Down Expand Up @@ -182,20 +184,21 @@ value or the String representation of the `HttpStatus` enumeration.
spring:
cloud:
gateway:
mvc:
routes:
- id: circuitbreaker_route
uri: lb://backing-service:8088
predicates:
- Path=/consumingServiceEndpoint
filters:
- name: CircuitBreaker
args:
name: myCircuitBreaker
fallbackUri: forward:/inCaseOfFailureUseThis
statusCodes:
- 500
- "NOT_FOUND"
server:
webmvc:
routes:
- id: circuitbreaker_route
uri: lb://backing-service:8088
predicates:
- Path=/consumingServiceEndpoint
filters:
- name: CircuitBreaker
args:
name: myCircuitBreaker
fallbackUri: forward:/inCaseOfFailureUseThis
statusCodes:
- 500
- "NOT_FOUND"
----

.GatewaySampleApplication.java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ The following example configures a `DedupeResponseHeader` filter:
spring:
cloud:
gateway:
mvc:
routes:
- id: dedupe_response_header_route
uri: https://example.org
predicates:
- Path=/hello
filters:
- DedupeResponseHeader=Access-Control-Allow-Credentials Access-Control-Allow-Origin
server:
webmvc:
routes:
- id: dedupe_response_header_route
uri: https://example.org
predicates:
- Path=/hello
filters:
- DedupeResponseHeader=Access-Control-Allow-Credentials Access-Control-Allow-Origin
----
.GatewaySampleApplication.java
[source,java]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,26 @@ The `FallbackHeaders` factory lets you add Spring Cloud CircuitBreaker execution
spring:
cloud:
gateway:
mvc:
routes:
- id: ingredients
uri: lb://ingredients
predicates:
- Path=/ingredients/**
filters:
- name: CircuitBreaker
args:
name: fetchIngredients
fallbackUri: forward:/fallback
- id: ingredients-fallback
uri: http://localhost:9994
predicates:
- Path=/fallback
filters:
- name: FallbackHeaders
args:
executionExceptionTypeHeaderName: Test-Header
server:
webmvc:
routes:
- id: ingredients
uri: lb://ingredients
predicates:
- Path=/ingredients/**
filters:
- name: CircuitBreaker
args:
name: fetchIngredients
fallbackUri: forward:/fallback
- id: ingredients-fallback
uri: http://localhost:9994
predicates:
- Path=/fallback
filters:
- name: FallbackHeaders
args:
executionExceptionTypeHeaderName: Test-Header
----

.GatewaySampleApplication.java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ The following listing configures a LoadBalancer Filter:
spring:
cloud:
gateway:
mvc:
routes:
- id: api_route
uri: lb://apiservice
predicates:
- Path=/api/**
server:
webmvc:
routes:
- id: api_route
uri: lb://apiservice
predicates:
- Path=/api/**
----

WARNING: If using the `lb()` filter, it needs to be after any filter that manipulates the path such as `setPath()` or `stripPrefix()`, otherwise the resulting url could be incorrect. The `lb:` scheme handler in configuration, automatically puts the filter in the highest precedence order.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ The following example configures a `MapRequestHeader`:
spring:
cloud:
gateway:
mvc:
routes:
- id: map_request_header_route
uri: https://example.org
predicates:
- Path=/mypath
filters:
- MapRequestHeader=Blue, X-Request-Red
server:
webmvc:
routes:
- id: map_request_header_route
uri: https://example.org
predicates:
- Path=/mypath
filters:
- MapRequestHeader=Blue, X-Request-Red
----

.GatewaySampleApplication.java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ The following example configures a `PrefixPath` filter:
spring:
cloud:
gateway:
mvc:
routes:
- id: prefixpath_route
uri: https://example.org
predicates:
- Path=/**
filters:
- PrefixPath=/mypath
server:
webmvc:
routes:
- id: prefixpath_route
uri: https://example.org
predicates:
- Path=/**
filters:
- PrefixPath=/mypath
----

.GatewaySampleApplication.java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ The following example configures a `PreserveHostHeader` filter:
spring:
cloud:
gateway:
mvc:
routes:
- id: preserve_host_route
uri: https://example.org
predicates:
- Path=/**
filters:
- PreserveHostHeader
server:
webmvc:
routes:
- id: preserve_host_route
uri: https://example.org
predicates:
- Path=/**
filters:
- PreserveHostHeader
----

.GatewaySampleApplication.java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ The following listing configures a `RedirectTo` filter:
spring:
cloud:
gateway:
mvc:
routes:
- id: redirectto_route
uri: https://example.org
predicates:
- Path=/**
filters:
- RedirectTo=302, https://acme.org
server:
webmvc:
routes:
- id: redirectto_route
uri: https://example.org
predicates:
- Path=/**
filters:
- RedirectTo=302, https://acme.org
----

.GatewaySampleApplication.java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ The following example configures an `RemoveJsonAttributesResponseBody` filter:
spring:
cloud:
gateway:
mvc:
routes:
- id: removejsonattributes_route
uri: https://example.org
filters:
- RemoveJsonAttributesResponseBody=id,color
server:
webmvc:
routes:
- id: removejsonattributes_route
uri: https://example.org
filters:
- RemoveJsonAttributesResponseBody=id,color
----

This removes attributes "id" and "color" from the JSON content body at root level.
Expand Down
Loading
Loading