gpt4 book ai didi

java - Spring Cloud 、Zuul https

转载 作者:行者123 更新时间:2023-11-30 10:43:15 24 4
gpt4 key购买 nike

我的网关应用程序(使用 zuul)中的 https 服务有问题它在代理 http 服务时效果很好,但我在代理 https 服务时遇到问题我有异常(exception)

java.lang.IllegalStateException: Could not create URI object: Expected scheme-specific part at index 6: https:
at org.springframework.web.util.HierarchicalUriComponents.toUri(HierarchicalUriComponents.java:430) ~[spring-web-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.cloud.netflix.ribbon.RibbonClientConfiguration$OverrideRestClient.reconstructURIWithServer(RibbonClientConfiguration.java:184) ~[spring-cloud-netflix-core-1
at com.netflix.client.AbstractLoadBalancerAwareClient$1.call(AbstractLoadBalancerAwareClient.java:106) ~[ribbon-loadbalancer-2.1.5.jar:2.1.5]
at com.netflix.loadbalancer.reactive.LoadBalancerCommand$3$1.call(LoadBalancerCommand.java:303) ~[ribbon-loadbalancer-2.1.5.jar:2.1.5]
at com.netflix.loadbalancer.reactive.LoadBalancerCommand$3$1.call(LoadBalancerCommand.java:287) ~[ribbon-loadbalancer-2.1.5.jar:2.1.5]
at rx.internal.util.ScalarSynchronousObservable$4.call(ScalarSynchronousObservable.java:223) ~[rxjava-1.1.5.jar:1.1.5]
at rx.internal.util.ScalarSynchronousObservable$4.call(ScalarSynchronousObservable.java:220) ~[rxjava-1.1.5.jar:1.1.5]
at rx.Observable.unsafeSubscribe(Observable.java:8460) ~[rxjava-1.1.5.jar:1.1.5]
... 150 common frames omitted
aused by: java.net.URISyntaxException: Expected scheme-specific part at index 6: https:
at java.net.URI$Parser.fail(URI.java:2848) ~[na:1.8.0_92]
at java.net.URI$Parser.failExpecting(URI.java:2854) ~[na:1.8.0_92]
at java.net.URI$Parser.parse(URI.java:3057) ~[na:1.8.0_92]
at java.net.URI.<init>(URI.java:673) ~[na:1.8.0_92]

我的网关配置

server:
ssl:
key-store: classpath:my.jks
key-store-password: secret
key-password: secret
spring:
application:
name: mille-gateway
cloud:
config:
discovery:
enabled: true
serviceId: mille-config-server
eureka:
client:
healthcheck:
enabled: true
ribbon:
IsSecure: true
zuul:
ignoredServices: '*'
routes:
test:
path: /test/**
serviceId: mille-test2

test:
ribbon:
ReadTimeout: 5000
MaxAutoRetries: 2
IsSecure: true
My Registry ( Eureka ) server
server:
port: 8761

Eureka :

 instance:
hostname: localhost
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
server:
enableSelfPreservation: false

我的客户端配置

spring:
application:
name: mille-test2
cloud:
config:
discovery:
enabled: true
serviceId: mille-config-server
eureka:
client:
healthcheck:
enabled: true
server:
port: 50000
ssl:
key-store: classpath:my.jks
key-store-password: secret
key-password: secret

eureka:
client:
enabled: true
serviceUrl:
defaultZone: http://localhost:8761/eureka/
instance:
nonSecurePortEnabled: false
securePortEnabled: true
securePort: ${server.port}
instanceId: ${spring.application.name}:${spring.application.instance_id:${random.value}}
statusPageUrl: https://${eureka.hostname}:${server.port}/info
healthCheckUrl: https://${eureka.hostname}:${server.port}/health
homePageUrl: https://${eureka.instance.hostname}:${server.port}/
secureVirtualHostName: ${spring.application.name}
metadataMap:
hostname: ${eureka.instance.hostname}
securePort: ${server.port}

可能是什么问题?

最佳答案

我在 Brixton.SR6 的调试器中发现了这个问题。

  • FeignLoadBalancer.reconstructURIWithServer(...) 在调用实际将服务器添加到 uri 的父类(super class)方法之前调用 RibbonUtils.updateToHttpsIfNeeded(...)。
  • 传入的uri为“”,这是正常情况下传入的url与zuul映射完全匹配,使用服务发现获取服务器/端口。
  • updateToHttpsIfNeeded() 添加“https”并通过 build(true) 调用 UriComponentsBuilder 以创建 HierarchicalUriComponents 的实例。
  • 然后在该实例上调用 toUri(),由于传递给 build() 的 true,它遵循 encode == true 路径并调用 new URI(toString())(第 415 行)。 toString() 返回“https:”,因为我们已经设置了方案,但没有设置服务器或端口。
  • URI 根本不喜欢那样并抛出 java.net.URISyntaxException:索引 6 处的预期方案特定部分:https:。

至于解决问题,也许FeignLoadBalancer应该在URI中设置服务器和端口后才能确保https?或者 RibbonUtils.updateToHttpsIfNeeded 应该在调用 toUri() 之前在 UriComponentsBuilder 中设置服务器和端口——它有服务器实例。

这解释了为什么它只发生在安全连接上。在映射中使用精确的 url 匹配时,我还没有找到任何解决方法,除了恢复到 Brixton.SR5,它工作正常,因为对 build() 的调用没有传递 true 标志,所以 new URI() 没有被调用.

编辑:另见 spring-cloud-netflix issue 1099 .

关于java - Spring Cloud 、Zuul https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37833756/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com