Skip to content

Commit

Permalink
Merge pull request #3 from saasquatch/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
slisaasquatch authored Jun 23, 2020
2 parents 4fdf8b1 + 08e2783 commit 601e4c0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 29 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ Maven
<dependency>
<groupId>com.github.saasquatch</groupId>
<artifactId>apache-client5-reactive</artifactId>
<version>0.0.1</version>
<version>0.0.2</version>
</dependency>
```

Gradle

```gradle
compile 'com.github.saasquatch:apache-client5-reactive:0.0.1'
compile 'com.github.saasquatch:apache-client5-reactive:0.0.2'
```

## License
Expand Down
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.saasquatch</groupId>
<artifactId>apache-client5-reactive</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.2-SNAPSHOT</version>
<packaging>jar</packaging>

<name>apache-client5-reactive</name>
Expand All @@ -19,7 +19,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>5.6.0</junit.version>
<junit.version>5.6.2</junit.version>
</properties>

<dependencies>
Expand All @@ -38,17 +38,17 @@
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>5.0</version>
<version>5.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.core5</groupId>
<artifactId>httpcore5-reactive</artifactId>
<version>5.0</version>
<version>5.0.1</version>
</dependency>
<dependency>
<groupId>io.reactivex.rxjava3</groupId>
<artifactId>rxjava</artifactId>
<version>3.0.0</version>
<version>3.0.4</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

import java.nio.ByteBuffer;
import java.util.Objects;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.apache.hc.client5.http.async.HttpAsyncClient;
import org.apache.hc.client5.http.impl.async.MinimalHttpAsyncClient;
import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.core5.http.HttpResponse;
import org.apache.hc.core5.http.Message;
import org.apache.hc.core5.http.nio.AsyncPushConsumer;
Expand Down Expand Up @@ -38,8 +34,8 @@ public <T> Publisher<T> execute(AsyncRequestProducer requestProducer,
Objects.requireNonNull(requestProducer);
Objects.requireNonNull(responseConsumer);
return Maybe.<T>create(emitter -> {
httpAsyncClient.execute(requestProducer, responseConsumer, pushHandlerFactory,
defaultHttpContext(context), FutureCallbacks.maybeEmitter(emitter));
httpAsyncClient.execute(requestProducer, responseConsumer, pushHandlerFactory, context,
FutureCallbacks.maybeEmitter(emitter));
}).toFlowable();
}

Expand All @@ -56,23 +52,8 @@ public Publisher<Message<HttpResponse, Publisher<ByteBuffer>>> streamingExecute(
return Maybe.<Message<HttpResponse, Publisher<ByteBuffer>>>create(emitter -> {
final ReactiveResponseConsumer responseConsumer =
new ReactiveResponseConsumer(FutureCallbacks.maybeEmitter(emitter));
httpAsyncClient.execute(requestProducer, responseConsumer, pushHandlerFactory,
defaultHttpContext(context), null);
httpAsyncClient.execute(requestProducer, responseConsumer, pushHandlerFactory, context, null);
}).toFlowable();
}

/**
* Create a default {@link HttpContext} if the given one is null. In theory this method should not
* be needed, since according to the JavaDoc in {@link HttpAsyncClient}, {@link HttpContext} can
* be null. However, in Apache HttpClient version 5.0 there's a bug where some implementations of
* {@link HttpAsyncClient} like {@link MinimalHttpAsyncClient} reject null {@link HttpContext}. An
* issue has already been filed
* <a href="https://issues.apache.org/jira/browse/HTTPCLIENT-2059">here</a>. Once that's fixed,
* this method can be removed.
*/
@Nonnull
private static HttpContext defaultHttpContext(@Nullable HttpContext context) {
return context == null ? HttpClientContext.create() : context;
}

}

0 comments on commit 601e4c0

Please sign in to comment.