Apache camel cxf端点 - 指定http(s)代理?

时间:2017-09-01 01:55:12

标签: apache-camel cxf http-proxy

我一直在尝试使用spring java配置在Camel中设置一个CXF端点:

@Bean
public CxfEndpoint anEndpoint() {
    CxfEndpoint endpoint = new CxfEndpoint();
    endpoint.setAddress(getEndpointUrl());
    endpoint.setServiceClass(ServiceSOAP.class);
    endpoint.setWsdlURL("/wsdl/ServiceSOAP.wsdl");

    String httpProxyHost = httpProxyHost();
    String httpProxyPort = httpProxyPort();

    Map<String, Object> properties = new HashMap<>();

    properties.put("https.proxyHost", httpProxyHost());
    properties.put("https.proxyPort", httpProxyPort());
    properties.put("http.proxyHost", httpProxyHost());
    properties.put("http.proxyPort", httpProxyPort());

    endpoint.setProperties(properties);
    return endpoint;
}

但是,这不适用于http或https端点网址。

我也尝试直接在CamelContext上设置这些属性,结果相同。

该路由在环境中正常工作,可直接连接到互联网,例如本地,但不能在http代理后面部署。

我们正在使用apache camel 2.15.2和apache cxf 3.1.0。非常感谢任何帮助!

1 个答案:

答案 0 :(得分:3)

如果曲折的话,解决方案结果很简单。必须使用CxfEndpointConfigurator来设置HTTPConduit属性,如下所示:

@Bean
public CxfEndpoint anEndpoint() {
    CxfEndpoint endpoint = new CxfEndpoint();
    endpoint.setAddress(getEndpointUrl());
    endpoint.setServiceClass(ServiceSOAP.class);
    endpoint.setWsdlURL("/wsdl/ServiceSOAP.wsdl");

    endpoint.setCxfEndpointConfigurer(anEndpointClientConfigurer());

    return endpoint;
}

private CxfEndpointConfigurer anEndpointClientConfigurer() {
    return new CxfEndpointConfigurer() {

        @Override
        public void configure(AbstractWSDLBasedEndpointFactory factoryBean) {
        }

        @Override
        public void configureClient(Client client) {
                HTTPConduit conduit = (HTTPConduit) client.getConduit();
                HTTPClientPolicy policy = new HTTPClientPolicy();
                policy.setProxyServer(httpProxyHost());
                policy.setProxyServerPort(httpProxyPort());

                conduit.setClient(policy);
            }
        }

参考文献:12