Package net.openesb.sdk.http

Source Code of net.openesb.sdk.http.HttpRequestFactory

package net.openesb.sdk.http;

import net.openesb.sdk.Request;
import net.openesb.sdk.ClientConfiguration;
import net.openesb.sdk.OpenESBClientException;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpHead;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpRequestBase;

/**
* Responsible for creating Apache HttpClient 4 request objects.
*
* @author David BRASSELY (brasseld at gmail.com)
* @author OpenESB Community
*/
public class HttpRequestFactory {

    HttpRequestBase createHttpRequest(Request<?> request, ClientConfiguration clientConfiguration, HttpEntity previousEntity) {
        String uri = request.getResourcePath();
       
        HttpRequestBase httpRequest;
        if (request.getHttpMethod() == HttpMethodName.POST) {
            HttpPost postMethod = new HttpPost(uri);
           
            httpRequest = postMethod;
        } else if (request.getHttpMethod() == HttpMethodName.GET) {
            httpRequest = new HttpGet(uri);
        } else if (request.getHttpMethod() == HttpMethodName.DELETE) {
            httpRequest = new HttpDelete(uri);
        } else if (request.getHttpMethod() == HttpMethodName.HEAD) {
            httpRequest = new HttpHead(uri);
        } else {
            throw new OpenESBClientException("Unknown HTTP method name: " + request.getHttpMethod());
        }
       
        return httpRequest;
    }
}
TOP

Related Classes of net.openesb.sdk.http.HttpRequestFactory

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.