使用 ProducerTemplate 使用 Camel 进行代理身份验证

编程入门 行业动态 更新时间:2024-10-22 11:02:05
本文介绍了使用 ProducerTemplate 使用 Camel 进行代理身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个使用 Camel 并在 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 中部署代码时,camelContext 对象为空.

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

2)我尝试在ServiceMix的etc/system.properties文件中设置代理设置.

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

3) 我尝试在 camel-context.xml 中使用 http-conf:conduit,如下所示:

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 时工作.任何帮助将不胜感激.

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

谢谢.

推荐答案

试试这个代码:

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

更多推荐

使用 ProducerTemplate 使用 Camel 进行代理身份验证

本文发布于:2023-11-03 16:18:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1555555.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:身份验证   ProducerTemplate   Camel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!