我試圖在Camel的http4組件上使用http代理。代理在使用Intellij的HTTP代理「檢查連接」選項進行測試時工作。在Apache Camel的http4端點上使用http代理
但是我不知道如何通過Camel正確配置它。運行以下集成測試時,會拋出「ConnectException:Connection timed out」。任何人都可以澄清如何正確設置代理細節嗎?
public class SimpleHttpProxyIT extends CamelTestSupport {
public static final String DIRECT_START = "direct:start";
public static final String MOCK_RESULT = "mock:result";
@Produce(uri = DIRECT_START)
protected ProducerTemplate basic;
@EndpointInject(uri = MOCK_RESULT)
protected MockEndpoint resultEndpoint;
@Test
public void testBasic() throws Exception {
basic.sendBody(null);
resultEndpoint.setExpectedMessageCount(1);
resultEndpoint.assertIsSatisfied();
}
@Override
public RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from(DIRECT_START)
.id("SunriseTest")
.log(LoggingLevel.INFO, "About to hit sunrise")
.setHeader(Exchange.HTTP_URI, simple("http://api.sunrise-sunset.org/json?lat=36.7201600&lng=-4.4203400"))
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getProperties().put("http.proxyAuthHost", "myproxy.company.org");
exchange.getProperties().put("http.proxyAuthPort", "10000");
exchange.getProperties().put("http.proxyAuthMethod", "Basic");
exchange.getProperties().put("http.proxyAuthUsername", "myusername");
exchange.getProperties().put("http.proxyAuthPassword", "mypassword");
}
})
.recipientList(simple("http4:dummyhost"))
.log(LoggingLevel.INFO, "Done")
.to(MOCK_RESULT);
}
};
}
}