Skip to content

Commit

Permalink
Move SimpleClient to extra submodule, close #1004
Browse files Browse the repository at this point in the history
  • Loading branch information
slandelle committed Oct 13, 2015
1 parent 4a4b475 commit 7c01408
Show file tree
Hide file tree
Showing 16 changed files with 101 additions and 67 deletions.
19 changes: 0 additions & 19 deletions client/src/test/java/org/asynchttpclient/BasicAuthTest.java
Expand Up @@ -31,9 +31,6 @@
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;


import org.asynchttpclient.request.body.generator.InputStreamBodyGenerator;
import org.asynchttpclient.simple.SimpleAsyncHttpClient;
import org.asynchttpclient.simple.consumer.AppendableBodyConsumer;
import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.server.handler.AbstractHandler;
Expand Down Expand Up @@ -323,22 +320,6 @@ public void basicAuthFileNoKeepAliveTest() throws Exception {
} }
} }


@Test(groups = { "standalone", "default_provider" })
public void stringBuilderBodyConsumerTest() throws Exception {

try (SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setRealmPrincipal(USER).setRealmPassword(ADMIN).setUrl(getTargetUrl())
.setHeader("Content-Type", "text/html").build()) {
StringBuilder s = new StringBuilder();
Future<Response> future = client.post(new InputStreamBodyGenerator(new ByteArrayInputStream(MY_MESSAGE.getBytes())), new AppendableBodyConsumer(s));

Response response = future.get();
assertEquals(response.getStatusCode(), 200);
assertEquals(s.toString(), MY_MESSAGE);
assertEquals(response.getStatusCode(), HttpServletResponse.SC_OK);
assertNotNull(response.getHeader("X-Auth"));
}
}

@Test(groups = { "standalone", "default_provider" }) @Test(groups = { "standalone", "default_provider" })
public void noneAuthTest() throws IOException, ExecutionException, TimeoutException, InterruptedException { public void noneAuthTest() throws IOException, ExecutionException, TimeoutException, InterruptedException {
try (AsyncHttpClient client = new DefaultAsyncHttpClient()) { try (AsyncHttpClient client = new DefaultAsyncHttpClient()) {
Expand Down
19 changes: 0 additions & 19 deletions client/src/test/java/org/asynchttpclient/proxy/HttpsProxyTest.java
Expand Up @@ -29,7 +29,6 @@
import org.asynchttpclient.DefaultAsyncHttpClient; import org.asynchttpclient.DefaultAsyncHttpClient;
import org.asynchttpclient.RequestBuilder; import org.asynchttpclient.RequestBuilder;
import org.asynchttpclient.Response; import org.asynchttpclient.Response;
import org.asynchttpclient.simple.SimpleAsyncHttpClient;
import org.asynchttpclient.test.EchoHandler; import org.asynchttpclient.test.EchoHandler;
import org.eclipse.jetty.proxy.ConnectHandler; import org.eclipse.jetty.proxy.ConnectHandler;
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Server;
Expand Down Expand Up @@ -126,22 +125,4 @@ public Response onCompleted(Response response) throws Exception {
assertEquals(r.getHeader("X-Connection"), HttpHeaders.Values.KEEP_ALIVE); assertEquals(r.getHeader("X-Connection"), HttpHeaders.Values.KEEP_ALIVE);
} }
} }

@Test(groups = { "online", "default_provider" })
public void testSimpleAHCConfigProxy() throws IOException, InterruptedException, ExecutionException, TimeoutException {

try (SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder()//
.setProxyHost("127.0.0.1")//
.setProxyPort(port1)//
.setFollowRedirect(true)//
.setUrl(getTargetUrl2())//
.setAcceptAnyCertificate(true)//
.setHeader("Content-Type", "text/html")//
.build()) {
Response r = client.get().get();

assertEquals(r.getStatusCode(), 200);
assertEquals(r.getHeader("X-Connection"), HttpHeaders.Values.KEEP_ALIVE);
}
}
} }
1 change: 1 addition & 0 deletions extras/pom.xml
Expand Up @@ -17,6 +17,7 @@
<module>jdeferred</module> <module>jdeferred</module>
<module>registry</module> <module>registry</module>
<module>rxjava</module> <module>rxjava</module>
<module>simple</module>
</modules> </modules>


<dependencies> <dependencies>
Expand Down
11 changes: 11 additions & 0 deletions extras/simple/pom.xml
@@ -0,0 +1,11 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>async-http-client-extras-parent</artifactId>
<groupId>org.asynchttpclient</groupId>
<version>2.0.0-SNAPSHOT</version>
</parent>
<artifactId>async-http-client-extras-simple</artifactId>
<name>Asynchronous Http Simple Client</name>
<description>The Async Http Simple Client.</description>
</project>
Expand Up @@ -10,7 +10,7 @@
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * "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. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
*/ */
package org.asynchttpclient.simple.consumer; package org.asynchttpclient.extras.simple;


import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;


Expand Down
Expand Up @@ -11,14 +11,12 @@
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
*/ */


package org.asynchttpclient.simple.consumer; package org.asynchttpclient.extras.simple;


import java.io.Closeable; import java.io.Closeable;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;


import org.asynchttpclient.simple.SimpleAsyncHttpClient;

/** /**
* A simple API to be used with the {@link SimpleAsyncHttpClient} class in order to process response's bytes. * A simple API to be used with the {@link SimpleAsyncHttpClient} class in order to process response's bytes.
*/ */
Expand Down
Expand Up @@ -10,7 +10,7 @@
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * "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. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
*/ */
package org.asynchttpclient.simple.consumer; package org.asynchttpclient.extras.simple;


import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
Expand Down
Expand Up @@ -10,7 +10,7 @@
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * "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. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
*/ */
package org.asynchttpclient.simple.consumer; package org.asynchttpclient.extras.simple;


import java.io.IOException; import java.io.IOException;
import java.io.RandomAccessFile; import java.io.RandomAccessFile;
Expand Down
Expand Up @@ -10,7 +10,7 @@
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * "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. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
*/ */
package org.asynchttpclient.simple.consumer; package org.asynchttpclient.extras.simple;


import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
Expand Down
Expand Up @@ -11,7 +11,7 @@
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
*/ */


package org.asynchttpclient.simple.consumer; package org.asynchttpclient.extras.simple;


import java.io.IOException; import java.io.IOException;


Expand Down
@@ -1,4 +1,4 @@
package org.asynchttpclient.simple; package org.asynchttpclient.extras.simple;


/* /*
* Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved.
Expand Down
Expand Up @@ -10,7 +10,7 @@
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * "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. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
*/ */
package org.asynchttpclient.simple; package org.asynchttpclient.extras.simple;


import static org.asynchttpclient.Dsl.*; import static org.asynchttpclient.Dsl.*;
import static org.asynchttpclient.util.MiscUtils.closeSilently; import static org.asynchttpclient.util.MiscUtils.closeSilently;
Expand Down Expand Up @@ -48,9 +48,8 @@
import org.asynchttpclient.proxy.ProxyServer; import org.asynchttpclient.proxy.ProxyServer;
import org.asynchttpclient.request.body.generator.BodyGenerator; import org.asynchttpclient.request.body.generator.BodyGenerator;
import org.asynchttpclient.request.body.multipart.Part; import org.asynchttpclient.request.body.multipart.Part;
import org.asynchttpclient.simple.consumer.BodyConsumer;
import org.asynchttpclient.simple.consumer.ResumableBodyConsumer;
import org.asynchttpclient.uri.Uri; import org.asynchttpclient.uri.Uri;

import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.HttpHeaders;


/** /**
Expand Down
Expand Up @@ -11,7 +11,7 @@
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
*/ */


package org.asynchttpclient.simple; package org.asynchttpclient.extras.simple;




/** /**
Expand Down
@@ -0,0 +1,68 @@
package org.asynchttpclient.extras.simple;

import static org.asynchttpclient.test.TestUtils.*;
import static org.testng.Assert.assertEquals;
import io.netty.handler.codec.http.HttpHeaders;

import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;

import org.asynchttpclient.AbstractBasicTest;
import org.asynchttpclient.Response;
import org.asynchttpclient.test.EchoHandler;
import org.eclipse.jetty.proxy.ConnectHandler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class HttpsProxyTest extends AbstractBasicTest {

private Server server2;

public AbstractHandler configureHandler() throws Exception {
return new ConnectHandler();
}

@BeforeClass(alwaysRun = true)
public void setUpGlobal() throws Exception {
port1 = findFreePort();
server = newJettyHttpServer(port1);
server.setHandler(configureHandler());
server.start();

port2 = findFreePort();

server2 = newJettyHttpsServer(port2);
server2.setHandler(new EchoHandler());
server2.start();

logger.info("Local HTTP server started successfully");
}

@AfterClass(alwaysRun = true)
public void tearDownGlobal() throws Exception {
server.stop();
server2.stop();
}

@Test(groups = { "online", "default_provider" })
public void testSimpleAHCConfigProxy() throws IOException, InterruptedException, ExecutionException, TimeoutException {

try (SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder()//
.setProxyHost("127.0.0.1")//
.setProxyPort(port1)//
.setFollowRedirect(true)//
.setUrl(getTargetUrl2())//
.setAcceptAnyCertificate(true)//
.setHeader("Content-Type", "text/html")//
.build()) {
Response r = client.get().get();

assertEquals(r.getStatusCode(), 200);
assertEquals(r.getHeader("X-Connection"), HttpHeaders.Values.KEEP_ALIVE);
}
}
}
Expand Up @@ -10,26 +10,23 @@
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * "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. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
*/ */
package org.asynchttpclient.simple; package org.asynchttpclient.extras.simple;


import static org.testng.Assert.assertEquals; import static org.testng.Assert.*;
import static org.testng.Assert.assertTrue;


import org.asynchttpclient.AbstractBasicTest; import java.io.ByteArrayOutputStream;
import org.asynchttpclient.Response; import java.io.IOException;
import org.asynchttpclient.simple.SimpleAsyncHttpClient; import java.util.concurrent.Future;
import org.asynchttpclient.simple.SimpleAsyncHttpClient.ErrorDocumentBehaviour;
import org.asynchttpclient.simple.consumer.OutputStreamBodyConsumer;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.testng.annotations.Test;


import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;


import java.io.ByteArrayOutputStream; import org.asynchttpclient.AbstractBasicTest;
import java.io.IOException; import org.asynchttpclient.Response;
import java.util.concurrent.Future; import org.asynchttpclient.extras.simple.SimpleAsyncHttpClient.ErrorDocumentBehaviour;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.testng.annotations.Test;


/** /**
* @author Benjamin Hanzelmann * @author Benjamin Hanzelmann
Expand Down
Expand Up @@ -10,7 +10,7 @@
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * "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. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
*/ */
package org.asynchttpclient.simple; package org.asynchttpclient.extras.simple;


import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
import static org.testng.Assert.*; import static org.testng.Assert.*;
Expand All @@ -30,8 +30,6 @@
import org.asynchttpclient.request.body.generator.FileBodyGenerator; import org.asynchttpclient.request.body.generator.FileBodyGenerator;
import org.asynchttpclient.request.body.generator.InputStreamBodyGenerator; import org.asynchttpclient.request.body.generator.InputStreamBodyGenerator;
import org.asynchttpclient.request.body.multipart.ByteArrayPart; import org.asynchttpclient.request.body.multipart.ByteArrayPart;
import org.asynchttpclient.simple.consumer.AppendableBodyConsumer;
import org.asynchttpclient.simple.consumer.OutputStreamBodyConsumer;
import org.asynchttpclient.uri.Uri; import org.asynchttpclient.uri.Uri;
import org.testng.annotations.Test; import org.testng.annotations.Test;


Expand Down

0 comments on commit 7c01408

Please sign in to comment.