http://git-wip-us.apache.org/repos/asf/camel/blob/82526729/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProxyServerTest.java ---------------------------------------------------------------------- diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProxyServerTest.java b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProxyServerTest.java index 7fc0d2d..edd23e8 100644 --- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProxyServerTest.java +++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProxyServerTest.java @@ -24,6 +24,7 @@ import java.util.Map; import org.apache.camel.Exchange; import org.apache.camel.Processor; +import org.apache.camel.component.http4.handler.BasicValidationHandler; import org.apache.camel.component.http4.handler.HeaderValidationHandler; import org.apache.camel.component.http4.handler.ProxyAuthenticationValidationHandler; import org.apache.camel.util.URISupport; @@ -39,8 +40,12 @@ import org.apache.http.HttpResponseInterceptor; import org.apache.http.HttpStatus; import org.apache.http.ProtocolException; import org.apache.http.auth.AUTH; -import org.apache.http.localserver.LocalTestServer; +import org.apache.http.impl.bootstrap.HttpServer; +import org.apache.http.impl.bootstrap.ServerBootstrap; +import org.apache.http.localserver.RequestBasicAuth; +import org.apache.http.localserver.ResponseBasicUnauthorized; import org.apache.http.protocol.HttpContext; +import org.apache.http.protocol.HttpProcessor; import org.apache.http.protocol.ImmutableHttpProcessor; import org.apache.http.protocol.ResponseContent; import org.junit.After; @@ -52,37 +57,48 @@ import org.junit.Test; * @version */ public class HttpProxyServerTest extends BaseHttpTest { - - private LocalTestServer proxy; - private String user = "camel"; - private String password = "password"; - - @Override + + private HttpServer proxy; + @Before + @Override public void setUp() throws Exception { - super.setUp(); - - List<HttpRequestInterceptor> requestInterceptors = new ArrayList<HttpRequestInterceptor>(); - requestInterceptors.add(new RequestProxyBasicAuth()); - List<HttpResponseInterceptor> responseInterceptors = new ArrayList<HttpResponseInterceptor>(); - responseInterceptors.add(new ResponseContent()); - responseInterceptors.add(new ResponseProxyBasicUnauthorized()); - ImmutableHttpProcessor httpproc = new ImmutableHttpProcessor(requestInterceptors, responseInterceptors); - - proxy = new LocalTestServer(httpproc, null); + Map<String, String> expectedHeaders = new HashMap<String, String>(); + expectedHeaders.put("Proxy-Connection", "Keep-Alive"); + proxy = ServerBootstrap.bootstrap(). + setHttpProcessor(getBasicHttpProcessor()). + setConnectionReuseStrategy(getConnectionReuseStrategy()). + setResponseFactory(getHttpResponseFactory()). + setExpectationVerifier(getHttpExpectationVerifier()). + setSslContext(getSSLContext()). + registerHandler("*", new HeaderValidationHandler("GET", null, null, getExpectedContent(), expectedHeaders)).create(); proxy.start(); + + super.setUp(); } - @Override @After + @Override public void tearDown() throws Exception { + super.tearDown(); + if (proxy != null) { proxy.stop(); } - - super.tearDown(); } + @Override + protected HttpProcessor getBasicHttpProcessor() { + List<HttpRequestInterceptor> requestInterceptors = new ArrayList<HttpRequestInterceptor>(); + requestInterceptors.add(new RequestProxyBasicAuth()); + List<HttpResponseInterceptor> responseInterceptors = new ArrayList<HttpResponseInterceptor>(); + responseInterceptors.add(new ResponseContent()); + responseInterceptors.add(new ResponseProxyBasicUnauthorized()); + ImmutableHttpProcessor httpproc = new ImmutableHttpProcessor(requestInterceptors, responseInterceptors); + return httpproc; + } + + @Test public void testDifferentHttpProxyConfigured() throws Exception { HttpEndpoint http1 = context.getEndpoint("http4://www.google.com?proxyAuthHost=myproxy&proxyAuthPort=1234", HttpEndpoint.class); @@ -99,12 +115,8 @@ public class HttpProxyServerTest extends BaseHttpTest { @Test public void httpGetWithProxyAndWithoutUser() throws Exception { - Map<String, String> expectedHeaders = new HashMap<String, String>(); - expectedHeaders.put("Host", getHostName() + ":" + getPort()); - expectedHeaders.put("Proxy-Connection", "Keep-Alive"); - proxy.register("*", new HeaderValidationHandler("GET", null, null, getExpectedContent(), expectedHeaders)); - Exchange exchange = template.request("http4://" + getHostName() + ":" + getPort() + "?proxyAuthHost=" + getProxyHost() + "&proxyAuthPort=" + getProxyPort(), new Processor() { + Exchange exchange = template.request("http4://" + getProxyHost() + ":" + getProxyPort() + "?proxyAuthHost=" + getProxyHost() + "&proxyAuthPort=" + getProxyPort(), new Processor() { public void process(Exchange exchange) throws Exception { } }); @@ -112,83 +124,12 @@ public class HttpProxyServerTest extends BaseHttpTest { assertExchange(exchange); } - @Test - public void httpGetWithProxyInCamelContextAndWithoutUser() throws Exception { - context.getProperties().put("http.proxyHost", getProxyHost()); - context.getProperties().put("http.proxyPort", String.valueOf(getProxyPort())); - - Map<String, String> expectedHeaders = new HashMap<String, String>(); - expectedHeaders.put("Host", getHostName() + ":" + getPort()); - expectedHeaders.put("Proxy-Connection", "Keep-Alive"); - - try { - proxy.register("*", new HeaderValidationHandler("GET", null, null, getExpectedContent(), expectedHeaders)); - - Exchange exchange = template.request("http4://" + getHostName() + ":" + getPort(), new Processor() { - public void process(Exchange exchange) throws Exception { - } - }); - - assertExchange(exchange); - } finally { - context.getProperties().remove("http.proxyHost"); - context.getProperties().remove("http.proxyPort"); - } - } - - @Test - public void httpGetWithDuplicateProxyConfigurationAndWithoutUser() throws Exception { - context.getProperties().put("http.proxyHost", "XXX"); - context.getProperties().put("http.proxyPort", "11111"); - - Map<String, String> expectedHeaders = new HashMap<String, String>(); - expectedHeaders.put("Host", getHostName() + ":" + getPort()); - expectedHeaders.put("Proxy-Connection", "Keep-Alive"); - - try { - proxy.register("*", new HeaderValidationHandler("GET", null, null, getExpectedContent(), expectedHeaders)); - - Exchange exchange = template.request("http4://" + getHostName() + ":" + getPort() + "?proxyAuthHost=" - + getProxyHost() + "&proxyAuthPort=" + getProxyPort(), new Processor() { - public void process(Exchange exchange) throws Exception { - } - }); - - assertExchange(exchange); - } finally { - context.getProperties().remove("http.proxyHost"); - context.getProperties().remove("http.proxyPort"); - } - } - - @Test - public void httpGetWithProxyAndWithUser() throws Exception { - proxy.register("*", new ProxyAuthenticationValidationHandler("GET", null, null, getExpectedContent(), user, password)); - - Exchange exchange = template.request("http4://" + getHostName() + ":" + getPort() + "?proxyAuthHost=" - + getProxyHost() + "&proxyAuthPort=" + getProxyPort() + "&proxyAuthUsername=camel&proxyAuthPassword=password", new Processor() { - public void process(Exchange exchange) throws Exception { - } - }); - - assertExchange(exchange); - } - - public void httpGetPullEndpointWithProxyAndWithUser() { - proxy.register("*", new ProxyAuthenticationValidationHandler("GET", null, null, getExpectedContent(), user, password)); - - Exchange exchange = consumer.receive("http4://" + getHostName() + ":" + getPort() + "?proxyAuthHost=" - + getProxyHost() + "&proxyAuthPort=" + getProxyPort() + "&proxyAuthUsername=camel&proxyAuthPassword=password"); - - assertExchange(exchange); - } - private String getProxyHost() { - return proxy.getServiceAddress().getHostName(); + return proxy.getInetAddress().getHostName(); } private int getProxyPort() { - return proxy.getServiceAddress().getPort(); + return proxy.getLocalPort(); } class RequestProxyBasicAuth implements HttpRequestInterceptor {
http://git-wip-us.apache.org/repos/asf/camel/blob/82526729/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpQueryTest.java ---------------------------------------------------------------------- diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpQueryTest.java b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpQueryTest.java index bb8bbcd..b7374b6 100644 --- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpQueryTest.java +++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpQueryTest.java @@ -19,7 +19,10 @@ package org.apache.camel.component.http4; import org.apache.camel.Exchange; import org.apache.camel.Processor; import org.apache.camel.component.http4.handler.BasicValidationHandler; -import org.apache.http.localserver.LocalTestServer; +import org.apache.http.impl.bootstrap.HttpServer; +import org.apache.http.impl.bootstrap.ServerBootstrap; +import org.junit.After; +import org.junit.Before; import org.junit.Test; /** @@ -28,9 +31,39 @@ import org.junit.Test; */ public class HttpQueryTest extends BaseHttpTest { + private HttpServer localServer; + + @Before + @Override + public void setUp() throws Exception { + localServer = ServerBootstrap.bootstrap(). + setHttpProcessor(getBasicHttpProcessor()). + setConnectionReuseStrategy(getConnectionReuseStrategy()). + setResponseFactory(getHttpResponseFactory()). + setExpectationVerifier(getHttpExpectationVerifier()). + setSslContext(getSSLContext()). + registerHandler("/", new BasicValidationHandler("GET", "hl=en&q=camel", null, getExpectedContent())). + registerHandler("/test/", new BasicValidationHandler("GET", "my=@+camel", null, getExpectedContent())). + registerHandler("/user/pass", new BasicValidationHandler("GET", "password=baa&username=foo", null, getExpectedContent())). + create(); + localServer.start(); + + super.setUp(); + } + + @After + @Override + public void tearDown() throws Exception { + super.tearDown(); + + if (localServer != null) { + localServer.stop(); + } + } + @Test public void httpQuery() throws Exception { - Exchange exchange = template.request("http4://" + getHostName() + ":" + getPort() + "/?hl=en&q=camel", new Processor() { + Exchange exchange = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/?hl=en&q=camel", new Processor() { public void process(Exchange exchange) throws Exception { } }); @@ -40,7 +73,7 @@ public class HttpQueryTest extends BaseHttpTest { @Test public void httpQueryHeader() throws Exception { - Exchange exchange = template.request("http4://" + getHostName() + ":" + getPort() + "/", new Processor() { + Exchange exchange = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/", new Processor() { public void process(Exchange exchange) throws Exception { exchange.getIn().setHeader(Exchange.HTTP_QUERY, "hl=en&q=camel"); } @@ -51,7 +84,7 @@ public class HttpQueryTest extends BaseHttpTest { @Test public void httpQueryWithEscapedCharacter() throws Exception { - Exchange exchange = template.request("http4://" + getHostName() + ":" + getPort() + "/test/?my=%40%20camel", new Processor() { + Exchange exchange = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/test/?my=%40%20camel", new Processor() { public void process(Exchange exchange) throws Exception { } }); @@ -61,18 +94,11 @@ public class HttpQueryTest extends BaseHttpTest { @Test public void httpQueryWithUsernamePassword() throws Exception { - Exchange exchange = template.request("http4://" + getHostName() + ":" + getPort() + "/user/pass?password=baa&username=foo", new Processor() { + Exchange exchange = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/user/pass?password=baa&username=foo", new Processor() { public void process(Exchange exchange) throws Exception { } }); assertExchange(exchange); } - - @Override - protected void registerHandler(LocalTestServer server) { - server.register("/", new BasicValidationHandler("GET", "hl=en&q=camel", null, getExpectedContent())); - server.register("/test/", new BasicValidationHandler("GET", "my=@+camel", null, getExpectedContent())); - server.register("/user/pass", new BasicValidationHandler("GET", "password=baa&username=foo", null, getExpectedContent())); - } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/82526729/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpRedirectTest.java ---------------------------------------------------------------------- diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpRedirectTest.java b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpRedirectTest.java index 1251e13..6acee6e 100644 --- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpRedirectTest.java +++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpRedirectTest.java @@ -25,8 +25,12 @@ import org.apache.http.HttpException; import org.apache.http.HttpRequest; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; +import org.apache.http.impl.bootstrap.HttpServer; +import org.apache.http.impl.bootstrap.ServerBootstrap; import org.apache.http.protocol.HttpContext; import org.apache.http.protocol.HttpRequestHandler; +import org.junit.After; +import org.junit.Before; import org.junit.Test; /** @@ -34,12 +38,40 @@ import org.junit.Test; */ public class HttpRedirectTest extends BaseHttpTest { + private HttpServer localServer; + + @Before + @Override + public void setUp() throws Exception { + localServer = ServerBootstrap.bootstrap(). + setHttpProcessor(getBasicHttpProcessor()). + setConnectionReuseStrategy(getConnectionReuseStrategy()). + setResponseFactory(getHttpResponseFactory()). + setExpectationVerifier(getHttpExpectationVerifier()). + setSslContext(getSSLContext()). + registerHandler("/test", new RedirectHandler(HttpStatus.SC_MOVED_PERMANENTLY)). + registerHandler("/someplaceelse", new BasicValidationHandler("GET", null, null, "Bye World")). + registerHandler("/test", new RedirectHandler(HttpStatus.SC_MOVED_PERMANENTLY)). + create(); + localServer.start(); + + super.setUp(); + } + + @After + @Override + public void tearDown() throws Exception { + super.tearDown(); + + if (localServer != null) { + localServer.stop(); + } + } + @Test public void httpRedirect() throws Exception { - // force a 301 redirect - localServer.register("/test", new RedirectHandler(HttpStatus.SC_MOVED_PERMANENTLY)); - String uri = "http4://" + getHostName() + ":" + getPort() + String uri = "http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/test?httpClient.redirectsEnabled=false&httpClient.socketTimeout=60000&httpClient.connectTimeout=60000" + "&httpClient.staleConnectionCheckEnabled=false"; Exchange out = template.request(uri, new Processor() { @@ -52,16 +84,13 @@ public class HttpRedirectTest extends BaseHttpTest { HttpOperationFailedException cause = out.getException(HttpOperationFailedException.class); assertNotNull(cause); assertEquals(HttpStatus.SC_MOVED_PERMANENTLY, cause.getStatusCode()); - assertEquals("http4://" + getHostName() + ":" + getPort() + "/someplaceelse", cause.getRedirectLocation()); + assertEquals("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/someplaceelse", cause.getRedirectLocation()); } @Test public void httpHandleRedirect() throws Exception { - // force a 301 redirect - localServer.register("/test", new RedirectHandler(HttpStatus.SC_MOVED_PERMANENTLY)); - localServer.register("/someplaceelse", new BasicValidationHandler("GET", null, null, "Bye World")); - String uri = "http4://" + getHostName() + ":" + getPort() + String uri = "http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/test?httpClient.socketTimeout=60000&httpClient.connectTimeout=60000" + "&httpClient.staleConnectionCheckEnabled=false"; Exchange out = template.request(uri, new Processor() { @@ -84,7 +113,7 @@ public class HttpRedirectTest extends BaseHttpTest { } public void handle(HttpRequest httpRequest, HttpResponse httpResponse, HttpContext httpContext) throws HttpException, IOException { - httpResponse.setHeader("location", "http4://" + getHostName() + ":" + getPort() + "/someplaceelse"); + httpResponse.setHeader("location", "http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/someplaceelse"); httpResponse.setStatusCode(code); } } http://git-wip-us.apache.org/repos/asf/camel/blob/82526729/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpSOTimeoutTest.java ---------------------------------------------------------------------- diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpSOTimeoutTest.java b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpSOTimeoutTest.java index f2b17b0..3317ecc 100644 --- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpSOTimeoutTest.java +++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpSOTimeoutTest.java @@ -19,7 +19,10 @@ package org.apache.camel.component.http4; import org.apache.camel.Exchange; import org.apache.camel.Processor; import org.apache.camel.component.http4.handler.DelayValidationHandler; -import org.apache.http.localserver.LocalTestServer; +import org.apache.http.impl.bootstrap.HttpServer; +import org.apache.http.impl.bootstrap.ServerBootstrap; +import org.junit.After; +import org.junit.Before; import org.junit.Test; /** @@ -28,9 +31,36 @@ import org.junit.Test; */ public class HttpSOTimeoutTest extends BaseHttpTest { + private HttpServer localServer; + + @Before + @Override + public void setUp() throws Exception { + localServer = ServerBootstrap.bootstrap(). + setHttpProcessor(getBasicHttpProcessor()). + setConnectionReuseStrategy(getConnectionReuseStrategy()). + setResponseFactory(getHttpResponseFactory()). + setExpectationVerifier(getHttpExpectationVerifier()). + setSslContext(getSSLContext()). + registerHandler("/", new DelayValidationHandler("GET", null, null, getExpectedContent(), 2000)).create(); + localServer.start(); + + super.setUp(); + } + + @After + @Override + public void tearDown() throws Exception { + super.tearDown(); + + if (localServer != null) { + localServer.stop(); + } + } + @Test public void httpGet() throws Exception { - Exchange exchange = template.request("http4://" + getHostName() + ":" + getPort() + "?httpClient.SocketTimeout=5000", new Processor() { + Exchange exchange = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "?httpClient.SocketTimeout=5000", new Processor() { public void process(Exchange exchange) throws Exception { } }); @@ -40,16 +70,11 @@ public class HttpSOTimeoutTest extends BaseHttpTest { @Test public void httpGetShouldThrowASocketTimeoutException() throws Exception { - Exchange reply = template.request("http4://" + getHostName() + ":" + getPort() + "?httpClient.SocketTimeout=1000", new Processor() { + Exchange reply = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "?httpClient.SocketTimeout=1000", new Processor() { public void process(Exchange exchange) throws Exception { } }); Exception e = reply.getException(); assertNotNull("Should have thrown an exception", e); } - - @Override - protected void registerHandler(LocalTestServer server) { - server.register("/", new DelayValidationHandler("GET", null, null, getExpectedContent(), 2000)); - } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/82526729/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpThrowExceptionOnFailureTest.java ---------------------------------------------------------------------- diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpThrowExceptionOnFailureTest.java b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpThrowExceptionOnFailureTest.java index 1f52175..237dfc2 100644 --- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpThrowExceptionOnFailureTest.java +++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpThrowExceptionOnFailureTest.java @@ -23,7 +23,10 @@ import org.apache.camel.Message; import org.apache.camel.Processor; import org.apache.camel.component.http4.handler.BasicValidationHandler; import org.apache.http.HttpStatus; -import org.apache.http.localserver.LocalTestServer; +import org.apache.http.impl.bootstrap.HttpServer; +import org.apache.http.impl.bootstrap.ServerBootstrap; +import org.junit.After; +import org.junit.Before; import org.junit.Test; /** @@ -32,9 +35,36 @@ import org.junit.Test; */ public class HttpThrowExceptionOnFailureTest extends BaseHttpTest { + private HttpServer localServer; + + @Before + @Override + public void setUp() throws Exception { + localServer = ServerBootstrap.bootstrap(). + setHttpProcessor(getBasicHttpProcessor()). + setConnectionReuseStrategy(getConnectionReuseStrategy()). + setResponseFactory(getHttpResponseFactory()). + setExpectationVerifier(getHttpExpectationVerifier()). + setSslContext(getSSLContext()). + registerHandler("/", new BasicValidationHandler("GET", null, null, getExpectedContent())).create(); + localServer.start(); + + super.setUp(); + } + + @After + @Override + public void tearDown() throws Exception { + super.tearDown(); + + if (localServer != null) { + localServer.stop(); + } + } + @Test public void httpGetWhichReturnsHttp501() throws Exception { - Exchange exchange = template.request("http4://" + getHostName() + ":" + getPort() + "/XXX?throwExceptionOnFailure=false", new Processor() { + Exchange exchange = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/XXX?throwExceptionOnFailure=false", new Processor() { public void process(Exchange exchange) throws Exception { } }); @@ -51,7 +81,7 @@ public class HttpThrowExceptionOnFailureTest extends BaseHttpTest { @Test public void httpGetWhichReturnsHttp501ShouldThrowAnException() throws Exception { - Exchange reply = template.request("http4://" + getHostName() + ":" + getPort() + "/XXX?throwExceptionOnFailure=true", new Processor() { + Exchange reply = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/XXX?throwExceptionOnFailure=true", new Processor() { public void process(Exchange exchange) throws Exception { } }); @@ -61,9 +91,4 @@ public class HttpThrowExceptionOnFailureTest extends BaseHttpTest { HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, e); assertEquals(501, cause.getStatusCode()); } - - @Override - protected void registerHandler(LocalTestServer server) { - server.register("/", new BasicValidationHandler("GET", null, null, getExpectedContent())); - } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/82526729/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpWithHttpUriHeaderTest.java ---------------------------------------------------------------------- diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpWithHttpUriHeaderTest.java b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpWithHttpUriHeaderTest.java index 45c27de..44ff304 100644 --- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpWithHttpUriHeaderTest.java +++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpWithHttpUriHeaderTest.java @@ -19,6 +19,10 @@ package org.apache.camel.component.http4; import org.apache.camel.Exchange; import org.apache.camel.Processor; import org.apache.camel.component.http4.handler.BasicValidationHandler; +import org.apache.http.impl.bootstrap.HttpServer; +import org.apache.http.impl.bootstrap.ServerBootstrap; +import org.junit.After; +import org.junit.Before; import org.junit.Test; /** @@ -27,13 +31,39 @@ import org.junit.Test; */ public class HttpWithHttpUriHeaderTest extends BaseHttpTest { + private HttpServer localServer; + + @Before + @Override + public void setUp() throws Exception { + localServer = ServerBootstrap.bootstrap(). + setHttpProcessor(getBasicHttpProcessor()). + setConnectionReuseStrategy(getConnectionReuseStrategy()). + setResponseFactory(getHttpResponseFactory()). + setExpectationVerifier(getHttpExpectationVerifier()). + setSslContext(getSSLContext()). + registerHandler("/", new BasicValidationHandler("GET", null, null, getExpectedContent())).create(); + localServer.start(); + + super.setUp(); + } + + @After + @Override + public void tearDown() throws Exception { + super.tearDown(); + + if (localServer != null) { + localServer.stop(); + } + } + @Test public void notBridgeEndpointWithDefault() throws Exception { - localServer.register("/", new BasicValidationHandler("GET", null, null, getExpectedContent())); Exchange exchange = template.request("http4://host/", new Processor() { public void process(Exchange exchange) throws Exception { - exchange.getIn().setHeader(Exchange.HTTP_URI, "http4://" + getHostName() + ":" + getPort() + "/"); + exchange.getIn().setHeader(Exchange.HTTP_URI, "http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/"); } }); assertExchange(exchange); http://git-wip-us.apache.org/repos/asf/camel/blob/82526729/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpsAuthenticationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpsAuthenticationTest.java b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpsAuthenticationTest.java index abe552d..39cca39 100644 --- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpsAuthenticationTest.java +++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpsAuthenticationTest.java @@ -26,12 +26,15 @@ import org.apache.camel.impl.JndiRegistry; import org.apache.http.HttpRequestInterceptor; import org.apache.http.HttpResponseInterceptor; import org.apache.http.conn.ssl.AllowAllHostnameVerifier; +import org.apache.http.impl.bootstrap.HttpServer; +import org.apache.http.impl.bootstrap.ServerBootstrap; import org.apache.http.localserver.RequestBasicAuth; import org.apache.http.localserver.ResponseBasicUnauthorized; - import org.apache.http.protocol.HttpProcessor; import org.apache.http.protocol.ImmutableHttpProcessor; import org.apache.http.protocol.ResponseContent; +import org.junit.After; +import org.junit.Before; import org.junit.Test; /** @@ -42,7 +45,33 @@ public class HttpsAuthenticationTest extends BaseHttpsTest { private String user = "camel"; private String password = "password"; + private HttpServer localServer; + + @Before + @Override + public void setUp() throws Exception { + localServer = ServerBootstrap.bootstrap(). + setHttpProcessor(getBasicHttpProcessor()). + setConnectionReuseStrategy(getConnectionReuseStrategy()). + setResponseFactory(getHttpResponseFactory()). + setExpectationVerifier(getHttpExpectationVerifier()). + setSslContext(getSSLContext()). + registerHandler("/", new AuthenticationValidationHandler("GET", null, null, getExpectedContent(), user, password)).create(); + localServer.start(); + + super.setUp(); + } + @After + @Override + public void tearDown() throws Exception { + super.tearDown(); + + if (localServer != null) { + localServer.stop(); + } + } + @Override protected JndiRegistry createRegistry() throws Exception { JndiRegistry registry = super.createRegistry(); @@ -53,12 +82,12 @@ public class HttpsAuthenticationTest extends BaseHttpsTest { @Test public void httpsGetWithAuthentication() throws Exception { - localServer.register("/", new AuthenticationValidationHandler("GET", null, null, getExpectedContent(), user, password)); - Exchange exchange = template.request("https4://127.0.0.1:" + getPort() + "/?authUsername=camel&authPassword=password&x509HostnameVerifier=x509HostnameVerifier", new Processor() { - public void process(Exchange exchange) throws Exception { - } - }); + Exchange exchange = template.request("https4://127.0.0.1:" + localServer.getLocalPort() + + "/?authUsername=camel&authPassword=password&x509HostnameVerifier=x509HostnameVerifier", new Processor() { + public void process(Exchange exchange) throws Exception { + } + }); assertExchange(exchange); } http://git-wip-us.apache.org/repos/asf/camel/blob/82526729/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpsGetTest.java ---------------------------------------------------------------------- diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpsGetTest.java b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpsGetTest.java index 4541fb4..59d189d 100644 --- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpsGetTest.java +++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpsGetTest.java @@ -21,6 +21,10 @@ import org.apache.camel.Processor; import org.apache.camel.component.http4.handler.BasicValidationHandler; import org.apache.camel.impl.JndiRegistry; import org.apache.http.conn.ssl.AllowAllHostnameVerifier; +import org.apache.http.impl.bootstrap.HttpServer; +import org.apache.http.impl.bootstrap.ServerBootstrap; +import org.junit.After; +import org.junit.Before; import org.junit.Test; /** @@ -29,6 +33,33 @@ import org.junit.Test; */ public class HttpsGetTest extends BaseHttpsTest { + private HttpServer localServer; + + @Before + @Override + public void setUp() throws Exception { + localServer = ServerBootstrap.bootstrap(). + setHttpProcessor(getBasicHttpProcessor()). + setConnectionReuseStrategy(getConnectionReuseStrategy()). + setResponseFactory(getHttpResponseFactory()). + setExpectationVerifier(getHttpExpectationVerifier()). + setSslContext(getSSLContext()). + registerHandler("/mail/", new BasicValidationHandler("GET", null, null, getExpectedContent())).create(); + localServer.start(); + + super.setUp(); + } + + @After + @Override + public void tearDown() throws Exception { + super.tearDown(); + + if (localServer != null) { + localServer.stop(); + } + } + @Override protected JndiRegistry createRegistry() throws Exception { JndiRegistry registry = super.createRegistry(); @@ -39,9 +70,8 @@ public class HttpsGetTest extends BaseHttpsTest { @Test public void httpsGet() throws Exception { - localServer.register("/mail/", new BasicValidationHandler("GET", null, null, getExpectedContent())); - Exchange exchange = template.request("https4://127.0.0.1:" + getPort() + "/mail/?x509HostnameVerifier=x509HostnameVerifier", new Processor() { + Exchange exchange = template.request("https4://127.0.0.1:" + localServer.getLocalPort() + "/mail/?x509HostnameVerifier=x509HostnameVerifier", new Processor() { public void process(Exchange exchange) throws Exception { } }); http://git-wip-us.apache.org/repos/asf/camel/blob/82526729/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpsSslContextParametersGetTest.java ---------------------------------------------------------------------- diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpsSslContextParametersGetTest.java b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpsSslContextParametersGetTest.java index ec0a436..abd3aaa 100644 --- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpsSslContextParametersGetTest.java +++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpsSslContextParametersGetTest.java @@ -21,9 +21,40 @@ import org.apache.camel.Processor; import org.apache.camel.component.http4.handler.BasicValidationHandler; import org.apache.camel.impl.JndiRegistry; import org.apache.camel.util.jsse.SSLContextParameters; +import org.apache.http.impl.bootstrap.HttpServer; +import org.apache.http.impl.bootstrap.ServerBootstrap; +import org.junit.After; +import org.junit.Before; import org.junit.Test; public class HttpsSslContextParametersGetTest extends HttpsGetTest { + + private HttpServer localServer; + + @Before + @Override + public void setUp() throws Exception { + localServer = ServerBootstrap.bootstrap(). + setHttpProcessor(getBasicHttpProcessor()). + setConnectionReuseStrategy(getConnectionReuseStrategy()). + setResponseFactory(getHttpResponseFactory()). + setExpectationVerifier(getHttpExpectationVerifier()). + setSslContext(getSSLContext()). + registerHandler("/mail/", new BasicValidationHandler("GET", null, null, getExpectedContent())).create(); + localServer.start(); + + super.setUp(); + } + + @After + @Override + public void tearDown() throws Exception { + super.tearDown(); + + if (localServer != null) { + localServer.stop(); + } + } @Override protected JndiRegistry createRegistry() throws Exception { @@ -35,12 +66,12 @@ public class HttpsSslContextParametersGetTest extends HttpsGetTest { @Test public void httpsGet() throws Exception { - localServer.register("/mail/", new BasicValidationHandler("GET", null, null, getExpectedContent())); - Exchange exchange = template.request("https4://127.0.0.1:" + getPort() + "/mail/?x509HostnameVerifier=x509HostnameVerifier&sslContextParametersRef=sslContextParameters", new Processor() { - public void process(Exchange exchange) throws Exception { - } - }); + Exchange exchange = template.request("https4://127.0.0.1:" + localServer.getLocalPort() + + "/mail/?x509HostnameVerifier=x509HostnameVerifier&sslContextParametersRef=sslContextParameters", new Processor() { + public void process(Exchange exchange) throws Exception { + } + }); assertExchange(exchange); } http://git-wip-us.apache.org/repos/asf/camel/blob/82526729/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpsTwoComponentsSslContextParametersGetTest.java ---------------------------------------------------------------------- diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpsTwoComponentsSslContextParametersGetTest.java b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpsTwoComponentsSslContextParametersGetTest.java index 9a9793f..03ac012 100644 --- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpsTwoComponentsSslContextParametersGetTest.java +++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpsTwoComponentsSslContextParametersGetTest.java @@ -21,12 +21,42 @@ import org.apache.camel.impl.JndiRegistry; import org.apache.camel.test.AvailablePortFinder; import org.apache.camel.util.jsse.SSLContextParameters; import org.apache.http.conn.ssl.AllowAllHostnameVerifier; +import org.apache.http.impl.bootstrap.HttpServer; +import org.apache.http.impl.bootstrap.ServerBootstrap; +import org.junit.After; +import org.junit.Before; import org.junit.Test; public class HttpsTwoComponentsSslContextParametersGetTest extends BaseHttpsTest { private int port2; + private HttpServer localServer; + + @Before + @Override + public void setUp() throws Exception { + localServer = ServerBootstrap.bootstrap(). + setHttpProcessor(getBasicHttpProcessor()). + setConnectionReuseStrategy(getConnectionReuseStrategy()). + setResponseFactory(getHttpResponseFactory()). + setExpectationVerifier(getHttpExpectationVerifier()). + setSslContext(getSSLContext()). + create(); + localServer.start(); + + super.setUp(); + } + @After + @Override + public void tearDown() throws Exception { + super.tearDown(); + + if (localServer != null) { + localServer.stop(); + } + } + @Override protected JndiRegistry createRegistry() throws Exception { JndiRegistry registry = super.createRegistry(); @@ -50,10 +80,10 @@ public class HttpsTwoComponentsSslContextParametersGetTest extends BaseHttpsTest context.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { - port2 = AvailablePortFinder.getNextAvailable(getPort()); + port2 = AvailablePortFinder.getNextAvailable(localServer.getLocalPort()); from("direct:foo") - .to("http4s-foo://127.0.0.1:" + getPort() + "/mail?x509HostnameVerifier=x509HostnameVerifier&sslContextParametersRef=sslContextParameters"); + .to("http4s-foo://127.0.0.1:" + localServer.getLocalPort() + "/mail?x509HostnameVerifier=x509HostnameVerifier&sslContextParametersRef=sslContextParameters"); from("direct:bar") .to("http4s-bar://127.0.0.1:" + port2 + "/mail?x509HostnameVerifier=x509HostnameVerifier&sslContextParametersRef=sslContextParameters2"); http://git-wip-us.apache.org/repos/asf/camel/blob/82526729/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpsTwoDifferentSslContextParametersGetTest.java ---------------------------------------------------------------------- diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpsTwoDifferentSslContextParametersGetTest.java b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpsTwoDifferentSslContextParametersGetTest.java index c98ef31..fc0c1ee 100644 --- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpsTwoDifferentSslContextParametersGetTest.java +++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpsTwoDifferentSslContextParametersGetTest.java @@ -21,12 +21,42 @@ import org.apache.camel.builder.RouteBuilder; import org.apache.camel.impl.JndiRegistry; import org.apache.camel.util.jsse.SSLContextParameters; import org.apache.http.conn.ssl.AllowAllHostnameVerifier; +import org.apache.http.impl.bootstrap.HttpServer; +import org.apache.http.impl.bootstrap.ServerBootstrap; +import org.junit.After; +import org.junit.Before; import org.junit.Ignore; import org.junit.Test; @Ignore("Now we support to set sslContextParameters on different endpoints") public class HttpsTwoDifferentSslContextParametersGetTest extends BaseHttpsTest { + + private HttpServer localServer; + @Before + @Override + public void setUp() throws Exception { + localServer = ServerBootstrap.bootstrap(). + setHttpProcessor(getBasicHttpProcessor()). + setConnectionReuseStrategy(getConnectionReuseStrategy()). + setResponseFactory(getHttpResponseFactory()). + setExpectationVerifier(getHttpExpectationVerifier()). + setSslContext(getSSLContext()). + create(); + localServer.start(); + + super.setUp(); + } + + @After + @Override + public void tearDown() throws Exception { + super.tearDown(); + + if (localServer != null) { + localServer.stop(); + } + } @Override protected JndiRegistry createRegistry() throws Exception { JndiRegistry registry = super.createRegistry(); @@ -48,10 +78,10 @@ public class HttpsTwoDifferentSslContextParametersGetTest extends BaseHttpsTest @Override public void configure() throws Exception { from("direct:foo") - .to("https4://127.0.0.1:" + getPort() + "/mail?x509HostnameVerifier=x509HostnameVerifier&sslContextParametersRef=sslContextParameters"); + .to("https4://127.0.0.1:" + localServer.getLocalPort() + "/mail?x509HostnameVerifier=x509HostnameVerifier&sslContextParametersRef=sslContextParameters"); from("direct:bar") - .to("https4://127.0.0.1:" + getPort() + "/mail?x509HostnameVerifier=x509HostnameVerifier&sslContextParametersRef=sslContextParameters2"); + .to("https4://127.0.0.1:" + localServer.getLocalPort() + "/mail?x509HostnameVerifier=x509HostnameVerifier&sslContextParametersRef=sslContextParameters2"); } }); try {