From a07461f4bdf12cb4edf186b5b7ad66f26cc9aa61 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Wed, 22 Jun 2016 11:25:04 +0200 Subject: [PATCH] Code cleanups. --- .../org/eclipse/jetty/client/HttpProxy.java | 9 ++++---- .../client/http/HttpReceiverOverHTTP.java | 2 +- .../proxy/ForwardProxyTLSServerTest.java | 21 +++++++++++++------ 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpProxy.java b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpProxy.java index 94e8d21e6d2..2ca99e7fcfd 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpProxy.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpProxy.java @@ -27,7 +27,6 @@ import org.eclipse.jetty.client.api.Connection; import org.eclipse.jetty.client.api.Destination; import org.eclipse.jetty.client.api.Request; import org.eclipse.jetty.client.api.Response; -import org.eclipse.jetty.client.api.Result; import org.eclipse.jetty.client.http.HttpConnectionOverHTTP; import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.http.HttpMethod; @@ -173,24 +172,24 @@ public class HttpProxy extends ProxyConfiguration.Proxy connection.send(connect, result -> { // The EndPoint may have changed during the conversation, get the latest. - EndPoint endPoint1 = (EndPoint)conversation.getAttribute(EndPoint.class.getName()); + EndPoint endPoint = (EndPoint)conversation.getAttribute(EndPoint.class.getName()); if (result.isSucceeded()) { Response response = result.getResponse(); if (response.getStatus() == HttpStatus.OK_200) { - tunnelSucceeded(endPoint1); + tunnelSucceeded(endPoint); } else { HttpResponseException failure = new HttpResponseException("Unexpected " + response + " for " + result.getRequest(), response); - tunnelFailed(endPoint1, failure); + tunnelFailed(endPoint, failure); } } else { - tunnelFailed(endPoint1, result.getFailure()); + tunnelFailed(endPoint, result.getFailure()); } }); } diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/http/HttpReceiverOverHTTP.java b/jetty-client/src/main/java/org/eclipse/jetty/client/http/HttpReceiverOverHTTP.java index a201b31a238..b9bfb112a6a 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/http/HttpReceiverOverHTTP.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/http/HttpReceiverOverHTTP.java @@ -165,7 +165,7 @@ public class HttpReceiverOverHTTP extends HttpReceiver implements HttpParser.Res protected void fillInterested() { - getHttpChannel().getHttpConnection().fillInterested(); + getHttpConnection().fillInterested(); } private void shutdown() diff --git a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ForwardProxyTLSServerTest.java b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ForwardProxyTLSServerTest.java index c80a6e868b7..82ed4caa6d8 100644 --- a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ForwardProxyTLSServerTest.java +++ b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ForwardProxyTLSServerTest.java @@ -181,6 +181,7 @@ public class ForwardProxyTLSServerTest .scheme(HttpScheme.HTTPS.asString()) .method(HttpMethod.GET) .path("/echo?body=" + URLEncoder.encode(body, "UTF-8")) + .timeout(5, TimeUnit.SECONDS) .send(); Assert.assertEquals(HttpStatus.OK_200, response.getStatus()); @@ -210,6 +211,7 @@ public class ForwardProxyTLSServerTest .scheme(HttpScheme.HTTPS.asString()) .method(HttpMethod.GET) .path("/echo?body=" + URLEncoder.encode(body, "UTF-8")) + .timeout(5, TimeUnit.SECONDS) .send(); Assert.assertEquals(HttpStatus.OK_200, response1.getStatus()); @@ -224,6 +226,7 @@ public class ForwardProxyTLSServerTest .header(HttpHeader.CONTENT_TYPE, MimeTypes.Type.FORM_ENCODED.asString()) .header(HttpHeader.CONTENT_LENGTH, String.valueOf(content.length())) .content(new StringContentProvider(content)) + .timeout(5, TimeUnit.SECONDS) .send(); Assert.assertEquals(HttpStatus.OK_200, response2.getStatus()); @@ -250,11 +253,11 @@ public class ForwardProxyTLSServerTest { final AtomicReference connection = new AtomicReference<>(); final CountDownLatch connectionLatch = new CountDownLatch(1); - String body1 = "BODY"; + String content1 = "BODY"; ContentResponse response1 = httpClient.newRequest("localhost", serverConnector.getLocalPort()) .scheme(HttpScheme.HTTPS.asString()) .method(HttpMethod.GET) - .path("/echo?body=" + URLEncoder.encode(body1, "UTF-8")) + .path("/echo?body=" + URLEncoder.encode(content1, "UTF-8")) .onRequestCommit(request -> { Destination destination = httpClient.getDestination(HttpScheme.HTTPS.asString(), "localhost", serverConnector.getLocalPort()); @@ -268,15 +271,16 @@ public class ForwardProxyTLSServerTest } }); }) + .timeout(5, TimeUnit.SECONDS) .send(); Assert.assertEquals(HttpStatus.OK_200, response1.getStatus()); String content = response1.getContentAsString(); - Assert.assertEquals(body1, content); + Assert.assertEquals(content1, content); Assert.assertTrue(connectionLatch.await(5, TimeUnit.SECONDS)); - String body2 = "body=" + body1; + String body2 = "body=" + content1; org.eclipse.jetty.client.api.Request request2 = httpClient.newRequest("localhost", serverConnector.getLocalPort()) .scheme(HttpScheme.HTTPS.asString()) .method(HttpMethod.POST) @@ -291,8 +295,8 @@ public class ForwardProxyTLSServerTest ContentResponse response2 = listener2.get(5, TimeUnit.SECONDS); Assert.assertEquals(HttpStatus.OK_200, response2.getStatus()); - String content2 = response1.getContentAsString(); - Assert.assertEquals(body1, content2); + String content2 = response2.getContentAsString(); + Assert.assertEquals(content1, content2); } finally { @@ -341,6 +345,7 @@ public class ForwardProxyTLSServerTest .path("/echo?body=" + URLEncoder.encode(body, "UTF-8")) // Long idle timeout for the request. .idleTimeout(10 * idleTimeout, TimeUnit.MILLISECONDS) + .timeout(5, TimeUnit.SECONDS) .send(); Assert.assertEquals(HttpStatus.OK_200, response.getStatus()); @@ -372,6 +377,7 @@ public class ForwardProxyTLSServerTest .scheme(HttpScheme.HTTPS.asString()) .method(HttpMethod.GET) .path("/echo?body=" + URLEncoder.encode(body, "UTF-8")) + .timeout(5, TimeUnit.SECONDS) .send(); Assert.fail(); } @@ -404,6 +410,7 @@ public class ForwardProxyTLSServerTest .scheme(HttpScheme.HTTPS.asString()) .method(HttpMethod.GET) .path("/echo?body=" + URLEncoder.encode(body, "UTF-8")) + .timeout(5, TimeUnit.SECONDS) .send(); Assert.fail(); } @@ -438,6 +445,7 @@ public class ForwardProxyTLSServerTest { httpClient.newRequest("localhost", serverConnector.getLocalPort()) .scheme(HttpScheme.HTTPS.asString()) + .timeout(5, TimeUnit.SECONDS) .send(); Assert.fail(); } @@ -516,6 +524,7 @@ public class ForwardProxyTLSServerTest .scheme(HttpScheme.HTTPS.asString()) .method(HttpMethod.GET) .path("/echo?body=" + URLEncoder.encode(body, "UTF-8")) + .timeout(5, TimeUnit.SECONDS) .send(); Assert.assertEquals(HttpStatus.OK_200, response.getStatus());