Replace com.ning/async-http-client with new package

Notice at:
https://github.com/ning/async-http-client
This commit is contained in:
Michael Walker
2018-02-09 14:43:18 +00:00
parent 7a01c054da
commit 9bb7576f0b
9 changed files with 34 additions and 90 deletions

View File

@@ -1,6 +1,6 @@
package uk.ac.ic.wlgitbridge.bridge.resource;
import com.ning.http.client.AsyncHttpClient;
import static org.asynchttpclient.Dsl.*;
import uk.ac.ic.wlgitbridge.bridge.db.DBStore;
import uk.ac.ic.wlgitbridge.data.filestore.RawFile;
import uk.ac.ic.wlgitbridge.data.filestore.RepositoryFile;
@@ -31,7 +31,7 @@ public class UrlResourceCache implements ResourceCache {
}
public UrlResourceCache(DBStore dbStore) {
this(dbStore, new NingHttpClient(new AsyncHttpClient()));
this(dbStore, new NingHttpClient(asyncHttpClient()));
}
@Override
@@ -82,8 +82,7 @@ public class UrlResourceCache implements ResourceCache {
Log.info("GET -> " + url);
try {
contents = http.get(url, hs -> {
List<String> contentLengths
= hs.getHeaders().get("Content-Length");
List<String> contentLengths = hs.getAll("Content-Length");
if (!maxFileSize.isPresent()) {
return true;
}

View File

@@ -1,6 +1,7 @@
package uk.ac.ic.wlgitbridge.io.http.ning;
import com.ning.http.client.*;
import io.netty.handler.codec.http.HttpHeaders;
import org.asynchttpclient.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import uk.ac.ic.wlgitbridge.util.FunctionT;
@@ -23,7 +24,7 @@ public class NingHttpClient implements NingHttpClientFacade {
@Override
public <E extends Exception> byte[] get(
String url,
FunctionT<HttpResponseHeaders, Boolean, E> handler
FunctionT<HttpHeaders, Boolean, E> handler
) throws ExecutionException {
try {
return http
@@ -33,19 +34,19 @@ public class NingHttpClient implements NingHttpClientFacade {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
@Override
public STATE onHeadersReceived(
HttpResponseHeaders headers
public State onHeadersReceived(
HttpHeaders headers
) throws E {
return handler.apply(headers)
? STATE.CONTINUE : STATE.ABORT;
? State.CONTINUE : State.ABORT;
}
@Override
public STATE onBodyPartReceived(
public State onBodyPartReceived(
HttpResponseBodyPart content
) throws IOException {
bytes.write(content.getBodyPartBytes());
return STATE.CONTINUE;
return State.CONTINUE;
}
@Override

View File

@@ -1,6 +1,6 @@
package uk.ac.ic.wlgitbridge.io.http.ning;
import com.ning.http.client.HttpResponseHeaders;
import io.netty.handler.codec.http.HttpHeaders;
import uk.ac.ic.wlgitbridge.util.FunctionT;
import java.util.concurrent.ExecutionException;
@@ -16,7 +16,7 @@ public interface NingHttpClientFacade {
*/
<E extends Exception> byte[] get(
String url,
FunctionT<HttpResponseHeaders, Boolean, E> handler
FunctionT<HttpHeaders, Boolean, E> handler
) throws ExecutionException;
}

View File

@@ -1,46 +0,0 @@
package uk.ac.ic.wlgitbridge.io.http.ning;
import com.ning.http.client.FluentCaseInsensitiveStringsMap;
import com.ning.http.client.HttpResponseHeaders;
import java.util.*;
public class NingHttpHeaders extends HttpResponseHeaders {
private final FluentCaseInsensitiveStringsMap map;
private NingHttpHeaders(FluentCaseInsensitiveStringsMap map) {
this.map = map;
}
public static NingHttpHeadersBuilder builder() {
return new NingHttpHeadersBuilder();
}
@Override
public FluentCaseInsensitiveStringsMap getHeaders() {
return map;
}
public static class NingHttpHeadersBuilder {
private final Map<String, Collection<String>> map;
private NingHttpHeadersBuilder() {
map = new HashMap<>();
}
public NingHttpHeadersBuilder addHeader(String key, String... values) {
map.computeIfAbsent(key, __ -> new ArrayList<>())
.addAll(Arrays.asList(values));
return this;
}
public NingHttpHeaders build() {
return new NingHttpHeaders(
new FluentCaseInsensitiveStringsMap(map));
}
}
}

View File

@@ -3,7 +3,8 @@ package uk.ac.ic.wlgitbridge.snapshot.base;
import com.google.api.client.http.*;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.ning.http.client.AsyncHttpClient;
import org.asynchttpclient.AsyncHttpClient;
import static org.asynchttpclient.Dsl.*;
import uk.ac.ic.wlgitbridge.snapshot.exception.FailedConnectionException;
import uk.ac.ic.wlgitbridge.util.Instance;
import uk.ac.ic.wlgitbridge.util.Log;
@@ -17,7 +18,7 @@ import java.util.concurrent.*;
*/
public abstract class Request<T extends Result> {
public static final AsyncHttpClient httpClient = new AsyncHttpClient();
public static final AsyncHttpClient httpClient = asyncHttpClient();
private static final Executor executor = Executors.newCachedThreadPool();

View File

@@ -2,7 +2,7 @@ package uk.ac.ic.wlgitbridge.snapshot.servermock.server;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.ning.http.client.AsyncHttpClient;
import static org.asynchttpclient.Dsl.*;
import uk.ac.ic.wlgitbridge.util.Log;
import java.io.IOException;
@@ -30,17 +30,9 @@ public class PostbackThread extends Thread {
@Override
public void run() {
try {
new AsyncHttpClient().preparePost(
asyncHttpClient().preparePost(
url
).setBody(postback).execute().get().getResponseBody();
} catch (IOException e) {
Log.warn(
"IOException on postback, url: " +
url +
", postback: " +
postback,
e
);
} catch (InterruptedException e) {
Log.warn(
"Interrupted on postback, url: " +