java - Apache Camel : Proxy code

标签 java http proxy apache-camel

我正在尝试通过我的 java 代码连接到 Google Api,并且为此使用 apache Camel。我必须首先在代理服务器上进行身份验证,然后请求将转发到谷歌。但是,尽管我提供了我的凭据,但我无法实现身份验证。

context.getProperties().put("http.proxyAuthMethod","Digest");
            context.getProperties().put("http.proxyHost", "foo");
            context.getProperties().put("http.proxyPort", "80");
            context.getProperties().put("http.proxyAuthUsername",
                    "bar");
            context.getProperties().put("http.proxyAuthPassword", "foo");

我也尝试过使用 HTTP Endpoint

HttpEndpoint endpoint = (HttpEndpoint) context.getEndpoint("https://foo/bar"); 
Map<String, Object> options = new HashMap<String, Object>();
            options.put("proxyAuthUsername","foo");
            options.put("proxyAuthPassword","bar");
            options.put("proxyAuthMethod","Basic");
            endpoint.configureProperties(options);
            endpoint.setProxyHost("foo");
            endpoint.setProxyPort(80);

我仍然收到 407 响应代码,以及一条需要代理进行身份验证的消息。任何人都可以给我指点一下吗?

谢谢

最佳答案

昨晚我终于让代理代码工作了,尽管我不知道为什么上述两种方法不起作用。但我开始使用 Spring XML 配置文件进行 Camel 路由,并且我能够通过以下配置来实现这一目标:

<camel:to uri="http://www.google.com/search?proxyAuthMethod=Basic&amp;proxyPort=xx&amp;proxyHost=xxxxxxx&amp;proxyAuthUsername=username&amp;proxyAuthPassword=password" />

关于java - Apache Camel : Proxy code,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10191789/

相关文章:

http - Indy IdHTTP 未正确报告状态

java - 如何跟踪普通 Spring 微服务应用程序(非 Spring boot)中的请求?

http - gorilla 处理程序写入文件

java - 如何在Zuul后置过滤器中拦截和编辑响应体?

JavaFX : How to populate data to TableView from different Thread(Netty)

java - java可以连接wildcard ssl吗

java - itext库Document.add(Element element)方法在写入PDF文件时磁盘已满时返回true并且不会抛出任何异常

java - 如何识别线程的启动者

proxy - 终端没有网络

android - 为 android 下载管理器类设置代理