Skip to content

Commit

Permalink
Fixed deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
ok2c committed Nov 22, 2023
1 parent 7172afa commit e899aae
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.ok2c.hc5.json.http;

import java.net.URI;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

import org.apache.hc.client5.http.async.methods.SimpleHttpRequest;
import org.apache.hc.client5.http.async.methods.SimpleHttpRequests;
import org.apache.hc.client5.http.async.methods.SimpleRequestBuilder;
import org.apache.hc.client5.http.async.methods.SimpleRequestProducer;
import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
import org.apache.hc.client5.http.impl.async.HttpAsyncClients;
Expand All @@ -28,7 +27,7 @@ void testRequestWithINVALIDrequest() throws Exception {
// Verify that a request to self with an invalid url still calls the completion.
try (CloseableHttpAsyncClient httpClient = HttpAsyncClients.createHttp2Default()) {
httpClient.start();
SimpleHttpRequest request = SimpleHttpRequests.get(URI.create("http://localhost/INVALID"));
SimpleHttpRequest request = SimpleRequestBuilder.get("http://localhost/INVALID").build();
JsonFactory jsonFactory = mapper.getFactory();
JsonTokenEventHandler mockJsonTokenEventHandler = Mockito.mock(JsonTokenEventHandler.class);
@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.Collections;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

import org.apache.hc.client5.http.HttpResponseException;
import org.apache.hc.client5.http.protocol.HttpClientContext;
Expand Down Expand Up @@ -65,8 +67,11 @@ public void cancelled() {
consumer.streamEnd(null);

// SUCCESS: Non-JSON content-type is ignored by the consumer, it returns a 'null' to the callback.
assertThat(resultFuture).hasFailedWithThrowableThat()
.isInstanceOf(HttpResponseException.class);
assertThat(resultFuture)
.failsWithin(Duration.ofMinutes(1))
.withThrowableThat()
.isInstanceOf(ExecutionException.class)
.withCauseInstanceOf(HttpResponseException.class);
}

@Test
Expand Down Expand Up @@ -103,8 +108,11 @@ public void cancelled() {
consumer.streamEnd(null);

// FAILS: consumer attempts to parse the error body as it was a successful response and throws a parsing error
assertThat(resultFuture).hasFailedWithThrowableThat()
.isInstanceOf(HttpResponseException.class);
assertThat(resultFuture)
.failsWithin(Duration.ofMinutes(1))
.withThrowableThat()
.isInstanceOf(ExecutionException.class)
.withCauseInstanceOf(HttpResponseException.class);
}

@Test
Expand Down Expand Up @@ -141,8 +149,11 @@ public void cancelled() {
consumer.streamEnd(null);

// FAILS: consumer attempts to parse the error body as it was a successful response and throws a parsing error
assertThat(resultFuture).hasFailedWithThrowableThat()
.isInstanceOf(HttpResponseException.class);
assertThat(resultFuture)
.failsWithin(Duration.ofMinutes(1))
.withThrowableThat()
.isInstanceOf(ExecutionException.class)
.withCauseInstanceOf(HttpResponseException.class);
}

private static <T> void handleResponseResult(Message<HttpResponse, T> result, CompletableFuture<T> resultFuture) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
import java.net.URI;
import java.util.concurrent.Future;

import org.apache.hc.client5.http.async.methods.BasicHttpRequests;
import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
import org.apache.hc.client5.http.impl.async.HttpAsyncClients;
import org.apache.hc.core5.concurrent.FutureCallback;
import org.apache.hc.core5.http.HttpResponse;
import org.apache.hc.core5.http.Message;
import org.apache.hc.core5.http.message.BasicNameValuePair;
import org.apache.hc.core5.http.support.BasicRequestBuilder;
import org.apache.hc.core5.io.CloseMode;

import com.fasterxml.jackson.core.JsonFactory;
Expand All @@ -48,7 +48,7 @@ public static void main(String... args) throws Exception {
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
System.out.println("Executing POST " + uri);
Future<?> future = client.execute(
JsonRequestProducers.create(BasicHttpRequests.post(uri),
JsonRequestProducers.create(BasicRequestBuilder.post(uri).build(),
new BasicNameValuePair("name", "value"), objectMapper),
JsonResponseConsumers.create(objectMapper, RequestData.class),
new FutureCallback<Message<HttpResponse, RequestData>>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
import java.net.URI;
import java.util.concurrent.Future;

import org.apache.hc.client5.http.async.methods.BasicHttpRequests;
import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
import org.apache.hc.client5.http.impl.async.HttpAsyncClients;
import org.apache.hc.core5.concurrent.FutureCallback;
import org.apache.hc.core5.http.HttpResponse;
import org.apache.hc.core5.http.Message;
import org.apache.hc.core5.http.message.BasicNameValuePair;
import org.apache.hc.core5.http.support.BasicRequestBuilder;
import org.apache.hc.core5.io.CloseMode;

import com.fasterxml.jackson.core.JsonFactory;
Expand All @@ -48,7 +48,7 @@ public static void main(String... args) throws Exception {
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
System.out.println("Executing POST " + uri);
Future<?> future = client.execute(
JsonRequestProducers.create(BasicHttpRequests.post(uri),
JsonRequestProducers.create(BasicRequestBuilder.post(uri).build(),
objectMapper,
channel -> {
channel.write(new BasicNameValuePair("name1", "value1"));
Expand Down

0 comments on commit e899aae

Please sign in to comment.