我一直在尝试使用 Apache Camel 的 Http4 组件连接到需要基本身份验证的 HTTPS URL。连接需要通过经过身份验证的 HTTP 代理完成。
所以,根据 docs ,我这样配置 Camel 端点:
.toD("https4://target.host/resource?
bridgeEndpoint=true
&mapHttpMessageBody=false
&proxyAuthHost=my.proxy.host
&proxyAuthPort=myProxyPort
&proxyAuthUsername=proxyUser
&proxyAuthPassword=proxyPassword
&proxyAuthScheme=http4
&authenticationPreemptive=true
&authUsername=myUser
&authPassword=myPassword")
这会导致目标服务器发出 403 - Forbidden
响应。查看org.apache.http.wire
日志,它显示代理凭据proxyUser/proxyPassword被转发到目标服务器,而不是Authorization
header 中预期的 myUser/myPassword。
调试 CompositeHTTPConfigurer.configureHttpClient
的源代码, ProxyHttpClientConfigurer.configureHttpClient
和 BasicAuthenticationHttpClientConfigurer.configureHttpClient
,似乎因为两个配置程序都通过 setDefaultCredentialsProvider
将其凭据设置为 HttpClientBuilder
,其中一个在该过程中丢失 - 被覆盖。
看起来这可能是 Camel 的 Http4 组件中的一个错误?或者我错过了什么?
这是带有 Spring Boot 1.5.1.RELEASE 的 Camel 2.18.2。
请您参考如下方法:
在Apache Camel Users list上提出这个问题后,看来这个bug已经被确认了。
我使用camel-http
而不是camel-http4
解决了这个问题。端点参数需要稍微调整:
.toD("https://target.host/resource?
bridgeEndpoint=true
&proxyHost=my.proxy.host
&proxyPort=myProxyPort
&proxyAuthUsername=proxyUser
&proxyAuthPassword=proxyPassword
&proxyAuthMethod=Basic
&authUsername=myUser
&authPassword=myPassword
&authMethod=Basic
&httpClient.authenticationPreemptive=true")