diff --git a/container/spi/src/main/java/org/jboss/arquillian/container/spi/client/protocol/metadata/HTTPContext.java b/container/spi/src/main/java/org/jboss/arquillian/container/spi/client/protocol/metadata/HTTPContext.java index 916b0575c..a80202f44 100644 --- a/container/spi/src/main/java/org/jboss/arquillian/container/spi/client/protocol/metadata/HTTPContext.java +++ b/container/spi/src/main/java/org/jboss/arquillian/container/spi/client/protocol/metadata/HTTPContext.java @@ -31,14 +31,32 @@ public class HTTPContext extends NamedContext { private final String host; private final int port; + private final boolean secure; private final Set servlets; public HTTPContext(String host, int port) { - this("no-named", host, port); + this("no-named", host, port, false); + } + + public HTTPContext(String host, int port, boolean secure) { + this("no-named", host, port, secure); } public HTTPContext(String name, String host, int port) { + this(name, host, port, false); + } + + /** + * Creates a new HTTP context. + * + * @param name the name for the context + * @param host the host for the context + * @param port the port for the context + * @param secure whether this is a secure context. {@code true} will result in a https protocol, otherwise http will + * be used for the protocol + */ + public HTTPContext(String name, String host, int port, boolean secure) { super(name); if (host == null) { @@ -46,6 +64,7 @@ public HTTPContext(String name, String host, int port) { } this.host = host; this.port = port; + this.secure = secure; this.servlets = new HashSet(); } @@ -85,9 +104,18 @@ public Servlet getServletByName(String name) { return null; } + /** + * Indicates whether this is a secure HTTP connection (https). + * + * @return {@code true} if this should be a secure connection, otherwise {@code false} + */ + public boolean isSecure() { + return secure; + } + @Override public String toString() { - return "HTTPContext [host=" + host + ", port=" + port + ", servlets=" + toString(servlets) + "]"; + return "HTTPContext [host=" + host + ", port=" + port + ", secure=" + secure + ", servlets=" + toString(servlets) + "]"; } private String toString(Set servlets) { diff --git a/container/spi/src/main/java/org/jboss/arquillian/container/spi/client/protocol/metadata/Servlet.java b/container/spi/src/main/java/org/jboss/arquillian/container/spi/client/protocol/metadata/Servlet.java index 022516e0f..fc1732ad9 100644 --- a/container/spi/src/main/java/org/jboss/arquillian/container/spi/client/protocol/metadata/Servlet.java +++ b/container/spi/src/main/java/org/jboss/arquillian/container/spi/client/protocol/metadata/Servlet.java @@ -28,12 +28,14 @@ */ public class Servlet { static final String HTTP_SCHEME = "http://"; + static final String HTTPS_SCHEME = "https://"; static final String ROOT_CONTEXT = "/"; private final String name; private final String contextRoot; + private String scheme; private String host; private int port; @@ -68,6 +70,7 @@ void setParent(HTTPContext context) { if (context.getHost() == null) { throw new IllegalArgumentException(context.getClass().getSimpleName() + " host must not be null"); } + this.scheme = context.isSecure() ? HTTPS_SCHEME : HTTP_SCHEME; this.host = context.getHost(); this.port = context.getPort(); } @@ -105,7 +108,7 @@ public URI getFullURI() { } private String getBaseURIAsString() { - return HTTP_SCHEME + host + ":" + port + contextRoot + "/"; + return scheme + host + ":" + port + contextRoot + "/"; } /** diff --git a/container/test-impl-base/src/main/java/org/jboss/arquillian/container/test/impl/enricher/resource/URLResourceProvider.java b/container/test-impl-base/src/main/java/org/jboss/arquillian/container/test/impl/enricher/resource/URLResourceProvider.java index 29307647c..6116c5d0a 100644 --- a/container/test-impl-base/src/main/java/org/jboss/arquillian/container/test/impl/enricher/resource/URLResourceProvider.java +++ b/container/test-impl-base/src/main/java/org/jboss/arquillian/container/test/impl/enricher/resource/URLResourceProvider.java @@ -124,7 +124,7 @@ private URL toURL(Servlet servlet) { private URL toURL(HTTPContext context) { try { - return new URI("http", null, context.getHost(), context.getPort(), null, null, null).toURL(); + return new URI(context.isSecure() ? "https" : "http", null, context.getHost(), context.getPort(), null, null, null).toURL(); } catch (Exception e) { throw new RuntimeException("Could not convert HTTPContext to URL, " + context, e); } diff --git a/container/test-impl-base/src/test/java/org/jboss/arquillian/container/test/impl/enricher/resource/URLResourceProviderTestCase.java b/container/test-impl-base/src/test/java/org/jboss/arquillian/container/test/impl/enricher/resource/URLResourceProviderTestCase.java index d0f6b46f6..d4a22fde9 100644 --- a/container/test-impl-base/src/test/java/org/jboss/arquillian/container/test/impl/enricher/resource/URLResourceProviderTestCase.java +++ b/container/test-impl-base/src/test/java/org/jboss/arquillian/container/test/impl/enricher/resource/URLResourceProviderTestCase.java @@ -54,6 +54,17 @@ public void shouldBeAbleToInjectBaseContextURL() throws Exception { Assert.assertEquals("http://TEST:8080", test.url.toExternalForm()); } + @Test + public void shouldBeAbleToInjectBaseContextURLSecure() throws Exception { + URLBaseContextClass test = execute( + URLBaseContextClass.class, + ProtocolMetaData.class, + new ProtocolMetaData() + .addContext(new HTTPContext("TEST", 8080, true))); + + Assert.assertEquals("https://TEST:8080", test.url.toExternalForm()); + } + @Test public void shouldBeAbleToInjectBaseContextURLQualified() throws Exception { URLBaseContextClassQualified test = execute( @@ -79,6 +90,18 @@ public void shouldBeAbleToInjectServletContextURL() throws Exception { Assert.assertEquals("http://TEST:8080/test/", test.url.toExternalForm()); } + @Test + public void shouldBeAbleToInjectServletContextURLSecure() throws Exception { + URLServletContextClass test = execute( + URLServletContextClass.class, + ProtocolMetaData.class, + new ProtocolMetaData() + .addContext(new HTTPContext("TEST", 8080, true) + .add(new Servlet(URLServletContextClass.class.getSimpleName(), "/test")))); + + Assert.assertEquals("https://TEST:8080/test/", test.url.toExternalForm()); + } + @Test public void shouldBeAbleToInjectServletContextURLQualified() throws Exception { URLServletContextClassQualified test = execute(