2017-02-27 37 views
0

Camelのhttp4コンポーネントでhttpプロキシを使用しようとしています。プロキシは、IntellijのHTTPプロキシ「接続の確認」オプションを使用してテストするときに機能します。Apache Camelのhttp4エンドポイントでhttpプロキシを使用する

しかし、キャメルを介して正しく設定する方法はわかりません。次の統合テストを実行すると、「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

私はそれはURIのプロパティを設定するexchange.setProperty(...)

0

が働いていたしなければならない必要があると思うだろう。私は交換ではなくコンテキストに設定することを指していたので、「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); 
      } 
     }; 
    } 
} 
関連する問題