@@ -110,7 +110,6 @@ public void handle(Throwable t, HttpRequest request, HttpResponder responder) {
110110 };
111111
112112 protected static NettyHttpService service ;
113- protected static URI baseURI ;
114113
115114 protected static NettyHttpService .Builder createBaseNettyHttpServiceBuilder () {
116115 return NettyHttpService .builder ("test" )
@@ -132,8 +131,6 @@ public void modify(ChannelPipeline pipeline) {
132131 public static void setup () throws Exception {
133132 service = createBaseNettyHttpServiceBuilder ().build ();
134133 service .start ();
135- int port = service .getBindAddress ().getPort ();
136- baseURI = URI .create (String .format ("http://localhost:%d" , port ));
137134 }
138135
139136 @ AfterClass
@@ -165,11 +162,16 @@ public static void teardown() throws Exception {
165162 Assert .assertTrue ("Some netty threads are still alive. Please see logs above" , passed );
166163 }
167164
165+ protected final URI getBaseURI () {
166+ return URI .create (String .format ("%s://localhost:%d" , service .isSSLEnabled () ? "https" : "http" ,
167+ service .getBindAddress ().getPort ()));
168+ }
169+
168170 @ Test
169171 public void testUploadDisconnect () throws Exception {
170172 File filePath = new File (tmpFolder .newFolder (), "test.txt" );
171173
172- URI uri = baseURI .resolve ("/test/v1/stream/upload/file" );
174+ URI uri = getBaseURI () .resolve ("/test/v1/stream/upload/file" );
173175 try (Socket socket = createRawSocket (uri .toURL ())) {
174176
175177 // Make a PUT call through socket, so that we can close it prematurely
@@ -378,7 +380,7 @@ public void testNonExistingMethods() throws IOException {
378380
379381 @ Test
380382 public void testKeepAlive () throws Exception {
381- final URL url = baseURI .resolve ("/test/v1/tweets/1" ).toURL ();
383+ final URL url = getBaseURI () .resolve ("/test/v1/tweets/1" ).toURL ();
382384
383385 ThreadFactory threadFactory = new ThreadFactory () {
384386 private final AtomicInteger id = new AtomicInteger (0 );
@@ -639,7 +641,7 @@ public void testDefaultQueryParam() throws IOException {
639641
640642 @ Test (timeout = 5000 )
641643 public void testConnectionClose () throws Exception {
642- URL url = baseURI .resolve ("/test/v1/connectionClose" ).toURL ();
644+ URL url = getBaseURI () .resolve ("/test/v1/connectionClose" ).toURL ();
643645
644646 // Fire http request using raw socket so that we can verify the connection get closed by the server
645647 // after the response.
@@ -832,7 +834,7 @@ protected Socket createRawSocket(URL url) throws IOException {
832834 }
833835
834836 protected HttpURLConnection request (String path , HttpMethod method , boolean keepAlive ) throws IOException {
835- URL url = baseURI .resolve (path ).toURL ();
837+ URL url = getBaseURI () .resolve (path ).toURL ();
836838 HttpURLConnection urlConn = (HttpURLConnection ) url .openConnection ();
837839 if (method == HttpMethod .POST || method == HttpMethod .PUT ) {
838840 urlConn .setDoOutput (true );
0 commit comments