Skip to content

Commit

Permalink
Updated routes dsl to deal with new routes java api.
Browse files Browse the repository at this point in the history
  • Loading branch information
spencergibb committed Dec 1, 2017
1 parent ddd2e65 commit 43d47e6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@ class RouteLocatorDsl(val builder: RouteLocatorBuilder) {
return routes.build()
}

/**
* A helper to return a composed [Predicate] that tests against this [Predicate] AND the [other] predicate
*/
infix fun BooleanSpec.and(other: BooleanSpec) =
this.routeBuilder.predicate(this.predicate.and(other.predicate))

/**
* A helper to return a composed [Predicate] that tests against this [Predicate] OR the [other] predicate
*/
infix fun BooleanSpec.or(other: BooleanSpec) =
this.routeBuilder.predicate(this.predicate.or(other.predicate))


}

/**
Expand All @@ -86,16 +99,3 @@ fun PredicateSpec.filters(init: GatewayFilterSpec.() -> Unit) {
}


/**
* A helper to return a composed [Predicate] that tests against this [Predicate] AND the [other] predicate
*/
infix fun BooleanSpec.and(other: BooleanSpec) =
this.routeBuilder.predicate(this.predicate.and(other.predicate))

/**
* A helper to return a composed [Predicate] that tests against this [Predicate] OR the [other] predicate
*/
infix fun BooleanSpec.or(other: BooleanSpec) =
this.routeBuilder.predicate(this.predicate.or(other.predicate))


Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
package org.springframework.cloud.gateway.sample

import org.springframework.cloud.gateway.filter.factory.GatewayFilters.addResponseHeader
import org.springframework.cloud.gateway.handler.predicate.RoutePredicates.host
import org.springframework.cloud.gateway.handler.predicate.RoutePredicates.path
import org.springframework.cloud.gateway.route.RouteLocator
import org.springframework.cloud.gateway.route.gateway
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder
import org.springframework.cloud.gateway.route.builder.filters
import org.springframework.cloud.gateway.route.builder.routes
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

@Configuration
class AdditionalRoutes {

@Bean
fun additionalRouteLocator(): RouteLocator = gateway {
fun additionalRouteLocator(builder: RouteLocatorBuilder): RouteLocator = builder.routes {
route(id = "test-kotlin") {
host("kotlin.abc.org") and path("/image/png")
filters {
addResponseHeader("X-TestHeader", "foobar")
}
uri("http://httpbin.org:80")
predicate(host("kotlin.abc.org") and path("/image/png"))
add(addResponseHeader("X-TestHeader", "foobar"))
}
}

Expand Down

0 comments on commit 43d47e6

Please sign in to comment.