This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.cardinalhealth.connectgateway; | |
import brave.Span; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import org.springframework.cloud.gateway.filter.GatewayFilterChain; | |
import org.springframework.cloud.gateway.filter.GlobalFilter; | |
import org.springframework.cloud.gateway.route.Route; | |
import org.springframework.cloud.sleuth.instrument.web.TraceWebFilter; | |
import org.springframework.stereotype.Component; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Bean | |
public RouteLocator customRouteLocator(RouteLocatorBuilder builder, | |
SimpleLoggingFilter loggingFilter, | |
RouteServiceForwardingFilter forwardingFilter) { | |
return builder.routes() | |
.route(r -> | |
r.header(FORWARDED_URL, ".*") | |
.and() | |
.header(PROXY_METADATA, ".*") | |
.and() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
public class RouteServiceForwardingFilter implements GatewayFilter { | |
@Override | |
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) { | |
try { | |
String forwardUrl = exchange.getRequest().getHeaders().get(FORWARDED_URL).get(0); | |
exchange.getAttributes().put(GATEWAY_REQUEST_URL_ATTR, new URI(forwardUrl)); | |
return chain.filter(exchange); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Bean | |
public RouteLocator customRouteLocator(RouteLocatorBuilder builder, SimpleLoggingFilter loggingFilter) { | |
return builder.routes() | |
.route(r -> | |
r.header(FORWARDED_URL, ".*") | |
.and() | |
.header(PROXY_METADATA, ".*") | |
.and() | |
.header(PROXY_SIGNATURE, ".*") | |
.filters(f -> f.add(loggingFilter)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
public class SimpleLoggingFilter implements GatewayFilter { | |
private static final Logger log = LoggerFactory.getLogger(SimpleLoggingFilter.class); | |
@Override | |
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) { | |
log.info("Method:{} Host:{} Path:{} QueryParams:{}", | |
exchange.getRequest().getMethod(), | |
exchange.getRequest().getURI().getHost(), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Bean | |
public RouteLocator customRouteLocator(RouteLocatorBuilder builder, SimpleLoggingFilter loggingFilter) { | |
return builder.routes() | |
.route(r -> | |
r.header(FORWARDED_URL, ".*") | |
.and() | |
.header(PROXY_METADATA, ".*") | |
.and() | |
.header(PROXY_SIGNATURE, ".*") | |
.filters(f -> f.add(loggingFilter)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@EnableGateway | |
@SpringBootApplication | |
public class SpringCloudGatewayApplication { | |
private final String cookieName = "beta_active"; | |
private final String headerName = "X-Beta-active"; | |
private final String betaActiveValue = "true"; | |
/** | |
* They're in the beta if they have a cookie or request header set |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"provider": { | |
"name": "Provider" | |
}, | |
"consumer": { | |
"name": "Consumer" | |
}, | |
"interactions": [ | |
{ | |
"description": "A fraudulent fraud check request", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(PactRunner.class) | |
@Provider("some-provider") | |
@PactFolder("/some/path/pact") | |
@WebIntegrationTest("server.port=8080") | |
@SpringApplicationConfiguration(SomeSpringBootApplication.class) | |
public class ProviderPactTest { | |
private static TestContextManager testContextManager; | |
@TestTarget | |
public final HttpTarget target = new HttpTarget(8080); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ConfigurationProperties("*.config")?? | |
public class Config { | |
private String foo; | |
private String bar; | |
public String getFoo() { | |
return foo; | |
} | |
public void setFoo(String foo) { |
NewerOlder