java - Camel Http4 使用基本身份验证和代理身份验证

标签 java apache-camel proxy-authentication camel-http

我一直在尝试使用 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.configureHttpClientBasicAuthenticationHttpClientConfigurer.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")

关于java - Camel Http4 使用基本身份验证和代理身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42629981/

相关文章:

java - 我如何以最佳方式使用 StringBuilder 的 toString 方法

java - 无法获取父类(super class)中定义的上下文

java - 带有 Angular 的 Spring Boot。从源 'http://localhost:8080/' 访问位于 'http://localhost:4200' 的 XMLHttpRequest 已被 CORS 策略阻止

java - 在 Talend 路由中使用特定版本的 Bean

java - Camel + MyBatis + Apache Aries

c# - 远程服务器返回错误 : (407) Proxy Authentication Required

authentication - 使用 AWS CloudFront 时,如何向公众隐藏自定义源服务器?

java - 将整数拆分为数字的最快方法是什么?

apache-camel - Hawt.io 阻止 Jvisualvm 连接到 JVM

HTTP 规范 : Proxy-Authorization and Authorization headers