Search in sources :

Example 1 with DefaultClientHttpResponse

use of com.alibaba.nacos.common.http.client.response.DefaultClientHttpResponse in project nacos by alibaba.

the class DefaultAsyncHttpClientRequest method execute.

@Override
public <T> void execute(URI uri, String httpMethod, RequestHttpEntity requestHttpEntity, final ResponseHandler<T> responseHandler, final Callback<T> callback) throws Exception {
    HttpRequestBase httpRequestBase = DefaultHttpClientRequest.build(uri, httpMethod, requestHttpEntity);
    asyncClient.execute(httpRequestBase, new FutureCallback<HttpResponse>() {

        @Override
        public void completed(HttpResponse result) {
            DefaultClientHttpResponse response = new DefaultClientHttpResponse(result);
            try {
                HttpRestResult<T> httpRestResult = responseHandler.handle(response);
                callback.onReceive(httpRestResult);
            } catch (Exception e) {
                callback.onError(e);
            } finally {
                HttpClientUtils.closeQuietly(result);
            }
        }

        @Override
        public void failed(Exception ex) {
            callback.onError(ex);
        }

        @Override
        public void cancelled() {
            callback.onCancel();
        }
    });
}
Also used : HttpRequestBase(org.apache.http.client.methods.HttpRequestBase) HttpRestResult(com.alibaba.nacos.common.http.HttpRestResult) DefaultClientHttpResponse(com.alibaba.nacos.common.http.client.response.DefaultClientHttpResponse) HttpResponse(org.apache.http.HttpResponse) DefaultClientHttpResponse(com.alibaba.nacos.common.http.client.response.DefaultClientHttpResponse) IOException(java.io.IOException)

Example 2 with DefaultClientHttpResponse

use of com.alibaba.nacos.common.http.client.response.DefaultClientHttpResponse in project nacos by alibaba.

the class DefaultHttpClientRequest method execute.

@Override
public HttpClientResponse execute(URI uri, String httpMethod, RequestHttpEntity requestHttpEntity) throws Exception {
    HttpRequestBase request = build(uri, httpMethod, requestHttpEntity, defaultConfig);
    CloseableHttpResponse response = client.execute(request);
    return new DefaultClientHttpResponse(response);
}
Also used : HttpRequestBase(org.apache.http.client.methods.HttpRequestBase) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) DefaultClientHttpResponse(com.alibaba.nacos.common.http.client.response.DefaultClientHttpResponse)

Aggregations

DefaultClientHttpResponse (com.alibaba.nacos.common.http.client.response.DefaultClientHttpResponse)2 HttpRequestBase (org.apache.http.client.methods.HttpRequestBase)2 HttpRestResult (com.alibaba.nacos.common.http.HttpRestResult)1 IOException (java.io.IOException)1 HttpResponse (org.apache.http.HttpResponse)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1