summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/host-tomcat/src/test
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2008-08-09 06:11:54 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2008-08-09 06:11:54 +0000
commita49037c45192b749c045cbd27798f146192fa8d5 (patch)
tree84744e23c21bdf1312b3200ef270681c9a479c49 /java/sca/modules/host-tomcat/src/test
parentf30981d7dab6a6f9992bfd512b835cada3fa2d7f (diff)
Enable the https support for embedded tomcat and jetty with unit tests
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@684186 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r--java/sca/modules/host-tomcat/src/test/java/org/apache/tuscany/sca/http/tomcat/TomcatServerTestCase.java44
-rw-r--r--java/sca/modules/host-tomcat/src/test/resources/tuscany.keyStorebin0 -> 1265 bytes
2 files changed, 42 insertions, 2 deletions
diff --git a/java/sca/modules/host-tomcat/src/test/java/org/apache/tuscany/sca/http/tomcat/TomcatServerTestCase.java b/java/sca/modules/host-tomcat/src/test/java/org/apache/tuscany/sca/http/tomcat/TomcatServerTestCase.java
index 7ca5325ccb..afbec52cd9 100644
--- a/java/sca/modules/host-tomcat/src/test/java/org/apache/tuscany/sca/http/tomcat/TomcatServerTestCase.java
+++ b/java/sca/modules/host-tomcat/src/test/java/org/apache/tuscany/sca/http/tomcat/TomcatServerTestCase.java
@@ -20,10 +20,15 @@ package org.apache.tuscany.sca.http.tomcat;
import java.io.BufferedReader;
import java.io.IOException;
+import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
+import java.net.URL;
+import javax.net.ssl.HostnameVerifier;
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLSession;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
@@ -91,7 +96,38 @@ public class TomcatServerTestCase extends TestCase {
service.stop();
assertTrue(servlet.invoked);
}
+
+ /**
+ * Verifies requests are properly routed according to the Servlet mapping
+ */
+ public void testRegisterServletMappingSSL() throws Exception {
+ System.setProperty("javax.net.ssl.keyStore", "target/test-classes/tuscany.keyStore");
+ System.setProperty("javax.net.ssl.keyStorePassword", "apache");
+ TomcatServer service = new TomcatServer(workScheduler);
+ TestServlet servlet = new TestServlet();
+ try {
+ service.addServletMapping("https://127.0.0.1:" + HTTP_PORT + "/foo", servlet);
+ } finally {
+ System.clearProperty("javax.net.ssl.keyStore");
+ System.clearProperty("javax.net.ssl.keyStorePassword");
+ }
+ System.setProperty("javax.net.ssl.trustStore", "target/test-classes/tuscany.keyStore");
+ System.setProperty("javax.net.ssl.trustStorePassword", "apache");
+ URL url = new URL("https://127.0.0.1:8085/foo");
+ HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
+ conn.setHostnameVerifier(new HostnameVerifier() {
+ public boolean verify(String hostname, SSLSession session) {
+ return true;
+ }}
+ );
+ conn.connect();
+ read(conn.getInputStream());
+
+ service.stop();
+ assertTrue(servlet.invoked);
+
+ }
/**
* Verifies that Servlets can be registered with multiple ports
*/
@@ -244,9 +280,14 @@ public class TomcatServerTestCase extends TestCase {
}
private static String read(Socket socket) throws IOException {
+ InputStream is = socket.getInputStream();
+ return read(is);
+ }
+
+ private static String read(InputStream is) throws IOException {
BufferedReader reader = null;
try {
- reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+ reader = new BufferedReader(new InputStreamReader(is));
StringBuffer sb = new StringBuffer();
String str;
while ((str = reader.readLine()) != null) {
@@ -259,7 +300,6 @@ public class TomcatServerTestCase extends TestCase {
}
}
}
-
private class TestServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
boolean invoked;
diff --git a/java/sca/modules/host-tomcat/src/test/resources/tuscany.keyStore b/java/sca/modules/host-tomcat/src/test/resources/tuscany.keyStore
new file mode 100644
index 0000000000..7ea23f7ff4
--- /dev/null
+++ b/java/sca/modules/host-tomcat/src/test/resources/tuscany.keyStore
Binary files differ