Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java SpringGateway:如何根据请求头和路径动态设置URI和路径_Java_Spring_Spring Boot_Spring Cloud_Spring Cloud Gateway - Fatal编程技术网

Java SpringGateway:如何根据请求头和路径动态设置URI和路径

Java SpringGateway:如何根据请求头和路径动态设置URI和路径,java,spring,spring-boot,spring-cloud,spring-cloud-gateway,Java,Spring,Spring Boot,Spring Cloud,Spring Cloud Gateway,假设我有一个传入请求: 主机:my XXX.domain.com和路径/YYY/ZZZ,我想将该请求路由到uriXXX.YYY.internal.domain.com/ZZZ。我怎样才能做到呢 标准api似乎不允许任何类型的模式提取 builder.routes() .route{ it .header(xxx,xxx) .path("/*/**") .uri("i can't use here anything c

假设我有一个传入请求: 主机:
my XXX.domain.com
和路径
/YYY/ZZZ
,我想将该请求路由到uri
XXX.YYY.internal.domain.com/ZZZ
。我怎样才能做到呢

标准api似乎不允许任何类型的模式提取

builder.routes()
    .route{ it
            .header(xxx,xxx)
            .path("/*/**")
            .uri("i can't use here anything captured in header or path function")
    }
有一个函数允许我访问请求并允许返回任何URI

                        .filters{
                            it.changeRequestUri {
                                val service = it.request....
                                Optional.of(URI("http://...."))
                            }
                        }
                        .uri("https://this will be ignored")
但我无法在那里设定路径


是否有任何现有的api可以简单地实现它,或者我必须编写自定义过滤器?如何正确地做这件事?

这对我来说很有用

.filters{
    it.changeRequestUri {
        val (service, environment, newPath) = computeUrlParts(it)
        Optional.of(URI("http://$environment$service.internal.my-company.com/$newPath"))
    }
}
.uri("http://postman-echo.com") //ignored

这就是我的工作

.filters{
    it.changeRequestUri {
        val (service, environment, newPath) = computeUrlParts(it)
        Optional.of(URI("http://$environment$service.internal.my-company.com/$newPath"))
    }
}
.uri("http://postman-echo.com") //ignored

uri属性不应包含路径。使用诸如
SetPath
RewritePath
之类的筛选器来更改路径。@Spencergib
SetPath
RewritePath
都不允许根据输入路径设置路径,或者它们不允许设置路径。这里是重写和设置路径。您还可以在
host()
谓词中执行路径
{myval}
。uri属性不应包含路径。使用诸如
SetPath
RewritePath
之类的筛选器来更改路径。@Spencergib
SetPath
RewritePath
都不允许根据输入路径设置路径,或者它们不允许设置路径。这里是重写和设置路径。您还可以在
host()
谓词中执行路径
{myval}