Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将http代理与Apache Camel';s http4端点_Java_Apache Camel - Fatal编程技术网

Java 将http代理与Apache Camel';s http4端点

Java 将http代理与Apache Camel';s http4端点,java,apache-camel,Java,Apache Camel,我正在尝试将http代理与Camel的http4组件一起使用。当使用Intellij的HTTP代理“检查连接”选项进行测试时,代理可以工作 但是,我不知道如何通过Camel正确配置它。运行以下集成测试时,将抛出“ConnectException:连接超时”。有谁能澄清如何正确设置代理详细信息吗 public class SimpleHttpProxyIT extends CamelTestSupport { public static final String DIRECT_START

我正在尝试将http代理与Camel的http4组件一起使用。当使用Intellij的HTTP代理“检查连接”选项进行测试时,代理可以工作

但是,我不知道如何通过Camel正确配置它。运行以下集成测试时,将抛出“ConnectException:连接超时”。有谁能澄清如何正确设置代理详细信息吗

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);
            }
        };
    }
}

我认为应该是
exchange.setProperty(…)
在URI中设置属性。我误读了有关“在URI之外使用代理设置”(Using Proxy Settings of the URI)的文档,因为这是指在上下文中设置代理设置,而不是在交换中设置代理设置

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);
            }
        };
    }
}