@Override public void completed(HttpResponse httpResponse) { try { final Map<String, String> headersMap = new HashMap<>(); for (Header header : httpResponse.getAllHeaders()) { headersMap.put(header.getName(), header.getValue()); } final StatusLine statusLine = httpResponse.getStatusLine(); final Response response = new Response(statusLine.getStatusCode(), statusLine.getReasonPhrase(), headersMap, httpResponse.getEntity().getContent()); @SuppressWarnings("unchecked") final T t = converter == null ? (T) response : converter.convert(response); result = t; if (callback != null) { callback.onCompleted(result); } } catch (IOException | RuntimeException e) { exception = e; if (callback != null) { callback.onThrowable(e); } } finally { latch.countDown(); } }
@Override public T onCompleted(com.ning.http.client.Response ningResponse) { try { final Map<String, String> headersMap = new HashMap<>(); for (Map.Entry<String, List<String>> header : ningResponse.getHeaders().entrySet()) { final StringBuilder value = new StringBuilder(); for (String str : header.getValue()) { value.append(str); } headersMap.put(header.getKey(), value.toString()); } final Response response = new Response(ningResponse.getStatusCode(), ningResponse.getStatusText(), headersMap, ningResponse.getResponseBodyAsStream()); @SuppressWarnings("unchecked") final T t = converter == null ? (T) response : converter.convert(response); if (callback != null) { callback.onCompleted(t); } return t; } catch (IOException | RuntimeException e) { onThrowable(e); return null; } }
@Override public T onCompleted(org.asynchttpclient.Response ahcResponse) { try { final Map<String, String> headersMap = new HashMap<>(); for (Map.Entry<String, String> header : ahcResponse.getHeaders()) { headersMap.put(header.getKey(), header.getValue()); } final Response response = new Response(ahcResponse.getStatusCode(), ahcResponse.getStatusText(), headersMap, ahcResponse.getResponseBodyAsStream()); @SuppressWarnings("unchecked") final T t = converter == null ? (T) response : converter.convert(response); if (callback != null) { callback.onCompleted(t); } return t; } catch (IOException | RuntimeException e) { onThrowable(e); return null; } }