Example usage for org.apache.http.client.methods HttpPut HttpPut

List of usage examples for org.apache.http.client.methods HttpPut HttpPut

Introduction

In this page you can find the example usage for org.apache.http.client.methods HttpPut HttpPut.

Prototype

public HttpPut(final String uri) 

Source Link

Usage

From source file:com.bjorsond.android.timeline.sync.ServerUploader.java

protected static void putGroupToGAE(final String jsonString) {
    // Using PUT here
    final HttpPut httpPut = new HttpPut("/rest/group/");
    makeJSONHttpRequestContentTypeHeader(httpPut);
    sendJSONTOGAEServer(jsonString, Constants.targetHost, httpPut);
}

From source file:com.mikecorrigan.bohrium.pubsub.Transaction.java

public void run() {
    Log.v(TAG, "send");

    mStatusCode = -1;//from  w  w  w.j  a v a2s .  c  o m
    mStatusReason = null;
    mResponseBody = null;

    Log.v(TAG, "baseUri=" + mBaseUriString);
    Log.v(TAG, "authCookie=" + mAuthCookie);
    Log.v(TAG, "method=" + mMethod);
    Log.v(TAG, "uri=" + mUriString);
    if (mRequestBody != null) {
        Log.v(TAG, "requestBody=" + mRequestBody);
    }

    // Encode URI.
    URI uri;
    try {
        uri = new URI(mBaseUriString + "/" + mUriString);
        Log.v(TAG, "uri=" + uri);
    } catch (URISyntaxException e) {
        Log.w(TAG, "Invalid URI, " + e);
        uri = null;
    }

    if (uri != null) {
        // Dispatch method.
        switch (mMethod) {
        case "GET": {
            read(new HttpGet(uri));
            break;
        }
        case "DELETE": {
            read(new HttpDelete(uri));
            break;
        }
        case "PUT": {
            readWrite(new HttpPut(uri));
            break;
        }
        case "POST": {
            readWrite(new HttpPost(uri));
            break;
        }
        default: {
            Log.e(TAG, "Unsupported method, " + mMethod);
            break;
        }
        }
    }

    Log.v(TAG, "statusCode=" + mStatusCode);
    Log.v(TAG, "statusReason=" + mStatusReason);
    Log.v(TAG, "responseBody=" + mResponseBody);
}

From source file:com.googlecode.webutilities.servlets.WebProxyServlet.java

private HttpUriRequest getRequest(String method, String url) {
    if (HttpPost.METHOD_NAME.equals(method)) {
        return new HttpPost(url);
    } else if (HttpPut.METHOD_NAME.equals(method)) {
        return new HttpPut(url);
    } else if (HttpDelete.METHOD_NAME.equals(method)) {
        return new HttpDelete(url);
    } else if (HttpOptions.METHOD_NAME.equals(method)) {
        return new HttpOptions(url);
    } else if (HttpHead.METHOD_NAME.equals(method)) {
        return new HttpHead(url);
    }/*  www.  j a v a2 s  . com*/
    return new HttpGet(url);
}

From source file:org.fcrepo.camel.FedoraClient.java

/**
 * Make a PUT request/* w  w  w  .  j  av  a2  s. c  o  m*/
 */
public FedoraResponse put(final URI url, final String body, final String contentType)
        throws ClientProtocolException, IOException, HttpOperationFailedException {

    final HttpPut request = new HttpPut(url);
    if (contentType != null) {
        request.addHeader("Content-Type", contentType);
    }
    if (body != null) {
        request.setEntity(new StringEntity(body));
    }

    final HttpResponse response = httpclient.execute(request);
    final int status = response.getStatusLine().getStatusCode();
    final String contentTypeHeader = getContentTypeHeader(response);

    if ((status >= 200 && status < 300) || !this.throwExceptionOnFailure) {
        final HttpEntity entity = response.getEntity();
        return new FedoraResponse(url, status, contentTypeHeader, null,
                entity != null ? EntityUtils.toString(entity) : null);
    } else {
        throw buildHttpOperationFailedException(url, response);
    }
}

From source file:org.fashiontec.bodyapps.sync.SyncPic.java

/**
 * Multipart put request for images.// w  w  w  .  ja  v a2s.c o  m
 * @param url
 * @param path
 * @return
 */
public HttpResponse put(String url, String path) {
    HttpResponse response = null;
    try {
        File file = new File(path);
        HttpClient client = new DefaultHttpClient();
        HttpPut post = new HttpPut(url);

        InputStreamEntity entity = new InputStreamEntity(new FileInputStream(file.getPath()), file.length());
        entity.setContentType("image/jpeg");
        entity.setChunked(true);
        post.setEntity(entity);

        response = client.execute(post);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return response;
}