Package br.com.caelum.restfulie.http

Source Code of br.com.caelum.restfulie.http.AsynchronousRequest

package br.com.caelum.restfulie.http;

import java.util.concurrent.Callable;
import br.com.caelum.restfulie.Response;

/**
* An asynchronous HTTP request.
*
* @author samuel portela
*/
public class AsynchronousRequest implements Callable<Response> {

    private final Request request;
    private final HttpMethod httpMethod;
    private final Object payload;
    private final RequestCallback requestCallback;
   
    public AsynchronousRequest(Request request, HttpMethod httpMethod, RequestCallback requestCallback) {
        this(request, httpMethod, null, requestCallback);
    }
   
    public AsynchronousRequest(Request request, HttpMethod httpMethod, Object payload, RequestCallback requestCallback) {
        this.request = request;
        this.httpMethod = httpMethod;
        this.payload = payload;
        this.requestCallback = requestCallback;
    }

    public Request getRequest() {
        return request;
    }

    public HttpMethod getHttpMethod() {
        return httpMethod;
    }

    public Object getPayload() {
        return payload;
    }

    public Response call() {
        Response response = null;
        try {
            response = getHttpMethod().execute(request, payload);
            requestCallback.callback(response);
        }
        catch (Exception e) {
            requestCallback.onException(request, httpMethod, e);
        }
        return response;
    }

}
TOP

Related Classes of br.com.caelum.restfulie.http.AsynchronousRequest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.