151.15. 配置代理

HTTP4 组件提供配置代理的方法。

from("direct:start")
  .to("http4://oldhost?proxyAuthHost=www.myproxy.com&proxyAuthPort=80");

还支持通过 proxyAuthUsernameproxyAuthPassword 选项进行代理身份验证。

151.15.1. 使用 URI 之外的代理设置

为了避免系统属性冲突,您只能从 CamelContext 或 URI 设置代理配置。
Java DSL :

 context.getProperties().put("http.proxyHost", "172.168.18.9");
 context.getProperties().put("http.proxyPort" "8080");

Spring XML

   <camelContext>
       <properties>
           <property key="http.proxyHost" value="172.168.18.9"/>
           <property key="http.proxyPort" value="8080"/>
      </properties>
   </camelContext>

Camel 将首先从 Java 系统或 CamelContext Properties 设置设置,然后提供端点代理选项。
因此,您可以使用端点选项覆盖系统属性。

注意 Camel 2.8 中还有一个 http.proxyScheme 属性,您可以将其设置为显式配置要使用的方案。