Apache camel cxf 端点 - 指定 http(s) 代理?
Apache camel cxf endpoint - specify http(s) proxy?
我一直在尝试在 Camel 中设置 CXF 端点,使用 spring java 配置如下:
@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 端点 url。
我也试过直接在 CamelContext 上设置这些属性,结果相同。
该路由在直接连接到 Internet 的环境中工作正常,例如在本地,但在部署在 http 代理后面的地方则不然。
我们使用的是 apache camel 2.15.2 和 apache cxf 3.1.0。非常感谢任何帮助!
结果证明解决方案很简单,即使想起来很曲折。必须使用 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);
}
}
我一直在尝试在 Camel 中设置 CXF 端点,使用 spring java 配置如下:
@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 端点 url。
我也试过直接在 CamelContext 上设置这些属性,结果相同。
该路由在直接连接到 Internet 的环境中工作正常,例如在本地,但在部署在 http 代理后面的地方则不然。
我们使用的是 apache camel 2.15.2 和 apache cxf 3.1.0。非常感谢任何帮助!
结果证明解决方案很简单,即使想起来很曲折。必须使用 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);
}
}