diff --git a/multi/multi__developer_guide.html b/multi/multi__developer_guide.html index 1a432c09..06dcb185 100644 --- a/multi/multi__developer_guide.html +++ b/multi/multi__developer_guide.html @@ -1,3 +1,36 @@ - 9. Developer Guide

9. Developer Guide

TODO: overview of writing custom integrations

9.1 Writing Custom Route Predicate Factories

TODO: document writing Custom Route Predicate Factories

9.2 Writing Custom GatewayFilter Factories

TODO: document writing Custom GatewayFilter Factories

9.3 Writing Custom Global Filters

TODO: document writing Custom Global Filters

9.4 Writing Custom Route Locators and Writers

TODO: document writing Custom Route Locators and Writers

\ No newline at end of file + 9. Developer Guide

9. Developer Guide

TODO: overview of writing custom integrations

9.1 Writing Custom Route Predicate Factories

TODO: document writing Custom Route Predicate Factories

9.2 Writing Custom GatewayFilter Factories

In order to write a GatewayFilter you will need to implement GatewayFilterFactory. There is an abstract class called AbstractGatewayFilterFactory which you can extend.

PreGatewayFilterFactory.java.  +

---
+public class PreGatewayFilterFactory extends AbstractGatewayFilterFactory<PreGatewayFilterFactory.Config> {

+

public PreGatewayFilterFactory() {
+	super(Config.class);
+}
@Override
+public GatewayFilter apply(Config config) {
+	// grab configuration from Config object
+	return (exchange, chain) -> {
+           //If you want to build a "pre" filter you need to manipulate the
+           //request before calling change.filter
+           ServerHttpRequest.Builder builder = exchange.getRequest().mutate();
+           //use builder to manipulate the request
+           return chain.filter(exchange.mutate().request(request).build());
+	};
+}
public static class Config {
+       //Put the configuration properties for your filter here
+}

}

PostGatewayFilterFactory.java.  +

---
+public class PostGatewayFilterFactory extends AbstractGatewayFilterFactory<PostGatewayFilterFactory.Config> {

+

public PostGatewayFilterFactory() {
+	super(Config.class);
+}
@Override
+public GatewayFilter apply(Config config) {
+	// grab configuration from Config object
+	return (exchange, chain) -> {
+		return chain.filter(exchange).then(Mono.fromRunnable(() -> {
+			ServerHttpReponse response = exchange.getResponse();
+			//Manipulate the response in some way
+		}));
+	};
+}
public static class Config {
+       //Put the configuration properties for your filter here
+}

}

9.3 Writing Custom Global Filters

TODO: document writing Custom Global Filters

9.4 Writing Custom Route Locators and Writers

TODO: document writing Custom Route Locators and Writers

\ No newline at end of file diff --git a/single/spring-cloud-gateway.html b/single/spring-cloud-gateway.html index ae5e8a71..3da80c5b 100644 --- a/single/spring-cloud-gateway.html +++ b/single/spring-cloud-gateway.html @@ -368,7 +368,40 @@ using something like RouteDefinitionLocator beans are combined using logical and. By using the fluent Java API, you can use the and(), or() and negate() operators on the Predicate class.

7.2 DiscoveryClient Route Definition Locator

The Gateway can be configured to create routes based on services registered with a DiscoveryClient compatible service registry.

To enable this, set spring.cloud.gateway.discovery.locator.enabled=true and make sure a DiscoveryClient implementation is on the classpath and enabled (such as Netflix Eureka, Consul or Zookeeper).

8. Actuator API

TODO: document the /gateway actuator endpoint

9. Developer Guide

TODO: overview of writing custom integrations

9.1 Writing Custom Route Predicate Factories

TODO: document writing Custom Route Predicate Factories

9.2 Writing Custom GatewayFilter Factories

TODO: document writing Custom GatewayFilter Factories

9.3 Writing Custom Global Filters

TODO: document writing Custom Global Filters

9.4 Writing Custom Route Locators and Writers

TODO: document writing Custom Route Locators and Writers

10. Building a Simple Gateway Using Spring MVC or Webflux

Spring Cloud Gateway provides a utility object called ProxyExchange which you can use inside a regular Spring web handler as a method parameter. It supports basic downstream HTTP exchanges via methods that mirror the HTTP verbs. With MVC it also supports forwarding to a local handler via the forward() method. To use the ProxyExchange just include the right module in your classpath (either spring-cloud-gateway-mvc or spring-cloud-gateway-webflux).

MVC example (proxying a request to "/test" downstream to a remote server):

@RestController
+

This style also allows for more custom predicate assertions. The predicates defined by RouteDefinitionLocator beans are combined using logical and. By using the fluent Java API, you can use the and(), or() and negate() operators on the Predicate class.

7.2 DiscoveryClient Route Definition Locator

The Gateway can be configured to create routes based on services registered with a DiscoveryClient compatible service registry.

To enable this, set spring.cloud.gateway.discovery.locator.enabled=true and make sure a DiscoveryClient implementation is on the classpath and enabled (such as Netflix Eureka, Consul or Zookeeper).

8. Actuator API

TODO: document the /gateway actuator endpoint

9. Developer Guide

TODO: overview of writing custom integrations

9.1 Writing Custom Route Predicate Factories

TODO: document writing Custom Route Predicate Factories

9.2 Writing Custom GatewayFilter Factories

In order to write a GatewayFilter you will need to implement GatewayFilterFactory. There is an abstract class called AbstractGatewayFilterFactory which you can extend.

PreGatewayFilterFactory.java.  +

---
+public class PreGatewayFilterFactory extends AbstractGatewayFilterFactory<PreGatewayFilterFactory.Config> {

+

public PreGatewayFilterFactory() {
+	super(Config.class);
+}
@Override
+public GatewayFilter apply(Config config) {
+	// grab configuration from Config object
+	return (exchange, chain) -> {
+           //If you want to build a "pre" filter you need to manipulate the
+           //request before calling change.filter
+           ServerHttpRequest.Builder builder = exchange.getRequest().mutate();
+           //use builder to manipulate the request
+           return chain.filter(exchange.mutate().request(request).build());
+	};
+}
public static class Config {
+       //Put the configuration properties for your filter here
+}

}

PostGatewayFilterFactory.java.  +

---
+public class PostGatewayFilterFactory extends AbstractGatewayFilterFactory<PostGatewayFilterFactory.Config> {

+

public PostGatewayFilterFactory() {
+	super(Config.class);
+}
@Override
+public GatewayFilter apply(Config config) {
+	// grab configuration from Config object
+	return (exchange, chain) -> {
+		return chain.filter(exchange).then(Mono.fromRunnable(() -> {
+			ServerHttpReponse response = exchange.getResponse();
+			//Manipulate the response in some way
+		}));
+	};
+}
public static class Config {
+       //Put the configuration properties for your filter here
+}

}

9.3 Writing Custom Global Filters

TODO: document writing Custom Global Filters

9.4 Writing Custom Route Locators and Writers

TODO: document writing Custom Route Locators and Writers

10. Building a Simple Gateway Using Spring MVC or Webflux

Spring Cloud Gateway provides a utility object called ProxyExchange which you can use inside a regular Spring web handler as a method parameter. It supports basic downstream HTTP exchanges via methods that mirror the HTTP verbs. With MVC it also supports forwarding to a local handler via the forward() method. To use the ProxyExchange just include the right module in your classpath (either spring-cloud-gateway-mvc or spring-cloud-gateway-webflux).

MVC example (proxying a request to "/test" downstream to a remote server):

@RestController
 @SpringBootApplication
 public class GatewaySampleApplication {
 
diff --git a/spring-cloud-gateway.xml b/spring-cloud-gateway.xml
index fbd0126c..a76e7c5e 100644
--- a/spring-cloud-gateway.xml
+++ b/spring-cloud-gateway.xml
@@ -935,7 +935,58 @@ public RouteLocator customRouteLocator(RouteLocatorBuilder builder, ThrottleGate
 
 
Writing Custom GatewayFilter Factories -TODO: document writing Custom GatewayFilter Factories +In order to write a GatewayFilter you will need to implement GatewayFilterFactory. There is an abstract class called AbstractGatewayFilterFactory which you can extend. + +PreGatewayFilterFactory.java + +--- +public class PreGatewayFilterFactory extends AbstractGatewayFilterFactory<PreGatewayFilterFactory.Config> { + + +public PreGatewayFilterFactory() { + super(Config.class); +} +@Override +public GatewayFilter apply(Config config) { + // grab configuration from Config object + return (exchange, chain) -> { + //If you want to build a "pre" filter you need to manipulate the + //request before calling change.filter + ServerHttpRequest.Builder builder = exchange.getRequest().mutate(); + //use builder to manipulate the request + return chain.filter(exchange.mutate().request(request).build()); + }; +} +public static class Config { + //Put the configuration properties for your filter here +} +} + + +PostGatewayFilterFactory.java + +--- +public class PostGatewayFilterFactory extends AbstractGatewayFilterFactory<PostGatewayFilterFactory.Config> { + + +public PostGatewayFilterFactory() { + super(Config.class); +} +@Override +public GatewayFilter apply(Config config) { + // grab configuration from Config object + return (exchange, chain) -> { + return chain.filter(exchange).then(Mono.fromRunnable(() -> { + ServerHttpReponse response = exchange.getResponse(); + //Manipulate the response in some way + })); + }; +} +public static class Config { + //Put the configuration properties for your filter here +} +} +
Writing Custom Global Filters