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:edu.rit.csh.androidwebnews.HttpsPutAsyncTask.java

/**
 * The method that gets run when execute() is run. This sends the URL with the
 * PUT parameters to the server and gets the results
 *
 * @param params - [0] is the URL to got to, the rest are parameters to the request
 * @return String representation of page results
 *//*from   w  w  w.j  ava 2s .  c  o m*/
@Override
protected String doInBackground(BasicNameValuePair... params) {
    ArrayList<NameValuePair> nvp = new ArrayList<NameValuePair>();
    String line;
    try {
        HttpPut request = new HttpPut(params[0].getValue());
        request.addHeader("accept", "application/json");
        //params = Arrays.copyOfRange(params, 1, params.length);

        for (BasicNameValuePair param : params) {
            nvp.add(new BasicNameValuePair(param.getName(), param.getValue()));
        }

        request.setEntity(new UrlEncodedFormEntity(nvp));

        HttpResponse response = httpclient.execute(request);
        BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

        StringBuilder sb = new StringBuilder("");

        String NL = System.getProperty("line.separator");

        while ((line = in.readLine()) != null) {
            sb.append(line).append(NL);
        }
        in.close();
        return sb.toString();

    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return "";
}

From source file:es.ucm.look.data.remote.restful.RestMethod.java

/**
 * To Update an element/*ww w .j  a  v a2 s  .c om*/
 * 
 * @param url
 *       Element URI
 * @param c
 *       The element to update represented with a JSON
 * @return
 *       The response
 */
public static HttpResponse doPut(String url, JSONObject c) {
    HttpClient httpclient = new DefaultHttpClient();
    HttpPut request = new HttpPut(url);
    StringEntity s = null;
    try {
        s = new StringEntity(c.toString());
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    s.setContentEncoding("UTF-8");
    s.setContentType("application/json");

    request.setEntity(s);
    request.addHeader("accept", "application/json");

    try {
        return httpclient.execute(request);
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;

}

From source file:com.arrow.acn.client.api.CoreEventApi.java

public StatusModel putReceived(String hid) {
    String method = "putReceived";
    try {/* w  w  w. j a  v a 2  s  . co m*/
        URI uri = buildUri(PUT_RECEIVED_URL.replace("{hid}", hid));
        StatusModel result = execute(new HttpPut(uri), StatusModel.class);
        log(method, result);
        return result;
    } catch (Throwable e) {
        logError(method, e);
        throw new AcnClientException(method, e);
    }
}

From source file:org.apache.abdera2.common.protocol.RequestHelper.java

public static HttpUriRequest createRequest(String method, String uri, HttpEntity entity,
        RequestOptions options) {//w  ww  .j  a v a 2  s  .c  o  m
    if (method == null)
        return null;
    if (options == null)
        options = createAtomDefaultRequestOptions().get();
    Method m = Method.get(method);
    Method actual = null;
    HttpUriRequest httpMethod = null;
    if (options.isUsePostOverride() && !nopostoveride.contains(m)) {
        actual = m;
        m = Method.POST;
    }
    if (m == GET)
        httpMethod = new HttpGet(uri);
    else if (m == POST) {
        httpMethod = new HttpPost(uri);
        if (entity != null)
            ((HttpPost) httpMethod).setEntity(entity);
    } else if (m == PUT) {
        httpMethod = new HttpPut(uri);
        if (entity != null)
            ((HttpPut) httpMethod).setEntity(entity);
    } else if (m == DELETE)
        httpMethod = new HttpDelete(uri);
    else if (m == HEAD)
        httpMethod = new HttpHead(uri);
    else if (m == OPTIONS)
        httpMethod = new HttpOptions(uri);
    else if (m == TRACE)
        httpMethod = new HttpTrace(uri);
    //        else if (m == PATCH)
    //          httpMethod = new ExtensionRequest(m.name(),uri,entity);
    else
        httpMethod = new ExtensionRequest(m.name(), uri, entity);
    if (actual != null) {
        httpMethod.addHeader("X-HTTP-Method-Override", actual.name());
    }
    initHeaders(options, httpMethod);
    HttpParams params = httpMethod.getParams();
    if (!options.isUseExpectContinue()) {
        params.setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
    } else {
        if (options.getWaitForContinue() > -1)
            params.setIntParameter(CoreProtocolPNames.WAIT_FOR_CONTINUE, options.getWaitForContinue());
    }
    if (!(httpMethod instanceof HttpEntityEnclosingRequest))
        params.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, options.isFollowRedirects());
    return httpMethod;
}

From source file:org.talend.dataprep.api.service.command.folder.RenameFolder.java

private HttpRequestBase onExecute(final String id, final String newName) {
    try {// ww  w  . ja  va  2s. c  om
        final URIBuilder uriBuilder = new URIBuilder(preparationServiceUrl + "/folders/" + id + "/name");
        uriBuilder.addParameter("newName", newName);
        final HttpPut put = new HttpPut(uriBuilder.build());
        put.setEntity(new StringEntity(newName));
        return put;
    } catch (UnsupportedEncodingException | URISyntaxException e) {
        throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
    }
}

From source file:org.elasticsearch.shell.command.HttpPutCommand.java

@SuppressWarnings("unused")
public HttpCommandResponse execute(String url, String body) throws IOException {
    HttpPut httpPut = new HttpPut(url);
    httpPut.setEntity(new StringEntity(body, ContentType.DEFAULT_TEXT));
    return new HttpCommandResponse(shellHttpClient.getHttpClient().execute(httpPut));
}

From source file:com.vmware.vchs.publicapi.samples.Vcd.java

/**
 * Creates an org.apache.http.client.methods.HttpPut object adding in the http headers for a
 * vCloud PUT//from  w w  w  .  ja va  2  s .  com
 * 
 * @param url
 *            the url to make the get request to
 * @return the instance of HttpGet populated with the correct headers
 */
public HttpPut put(String url, DefaultSampleCommandLineOptions options) {
    HttpPut httpPut = new HttpPut(url);
    httpPut.setHeader(HttpHeaders.ACCEPT, SampleConstants.APPLICATION_PLUS_XML_VERSION + options.vcdVersion);
    httpPut.setHeader(SampleConstants.VCD_AUTHORIZATION_HEADER, vcdToken);

    return httpPut;
}

From source file:com.arrow.acn.client.api.RTUFirmwareApi.java

public StatusModel requestRTU(String softwareReleaseHid) {
    String method = "requestRTU";

    try {//from  ww  w .j  a  v a  2  s .  c  om
        URI uri = buildUri(REQUEST_URL.replace("{softwareReleaseHid}", softwareReleaseHid));
        StatusModel result = execute(new HttpPut(uri), StatusModel.class);
        log(method, result);
        return result;
    } catch (Throwable e) {
        logError(method, e);
        throw new AcnClientException(method, e);
    }
}

From source file:org.talend.dataprep.api.service.command.dataset.CreateOrUpdateDataSet.java

/**
 * Private constructor./*from www . j  a  va2 s .c  o  m*/
 *
 * @param id the dataset id.
 * @param name the dataset name.
 * @param dataSetContent the new dataset content.
 */
private CreateOrUpdateDataSet(String id, String name, InputStream dataSetContent) {
    super(GenericCommand.DATASET_GROUP);
    execute(() -> {
        try {
            URIBuilder uriBuilder = new URIBuilder(datasetServiceUrl + "/datasets/" + id + "/raw/");
            if (!StringUtils.isEmpty(name)) {
                uriBuilder.addParameter("name", name);
            }
            final HttpPut put = new HttpPut(uriBuilder.build()); // $NON-NLS-1$ //$NON-NLS-2$
            put.setEntity(new InputStreamEntity(dataSetContent));
            return put;
        } catch (URISyntaxException e) {
            throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
        }
    });
    onError(e -> new TDPException(APIErrorCodes.UNABLE_TO_CREATE_OR_UPDATE_DATASET, e));
    on(HttpStatus.NO_CONTENT, HttpStatus.ACCEPTED).then(emptyString());
    on(HttpStatus.OK).then(asString());
}

From source file:v2.service.generic.library.utils.HttpClientUtil.java

@Deprecated
public static HttpResponsePOJO jsonRequest(String url, String json, String requestType) throws Exception {
    HttpClient httpclient = createHttpClient();
    HttpEntityEnclosingRequestBase request = null;
    if ("POST".equalsIgnoreCase(requestType)) {
        request = new HttpPost(url);
    } else if ("PUT".equalsIgnoreCase(requestType)) {
        request = new HttpPut(url);
    }//from  ww  w  .ja va  2  s . c o m
    StringEntity params = new StringEntity(json, "UTF-8");
    request.setEntity(params);
    request.addHeader("content-type", "application/json");
    HttpResponsePOJO result = invoke(httpclient, request);
    return result;
}