diff --git a/pom.xml b/pom.xml index 8aa6e86cfc..8e717a951e 100644 --- a/pom.xml +++ b/pom.xml @@ -534,7 +534,7 @@ http://oss.sonatype.org/content/repositories/snapshots true 3.10.5.Final - 2.3.21 + 2.3.26 1.7 1.7 2.12 diff --git a/src/test/java/com/ning/http/client/async/ConnectionCloseTest.java b/src/test/java/com/ning/http/client/async/ConnectionCloseTest.java new file mode 100644 index 0000000000..d525eeceed --- /dev/null +++ b/src/test/java/com/ning/http/client/async/ConnectionCloseTest.java @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2016 AsyncHttpClient Project. All rights reserved. + * + * This program is licensed to you under the Apache License Version 2.0, + * and you may not use this file except in compliance with the Apache License Version 2.0. + * You may obtain a copy of the Apache License Version 2.0 at + * http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the Apache License Version 2.0 is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. + */ +package com.ning.http.client.async; + +import static com.ning.http.client.async.BasicHttpsTest.createSSLContext; + +import com.ning.http.client.AsyncHttpClient; +import com.ning.http.client.AsyncHttpClientConfig; +import com.ning.http.client.AsyncHttpClientConfig.Builder; +import com.ning.http.client.Request; +import com.ning.http.client.RequestBuilder; +import com.ning.http.client.Response; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.concurrent.atomic.AtomicBoolean; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.handler.AbstractHandler; +import org.eclipse.jetty.server.ssl.SslSocketConnector; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public abstract class ConnectionCloseTest extends AbstractBasicTest { + + @BeforeClass(alwaysRun = true) + public void setUpGlobal() throws Exception { + server = new Server(); + port1 = findFreePort(); + SslSocketConnector connector = new SslSocketConnector(); + connector.setHost("127.0.0.1"); + connector.setPort(port1); + + ClassLoader cl = getClass().getClassLoader(); + + URL cacertsUrl = cl.getResource("ssltest-cacerts.jks"); + String trustStoreFile = new File(cacertsUrl.toURI()).getAbsolutePath(); + connector.setTruststore(trustStoreFile); + connector.setTrustPassword("changeit"); + connector.setTruststoreType("JKS"); + + URL keystoreUrl = cl.getResource("ssltest-keystore.jks"); + String keyStoreFile = new File(keystoreUrl.toURI()).getAbsolutePath(); + connector.setKeystore(keyStoreFile); + connector.setKeyPassword("changeit"); + connector.setKeystoreType("JKS"); + + server.addConnector(connector); + + server.setHandler(configureHandler()); + server.start(); + log.info("Local HTTP server started successfully"); + } + + @AfterClass(alwaysRun = true) + public void tearDownGlobal() throws Exception { + server.stop(); + } + + public static class CloseConnectionHandler extends AbstractHandler { + + @Override + public void handle(String pathInContext, org.eclipse.jetty.server.Request request, HttpServletRequest httpRequest, + HttpServletResponse httpResponse) throws IOException, ServletException { + httpResponse.setHeader("Connection", "close"); + httpResponse.setStatus(200); + httpResponse.getOutputStream().flush(); + httpResponse.getOutputStream().close(); + } + } + + @Override + public AbstractHandler configureHandler() throws Exception { + return new CloseConnectionHandler(); + } + + @Test + public void handlesCloseResponse() throws IOException, InterruptedException, ExecutionException { + + AsyncHttpClientConfig config = new Builder().setSSLContext(createSSLContext(new AtomicBoolean(true))).build(); + + try (AsyncHttpClient client = getAsyncHttpClient(config)) { + Request request = new RequestBuilder("GET").setHeader("Connection", "keep-alive").setUrl(getTargetUrl()).build(); + Future responseFuture = client.executeRequest(request); + int status = responseFuture.get().getStatusCode(); + Assert.assertEquals(status, 200); + } + } + + protected String getTargetUrl() { + return String.format("https://127.0.0.1:%d/foo/test", port1); + } + +} + diff --git a/src/test/java/com/ning/http/client/async/grizzly/GrizzlyConnectionCloseTest.java b/src/test/java/com/ning/http/client/async/grizzly/GrizzlyConnectionCloseTest.java new file mode 100644 index 0000000000..577c1f7105 --- /dev/null +++ b/src/test/java/com/ning/http/client/async/grizzly/GrizzlyConnectionCloseTest.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2016 AsyncHttpClient Project. All rights reserved. + * + * This program is licensed to you under the Apache License Version 2.0, + * and you may not use this file except in compliance with the Apache License Version 2.0. + * You may obtain a copy of the Apache License Version 2.0 at + * http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the Apache License Version 2.0 is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. + */ +package com.ning.http.client.async.grizzly; + +import com.ning.http.client.AsyncHttpClient; +import com.ning.http.client.AsyncHttpClientConfig; +import com.ning.http.client.async.ConnectionCloseTest; +import com.ning.http.client.async.ProviderUtil; + +public class GrizzlyConnectionCloseTest extends ConnectionCloseTest { + + @Override + public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { + return ProviderUtil.grizzlyProvider(config); + } + +} diff --git a/src/test/java/com/ning/http/client/async/netty/NettyConnectionCloseTest.java b/src/test/java/com/ning/http/client/async/netty/NettyConnectionCloseTest.java new file mode 100644 index 0000000000..b17770788a --- /dev/null +++ b/src/test/java/com/ning/http/client/async/netty/NettyConnectionCloseTest.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2016 AsyncHttpClient Project. All rights reserved. + * + * This program is licensed to you under the Apache License Version 2.0, + * and you may not use this file except in compliance with the Apache License Version 2.0. + * You may obtain a copy of the Apache License Version 2.0 at + * http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the Apache License Version 2.0 is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. + */ +package com.ning.http.client.async.netty; + +import com.ning.http.client.AsyncHttpClient; +import com.ning.http.client.AsyncHttpClientConfig; +import com.ning.http.client.async.ConnectionCloseTest; +import com.ning.http.client.async.ProviderUtil; + +public class NettyConnectionCloseTest extends ConnectionCloseTest { + + @Override + public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { + return ProviderUtil.nettyProvider(config); + } +}