diff --git a/multi/multi__developer_guide.html b/multi/multi__developer_guide.html index 06dcb185..17ee88c9 100644 --- a/multi/multi__developer_guide.html +++ b/multi/multi__developer_guide.html @@ -1,36 +1,50 @@ 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 +

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 03b430e6..0d1b1b50 100644 --- a/single/spring-cloud-gateway.html +++ b/single/spring-cloud-gateway.html @@ -405,39 +405,53 @@ or check if an exchange has already been routed.

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
+

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 7156797e..94024336 100644
--- a/spring-cloud-gateway.xml
+++ b/spring-cloud-gateway.xml
@@ -1014,54 +1014,58 @@ public RouteLocator customRouteLocator(RouteLocatorBuilder builder, ThrottleGate
 
 PreGatewayFilterFactory.java
 
----
-public class PreGatewayFilterFactory extends AbstractGatewayFilterFactory<PreGatewayFilterFactory.Config> {
+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
+	}
+
+}
 
 
-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 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
+	}
+
+}
 
 
-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