From e3dd0cb83be2df2470595b272dc740a538b7c8f1 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Mon, 25 Jan 2016 13:23:41 -0700 Subject: [PATCH] 486511 - Server.getURI() returns wrong scheme on SSL/HTTPS --- .../main/java/org/eclipse/jetty/server/Server.java | 6 ++++-- .../ssl/SSLSelectChannelConnectorLoadTest.java | 13 +++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java index 1d81e6a615f..51c145d6067 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java @@ -654,7 +654,6 @@ public class Server extends HandlerWrapper implements Attributes /** * @return The URI of the first {@link NetworkConnector} and first {@link ContextHandler}, or null */ - @SuppressWarnings("resource") public URI getURI() { NetworkConnector connector=null; @@ -674,7 +673,10 @@ public class Server extends HandlerWrapper implements Attributes try { - String scheme=connector.getDefaultConnectionFactory().getProtocol().startsWith("SSL-")?"https":"http"; + String protocol = connector.getDefaultConnectionFactory().getProtocol(); + String scheme="http"; + if (protocol.startsWith("SSL-") || protocol.equals("SSL")) + scheme = "https"; String host=connector.getHost(); if (context!=null && context.getVirtualHosts()!=null && context.getVirtualHosts().length>0) diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SSLSelectChannelConnectorLoadTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SSLSelectChannelConnectorLoadTest.java index b5fde36ef73..a6d8aedcc38 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SSLSelectChannelConnectorLoadTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SSLSelectChannelConnectorLoadTest.java @@ -18,12 +18,16 @@ package org.eclipse.jetty.server.ssl; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + import java.io.BufferedReader; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; +import java.net.URI; import java.security.KeyStore; import java.util.Arrays; import java.util.Random; @@ -91,6 +95,15 @@ public class SSLSelectChannelConnectorLoadTest server.stop(); server.join(); } + + @Test + public void testGetURI() + { + URI uri = server.getURI(); + assertThat("Server.uri.scheme", uri.getScheme(), is("https")); + assertThat("Server.uri.port", uri.getPort(), is(connector.getLocalPort())); + assertThat("Server.uri.path", uri.getPath(), is("/")); + } @Test public void testLongLivedConnections() throws Exception