2017-02-27 45 views
0

我试图在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); 
      } 
     }; 
    } 
} 

回答

0

我想它应该应该exchange.setProperty(...)

0

设置在URI属性的工作。我误读了关于“在URI之外使用代理服务器设置”(http://camel.apache.org/http4.html)的文档,因为这涉及到将它们设置在上下文而不是交换

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")) 
         .recipientList(simple("http4:dummyhost?proxyAuthHost=myproxy.company.org&proxyAuthPort=10000&proxyAuthUsername=myusername&proxyAuthPassword=mypassword")) 
         .log(LoggingLevel.INFO, "Done") 
         .to(MOCK_RESULT); 
      } 
     }; 
    } 
}