Example usage for org.apache.commons.httpclient.methods PutMethod setContentChunked

List of usage examples for org.apache.commons.httpclient.methods PutMethod setContentChunked

Introduction

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

Prototype

public void setContentChunked(boolean paramBoolean) 

Source Link

Usage

From source file:com.bigdata.rdf.sail.remoting.GraphRepositoryClient.java

/**
 * @see {@link GraphRepository#update(String, String)}
 *///from  www.  ja v a  2 s.  c  om
public void update(String rdfXmlToDelete, String rdfXmlToAdd) throws Exception {

    // DELETE
    PutMethod put = new PutMethod(servletURL);
    try {

        // add the range header
        if (rdfXmlToDelete != null) {
            String triples = "triples[" + trim(rdfXmlToDelete) + "]";
            Header range = new Header(GraphRepositoryServlet.HTTP_RANGE, triples);
            put.addRequestHeader(range);
        }

        // set the body
        if (rdfXmlToAdd != null) {
            put.setRequestEntity(new StringRequestEntity(rdfXmlToAdd, // the rdf/xml body
                    GraphRepositoryServlet.RDF_XML, // includes the encoding
                    null // so we don't need to say it here.
            ));
            put.setContentChunked(true);
        }

        // Execute the method.
        int sc = getHttpClient().executeMethod(put);
        if (sc != HttpStatus.SC_OK) {
            throw new IOException("HTTP-PUT failed: " + put.getStatusLine());
        }

    } finally {
        // Release the connection.
        put.releaseConnection();
    }

}

From source file:org.apache.axis2.transport.http.HTTPSender.java

/**
 * Used to send a request via HTTP Put Method
 *
 * @param msgContext       - The MessageContext of the message
 * @param url              - The target URL
 * @param soapActionString - The soapAction string of the request
 * @throws AxisFault - Thrown in case an exception occurs
 *//* w w  w . ja v a 2  s  .c  o  m*/
private void sendViaPut(MessageContext msgContext, URL url, String soapActionString) throws AxisFault {

    HttpClient httpClient = getHttpClient(msgContext);

    /*  Same deal - this value never gets used, why is it here? --Glen
            String charEncoding =
        (String) msgContext.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING);
            
            if (charEncoding == null) {
    charEncoding = MessageContext.DEFAULT_CHAR_SET_ENCODING;
            }
    */

    PutMethod putMethod = new PutMethod();
    MessageFormatter messageFormatter = populateCommonProperties(msgContext, url, putMethod, httpClient,
            soapActionString);

    putMethod.setRequestEntity(new AxisRequestEntity(messageFormatter, msgContext, format, soapActionString,
            chunked, isAllowedRetry));

    if (!httpVersion.equals(HTTPConstants.HEADER_PROTOCOL_10) && chunked) {
        putMethod.setContentChunked(true);
    }

    String soapAction = messageFormatter.formatSOAPAction(msgContext, format, soapActionString);
    if (soapAction != null && !msgContext.isDoingREST()) {
        putMethod.setRequestHeader(HTTPConstants.HEADER_SOAP_ACTION, soapAction);
    }

    /*
     *   main excecution takes place..
     */
    try {
        executeMethod(httpClient, msgContext, url, putMethod);
        handleResponse(msgContext, putMethod);
    } catch (IOException e) {
        log.info("Unable to sendViaPut to url[" + url + "]", e);
        throw AxisFault.makeFault(e);
    } finally {
        cleanup(msgContext, putMethod);
    }
}

From source file:org.apache.axis2.transport.http.impl.httpclient3.HTTPSenderImpl.java

/**
 * Used to send a request via HTTP Put Method
 * /* w w w  .  j  ava  2 s.  c om*/
 * @param msgContext
 *            - The MessageContext of the message
 * @param url
 *            - The target URL
 * @param soapActionString
 *            - The soapAction string of the request
 * @throws AxisFault
 *             - Thrown in case an exception occurs
 */
protected void sendViaPut(MessageContext msgContext, URL url, String soapActionString) throws AxisFault {

    HttpClient httpClient = getHttpClient(msgContext);

    /*
     * Same deal - this value never gets used, why is it here? --Glen String
     * charEncoding = (String)
     * msgContext.getProperty(Constants.Configuration
     * .CHARACTER_SET_ENCODING);
     * 
     * if (charEncoding == null) { charEncoding =
     * MessageContext.DEFAULT_CHAR_SET_ENCODING; }
     */

    PutMethod putMethod = new PutMethod();
    MessageFormatter messageFormatter = populateCommonProperties(msgContext, url, putMethod, httpClient,
            soapActionString);

    putMethod.setRequestEntity(new AxisRequestEntityImpl(messageFormatter, msgContext, format, soapActionString,
            chunked, isAllowedRetry));

    if (!httpVersion.equals(HTTPConstants.HEADER_PROTOCOL_10) && chunked) {
        putMethod.setContentChunked(true);
    }

    String soapAction = messageFormatter.formatSOAPAction(msgContext, format, soapActionString);
    if (soapAction != null) {
        putMethod.setRequestHeader(HTTPConstants.HEADER_SOAP_ACTION, soapAction);
    }

    /*
     * main excecution takes place..
     */
    try {
        executeMethod(httpClient, msgContext, url, putMethod);
        handleResponse(msgContext, putMethod);
    } catch (IOException e) {
        log.info("Unable to sendViaPut to url[" + url + "]", e);
        throw AxisFault.makeFault(e);
    } finally {
        cleanup(msgContext, putMethod);
    }
}

From source file:org.talend.mdm.bulkload.client.BulkloadClientUtil.java

public static void bulkload(String url, String cluster, String concept, String datamodel, boolean validate,
        boolean smartpk, boolean insertonly, InputStream itemdata, String username, String password,
        String transactionId, String sessionId, String universe, String tokenKey, String tokenValue)
        throws Exception {
    HostConfiguration config = new HostConfiguration();
    URI uri = new URI(url, false, "UTF-8"); //$NON-NLS-1$
    config.setHost(uri);/*from  www.  ja  v a 2 s.com*/

    NameValuePair[] parameters = { new NameValuePair("cluster", cluster), //$NON-NLS-1$
            new NameValuePair("concept", concept), //$NON-NLS-1$
            new NameValuePair("datamodel", datamodel), //$NON-NLS-1$
            new NameValuePair("validate", String.valueOf(validate)), //$NON-NLS-1$
            new NameValuePair("action", "load"), //$NON-NLS-1$ //$NON-NLS-2$
            new NameValuePair("smartpk", String.valueOf(smartpk)), //$NON-NLS-1$
            new NameValuePair("insertonly", String.valueOf(insertonly)) }; //$NON-NLS-1$

    HttpClient client = new HttpClient();
    String user = universe == null || universe.trim().length() == 0 ? username : universe + "/" + username; //$NON-NLS-1$
    client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, password));
    HttpClientParams clientParams = client.getParams();
    clientParams.setAuthenticationPreemptive(true);
    clientParams.setCookiePolicy(CookiePolicy.IGNORE_COOKIES);

    PutMethod putMethod = new PutMethod();
    // This setPath call is *really* important (if not set, request will be sent to the JBoss root '/')
    putMethod.setPath(url);
    String responseBody;
    try {
        // Configuration
        putMethod.setRequestHeader("Content-Type", "text/xml; charset=utf8"); //$NON-NLS-1$ //$NON-NLS-2$
        if (transactionId != null) {
            putMethod.setRequestHeader("transaction-id", transactionId); //$NON-NLS-1$
        }
        if (sessionId != null) {
            putMethod.setRequestHeader("Cookie", STICKY_SESSION + "=" + sessionId); //$NON-NLS-1$ //$NON-NLS-2$
        }
        if (tokenKey != null && tokenValue != null) {
            putMethod.setRequestHeader(tokenKey, tokenValue);
        }

        putMethod.setQueryString(parameters);
        putMethod.setContentChunked(true);
        // Set the content of the PUT request
        putMethod.setRequestEntity(new InputStreamRequestEntity(itemdata));

        client.executeMethod(config, putMethod);
        responseBody = putMethod.getResponseBodyAsString();
        if (itemdata instanceof InputStreamMerger) {
            ((InputStreamMerger) itemdata).setAlreadyProcessed(true);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        putMethod.releaseConnection();
    }

    int statusCode = putMethod.getStatusCode();
    if (statusCode >= 500) {
        throw new BulkloadException(responseBody);
    } else if (statusCode >= 400) {
        throw new BulkloadException("Could not send data to MDM (HTTP status code: " + statusCode + ")."); //$NON-NLS-1$ //$NON-NLS-2$
    }
}