【问题标题】:use system properties proxy settings for camel http4使用骆驼http4的系统属性代理设置
【发布时间】:2015-07-31 11:24:16
【问题描述】:

我正在尝试对 http4 组件使用系统属性的代理设置,但无济于事。

documentation 给出了这个例子:

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

但这只是使用硬编码值。

有没有办法在 camelContext 属性中使用占位符?

【问题讨论】:

    标签: spring http proxy apache-camel system-properties


    【解决方案1】:

    首先,您需要PropertiesComponent 来解析&lt;camelContext&gt; 中的属性:

    <bean id="propertiesComponent" class="org.apache.camel.component.properties.PropertiesComponent" />
    

    如果您只需要对以下其中一项的支持,则无需指定位置:

    现在您可以在 camelContext 属性中使用占位符:

    <camelContext>
        <properties>
            <property key="http.proxyHost" value="{{http.proxyHost}}"/>
            <property key="http.proxyPort" value="{{http.proxyPort}}"/>
        </properties>
    </camelContext>
    

    另外需要注意的是,如果系统属性没有设置,这将失败。您可以(并且可能应该)在冒号后指定默认值

    <property key="http.proxyHost" value="{{http.proxyHost:}}"/>
    <property key="http.proxyPort" value="{{http.proxyPort:}}"/>
    

    以确保它在这两种情况下都有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-13
      • 2014-06-20
      • 1970-01-01
      • 2014-12-14
      • 1970-01-01
      相关资源
      最近更新 更多