使用ProducerTemplate骆驼代理身份验证 [英] Proxy authentication with Camel using ProducerTemplate

查看:159
本文介绍了使用ProducerTemplate骆驼代理身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个是用骆驼和ServiceMix的服务器上运行的项目,但我似乎无法得到它来访问外部Web服务,我怀疑这是因为我无法设置代理身份验证正确。

I have a project that's using Camel and running on a ServiceMix server, but I can't seem to get it to access external web services, and I suspect it's because I can't set the proxy authentication properly.

Exchange exchange = producerTemplate.request(url, new Processor() {
    public void process(Exchange exchange) throws Exception {
        exchange.getIn().setHeader(Exchange.HTTP_METHOD, "POST");
        exchange.getIn().setHeader(Exchange.CONTENT_TYPE, "application/json");
    }
});
response = exchange.getOut().getBody(String.class);

如果我把一个断点就上线,我看到ConnectionTimedOutException在交换对象和响应为空。

If I put a breakpoint on the last line, I see a ConnectionTimedOutException in the exchange object and the response is null.

我试过多种方式设置代理服务器。

I tried setting the proxies in a multitude of ways.

1)我想在一个类中设置代理服务器设置,实现 CamelContextAware

1) I tried setting the proxy settings in a class that implements CamelContextAware:

camelContext.getProperties().put("http.proxyHost", "...");
camelContext.getProperties().put("http.proxyPort", "8080");
camelContext.getProperties().put("http.proxyUser", "...");
camelContext.getProperties().put("http.proxyPassword", "...");
camelContext.getProperties().put("http.proxySet", "true");

这工作在独立模式,但是当我部署的ServiceMix的code时,camelContext对象为null。

This works in standalone mode, but when I deploy the code in ServiceMix, the camelContext object is null.

2)我试图在等/ system.properties 的ServiceMix的文件中设置代理服务器设置。

2) I tried setting the proxy settings in the etc/system.properties file of ServiceMix.

3)我试图用HTTP-conf的:管道将在骆驼context.xml中是这样的:

3) I tried using http-conf:conduit in the camel-context.xml like this:

<http-conf:conduit name="*.http-conduit">
    <http-conf:client ProxyServer="..." ProxyServerPort="8080" />
    <http-conf:proxyAuthorization>
        <conf-sec:UserName>...</conf-sec:UserName>
        <conf-sec:Password>...</conf-sec:Password>
    </http-conf:proxyAuthorization>
</http-conf:conduit>

不过,我想,如果我用了CXF客户端会才有效。

However, I think that'd only work if I used a cxf client.

没有什么工作,我需要同时在ServiceMix的部署它的工作。
任何帮助将大大AP preciated。

Nothing worked, and I need it to work while deployed on the ServiceMix. Any help would be greatly appreciated.

感谢。

推荐答案

试试这个code:

HTTPConduit conduit = (HTTPConduit)outMessage.getExchange().getConduit(outMessage);
HTTPClientPolicy policy = conduit.getClient();
policy.setProxyServer(PROXY_IP);
policy.setProxyServerPort(PROXY_PORT);
conduit.setClient(policy);

这篇关于使用ProducerTemplate骆驼代理身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆