Example usage for org.apache.commons.httpclient.methods FileRequestEntity writeRequest

List of usage examples for org.apache.commons.httpclient.methods FileRequestEntity writeRequest

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.methods FileRequestEntity writeRequest.

Prototype

public void writeRequest(final OutputStream out) throws IOException 

Source Link

Usage

From source file:org.switchyard.component.test.mixins.http.HTTPMixIn.java

/**
 * POST the specified request payload to the specified HTTP endpoint.
 * @param endpointURL The HTTP endpoint URL.
 * @param request The file resource containing the request payload.
 * @return The HTTP response payload./* www.j a v a2s . c o  m*/
 */
public String postFile(String endpointURL, String request) {

    FileRequestEntity requestEntity = new FileRequestEntity(new File(request), "text/xml; charset=utf-8");

    if (_dumpMessages) {
        _logger.info("Sending a POST request to [" + endpointURL + "]");
        ByteArrayOutputStream target = new ByteArrayOutputStream();
        try {
            requestEntity.writeRequest(target);
            _logger.info("Request body:[" + target.toString() + "]");
        } catch (IOException e) {
            _logger.error("Unable to write FileRequestEntity to stream", e);
        }
    }

    PostMethod postMethod = new PostMethod(endpointURL);
    postMethod.setRequestEntity(requestEntity);
    try {
        return execute(postMethod);
    } finally {
        postMethod.releaseConnection();
    }
}