/*
 * Copyright 2013-2017 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package org.springframework.cloud.gateway.sample;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.cloud.gateway.EnableGateway;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.Routes;
import org.springframework.context.annotation.Bean;

import static org.springframework.cloud.gateway.filter.factory.WebFilterFactories.addResponseHeader;
import static org.springframework.cloud.gateway.handler.predicate.RoutePredicates.host;
import static org.springframework.cloud.gateway.handler.predicate.RoutePredicates.path;
import static org.springframework.tuple.TupleBuilder.tuple;

/**
 * @author Spencer Gibb
 */
@SpringBootConfiguration
@EnableAutoConfiguration
@EnableGateway
public class GatewaySampleApplication {

	@Bean
	public RouteLocator customRouteLocator(ThrottleWebFilterFactory throttle) {
		return Routes.locator()
				.route("test")
					.uri("http://httpbin.org:80")
					.predicate(host("**.abc.org").and(path("/image/png")))
					.addResponseHeader("X-TestHeader", "foobar")
					.and()
				.route("test2")
					.uri("http://httpbin.org:80")
					.predicate(path("/image/webp"))
					.add(addResponseHeader("X-AnotherHeader", "baz"))
					.and()
				.route("test3")
					.order(-1)
					.uri("http://httpbin.org:80")
					.predicate(host("**.throttle.org").and(path("/get")))
					.add(throttle.apply(tuple().of("capacity", 1,
							"refillTokens", 1,
							"refillPeriod", 10,
							"refillUnit", "SECONDS")))
					.and()
				.build();
	}

	@Bean
	public ThrottleWebFilterFactory throttleWebFilterFactory() {
		return new ThrottleWebFilterFactory();
	}

	public static void main(String[] args) {
		SpringApplication.run(GatewaySampleApplication.class, args);
	}
}

@@ -1071,16 +1071,372 @@
 on.Bean;
+%0Aimport org.springframework.web.reactive.function.BodyInserters;%0Aimport org.springframework.web.reactive.function.server.RequestPredicates;%0Aimport org.springframework.web.reactive.function.server.RouterFunction;%0Aimport org.springframework.web.reactive.function.server.RouterFunctions;%0Aimport org.springframework.web.reactive.function.server.ServerResponse;
 %0A%0Aimport
@@ -2762,16 +2762,289 @@
 ();%0A%09%7D%0A%0A
+%09@Bean%0A%09public RouterFunction%3CServerResponse%3E testFunRouterFunction() %7B%0A%09%09RouterFunction%3CServerResponse%3E route = RouterFunctions.route(%0A%09%09%09%09RequestPredicates.path(%22/testfun%22),%0A%09%09%09%09request -%3E ServerResponse.ok().body(BodyInserters.fromObject(%22hello%22)));%0A%09%09return route;%0A%09%7D%0A%0A
 %09public 

Add sample RouterFunction