Skip to content

Update Grizzly to latest version and add test case for HTTPS close co… #1208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@
<distMgmtSnapshotsUrl>http://oss.sonatype.org/content/repositories/snapshots</distMgmtSnapshotsUrl>
<surefire.redirectTestOutputToFile>true</surefire.redirectTestOutputToFile>
<netty.version>3.10.5.Final</netty.version>
<grizzly.version>2.3.21</grizzly.version>
<grizzly.version>2.3.26</grizzly.version>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<surefire.version>2.12</surefire.version>
Expand Down
115 changes: 115 additions & 0 deletions src/test/java/com/ning/http/client/async/ConnectionCloseTest.java
Original file line number Diff line number Diff line change
@@ -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<Response> 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);
}

}

Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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);
}
}