You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2015/06/14 23:59:11 UTC
[1/4] camel git commit: CAMEL-8869 Upgrade httpcore and httpclient to
version 4.4.1 and start refactoring tests
Repository: camel
Updated Branches:
refs/heads/master 3c4b97f03 -> bd881496e
CAMEL-8869 Upgrade httpcore and httpclient to version 4.4.1 and start refactoring tests
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/2da8f198
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2da8f198
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2da8f198
Branch: refs/heads/master
Commit: 2da8f198b0f4ad303f2a4984403581b26a489ffc
Parents: 3c4b97f
Author: Andrea Cosentino <an...@gmail.com>
Authored: Sun Jun 14 15:33:00 2015 +0200
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Sun Jun 14 23:51:24 2015 +0200
----------------------------------------------------------------------
.../camel/component/http4/BaseHttpTest.java | 1 +
.../component/http4/HttpAuthenticationTest.java | 45 +++++++++++----
.../component/http4/HttpServerTestSupport.java | 59 --------------------
parent/pom.xml | 4 +-
4 files changed, 38 insertions(+), 71 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/2da8f198/components/camel-http4/src/test/java/org/apache/camel/component/http4/BaseHttpTest.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/BaseHttpTest.java b/components/camel-http4/src/test/java/org/apache/camel/component/http4/BaseHttpTest.java
index 1fd8d1c..ab9840a 100644
--- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/BaseHttpTest.java
+++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/BaseHttpTest.java
@@ -20,6 +20,7 @@ import java.util.Map;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
+import org.apache.camel.test.junit4.CamelTestSupport;
import org.apache.http.HttpStatus;
/**
http://git-wip-us.apache.org/repos/asf/camel/blob/2da8f198/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpAuthenticationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpAuthenticationTest.java b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpAuthenticationTest.java
index 5ca499c..3a29ef7 100644
--- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpAuthenticationTest.java
+++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpAuthenticationTest.java
@@ -27,12 +27,15 @@ import org.apache.camel.component.http4.handler.AuthenticationValidationHandler;
import org.apache.http.HttpRequestInterceptor;
import org.apache.http.HttpResponseInterceptor;
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.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;
/**
@@ -43,10 +46,37 @@ public class HttpAuthenticationTest extends BaseHttpTest {
private String user = "camel";
private String password = "password";
+
+ protected HttpServer localServer;
+
+ @Before
+ @Override
+ public void setUp() throws Exception {
+ localServer = ServerBootstrap.bootstrap().
+ setHttpProcessor(getBasicHttpProcessor()).
+ setConnectionReuseStrategy(getConnectionReuseStrategy()).
+ setResponseFactory(getHttpResponseFactory()).
+ setExpectationVerifier(getHttpExpectationVerifier()).
+ setSslContext(getSSLContext()).
+ registerHandler("/search", 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();
+ }
+ }
+
@Test
public void basicAuthenticationShouldSuccess() throws Exception {
- Exchange exchange = template.request("http4://" + getHostName() + ":" + getPort() + "/search?authUsername=" + user + "&authPassword=" + password, new Processor() {
+ Exchange exchange = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/search?authUsername=" + user + "&authPassword=" + password, new Processor() {
public void process(Exchange exchange) throws Exception {
}
});
@@ -56,7 +86,7 @@ public class HttpAuthenticationTest extends BaseHttpTest {
@Test
public void basicAuthenticationPreemptiveShouldSuccess() throws Exception {
- Exchange exchange = template.request("http4://" + getHostName() + ":" + getPort() + "/search?authUsername=" + user + "&authPassword="
+ Exchange exchange = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/search?authUsername=" + user + "&authPassword="
+ password + "&authenticationPreemptive=true", new Processor() {
public void process(Exchange exchange) throws Exception {
}
@@ -67,7 +97,7 @@ public class HttpAuthenticationTest extends BaseHttpTest {
@Test
public void basicAuthenticationShouldFailWithoutCreds() throws Exception {
- Exchange exchange = template.request("http4://" + getHostName() + ":" + getPort() + "/search?throwExceptionOnFailure=false", new Processor() {
+ Exchange exchange = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/search?throwExceptionOnFailure=false", new Processor() {
public void process(Exchange exchange) throws Exception {
}
});
@@ -77,7 +107,7 @@ public class HttpAuthenticationTest extends BaseHttpTest {
@Test
public void basicAuthenticationShouldFailWithWrongCreds() throws Exception {
- Exchange exchange = template.request("http4://" + getHostName() + ":" + getPort() + "/search?throwExceptionOnFailure=false&authUsername=camel&authPassword=wrong", new Processor() {
+ Exchange exchange = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/search?throwExceptionOnFailure=false&authUsername=camel&authPassword=wrong", new Processor() {
public void process(Exchange exchange) throws Exception {
}
});
@@ -96,11 +126,6 @@ public class HttpAuthenticationTest extends BaseHttpTest {
return httpproc;
}
- @Override
- protected void registerHandler(LocalTestServer server) {
- server.register("/search", new AuthenticationValidationHandler("GET", null, null, getExpectedContent(), user, password));
- }
-
protected void assertExchangeFailed(Exchange exchange) {
assertNotNull(exchange);
http://git-wip-us.apache.org/repos/asf/camel/blob/2da8f198/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpServerTestSupport.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpServerTestSupport.java b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpServerTestSupport.java
index eb73537..7fc1cc8 100644
--- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpServerTestSupport.java
+++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpServerTestSupport.java
@@ -21,11 +21,8 @@ import javax.net.ssl.SSLContext;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.apache.http.ConnectionReuseStrategy;
import org.apache.http.HttpResponseFactory;
-import org.apache.http.localserver.LocalTestServer;
import org.apache.http.protocol.HttpExpectationVerifier;
import org.apache.http.protocol.HttpProcessor;
-import org.junit.After;
-import org.junit.Before;
/**
* Abstract base class for unit testing using a http server.
@@ -36,35 +33,6 @@ import org.junit.Before;
*/
public abstract class HttpServerTestSupport extends CamelTestSupport {
- protected LocalTestServer localServer;
-
- @Before
- @Override
- public void setUp() throws Exception {
- localServer = new LocalTestServer(
- getBasicHttpProcessor(),
- getConnectionReuseStrategy(),
- getHttpResponseFactory(),
- getHttpExpectationVerifier(),
- getSSLContext(),
- false,
- new String[]{"TLSv1.2"});
- registerHandler(localServer);
- localServer.start();
-
- super.setUp();
- }
-
- @After
- @Override
- public void tearDown() throws Exception {
- super.tearDown();
-
- if (localServer != null) {
- localServer.stop();
- }
- }
-
/**
* Returns the org.apache.http.protocol.BasicHttpProcessor which should be
* used by the server.
@@ -114,31 +82,4 @@ public abstract class HttpServerTestSupport extends CamelTestSupport {
protected SSLContext getSSLContext() throws Exception {
return null;
}
-
- /**
- * Register the org.apache.http.protocol.HttpRequestHandler which handles
- * the request and set the proper response (headers and content).
- *
- * @param server
- */
- protected void registerHandler(LocalTestServer server) {
- }
-
- /**
- * Obtains the host name of the local test server.
- *
- * @return hostName
- */
- protected String getHostName() {
- return localServer.getServiceAddress().getHostName();
- }
-
- /**
- * Obtains the port of the local test server.
- *
- * @return port
- */
- protected int getPort() {
- return localServer.getServiceAddress().getPort();
- }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/2da8f198/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index ce2a7e7..34d0f34 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -217,8 +217,8 @@
<htmlunit.version>2.15</htmlunit.version>
<htmlunit-bundle-version>2.15_1</htmlunit-bundle-version>
<httpunit-version>1.7</httpunit-version>
- <httpcore4-version>4.3.3</httpcore4-version>
- <httpclient4-version>4.3.6</httpclient4-version>
+ <httpcore4-version>4.4.1</httpcore4-version>
+ <httpclient4-version>4.4.1</httpclient4-version>
<httpasyncclient-version>4.0.2</httpasyncclient-version>
<httpclient-version>3.1</httpclient-version>
<ibatis-bundle-version>2.3.4.726_4</ibatis-bundle-version>
[3/4] camel git commit: CAMEL-8869 Resolve Switching httpClient from
4.3.x to 4.4.x break tests
Posted by ac...@apache.org.
CAMEL-8869 Resolve Switching httpClient from 4.3.x to 4.4.x break tests
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/82526729
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/82526729
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/82526729
Branch: refs/heads/master
Commit: 825267293d5a5a32c41cd95cd540abee76cc514d
Parents: 2da8f19
Author: Andrea Cosentino <an...@gmail.com>
Authored: Sun Jun 14 23:05:33 2015 +0200
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Sun Jun 14 23:52:58 2015 +0200
----------------------------------------------------------------------
.../component/http4/HttpAuthenticationTest.java | 36 ++---
.../camel/component/http4/HttpBodyTest.java | 52 +++++--
.../component/http4/HttpBridgeEndpointTest.java | 41 ++++--
.../component/http4/HttpCamelHeadersTest.java | 47 +++++--
.../camel/component/http4/HttpCharsetTest.java | 43 ++++--
.../component/http4/HttpCompressionTest.java | 47 +++++--
.../component/http4/HttpConcurrentTest.java | 54 ++++++--
.../http4/HttpDefaultPortNumberTest.java | 51 +++++--
.../camel/component/http4/HttpMethodsTest.java | 70 +++++++---
.../http4/HttpNoConnectionRedeliveryTest.java | 42 ++++--
.../component/http4/HttpNoConnectionTest.java | 44 ++++--
.../camel/component/http4/HttpPathTest.java | 46 +++++--
.../http4/HttpPollingConsumerTest.java | 43 ++++--
.../http4/HttpProducerContentTypeTest.java | 60 +++++---
.../http4/HttpProducerSelectMethodTest.java | 54 ++++++--
.../HttpProducerTwoHeadersWithSameKeyTest.java | 83 ++++++++---
...ttpProducerTwoParametersWithSameKeyTest.java | 63 ++++++---
.../component/http4/HttpProxyServerTest.java | 137 ++++++-------------
.../camel/component/http4/HttpQueryTest.java | 50 +++++--
.../camel/component/http4/HttpRedirectTest.java | 47 +++++--
.../component/http4/HttpSOTimeoutTest.java | 41 ++++--
.../http4/HttpThrowExceptionOnFailureTest.java | 41 ++++--
.../http4/HttpWithHttpUriHeaderTest.java | 34 ++++-
.../http4/HttpsAuthenticationTest.java | 41 +++++-
.../camel/component/http4/HttpsGetTest.java | 34 ++++-
.../http4/HttpsSslContextParametersGetTest.java | 41 +++++-
...woComponentsSslContextParametersGetTest.java | 34 ++++-
...TwoDifferentSslContextParametersGetTest.java | 34 ++++-
28 files changed, 1033 insertions(+), 377 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/82526729/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpAuthenticationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpAuthenticationTest.java b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpAuthenticationTest.java
index 3a29ef7..4d6e947 100644
--- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpAuthenticationTest.java
+++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpAuthenticationTest.java
@@ -44,21 +44,21 @@ import org.junit.Test;
*/
public class HttpAuthenticationTest extends BaseHttpTest {
+ private HttpServer localServer;
+
private String user = "camel";
private String password = "password";
-
- protected HttpServer localServer;
-
+
@Before
@Override
public void setUp() throws Exception {
localServer = ServerBootstrap.bootstrap().
- setHttpProcessor(getBasicHttpProcessor()).
- setConnectionReuseStrategy(getConnectionReuseStrategy()).
- setResponseFactory(getHttpResponseFactory()).
- setExpectationVerifier(getHttpExpectationVerifier()).
- setSslContext(getSSLContext()).
- registerHandler("/search", new AuthenticationValidationHandler("GET", null, null, getExpectedContent(), user, password)).create();
+ setHttpProcessor(getBasicHttpProcessor()).
+ setConnectionReuseStrategy(getConnectionReuseStrategy()).
+ setResponseFactory(getHttpResponseFactory()).
+ setExpectationVerifier(getHttpExpectationVerifier()).
+ setSslContext(getSSLContext()).
+ registerHandler("/search", new AuthenticationValidationHandler("GET", null, null, getExpectedContent(), user, password)).create();
localServer.start();
super.setUp();
@@ -76,10 +76,11 @@ public class HttpAuthenticationTest extends BaseHttpTest {
@Test
public void basicAuthenticationShouldSuccess() throws Exception {
- Exchange exchange = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/search?authUsername=" + user + "&authPassword=" + password, new Processor() {
- public void process(Exchange exchange) throws Exception {
- }
- });
+ Exchange exchange = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/search?authUsername=" + user + "&authPassword="
+ + password, new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ }
+ });
assertExchange(exchange);
}
@@ -107,10 +108,11 @@ public class HttpAuthenticationTest extends BaseHttpTest {
@Test
public void basicAuthenticationShouldFailWithWrongCreds() throws Exception {
- Exchange exchange = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/search?throwExceptionOnFailure=false&authUsername=camel&authPassword=wrong", new Processor() {
- public void process(Exchange exchange) throws Exception {
- }
- });
+ Exchange exchange = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort()
+ + "/search?throwExceptionOnFailure=false&authUsername=camel&authPassword=wrong", new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ }
+ });
assertExchangeFailed(exchange);
}
http://git-wip-us.apache.org/repos/asf/camel/blob/82526729/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpBodyTest.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpBodyTest.java b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpBodyTest.java
index 1868bbd..104f14e 100644
--- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpBodyTest.java
+++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpBodyTest.java
@@ -25,7 +25,10 @@ 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.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;
@@ -37,6 +40,37 @@ public class HttpBodyTest extends BaseHttpTest {
private String protocolString = "http4://";
// default content encoding of the local test server
private String charset = "ISO-8859-1";
+ private HttpServer localServer;
+
+ @Before
+ @Override
+ public void setUp() throws Exception {
+ Map<String, String> expectedHeaders = new HashMap<String, String>();
+ expectedHeaders.put("Content-Type", "image/jpeg");
+
+ localServer = ServerBootstrap.bootstrap().
+ setHttpProcessor(getBasicHttpProcessor()).
+ setConnectionReuseStrategy(getConnectionReuseStrategy()).
+ setResponseFactory(getHttpResponseFactory()).
+ setExpectationVerifier(getHttpExpectationVerifier()).
+ setSslContext(getSSLContext()).
+ registerHandler("/post", new BasicValidationHandler("POST", null, getBody(), getExpectedContent())).
+ registerHandler("/post1", new HeaderValidationHandler("POST", null, null, getExpectedContent(), expectedHeaders)).
+ create();
+ localServer.start();
+
+ super.setUp();
+ }
+
+ @After
+ @Override
+ public void tearDown() throws Exception {
+ super.tearDown();
+
+ if (localServer != null) {
+ localServer.stop();
+ }
+ }
public String getProtocolString() {
return protocolString;
@@ -48,7 +82,7 @@ public class HttpBodyTest extends BaseHttpTest {
@Test
public void httpPostWithStringBody() throws Exception {
- Exchange exchange = template.request(getProtocolString() + getHostName() + ":" + getPort() + "/", new Processor() {
+ Exchange exchange = template.request(getProtocolString() + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/post", new Processor() {
public void process(Exchange exchange) throws Exception {
// without this property, camel use the os default encoding
// to create the byte array for the StringRequestEntity
@@ -62,7 +96,7 @@ public class HttpBodyTest extends BaseHttpTest {
@Test
public void httpPostWithByteArrayBody() throws Exception {
- Exchange exchange = template.request(getProtocolString() + getHostName() + ":" + getPort() + "/", new Processor() {
+ Exchange exchange = template.request(getProtocolString() + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/post", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody(getBody().getBytes(charset));
}
@@ -73,7 +107,7 @@ public class HttpBodyTest extends BaseHttpTest {
@Test
public void httpPostWithInputStreamBody() throws Exception {
- Exchange exchange = template.request(getProtocolString() + getHostName() + ":" + getPort() + "/", new Processor() {
+ Exchange exchange = template.request(getProtocolString() + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/post", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody(new ByteArrayInputStream(getBody().getBytes(charset)));
}
@@ -84,11 +118,8 @@ public class HttpBodyTest extends BaseHttpTest {
@Test
public void httpPostWithImage() throws Exception {
- Map<String, String> expectedHeaders = new HashMap<String, String>();
- expectedHeaders.put("Content-Type", "image/jpeg");
- localServer.register("/", new HeaderValidationHandler("POST", null, null, getExpectedContent(), expectedHeaders));
- Exchange exchange = template.send(getProtocolString() + getHostName() + ":" + getPort() + "/", new Processor() {
+ Exchange exchange = template.send(getProtocolString() + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/post1", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody(new File("src/test/data/logo.jpeg"));
exchange.getIn().setHeader("Content-Type", "image/jpeg");
@@ -98,11 +129,6 @@ public class HttpBodyTest extends BaseHttpTest {
assertExchange(exchange);
}
- @Override
- protected void registerHandler(LocalTestServer server) {
- server.register("/", new BasicValidationHandler("POST", null, getBody(), getExpectedContent()));
- }
-
protected String getBody() {
return "hl=de&q=camel+rocks";
}
http://git-wip-us.apache.org/repos/asf/camel/blob/82526729/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpBridgeEndpointTest.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpBridgeEndpointTest.java b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpBridgeEndpointTest.java
index 3bbfd29..862091b 100644
--- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpBridgeEndpointTest.java
+++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpBridgeEndpointTest.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,11 +31,38 @@ import org.junit.Test;
*/
public class HttpBridgeEndpointTest 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 notBridgeEndpoint() throws Exception {
Exchange exchange = template.request("http4://host/?bridgeEndpoint=false", new Processor() {
public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(Exchange.HTTP_URI, "http://" + getHostName() + ":" + getPort() + "/");
+ exchange.getIn().setHeader(Exchange.HTTP_URI, "http://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/");
}
});
@@ -41,7 +71,7 @@ public class HttpBridgeEndpointTest extends BaseHttpTest {
@Test
public void bridgeEndpoint() throws Exception {
- Exchange exchange = template.request("http4://" + getHostName() + ":" + getPort() + "/?bridgeEndpoint=true", new Processor() {
+ Exchange exchange = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/?bridgeEndpoint=true", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(Exchange.HTTP_URI, "http://host:8080/");
}
@@ -49,9 +79,4 @@ public class HttpBridgeEndpointTest extends BaseHttpTest {
assertExchange(exchange);
}
-
- @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/HttpCamelHeadersTest.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpCamelHeadersTest.java b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpCamelHeadersTest.java
index f51caa3..98741e1 100644
--- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpCamelHeadersTest.java
+++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpCamelHeadersTest.java
@@ -27,8 +27,11 @@ import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
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.apache.http.protocol.HttpContext;
+import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
/**
@@ -37,9 +40,40 @@ import org.junit.Test;
*/
public class HttpCamelHeadersTest extends BaseHttpTest {
+ private HttpServer localServer;
+
+ @Before
+ @Override
+ public void setUp() throws Exception {
+ Map<String, String> expectedHeaders = new HashMap<String, String>();
+ expectedHeaders.put("TestHeader", "test");
+ expectedHeaders.put("Accept-Language", "pl");
+
+ localServer = ServerBootstrap.bootstrap().
+ setHttpProcessor(getBasicHttpProcessor()).
+ setConnectionReuseStrategy(getConnectionReuseStrategy()).
+ setResponseFactory(getHttpResponseFactory()).
+ setExpectationVerifier(getHttpExpectationVerifier()).
+ setSslContext(getSSLContext()).
+ registerHandler("/", new MyHeaderValidationHandler("GET", "HTTP/1.0", getExpectedContent(), expectedHeaders)).create();
+ localServer.start();
+
+ super.setUp();
+ }
+
+ @After
+ @Override
+ public void tearDown() throws Exception {
+ super.tearDown();
+
+ if (localServer != null) {
+ localServer.stop();
+ }
+ }
+
@Test
public void httpHeadersShouldPresent() 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("TestHeader", "test");
exchange.getIn().setHeader("Accept-Language", "pl");
@@ -57,15 +91,6 @@ public class HttpCamelHeadersTest extends BaseHttpTest {
assertEquals("test", headers.get("TestHeader"));
assertEquals("pl", headers.get("Accept-Language"));
}
-
- @Override
- protected void registerHandler(LocalTestServer server) {
- Map<String, String> expectedHeaders = new HashMap<String, String>();
- expectedHeaders.put("TestHeader", "test");
- expectedHeaders.put("Accept-Language", "pl");
-
- server.register("/", new MyHeaderValidationHandler("GET", "HTTP/1.0", getExpectedContent(), expectedHeaders));
- }
class MyHeaderValidationHandler extends HeaderValidationHandler {
private String expectProtocolVersion;
http://git-wip-us.apache.org/repos/asf/camel/blob/82526729/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpCharsetTest.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpCharsetTest.java b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpCharsetTest.java
index 49041a1..a18f473 100644
--- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpCharsetTest.java
+++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpCharsetTest.java
@@ -21,7 +21,10 @@ import java.io.ByteArrayInputStream;
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;
/**
@@ -32,10 +35,37 @@ public class HttpCharsetTest extends BaseHttpTest {
// default content encoding of the local test server
private String charset = "ISO-8859-1";
+
+ 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("POST", null, getBody(), getExpectedContent())).create();
+ localServer.start();
+
+ super.setUp();
+ }
+
+ @After
+ @Override
+ public void tearDown() throws Exception {
+ super.tearDown();
+
+ if (localServer != null) {
+ localServer.stop();
+ }
+ }
@Test
public void sendCharsetInExchangeProperty() 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.setProperty(Exchange.CHARSET_NAME, charset);
exchange.getIn().setBody(getBody());
@@ -47,7 +77,7 @@ public class HttpCharsetTest extends BaseHttpTest {
@Test
public void sendByteArrayCharsetInExchangeProperty() 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.setProperty(Exchange.CHARSET_NAME, charset);
exchange.getIn().setBody(getBody().getBytes(charset));
@@ -59,7 +89,7 @@ public class HttpCharsetTest extends BaseHttpTest {
@Test
public void sendInputStreamCharsetInExchangeProperty() 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.setProperty(Exchange.CHARSET_NAME, charset);
exchange.getIn().setBody(new ByteArrayInputStream(getBody().getBytes(charset)));
@@ -69,11 +99,6 @@ public class HttpCharsetTest extends BaseHttpTest {
assertExchange(exchange);
}
- @Override
- protected void registerHandler(LocalTestServer server) {
- server.register("/", new BasicValidationHandler("POST", null, getBody(), getExpectedContent()));
- }
-
protected String getBody() {
char lattinSmallLetterAWithDiaeresis = 0x00E4;
char lattinSmallLetterOWithDiaeresis = 0x00F6;
http://git-wip-us.apache.org/repos/asf/camel/blob/82526729/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpCompressionTest.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpCompressionTest.java b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpCompressionTest.java
index e9aba3e..13d69d8 100644
--- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpCompressionTest.java
+++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpCompressionTest.java
@@ -40,13 +40,16 @@ import org.apache.http.HttpResponse;
import org.apache.http.HttpResponseInterceptor;
import org.apache.http.HttpStatus;
import org.apache.http.entity.HttpEntityWrapper;
-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.ResponseBasicUnauthorized;
import org.apache.http.message.BasicHeader;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpProcessor;
import org.apache.http.protocol.ImmutableHttpProcessor;
import org.apache.http.util.EntityUtils;
+import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
/**
@@ -55,9 +58,40 @@ import org.junit.Test;
*/
public class HttpCompressionTest extends BaseHttpTest {
+ private HttpServer localServer;
+
+ @Before
+ @Override
+ public void setUp() throws Exception {
+ Map<String, String> expectedHeaders = new HashMap<String, String>();
+ expectedHeaders.put("Content-Type", "text/plain");
+ expectedHeaders.put("Content-Encoding", "gzip");
+
+ localServer = ServerBootstrap.bootstrap().
+ setHttpProcessor(getBasicHttpProcessor()).
+ setConnectionReuseStrategy(getConnectionReuseStrategy()).
+ setResponseFactory(getHttpResponseFactory()).
+ setExpectationVerifier(getHttpExpectationVerifier()).
+ setSslContext(getSSLContext()).
+ registerHandler("/", new HeaderValidationHandler("POST", null, getBody(), getExpectedContent(), expectedHeaders)).create();
+ localServer.start();
+
+ super.setUp();
+ }
+
+ @After
+ @Override
+ public void tearDown() throws Exception {
+ super.tearDown();
+
+ if (localServer != null) {
+ localServer.stop();
+ }
+ }
+
@Test
public void compressedHttpPost() 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.CONTENT_TYPE, "text/plain");
exchange.getIn().setHeader(Exchange.CONTENT_ENCODING, "gzip");
@@ -87,15 +121,6 @@ public class HttpCompressionTest extends BaseHttpTest {
return httpproc;
}
- @Override
- protected void registerHandler(LocalTestServer server) {
- Map<String, String> expectedHeaders = new HashMap<String, String>();
- expectedHeaders.put("Content-Type", "text/plain");
- expectedHeaders.put("Content-Encoding", "gzip");
-
- server.register("/", new HeaderValidationHandler("POST", null, getBody(), getExpectedContent(), expectedHeaders));
- }
-
protected String getBody() {
return "hl=en&q=camel";
}
http://git-wip-us.apache.org/repos/asf/camel/blob/82526729/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpConcurrentTest.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpConcurrentTest.java b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpConcurrentTest.java
index 478cab9..54dc856 100644
--- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpConcurrentTest.java
+++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpConcurrentTest.java
@@ -32,9 +32,12 @@ import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.entity.StringEntity;
-import org.apache.http.localserver.LocalTestServer;
+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;
/**
@@ -44,19 +47,42 @@ public class HttpConcurrentTest extends BaseHttpTest {
private final AtomicInteger counter = new AtomicInteger();
+
+ private HttpServer localServer;
+
+ @Before
@Override
- protected void registerHandler(LocalTestServer server) {
- server.register("/", new HttpRequestHandler() {
- public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- // ignore
- }
- response.setStatusCode(HttpStatus.SC_OK);
- response.setEntity(new StringEntity("" + counter.incrementAndGet()));
- }
- });
+ public void setUp() throws Exception {
+ localServer = ServerBootstrap.bootstrap().
+ setHttpProcessor(getBasicHttpProcessor()).
+ setConnectionReuseStrategy(getConnectionReuseStrategy()).
+ setResponseFactory(getHttpResponseFactory()).
+ setExpectationVerifier(getHttpExpectationVerifier()).
+ setSslContext(getSSLContext()).
+ registerHandler("/", new HttpRequestHandler() {
+ public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ // ignore
+ }
+ response.setStatusCode(HttpStatus.SC_OK);
+ response.setEntity(new StringEntity("" + counter.incrementAndGet()));
+ }
+ }).create();
+ localServer.start();
+
+ super.setUp();
+ }
+
+ @After
+ @Override
+ public void tearDown() throws Exception {
+ super.tearDown();
+
+ if (localServer != null) {
+ localServer.stop();
+ }
}
@Test
@@ -78,7 +104,7 @@ public class HttpConcurrentTest extends BaseHttpTest {
final int index = i;
Future<String> out = executor.submit(new Callable<String>() {
public String call() throws Exception {
- return template.requestBody("http4://" + getHostName() + ":" + getPort(), null, String.class);
+ return template.requestBody("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort(), null, String.class);
}
});
responses.put(index, out);
http://git-wip-us.apache.org/repos/asf/camel/blob/82526729/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpDefaultPortNumberTest.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpDefaultPortNumberTest.java b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpDefaultPortNumberTest.java
index f08cfd9..7a3a7d9 100644
--- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpDefaultPortNumberTest.java
+++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpDefaultPortNumberTest.java
@@ -22,7 +22,10 @@ import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.http4.handler.BasicValidationHandler;
import org.apache.http.conn.HttpHostConnectException;
-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.Ignore;
import org.junit.Test;
@@ -32,15 +35,42 @@ import org.junit.Test;
@Ignore("We cannot run this test as default port 80 is not allows on most boxes")
public class HttpDefaultPortNumberTest 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("/search", 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 testHttpConnectionWithTwoRoutesAndOneWithDefaultPort() throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start")
- .to("http4://" + getHostName() + "/search");
+ .to("http4://" + localServer.getInetAddress().getHostName() + "/search");
from("direct:dummy")
- .to("http4://" + getHostName() + ":" + getPort() + "/search");
+ .to("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/search");
}
});
@@ -57,9 +87,9 @@ public class HttpDefaultPortNumberTest extends BaseHttpTest {
@Override
public void configure() throws Exception {
from("direct:start")
- .to("http4://" + getHostName() + ":80/search");
+ .to("http4://" + localServer.getInetAddress().getHostName() + ":80/search");
from("direct:dummy")
- .to("http4://" + getHostName() + ":" + getPort() + "/search");
+ .to("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/search");
}
});
@@ -76,9 +106,9 @@ public class HttpDefaultPortNumberTest extends BaseHttpTest {
@Override
public void configure() throws Exception {
from("direct:start")
- .to("http4://" + getHostName() + "/search");
+ .to("http4://" + localServer.getInetAddress().getHostName() + "/search");
from("direct:dummy")
- .to("http4://" + getHostName() + ":" + getPort() + "/search");
+ .to("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/search");
}
});
@@ -96,7 +126,7 @@ public class HttpDefaultPortNumberTest extends BaseHttpTest {
@Override
public void configure() throws Exception {
from("direct:start")
- .to("http4://" + getHostName() + "/search");
+ .to("http4://" + localServer.getInetAddress().getHostName() + "/search");
}
});
@@ -113,11 +143,6 @@ public class HttpDefaultPortNumberTest extends BaseHttpTest {
return true;
}
- @Override
- protected void registerHandler(LocalTestServer server) {
- server.register("/search", new BasicValidationHandler("GET", null, null, getExpectedContent()));
- }
-
private void assertRefused(Exchange exchange, String portExt) {
Map<String, Object> headers = exchange.getOut().getHeaders();
//no http response:
http://git-wip-us.apache.org/repos/asf/camel/blob/82526729/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpMethodsTest.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpMethodsTest.java b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpMethodsTest.java
index 6870a56..620e6cb 100644
--- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpMethodsTest.java
+++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpMethodsTest.java
@@ -23,6 +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.impl.bootstrap.HttpServer;
+import org.apache.http.impl.bootstrap.ServerBootstrap;
+import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
/**
@@ -31,11 +35,46 @@ import org.junit.Test;
*/
public class HttpMethodsTest 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("/get", new BasicValidationHandler("GET", null, null, getExpectedContent())).
+ registerHandler("/patch", new BasicValidationHandler("PATCH", null, null, getExpectedContent())).
+ registerHandler("/patch1", new BasicValidationHandler("PATCH", null, "rocks camel?", getExpectedContent())).
+ registerHandler("/post", new BasicValidationHandler("POST", null, null, getExpectedContent())).
+ registerHandler("/post1", new BasicValidationHandler("POST", null, null, getExpectedContent())).
+ registerHandler("/put", new BasicValidationHandler("PUT", null, null, getExpectedContent())).
+ registerHandler("/trace", new BasicValidationHandler("TRACE", null, null, getExpectedContent())).
+ registerHandler("/options", new BasicValidationHandler("OPTIONS", null, null, getExpectedContent())).
+ registerHandler("/delete", new BasicValidationHandler("DELETE", null, null, getExpectedContent())).
+ registerHandler("/head", new BasicValidationHandler("HEAD", 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 httpGet() throws Exception {
- localServer.register("/", new BasicValidationHandler("GET", null, null, getExpectedContent()));
- Exchange exchange = template.request("http4://" + getHostName() + ":" + getPort() + "/", new Processor() {
+ Exchange exchange = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/get", new Processor() {
public void process(Exchange exchange) throws Exception {
}
});
@@ -45,9 +84,8 @@ public class HttpMethodsTest extends BaseHttpTest {
@Test
public void httpPatch() throws Exception {
- localServer.register("/", new BasicValidationHandler("PATCH", null, null, getExpectedContent()));
- Exchange exchange = template.request("http4://" + getHostName() + ":" + getPort() + "/?throwExceptionOnFailure=false", new Processor() {
+ Exchange exchange = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/patch?throwExceptionOnFailure=false", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(Exchange.HTTP_METHOD, "PATCH");
}
@@ -66,9 +104,8 @@ public class HttpMethodsTest extends BaseHttpTest {
@Test
public void httpPatchWithBody() throws Exception {
- localServer.register("/", new BasicValidationHandler("PATCH", null, "rocks camel?", getExpectedContent()));
- Exchange exchange = template.request("http4://" + getHostName() + ":" + getPort() + "/?throwExceptionOnFailure=false", new Processor() {
+ Exchange exchange = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/patch1?throwExceptionOnFailure=false", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody("rocks camel?");
}
@@ -86,9 +123,8 @@ public class HttpMethodsTest extends BaseHttpTest {
@Test
public void httpPost() throws Exception {
- localServer.register("/", new BasicValidationHandler("POST", null, null, getExpectedContent()));
- Exchange exchange = template.request("http4://" + getHostName() + ":" + getPort() + "/", new Processor() {
+ Exchange exchange = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/post", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(Exchange.HTTP_METHOD, "POST");
}
@@ -99,9 +135,8 @@ public class HttpMethodsTest extends BaseHttpTest {
@Test
public void httpPostWithBody() throws Exception {
- localServer.register("/", new BasicValidationHandler("POST", null, "rocks camel?", getExpectedContent()));
- Exchange exchange = template.request("http4://" + getHostName() + ":" + getPort() + "/", new Processor() {
+ Exchange exchange = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/post1", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody("rocks camel?");
}
@@ -112,9 +147,8 @@ public class HttpMethodsTest extends BaseHttpTest {
@Test
public void httpPut() throws Exception {
- localServer.register("/", new BasicValidationHandler("PUT", null, null, getExpectedContent()));
- Exchange exchange = template.request("http4://" + getHostName() + ":" + getPort() + "/", new Processor() {
+ Exchange exchange = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/put", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(Exchange.HTTP_METHOD, "PUT");
}
@@ -125,9 +159,8 @@ public class HttpMethodsTest extends BaseHttpTest {
@Test
public void httpTrace() throws Exception {
- localServer.register("/", new BasicValidationHandler("TRACE", null, null, getExpectedContent()));
- Exchange exchange = template.request("http4://" + getHostName() + ":" + getPort() + "/", new Processor() {
+ Exchange exchange = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/trace", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(Exchange.HTTP_METHOD, "TRACE");
}
@@ -138,9 +171,8 @@ public class HttpMethodsTest extends BaseHttpTest {
@Test
public void httpOptions() throws Exception {
- localServer.register("/", new BasicValidationHandler("OPTIONS", null, null, getExpectedContent()));
- Exchange exchange = template.request("http4://" + getHostName() + ":" + getPort() + "/", new Processor() {
+ Exchange exchange = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/options", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(Exchange.HTTP_METHOD, "OPTIONS");
}
@@ -151,9 +183,8 @@ public class HttpMethodsTest extends BaseHttpTest {
@Test
public void httpDelete() throws Exception {
- localServer.register("/", new BasicValidationHandler("DELETE", null, null, getExpectedContent()));
- Exchange exchange = template.request("http4://" + getHostName() + ":" + getPort() + "/", new Processor() {
+ Exchange exchange = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/delete", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(Exchange.HTTP_METHOD, "DELETE");
}
@@ -164,9 +195,8 @@ public class HttpMethodsTest extends BaseHttpTest {
@Test
public void httpHead() throws Exception {
- localServer.register("/", new BasicValidationHandler("HEAD", null, null, getExpectedContent()));
- Exchange exchange = template.request("http4://" + getHostName() + ":" + getPort() + "/", new Processor() {
+ Exchange exchange = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/head", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(Exchange.HTTP_METHOD, "HEAD");
}
http://git-wip-us.apache.org/repos/asf/camel/blob/82526729/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpNoConnectionRedeliveryTest.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpNoConnectionRedeliveryTest.java b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpNoConnectionRedeliveryTest.java
index b34ccb3..44faf36 100644
--- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpNoConnectionRedeliveryTest.java
+++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpNoConnectionRedeliveryTest.java
@@ -17,11 +17,15 @@
package org.apache.camel.component.http4;
import java.net.ConnectException;
+import java.util.concurrent.TimeUnit;
import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
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;
/**
@@ -29,6 +33,33 @@ import org.junit.Test;
*/
public class HttpNoConnectionRedeliveryTest 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("/search", 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 httpConnectionOk() throws Exception {
Exchange exchange = template.request("direct:start", null);
@@ -41,7 +72,7 @@ public class HttpNoConnectionRedeliveryTest extends BaseHttpTest {
// stop server so there are no connection
// and wait for it to terminate
localServer.stop();
- localServer.awaitTermination(5000);
+ localServer.awaitTermination(5000, TimeUnit.MILLISECONDS);
Exchange exchange = template.request("direct:start", null);
assertTrue(exchange.isFailed());
@@ -54,11 +85,6 @@ public class HttpNoConnectionRedeliveryTest extends BaseHttpTest {
}
@Override
- protected void registerHandler(LocalTestServer server) {
- server.register("/search", new BasicValidationHandler("GET", null, null, getExpectedContent()));
- }
-
- @Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
@@ -71,7 +97,7 @@ public class HttpNoConnectionRedeliveryTest extends BaseHttpTest {
.maximumRedeliveryDelay(5000)
.useExponentialBackOff()
.end()
- .to("http4://" + getHostName() + ":" + getPort() + "/search");
+ .to("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/search");
}
};
}
http://git-wip-us.apache.org/repos/asf/camel/blob/82526729/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpNoConnectionTest.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpNoConnectionTest.java b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpNoConnectionTest.java
index f334d2f..fc147b9 100644
--- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpNoConnectionTest.java
+++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpNoConnectionTest.java
@@ -17,11 +17,15 @@
package org.apache.camel.component.http4;
import java.net.ConnectException;
+import java.util.concurrent.TimeUnit;
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;
/**
@@ -29,9 +33,36 @@ import org.junit.Test;
*/
public class HttpNoConnectionTest 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("/search", 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 httpConnectionOk() throws Exception {
- Exchange exchange = template.request("http4://" + getHostName() + ":" + getPort() + "/search", new Processor() {
+ Exchange exchange = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/search", new Processor() {
public void process(Exchange exchange) throws Exception {
}
});
@@ -41,10 +72,10 @@ public class HttpNoConnectionTest extends BaseHttpTest {
@Test
public void httpConnectionNotOk() throws Exception {
- String url = "http4://" + getHostName() + ":" + getPort() + "/search";
+ String url = "http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/search";
// stop server so there are no connection
localServer.stop();
- localServer.awaitTermination(1000);
+ localServer.awaitTermination(1000, TimeUnit.MILLISECONDS);
Exchange reply = template.request(url, null);
Exception e = reply.getException();
@@ -53,9 +84,4 @@ public class HttpNoConnectionTest extends BaseHttpTest {
assertTrue(cause.getMessage().contains("refused"));
}
- @Override
- protected void registerHandler(LocalTestServer server) {
- server.register("/search", new BasicValidationHandler("GET", null, null, getExpectedContent()));
- }
-
}
http://git-wip-us.apache.org/repos/asf/camel/blob/82526729/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpPathTest.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpPathTest.java b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpPathTest.java
index 38e3fff..0683c51 100644
--- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpPathTest.java
+++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpPathTest.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,38 @@ import org.junit.Test;
*/
public class HttpPathTest 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("/search", new BasicValidationHandler("GET", null, null, getExpectedContent())).
+ registerHandler("/test%20/path", 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 httpPath() throws Exception {
- Exchange exchange = template.request("http4://" + getHostName() + ":" + getPort() + "/search", new Processor() {
+ Exchange exchange = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/search", new Processor() {
public void process(Exchange exchange) throws Exception {
}
});
@@ -40,7 +72,7 @@ public class HttpPathTest extends BaseHttpTest {
@Test
public void httpPathHeader() 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_PATH, "search");
}
@@ -51,17 +83,11 @@ public class HttpPathTest extends BaseHttpTest {
@Test
public void httpEscapedCharacters() throws Exception {
- Exchange exchange = template.request("http4://" + getHostName() + ":" + getPort() + "/test%20/path", new Processor() {
+ Exchange exchange = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/test%20/path", new Processor() {
public void process(Exchange exchange) throws Exception {
}
});
assertExchange(exchange);
}
-
- @Override
- protected void registerHandler(LocalTestServer server) {
- server.register("/search", new BasicValidationHandler("GET", null, null, getExpectedContent()));
- server.register("/test%20/path", 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/HttpPollingConsumerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpPollingConsumerTest.java b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpPollingConsumerTest.java
index a638056..6cda297 100644
--- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpPollingConsumerTest.java
+++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpPollingConsumerTest.java
@@ -20,7 +20,10 @@ import java.net.SocketTimeoutException;
import org.apache.camel.RuntimeCamelException;
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;
/**
@@ -29,30 +32,52 @@ import org.junit.Test;
*/
public class HttpPollingConsumerTest 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(), 1000)).create();
+ localServer.start();
+
+ super.setUp();
+ }
+
+ @After
+ @Override
+ public void tearDown() throws Exception {
+ super.tearDown();
+
+ if (localServer != null) {
+ localServer.stop();
+ }
+ }
+
@Test
public void testReceive() throws Exception {
- String body = consumer.receiveBody("http4://" + getHostName() + ":" + getPort() + "/", String.class);
+ String body = consumer.receiveBody("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/", String.class);
assertEquals(getExpectedContent(), body);
}
@Test
public void testReceiveTimeout() throws Exception {
- String body = consumer.receiveBody("http4://" + getHostName() + ":" + getPort() + "/", 5000, String.class);
+ String body = consumer.receiveBody("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/", 5000, String.class);
assertEquals(getExpectedContent(), body);
}
@Test
public void testReceiveTimeoutTriggered() throws Exception {
try {
- consumer.receiveBody("http4://" + getHostName() + ":" + getPort() + "/", 250, String.class);
+ consumer.receiveBody("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/", 250, String.class);
fail("Should have thrown an exception");
} catch (RuntimeCamelException e) {
assertIsInstanceOf(SocketTimeoutException.class, e.getCause());
}
}
-
- @Override
- protected void registerHandler(LocalTestServer server) {
- server.register("/", new DelayValidationHandler("GET", null, null, getExpectedContent(), 1000));
- }
}
\ 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/HttpProducerContentTypeTest.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerContentTypeTest.java b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerContentTypeTest.java
index 601e89b..575b83d 100644
--- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerContentTypeTest.java
+++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerContentTypeTest.java
@@ -26,17 +26,58 @@ import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.entity.StringEntity;
-import org.apache.http.localserver.LocalTestServer;
+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;
public class HttpProducerContentTypeTest extends BaseHttpTest {
private static final String CONTENT_TYPE = "multipart/form-data;boundary=---------------------------j2radvtrk";
+
+ private HttpServer localServer;
+
+ @Before
+ @Override
+ public void setUp() throws Exception {
+ localServer = ServerBootstrap.bootstrap().
+ setHttpProcessor(getBasicHttpProcessor()).
+ setConnectionReuseStrategy(getConnectionReuseStrategy()).
+ setResponseFactory(getHttpResponseFactory()).
+ setExpectationVerifier(getHttpExpectationVerifier()).
+ setSslContext(getSSLContext()).
+ registerHandler("/content", new HttpRequestHandler() {
+ @Override
+ public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
+ String contentType = request.getFirstHeader(Exchange.CONTENT_TYPE).getValue();
+
+ assertEquals(CONTENT_TYPE, contentType);
+
+ response.setEntity(new StringEntity(contentType, "ASCII"));
+ response.setStatusCode(HttpStatus.SC_OK);
+ }
+ }).create();
+ localServer.start();
+
+ super.setUp();
+ }
+
+ @After
+ @Override
+ public void tearDown() throws Exception {
+ super.tearDown();
+
+ if (localServer != null) {
+ localServer.stop();
+ }
+ }
+
@Test
public void testContentTypeWithBoundary() throws Exception {
- Exchange out = template.request("http4://" + getHostName() + ":" + getPort() + "/content", new Processor() {
+ Exchange out = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/content", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
@@ -51,19 +92,4 @@ public class HttpProducerContentTypeTest extends BaseHttpTest {
assertEquals(CONTENT_TYPE, out.getOut().getBody(String.class));
}
-
- @Override
- protected void registerHandler(LocalTestServer server) {
- server.register("/content", new HttpRequestHandler() {
- @Override
- public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
- String contentType = request.getFirstHeader(Exchange.CONTENT_TYPE).getValue();
-
- assertEquals(CONTENT_TYPE, contentType);
-
- response.setEntity(new StringEntity(contentType, "ASCII"));
- response.setStatusCode(HttpStatus.SC_OK);
- }
- });
- }
}
\ 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/HttpProducerSelectMethodTest.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerSelectMethodTest.java b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerSelectMethodTest.java
index 09454fe..6b66dad 100644
--- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerSelectMethodTest.java
+++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerSelectMethodTest.java
@@ -18,7 +18,10 @@ package org.apache.camel.component.http4;
import org.apache.camel.Exchange;
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;
import static org.apache.camel.component.http4.HttpMethods.GET;
@@ -31,18 +34,41 @@ import static org.apache.camel.component.http4.HttpMethods.POST;
*/
public class HttpProducerSelectMethodTest extends BaseHttpTest {
+ private HttpServer localServer;
+
+ @Before
@Override
- protected void registerHandler(LocalTestServer server) {
- localServer.register("/myget", new BasicValidationHandler("GET", null, null, getExpectedContent()));
- localServer.register("/mypost", new BasicValidationHandler("POST", null, null, getExpectedContent()));
- localServer.register("/myget2", new BasicValidationHandler("GET", "q=Camel", null, getExpectedContent()));
+ public void setUp() throws Exception {
+ localServer = ServerBootstrap.bootstrap().
+ setHttpProcessor(getBasicHttpProcessor()).
+ setConnectionReuseStrategy(getConnectionReuseStrategy()).
+ setResponseFactory(getHttpResponseFactory()).
+ setExpectationVerifier(getHttpExpectationVerifier()).
+ setSslContext(getSSLContext()).
+ registerHandler("/myget", new BasicValidationHandler("GET", null, null, getExpectedContent())).
+ registerHandler("/mypost", new BasicValidationHandler("POST", null, null, getExpectedContent())).
+ registerHandler("/myget2", new BasicValidationHandler("GET", "q=Camel", null, getExpectedContent())).
+ create();
+ localServer.start();
+
+ super.setUp();
+ }
+
+ @After
+ @Override
+ public void tearDown() throws Exception {
+ super.tearDown();
+
+ if (localServer != null) {
+ localServer.stop();
+ }
}
@Test
public void noDataDefaultIsGet() throws Exception {
HttpComponent component = context.getComponent("http4", HttpComponent.class);
- HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http4://" + getHostName() + ":" + getPort() + "/myget");
+ HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/myget");
HttpProducer producer = new HttpProducer(endpoiont);
Exchange exchange = producer.createExchange();
exchange.getIn().setBody(null);
@@ -57,7 +83,7 @@ public class HttpProducerSelectMethodTest extends BaseHttpTest {
public void dataDefaultIsPost() throws Exception {
HttpComponent component = context.getComponent("http4", HttpComponent.class);
- HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http4://" + getHostName() + ":" + getPort() + "/mypost");
+ HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/mypost");
HttpProducer producer = new HttpProducer(endpoiont);
Exchange exchange = producer.createExchange();
@@ -73,7 +99,7 @@ public class HttpProducerSelectMethodTest extends BaseHttpTest {
public void withMethodPostInHeader() throws Exception {
HttpComponent component = context.getComponent("http4", HttpComponent.class);
- HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http4://" + getHostName() + ":" + getPort() + "/mypost");
+ HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/mypost");
HttpProducer producer = new HttpProducer(endpoiont);
Exchange exchange = producer.createExchange();
@@ -88,7 +114,7 @@ public class HttpProducerSelectMethodTest extends BaseHttpTest {
public void withMethodGetInHeader() throws Exception {
HttpComponent component = context.getComponent("http4", HttpComponent.class);
- HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http4://" + getHostName() + ":" + getPort() + "/myget");
+ HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/myget");
HttpProducer producer = new HttpProducer(endpoiont);
Exchange exchange = producer.createExchange();
@@ -103,7 +129,7 @@ public class HttpProducerSelectMethodTest extends BaseHttpTest {
public void withEndpointQuery() throws Exception {
HttpComponent component = context.getComponent("http4", HttpComponent.class);
- HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http4://" + getHostName() + ":" + getPort() + "/myget2?q=Camel");
+ HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/myget2?q=Camel");
HttpProducer producer = new HttpProducer(endpoiont);
Exchange exchange = producer.createExchange();
@@ -117,7 +143,7 @@ public class HttpProducerSelectMethodTest extends BaseHttpTest {
public void withQueryInHeader() throws Exception {
HttpComponent component = context.getComponent("http4", HttpComponent.class);
- HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http4://" + getHostName() + ":" + getPort() + "/myget2");
+ HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/myget2");
HttpProducer producer = new HttpProducer(endpoiont);
Exchange exchange = producer.createExchange();
@@ -132,12 +158,12 @@ public class HttpProducerSelectMethodTest extends BaseHttpTest {
public void withHttpURIInHeader() throws Exception {
HttpComponent component = context.getComponent("http4", HttpComponent.class);
- HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http4://" + getHostName() + ":" + getPort() + "/myget2");
+ HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/myget2");
HttpProducer producer = new HttpProducer(endpoiont);
Exchange exchange = producer.createExchange();
exchange.getIn().setBody("");
- exchange.getIn().setHeader(Exchange.HTTP_URI, "http://" + getHostName() + ":" + getPort() + "/myget2?q=Camel");
+ exchange.getIn().setHeader(Exchange.HTTP_URI, "http://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/myget2?q=Camel");
producer.start();
producer.process(exchange);
producer.stop();
@@ -147,7 +173,7 @@ public class HttpProducerSelectMethodTest extends BaseHttpTest {
public void withQueryInHeaderOverrideEndpoint() throws Exception {
HttpComponent component = context.getComponent("http4", HttpComponent.class);
- HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http4://" + getHostName() + ":" + getPort() + "/myget2?q=Donkey");
+ HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/myget2?q=Donkey");
HttpProducer producer = new HttpProducer(endpoiont);
Exchange exchange = producer.createExchange();
http://git-wip-us.apache.org/repos/asf/camel/blob/82526729/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerTwoHeadersWithSameKeyTest.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerTwoHeadersWithSameKeyTest.java b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerTwoHeadersWithSameKeyTest.java
index 2f531ef..207ac06 100644
--- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerTwoHeadersWithSameKeyTest.java
+++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerTwoHeadersWithSameKeyTest.java
@@ -22,15 +22,19 @@ import java.util.List;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
+import org.apache.camel.component.http4.handler.BasicValidationHandler;
import org.apache.http.Header;
import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.entity.StringEntity;
-import org.apache.http.localserver.LocalTestServer;
+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;
/**
@@ -38,9 +42,65 @@ import org.junit.Test;
*/
public class HttpProducerTwoHeadersWithSameKeyTest 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("/myapp", new HttpRequestHandler() {
+ @Override
+ public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
+ Header[] from = request.getHeaders("from");
+ assertEquals("me", from[0].getValue());
+ Header[] to = request.getHeaders("to");
+ assertEquals("[foo, bar]", to[0].getValue());
+
+ response.setHeader("bar", "yes");
+ response.addHeader("foo", "123");
+ response.addHeader("foo", "456");
+ response.setEntity(new StringEntity("OK", "ASCII"));
+ response.setStatusCode(HttpStatus.SC_OK);
+ }
+ }).
+ registerHandler("/myapp", new HttpRequestHandler() {
+ @Override
+ public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
+ Header[] from = request.getHeaders("from");
+ assertEquals("me", from[0].getValue());
+ Header[] to = request.getHeaders("to");
+ assertEquals("[foo, bar]", to[0].getValue());
+
+ response.setHeader("bar", "yes");
+ response.addHeader("foo", "123");
+ response.addHeader("foo", "456");
+ response.setEntity(new StringEntity("OK", "ASCII"));
+ response.setStatusCode(HttpStatus.SC_OK);
+ }
+ }).create();
+ localServer.start();
+
+ super.setUp();
+ }
+
+ @After
+ @Override
+ public void tearDown() throws Exception {
+ super.tearDown();
+
+ if (localServer != null) {
+ localServer.stop();
+ }
+ }
+
@Test
public void testTwoHeadersWithSameKeyHeader() throws Exception {
- Exchange out = template.request("http4://" + getHostName() + ":" + getPort() + "/myapp", new Processor() {
+ Exchange out = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/myapp", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody(null);
exchange.getIn().setHeader("from", "me");
@@ -63,23 +123,4 @@ public class HttpProducerTwoHeadersWithSameKeyTest extends BaseHttpTest {
assertEquals("456", foo.get(1));
}
- @Override
- protected void registerHandler(LocalTestServer server) {
- server.register("/myapp", new HttpRequestHandler() {
- @Override
- public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
- Header[] from = request.getHeaders("from");
- assertEquals("me", from[0].getValue());
- Header[] to = request.getHeaders("to");
- assertEquals("[foo, bar]", to[0].getValue());
-
- response.setHeader("bar", "yes");
- response.addHeader("foo", "123");
- response.addHeader("foo", "456");
- response.setEntity(new StringEntity("OK", "ASCII"));
- response.setStatusCode(HttpStatus.SC_OK);
- }
- });
- }
-
}
http://git-wip-us.apache.org/repos/asf/camel/blob/82526729/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerTwoParametersWithSameKeyTest.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerTwoParametersWithSameKeyTest.java b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerTwoParametersWithSameKeyTest.java
index 02ac40a..856e93c 100644
--- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerTwoParametersWithSameKeyTest.java
+++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerTwoParametersWithSameKeyTest.java
@@ -25,9 +25,12 @@ import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.entity.StringEntity;
-import org.apache.http.localserver.LocalTestServer;
+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;
/**
@@ -35,9 +38,48 @@ import org.junit.Test;
*/
public class HttpProducerTwoParametersWithSameKeyTest 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("/myapp", new HttpRequestHandler() {
+ @Override
+ public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
+ String uri = request.getRequestLine().getUri();
+ assertEquals("/myapp?from=me&to=foo&to=bar", uri);
+
+ response.setHeader("bar", "yes");
+ response.addHeader("foo", "123");
+ response.addHeader("foo", "456");
+ response.setEntity(new StringEntity("OK", "ASCII"));
+ response.setStatusCode(HttpStatus.SC_OK);
+ }
+ }).create();
+ localServer.start();
+
+ super.setUp();
+ }
+
+ @After
+ @Override
+ public void tearDown() throws Exception {
+ super.tearDown();
+
+ if (localServer != null) {
+ localServer.stop();
+ }
+ }
+
@Test
public void testTwoParametersWithSameKey() throws Exception {
- Exchange out = template.request("http4://" + getHostName() + ":" + getPort() + "/myapp?from=me&to=foo&to=bar", null);
+ Exchange out = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/myapp?from=me&to=foo&to=bar", null);
assertNotNull(out);
assertFalse("Should not fail", out.isFailed());
@@ -51,21 +93,4 @@ public class HttpProducerTwoParametersWithSameKeyTest extends BaseHttpTest {
assertEquals("456", foo.get(1));
}
- @Override
- protected void registerHandler(LocalTestServer server) {
- server.register("/myapp", new HttpRequestHandler() {
- @Override
- public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
- String uri = request.getRequestLine().getUri();
- assertEquals("/myapp?from=me&to=foo&to=bar", uri);
-
- response.setHeader("bar", "yes");
- response.addHeader("foo", "123");
- response.addHeader("foo", "456");
- response.setEntity(new StringEntity("OK", "ASCII"));
- response.setStatusCode(HttpStatus.SC_OK);
- }
- });
- }
-
}
[4/4] camel git commit: Component docs
Posted by ac...@apache.org.
Component docs
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/bd881496
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/bd881496
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/bd881496
Branch: refs/heads/master
Commit: bd881496e4bc80695d4a26c4334c91b51f754554
Parents: 8252672
Author: Andrea Cosentino <an...@gmail.com>
Authored: Sun Jun 14 23:53:56 2015 +0200
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Sun Jun 14 23:53:56 2015 +0200
----------------------------------------------------------------------
.../org/apache/camel/component/http4/HttpServerTestSupport.java | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/bd881496/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpServerTestSupport.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpServerTestSupport.java b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpServerTestSupport.java
index 7fc1cc8..4a63e86 100644
--- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpServerTestSupport.java
+++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpServerTestSupport.java
@@ -26,8 +26,7 @@ import org.apache.http.protocol.HttpProcessor;
/**
* Abstract base class for unit testing using a http server.
- * The setUp method starts the server before the camel context is started and
- * the tearDown method stops the server after the camel context is stopped.
+ * This class contains an empty configuration to be used.
*
* @version
*/
[2/4] camel git commit: CAMEL-8869 Resolve Switching httpClient from
4.3.x to 4.4.x break tests
Posted by ac...@apache.org.
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 {