brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [20/50] brooklyn-server git commit: https support for java web-apps
Date Mon, 01 Feb 2016 17:48:50 GMT
https support for java web-apps

- adds config keys for https-port and for enabled-protocols
- adds getHttpsPort and getEnabledProtocols to JavaWebAppDriver


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/41d171ee
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/41d171ee
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/41d171ee

Branch: refs/heads/0.4.0
Commit: 41d171eef8402d33129d1aa20ee9bcf06d3bb69d
Parents: e7fb0d4
Author: Aled Sage <aled.sage@gmail.com>
Authored: Thu Oct 4 10:34:08 2012 +0100
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Fri Oct 5 14:00:00 2012 +0100

----------------------------------------------------------------------
 .../main/java/brooklyn/test/HttpTestUtils.java  | 49 ++++++++++++++++----
 .../main/java/brooklyn/test/TestUtils.groovy    | 45 +++++++++---------
 2 files changed, 64 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/41d171ee/usage/test-support/src/main/java/brooklyn/test/HttpTestUtils.java
----------------------------------------------------------------------
diff --git a/usage/test-support/src/main/java/brooklyn/test/HttpTestUtils.java b/usage/test-support/src/main/java/brooklyn/test/HttpTestUtils.java
index d1f020d..a64adfa 100644
--- a/usage/test-support/src/main/java/brooklyn/test/HttpTestUtils.java
+++ b/usage/test-support/src/main/java/brooklyn/test/HttpTestUtils.java
@@ -7,9 +7,19 @@ import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.fail;
 
 import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLConnection;
 import java.util.Map;
 import java.util.NoSuchElementException;
 
+import javax.net.ssl.HostnameVerifier;
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLSession;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import com.google.common.base.Throwables;
 import com.google.common.collect.Maps;
 import com.google.common.util.concurrent.ListenableFuture;
@@ -24,9 +34,32 @@ public class HttpTestUtils {
 
 	// TODO Delete methods from TestUtils, to just have them here (or switch so TestUtils delegates
here,
 	// and deprecate methods in TestUtils until deleted).
-	
-    public static int getHttpStatusCode(String url) {
-        return TestUtils.urlRespondsStatusCode(url);
+
+    protected static final Logger LOG = LoggerFactory.getLogger(HttpTestUtils.class);
+
+    /**
+     * Connects to the given url and returns the connection.
+     */
+    public static URLConnection connectToUrl(String u) throws Exception {
+        URL url = new URL(u);
+        URLConnection connection = url.openConnection();
+        TrustingSslSocketFactory.configure(connection);
+        HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
+            @Override public boolean verify(String s, SSLSession sslSession) {
+                return true;
+            }
+        });
+        connection.connect();
+
+        connection.getContentLength(); // Make sure the connection is made.
+        return connection;
+    }
+
+    public static int getHttpStatusCode(String url) throws Exception {
+        URLConnection connection = connectToUrl(url);
+        int status = ((HttpURLConnection) connection).getResponseCode();
+        LOG.debug("connection to {} gives {}", url, status);
+        return status;
     }
 
     public static void assertUrlUnreachable(String url) {
@@ -118,10 +151,10 @@ public class HttpTestUtils {
     // TODO Part-duplicated from jclouds Throwables2
     @SuppressWarnings("unchecked")
     private static <T extends Throwable> T getFirstThrowableOfType(Throwable from,
Class<T> clazz) {
-       try {
-          return (T) find(getCausalChain(from), instanceOf(clazz));
-       } catch (NoSuchElementException e) {
-          return null;
-       }
+        try {
+            return (T) find(getCausalChain(from), instanceOf(clazz));
+        } catch (NoSuchElementException e) {
+            return null;
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/41d171ee/usage/test-support/src/main/java/brooklyn/test/TestUtils.groovy
----------------------------------------------------------------------
diff --git a/usage/test-support/src/main/java/brooklyn/test/TestUtils.groovy b/usage/test-support/src/main/java/brooklyn/test/TestUtils.groovy
index 7ccaba3..d2d340f 100644
--- a/usage/test-support/src/main/java/brooklyn/test/TestUtils.groovy
+++ b/usage/test-support/src/main/java/brooklyn/test/TestUtils.groovy
@@ -49,38 +49,35 @@ public class TestUtils {
         }
     }
 
-    /** Connects to the given HTTP URL and asserts that the response had status code 200.
*/
+    /**
+     * Connects to the given HTTP URL and asserts that the response had status code 200.
+     * @deprecated Use HttpTestUtils.getHttpStatusCode(url) == 200
+     */
+    @Deprecated
     public static boolean urlRespondsWithStatusCode200(String url) {
-        def connection = connectToURL(url)
-        int status = ((HttpURLConnection) connection).getResponseCode()
+        int status = HttpTestUtils.getHttpStatusCode(url);
         log.debug "connection to {} gives {}", url, status
         if (status == 404)
             throw new Exception("Connection to $url gave 404");
         return status == 200
     }
     
-    /** Connects to the given HTTP URL and asserts that the response had status code 200.
*/
+    /** 
+     * Connects to the given HTTP URL and asserts that the response had status code 200.
+     * @deprecated Use HttpTestUtils.getHttpStatusCode(url)
+     */
+    @Deprecated
     public static int urlRespondsStatusCode(String url) {
-        def connection = connectToURL(url)
-        int status = ((HttpURLConnection) connection).getResponseCode()
-        log.debug "connection to {} gives {}", url, status
-        return status;
+        return HttpTestUtils.getHttpStatusCode(url);
     }
     
-    /** Connects to the given url and returns the connection. */
-    public static URLConnection connectToURL(String u) {
-        URL url = [u]
-        URLConnection connection = url.openConnection()
-        TrustingSslSocketFactory.configure(connection)
-        HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
-            boolean verify(String s, SSLSession sslSession) {
-                return true;
-            }
-        });
-        connection.connect()
-
-        connection.getContentLength() // Make sure the connection is made.
-        return connection
+    /** 
+     * Connects to the given url and returns the connection.
+     * @deprecated Use HttpTestUtils.connectToUrl(url)
+     */
+    @Deprecated
+    public static URLConnection connectToURL(String url) {
+        return HttpTestUtils.connectToUrl(url);
     }
     
     // TODO calling groovy from java doesn't cope with generics here; stripping them :-(

@@ -326,6 +323,10 @@ public class TestUtils {
         String contents;
         TimeDuration timeout = flags.timeout in Number ? flags.timeout*TimeUnit.MILLISECONDS
: flags.timeout ?: 30*TimeUnit.SECONDS
         executeUntilSucceeds(timeout:timeout, maxAttempts:50) {
+            //URLConnection connection = connectToURL(url);
+            //connection.getContent();
+            //int status = ((HttpURLConnection) connection).getResponseCode()
+            def connection = connectToURL(url);
             contents = new URL(url).openStream().getText();
             assertTrue(contents!=null && contents.length()>0)
         }


Mime
View raw message