Skip to content

Commit 8951a89

Browse files
committed
BasicHttpProxyToHttpTest dead lock, close AsyncHttpClient#1172
1 parent cac062b commit 8951a89

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

client/src/test/java/org/asynchttpclient/BasicHttpProxyToHttpTest.java

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
import java.util.concurrent.Future;
2323

2424
import javax.servlet.ServletException;
25-
import javax.servlet.ServletRequest;
26-
import javax.servlet.ServletResponse;
2725
import javax.servlet.http.HttpServletRequest;
2826
import javax.servlet.http.HttpServletResponse;
2927

@@ -57,29 +55,26 @@ public class BasicHttpProxyToHttpTest {
5755
public static class BasicAuthProxyServlet extends ProxyServlet {
5856

5957
@Override
60-
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
58+
protected void service(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
6159
LOGGER.debug(">>> got a request !");
6260

63-
HttpServletRequest httpReq = (HttpServletRequest) req;
64-
HttpServletResponse httpRes = (HttpServletResponse) res;
65-
66-
String authorization = httpReq.getHeader(PROXY_AUTHORIZATION);
61+
String authorization = request.getHeader(PROXY_AUTHORIZATION);
6762
if (authorization == null) {
68-
httpRes.setStatus(HttpServletResponse.SC_PROXY_AUTHENTICATION_REQUIRED);
69-
httpRes.setHeader(PROXY_AUTHENTICATE, "Basic realm=\"Fake Realm\"");
70-
httpRes.getOutputStream().flush();
63+
response.setStatus(HttpServletResponse.SC_PROXY_AUTHENTICATION_REQUIRED);
64+
response.setHeader(PROXY_AUTHENTICATE, "Basic realm=\"Fake Realm\"");
65+
response.getOutputStream().flush();
7166

7267
} else if (authorization.equals("Basic am9obmRvZTpwYXNz")) {
73-
super.service(req, res);
68+
super.service(request, response);
7469

7570
} else {
76-
httpRes.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
77-
httpRes.getOutputStream().flush();
71+
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
72+
response.getOutputStream().flush();
7873
}
7974
}
8075
}
8176

82-
@BeforeClass(alwaysRun = true)
77+
@BeforeClass
8378
public void setUpGlobal() throws Exception {
8479

8580
httpPort = findFreePort();
@@ -92,7 +87,7 @@ public void setUpGlobal() throws Exception {
9287
proxy = new Server(proxyPort);
9388
ServletHandler servletHandler = new ServletHandler();
9489
ServletHolder servletHolder = servletHandler.addServletWithMapping(BasicAuthProxyServlet.class, "/*");
95-
servletHolder.setInitParameter("maxThreads", "5");
90+
servletHolder.setInitParameter("maxThreads", "20");
9691
proxy.setHandler(servletHandler);
9792
proxy.start();
9893

@@ -101,8 +96,20 @@ public void setUpGlobal() throws Exception {
10196

10297
@AfterClass(alwaysRun = true)
10398
public void tearDownGlobal() throws Exception {
104-
httpServer.stop();
105-
proxy.stop();
99+
if (proxy != null) {
100+
try {
101+
proxy.stop();
102+
} catch (Exception e) {
103+
LOGGER.error("Failed to properly close proxy", e);
104+
}
105+
}
106+
if (httpServer != null) {
107+
try {
108+
httpServer.stop();
109+
} catch (Exception e) {
110+
LOGGER.error("Failed to properly close server", e);
111+
}
112+
}
106113
}
107114

108115
@Test
@@ -111,7 +118,7 @@ public void nonPreemptyProxyAuthWithPlainHttpTarget() throws IOException, Interr
111118
String targetUrl = "http://localhost:" + httpPort + "/foo/bar";
112119
Request request = get(targetUrl)//
113120
.setProxyServer(proxyServer("127.0.0.1", proxyPort).setRealm(realm(AuthScheme.BASIC, "johndoe", "pass")))//
114-
//.setRealm(realm(AuthScheme.BASIC, "user", "passwd"))//
121+
// .setRealm(realm(AuthScheme.BASIC, "user", "passwd"))//
115122
.build();
116123
Future<Response> responseFuture = client.executeRequest(request);
117124
Response response = responseFuture.get();

0 commit comments

Comments
 (0)