Skip to content
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

Per request redirects #46

Closed
wants to merge 85 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
974b547
Removed required dependency on log4j in favor of a pluggable logging …
Jul 27, 2010
402b33b
Fix for http://github.com/ning/async-http-client/issues#issue/37
jfarcand Aug 31, 2010
5c698a8
Fix for http://github.com/AsyncHttpClient/async-http-client/issues#is…
jfarcand Aug 31, 2010
ad048d9
Fix merge conflict
jfarcand Aug 31, 2010
fdcc470
Reformat, add licence header
jfarcand Aug 31, 2010
df65589
Try to fix the Github bug that is not rendering correctly
jfarcand Aug 31, 2010
8423cfc
First drop of Basic/Digest authentication support, untested. Working …
jfarcand Sep 2, 2010
81c6a68
Fix typo in name
jfarcand Sep 2, 2010
b74ada9
Fix builder, add Basic Auth test
jfarcand Sep 2, 2010
0927394
Basic Auth now works, Digest fail one unit test
jfarcand Sep 2, 2010
52015c5
Digest Auth now working
jfarcand Sep 2, 2010
eedf9cc
Cosmetic clean, add infor about Jetty 6 code
jfarcand Sep 2, 2010
c72236d
Javadoc
jfarcand Sep 2, 2010
f851e42
Javadoc
jfarcand Sep 2, 2010
35de52c
Fix for http://github.com/ning/async-http-client/issues#issue/40
jfarcand Sep 3, 2010
ca0c8af
Make sure we always use UTF-8 as pointed out by Tatu
jfarcand Sep 3, 2010
bda5b63
Fix hardcoded port value
jfarcand Sep 3, 2010
fcba25d
Add missing class
jfarcand Sep 3, 2010
2690cbe
Fix for http://github.com/AsyncHttpClient/async-http-client/issues/is…
jfarcand Sep 3, 2010
1b2aa0f
Typo
jfarcand Sep 3, 2010
9f3b7a4
Rename method, Improve efficiency of digest(). Collaboration works wi…
jfarcand Sep 3, 2010
9c9223d
Merge branch 'basic_digest_implementation'
jfarcand Sep 3, 2010
a6d2db3
Javadoc improvement
jfarcand Sep 3, 2010
7ea6f0f
Make sure we still compile with JDK 5
jfarcand Sep 3, 2010
db0468a
Fix for http://github.com/AsyncHttpClient/async-http-client/issues/is…
jfarcand Sep 3, 2010
22a7b7c
Handle the case where the path is not specified, defaulting to /
jfarcand Sep 3, 2010
30b35e9
Better fix for http://github.com/AsyncHttpClient/async-http-client/is…
jfarcand Sep 3, 2010
fdbbdb8
Improve base64 encoding, url/percent encoding, resolve compiler warnings
Sep 4, 2010
e99c6e6
Add missing headers
jfarcand Sep 4, 2010
7d39bea
[maven-release-plugin] prepare release async-http-client-1.1.0
jfarcand Sep 4, 2010
49663b6
[maven-release-plugin] prepare for next development iteration
jfarcand Sep 4, 2010
ea8ce51
Fix pom
jfarcand Sep 4, 2010
6695269
Rollback the release version as the wrong URL for the project was used
jfarcand Sep 4, 2010
b283098
[maven-release-plugin] prepare release async-http-client-1.1.0
jfarcand Sep 4, 2010
9071cae
[maven-release-plugin] prepare for next development iteration
jfarcand Sep 4, 2010
ce5d52a
Fix for http://github.com/AsyncHttpClient/async-http-client/issues/is…
jfarcand Sep 8, 2010
7004f06
Fix for http://github.com/AsyncHttpClient/async-http-client/issues#is…
jfarcand Sep 8, 2010
4f85d4b
Cleanup
jfarcand Sep 8, 2010
8aacad1
Cleanup and Javadoc
jfarcand Sep 8, 2010
ecced56
Document AsyncHandler API and add a new ProgressAsyncHandler implemen…
jfarcand Sep 8, 2010
dcb8ed5
Final implementation of zero-byte copy when uploading File
jfarcand Sep 8, 2010
ccda173
Fix shaded jar version
jfarcand Sep 10, 2010
4dd265c
Fix for http://github.com/AsyncHttpClient/async-http-client/issues/is…
jfarcand Sep 10, 2010
99e57da
Do not expose a setFile and instead align with the rest of the API wh…
jfarcand Sep 10, 2010
0f933aa
Fix typo setBoby -> setBody
jfarcand Sep 10, 2010
50d4966
Fix base url
jloomis Aug 24, 2010
9575e6f
Merge branch 'master' of http://github.com/AsyncHttpClient/async-http…
jloomis Sep 11, 2010
92fb907
Fix for http://github.com/AsyncHttpClient/async-http-client/issues#is…
jfarcand Sep 13, 2010
8390597
Still can't get reaper to work.
neotyk Sep 14, 2010
47aa769
per request request timeout is working
neotyk Sep 14, 2010
3bbdc50
This test doesn't need to be so verbose.
neotyk Sep 14, 2010
e6434a8
Changed exception message when request is reaped to "Request timed ou…
neotyk Sep 14, 2010
2693153
Fix for http://github.com/AsyncHttpClient/async-http-client/issues#is…
jfarcand Sep 14, 2010
4943e20
Fix merge issue
jfarcand Sep 15, 2010
0e1f0f8
Fix typo
jfarcand Sep 15, 2010
ceadaaa
Reformat, no functional changes
jfarcand Sep 15, 2010
88a3241
Document why it is recommended to use an executor when executing inne…
jfarcand Sep 15, 2010
21560aa
Fix for http://github.com/AsyncHttpClient/async-http-client/issues/is…
jfarcand Sep 15, 2010
617299f
Remove work in progress
jfarcand Sep 15, 2010
2102376
Proper fix for Issue 14Z, this time without the junk added by IDEA
jfarcand Sep 15, 2010
2078a2a
Fix proper tmp location for ZeroCopy test
jfarcand Sep 15, 2010
9f94eeb
Refactor the method, no functional changes
jfarcand Sep 16, 2010
5afa97c
Fix for http://github.com/AsyncHttpClient/async-http-client/issues#is…
jfarcand Sep 16, 2010
3f6119b
Fix for http://github.com/AsyncHttpClient/async-http-client/issues#is…
jfarcand Sep 16, 2010
f69cc7e
We need -1 value for infinite waiting, 0 can be used for blank.
neotyk Sep 16, 2010
577daad
Refactor for code clarity. No functional changes
Sep 16, 2010
2957ef4
Merge branch 'master' of github.com:AsyncHttpClient/async-http-client
jfarcand Sep 16, 2010
2919b93
Per request and infinite timeout implemented and working.
neotyk Sep 17, 2010
65c0d0b
There may be some case when a response header could be sent in two ch…
jfarcand Sep 17, 2010
2c786e7
Fix for http://github.com/AsyncHttpClient/async-http-client/issues#is…
jfarcand Sep 17, 2010
d88e538
Fix for http://github.com/AsyncHttpClient/async-http-client/issues#is…
jfarcand Sep 17, 2010
dc2421c
Fix for http://github.com/AsyncHttpClient/async-http-client/issues#is…
jfarcand Sep 19, 2010
fb717bf
Add a unit test covering the / case
jfarcand Sep 19, 2010
6a305c7
Those files were'nt supposed to be push
jfarcand Sep 19, 2010
6dd336a
Fix unit tests failure
jfarcand Sep 19, 2010
c6df340
Merge branch 'master' of github.com:AsyncHttpClient/async-http-client
neotyk Sep 19, 2010
69a4c71
Don't add default port to host header
jloomis Sep 20, 2010
ee371ed
Merge branch 'master' of http://github.com/AsyncHttpClient/async-http…
jloomis Sep 20, 2010
bc733ec
Again making -1 for request timeout infinite.
neotyk Sep 20, 2010
7fb4fa1
Merge remote branch 'jenny/master'
jfarcand Sep 20, 2010
8e3990e
Merge branch 'master' of http://github.com/AsyncHttpClient/async-http…
jloomis Sep 20, 2010
02e4dc0
Escape from redirect loop
jloomis Sep 20, 2010
9355a94
Update Relative302 unit test to pass redirect loop escape
jloomis Sep 22, 2010
204df54
Allow urls with missing query param values
jloomis Sep 21, 2010
fbf4fde
Provide a setFollowRedirect method on the builder, to enable followin…
erwan Sep 23, 2010
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions README
Expand Up @@ -8,7 +8,7 @@ Async Http Client library purpose is to allow Java applications to easily execut
<repository>
<id>Sonatype</id>
<name>Sonatype Release</name>
<url>http://oss.sonatype.org/content/repositories/releases</url>
<url>http://oss.sonatype.org/content/repositories/releases </url>
</repository>

and then define the dependency as:
Expand All @@ -29,7 +29,7 @@ Then in your code you can simply do:
import java.util.concurrent.Future;

AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
Future<Response> f = asyncHttpClient.prepareGet("http://www.ning.com/").execute();
Future<Response> f = asyncHttpClient.prepareGet("http://www.ning.com/ ").execute();
Response r = f.get();

You can also accomplish asynchronous operation without using a Future if you want to receive and process the response in your handler:
Expand All @@ -38,7 +38,7 @@ You can also accomplish asynchronous operation without using a Future if you wan
import java.util.concurrent.Future;

AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
asyncHttpClient.prepareGet("http://www.ning.com/").execute(new AsyncCompletionHandler<Response>(){
asyncHttpClient.prepareGet("http://www.ning.com/ ").execute(new AsyncCompletionHandler<Response>(){

@Override
public Response onCompleted(Response response) throws Exception{
Expand All @@ -59,7 +59,7 @@ You can also mix Future with AsyncHandler to only retrieve part of the asynchron
import java.util.concurrent.Future;

AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
Future<Integer> f = asyncHttpClient.prepareGet("http://www.ning.com/").execute(new AsyncCompletionHandler<Integer>(){
Future<Integer> f = asyncHttpClient.prepareGet("http://www.ning.com/ ").execute(new AsyncCompletionHandler<Integer>(){

@Override
public Integer onCompleted(Response response) throws Exception{
Expand All @@ -81,7 +81,7 @@ You can also mix Future with AsyncHandler to only retrieve part of the asynchron
import java.util.concurrent.Future;

AsyncHttpClient c = new AsyncHttpClient();
Future<String> f = c.prepareGet("http://www.ning.com/").execute(new AsyncHandler<String>() {
Future<String> f = c.prepareGet("http://www.ning.com/ ").execute(new AsyncHandler<String>() {
private StringBuilder builder = new StringBuilder();

@Override
Expand Down
70 changes: 47 additions & 23 deletions pom.xml
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<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">
<parent>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
Expand All @@ -10,17 +9,17 @@
<groupId>com.ning</groupId>
<artifactId>async-http-client</artifactId>
<name>async-http-client</name>
<version>1.1.0-SNAPSHOT</version>
<version>1.2.0-SNAPSHOT</version>
<packaging>jar</packaging>
<description>
Async Http Client library purpose is to allow Java applications to easily execute HTTP requests and
asynchronously process the HTTP responses.
</description>
<url>http://github.com/ning/async-http-client</url>
<url>http://github.com/AsyncHttpClient/async-http-client</url>
<scm>
<connection>scm:git:git@github.com:ning/async-http-client.git</connection>
<url>scm:git:git@github.com:ning/async-http-client.git</url>
<developerConnection>scm:git:git@github.com:ning/async-http-client.git</developerConnection>
<connection>scm:git:git@github.com:AsynHttpClient/async-http-client.git</connection>
<url>scm:git:git@github.com:AsyncHttpClient/async-http-client.git</url>
<developerConnection>scm:git:git@github.com:AsyncHttpClient/async-http-client.git</developerConnection>
</scm>
<prerequisites>
<maven>2.0.9</maven>
Expand Down Expand Up @@ -57,7 +56,7 @@
<dependency>
<groupId>org.jboss.netty</groupId>
<artifactId>netty</artifactId>
<version>3.2.1.Final</version>
<version>3.2.2.Final</version>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
Expand All @@ -69,10 +68,19 @@
</exclusion>
</exclusions>
</dependency>

<!-- Provided logging implementations (aside from java.util.logging) -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.13</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.5.6</version>
<optional>true</optional>
</dependency>

<!-- Test dependencies -->
Expand All @@ -89,6 +97,18 @@
<version>7.1.4.v20100610</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-security</artifactId>
<version>7.1.4.v20100610</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.5.6</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<defaultGoal>install</defaultGoal>
Expand Down Expand Up @@ -158,6 +178,13 @@
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Dcom.ning.http.client.logging.LoggerProvider.class=com.ning.http.client.logging.Slf4jLoggerProvider</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
Expand Down Expand Up @@ -212,23 +239,18 @@
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>shaded</shadedClassifierName>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ComponentsXmlResourceTransformer"/>
</transformers>
<artifactSet>
<includes>
<include>com.google.collections:google-collections</include>
</includes>
<excludes>
<exclude>junit:junit</exclude>
<exclude>log4j:log4j</exclude>
<excluse>org.slf4j:slf4j-api</excluse>
</excludes>
</artifactSet>
<relocations>
<relocation>
<pattern>com.google.common</pattern>
<shadedPattern>com.ning.http.shaded.com.google.collections</shadedPattern>
</relocation>
</relocations>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
<transformer implementation="org.apache.maven.plugins.shade.resource.ComponentsXmlResourceTransformer" />
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"/>
</transformers>
</configuration>
</execution>
</executions>
Expand Down Expand Up @@ -271,6 +293,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<groups>standalone</groups>
<argLine>-Dcom.ning.http.client.logging.LoggerProvider.class=com.ning.http.client.logging.Slf4jLoggerProvider</argLine>
</configuration>
</plugin>
</plugins>
Expand All @@ -285,6 +308,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<groups>standalone, online</groups>
<argLine>-Dcom.ning.http.client.logging.LoggerProvider.class=com.ning.http.client.logging.Slf4jLoggerProvider</argLine>
</configuration>
</plugin>
</plugins>
Expand Down
63 changes: 56 additions & 7 deletions src/main/java/com/ning/http/client/AsyncCompletionHandler.java
Expand Up @@ -16,22 +16,41 @@
*/
package com.ning.http.client;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

import com.ning.http.client.logging.LogManager;
import com.ning.http.client.logging.Logger;

/**
* An {@link AsyncHandler} augmented with an {@link #onCompleted(Response)} convenience method which gets called
* when the {@link Response} has been fully received.
*
* <strong>NOTE:<strong> Sending another asynchronous request from an {@link AsyncHandler} must be done using
* another thread to avoid potential deadlock inside the {@link com.ning.http.client.AsyncHttpProvider}
*
* The recommended way is to use the {@link java.util.concurrent.ExecutorService} from the {@link com.ning.http.client.AsyncHttpClientConfig}:
* {@code
* &#64;Override
* public T onCompleted(Response response) throws Exception
* &#123;
* asyncHttpClient.getConfig().executorService().execute(new Runnable()
* &#123;
* public void run()
* &#123;
* asyncHttpClient.prepareGet(...);
* &#125;
* &#125;);
* return T;
* &#125;
* }
*
* @param <T> Type of the value that will be returned by the associated {@link java.util.concurrent.Future}
*/
public abstract class AsyncCompletionHandler<T> implements AsyncHandler<T> {
public abstract class AsyncCompletionHandler<T> implements AsyncHandler<T>, ProgressAsyncHandler<T> {

private final static Logger log = LogManager.getLogger(AsyncCompletionHandlerBase.class);
private final Logger log = LogManager.getLogger(AsyncCompletionHandlerBase.class);

private final Collection<HttpResponseBodyPart> bodies =
Collections.synchronizedCollection(new ArrayList<HttpResponseBodyPart>());
Expand Down Expand Up @@ -78,8 +97,7 @@ public final T onCompleted() throws Exception {
*/
/* @Override */
public void onThrowable(Throwable t) {
if (log.isDebugEnabled())
log.debug(t);
log.debug(t);
}

/**
Expand All @@ -89,4 +107,35 @@ public void onThrowable(Throwable t) {
* @return Type of the value that will be returned by the associated {@link java.util.concurrent.Future}
*/
abstract public T onCompleted(Response response) throws Exception;

/**
* Invoked when the content (a {@link java.io.File}, {@link String} or {@link java.io.FileInputStream} has been fully
* written on the I/O socket.
*
* @return a {@link com.ning.http.client.AsyncHandler.STATE} telling to CONTINUE or ABORT the current processing.
*/
public STATE onHeaderWriteCompleted() {
return STATE.CONTINUE;
}

/**
* Invoked when the content (a {@link java.io.File}, {@link String} or {@link java.io.FileInputStream} has been fully
* written on the I/O socket.
*
* @return a {@link com.ning.http.client.AsyncHandler.STATE} telling to CONTINUE or ABORT the current processing.
*/
public STATE onContentWriteCompleted() {
return STATE.CONTINUE;
}

/**
* Invoked when the I/O operation associated with the {@link Request} body as been progressed.
* @param amount The amount of bytes to transfer.
* @param current The amount of bytes transferred
* @param total The total number of bytes transferred
* @return a {@link com.ning.http.client.AsyncHandler.STATE} telling to CONTINUE or ABORT the current processing.
*/
public STATE onContentWriteProgess(long amount, long current, long total) {
return STATE.CONTINUE;
}
}
29 changes: 23 additions & 6 deletions src/main/java/com/ning/http/client/AsyncCompletionHandlerBase.java
Expand Up @@ -16,14 +16,33 @@
*/
package com.ning.http.client;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import com.ning.http.client.logging.LogManager;
import com.ning.http.client.logging.Logger;

/**
* Simple {@link AsyncHandler} of type {@link Response}
*
* <strong>NOTE:<strong> Sending another asynchronous request from an {@link AsyncHandler} must be done using
* another thread to avoid potential deadlock inside the {@link com.ning.http.client.AsyncHttpProvider}
*
* The recommended way is to use the {@link java.util.concurrent.ExecutorService} from the {@link com.ning.http.client.AsyncHttpClientConfig}:
* {@code
* &#64;Override
* public Response onCompleted(Response response) throws Exception
* &#123;
* asyncHttpClient.getConfig().executorService().execute(new Runnable()
* &#123;
* public void run()
* &#123;
* asyncHttpClient.prepareGet(...);
* &#125;
* &#125;);
* return response;
* &#125;
* }
*/
public class AsyncCompletionHandlerBase extends AsyncCompletionHandler<Response>{
private final static Logger log = LogManager.getLogger(AsyncCompletionHandlerBase.class);
private final Logger log = LogManager.getLogger(AsyncCompletionHandlerBase.class);

@Override
public Response onCompleted(Response response) throws Exception {
Expand All @@ -32,8 +51,6 @@ public Response onCompleted(Response response) throws Exception {

/* @Override */
public void onThrowable(Throwable t) {
if (log.isDebugEnabled()) {
log.debug(t);
}
log.debug(t);
}
}