List of usage examples for org.apache.http.client.methods HttpPut setEntity
public void setEntity(final HttpEntity entity)
From source file:com.vmware.content.samples.ImportOva.java
private void uploadOva(String ovaPath, String sessionId) throws Exception { SSLContextBuilder builder = new SSLContextBuilder(); builder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build()); CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build(); IOUtil.print("Streaming OVF to update session " + sessionId); try (TarArchiveInputStream tar = new TarArchiveInputStream(new FileInputStream(ovaPath))) { TarArchiveEntry entry;//w ww. j av a 2 s . c o m while ((entry = tar.getNextTarEntry()) != null) { long bytes = entry.getSize(); IOUtil.print("Uploading " + entry.getName() + " (" + entry.getSize() + " bytes)"); URI uploadUri = generateUploadUri(sessionId, entry.getName()); HttpPut request = new HttpPut(uploadUri); HttpEntity content = new TarBasedInputStreamEntity(tar, bytes); request.setEntity(content); HttpResponse response = httpclient.execute(request); EntityUtils.consumeQuietly(response.getEntity()); } } }
From source file:com.aliyun.oss.common.comm.HttpRequestFactory.java
public HttpRequestBase createHttpRequest(ServiceClient.Request request, ExecutionContext context) { String uri = request.getUri(); HttpRequestBase httpRequest;// w ww .j av a 2s. com HttpMethod method = request.getMethod(); if (method == HttpMethod.POST) { HttpPost postMethod = new HttpPost(uri); if (request.getContent() != null) { postMethod.setEntity(new RepeatableInputStreamEntity(request)); } httpRequest = postMethod; } else if (method == HttpMethod.PUT) { HttpPut putMethod = new HttpPut(uri); if (request.getContent() != null) { if (request.isUseChunkEncoding()) { putMethod.setEntity(buildChunkedInputStreamEntity(request)); } else { putMethod.setEntity(new RepeatableInputStreamEntity(request)); } } httpRequest = putMethod; } else if (method == HttpMethod.GET) { httpRequest = new HttpGet(uri); } else if (method == HttpMethod.DELETE) { httpRequest = new HttpDelete(uri); } else if (method == HttpMethod.HEAD) { httpRequest = new HttpHead(uri); } else if (method == HttpMethod.OPTIONS) { httpRequest = new HttpOptions(uri); } else { throw new ClientException("Unknown HTTP method name: " + method.toString()); } configureRequestHeaders(request, context, httpRequest); return httpRequest; }
From source file:org.apache.geode.rest.internal.web.RestSecurityDUnitTest.java
protected HttpResponse doPut(String query, String username, String password, String body) throws MalformedURLException { HttpPut httpPut = new HttpPut(CONTEXT + query); httpPut.addHeader("content-type", "application/json"); httpPut.setEntity(new StringEntity(body, StandardCharsets.UTF_8)); return doRequest(httpPut, username, password); }
From source file:de.dentrassi.pm.jenkins.UploaderV2.java
@Override public void upload(final File file, final String filename) throws IOException { final URI uri = makeUrl(filename); final HttpPut httppost = new HttpPut(uri); final InputStream stream = new FileInputStream(file); try {// w w w. j av a 2 s. c om httppost.setEntity(new InputStreamEntity(stream, file.length())); final HttpResponse response = this.client.execute(httppost); final HttpEntity resEntity = response.getEntity(); if (resEntity != null) { switch (response.getStatusLine().getStatusCode()) { case 200: addUploadedArtifacts(filename, resEntity); break; default: addUploadFailure(filename, response); break; } } } finally { stream.close(); } }
From source file:org.apache.cloudstack.storage.datastore.util.DateraUtil.java
public static void updateAppInstanceIops(DateraObject.DateraConnection conn, String appInstance, int totalIops) throws UnsupportedEncodingException, DateraObject.DateraError { if (getAppInstancePerformancePolicy(conn, appInstance) == null) { createAppInstancePerformancePolicy(conn, appInstance, totalIops); } else {/*from w w w . jav a 2 s .c o m*/ HttpPut url = new HttpPut(generateApiUrl("app_instances", appInstance, "storage_instances", DateraObject.DEFAULT_STORAGE_NAME, "volumes", DateraObject.DEFAULT_VOLUME_NAME, "performance_policy")); DateraObject.PerformancePolicy performancePolicy = new DateraObject.PerformancePolicy(totalIops); url.setEntity(new StringEntity(gson.toJson(performancePolicy))); executeApiRequest(conn, url); } }
From source file:com.github.dziga.orest.client.HttpRestClient.java
int Put(String body) throws IOException, URISyntaxException { URIBuilder b = new URIBuilder().setScheme(scheme).setHost(host).setPath(path); addQueryParams(b);//from w w w . j a va 2 s.co m URI fullUri = b.build(); HttpPut putMethod = new HttpPut(fullUri); HttpEntity entity = new StringEntity(body); putMethod.setEntity(entity); putMethod = (HttpPut) addHeadersToMethod(putMethod); processResponse(httpClient.execute(putMethod)); return getResponseCode(); }
From source file:com.jzboy.couchdb.http.CouchHttpClient.java
/** * Sends a PUT request to the specified CouchDB endpoint. * If the request fails due to a socket exception, e.g. the server refuses the request, it is retried several times. * @param uri CouchDB API endpoint//from w ww. ja v a 2s .c om * @param data request data * @param retry maximum number of retries if the request fails * @return the JSON tree parsed form the response body * @throws IOException if the HttpClient throws an IOException * @throws CouchDBException if CouchDB returns an error - response code >= 300. The response details are * encapsulated in the exception. */ public JsonNode put(URI uri, String data, int retry) throws IOException, CouchDBException { HttpPut req = new HttpPut(uri); if (data != null) req.setEntity(new StringEntity(data)); return execRequest(req, retry); }
From source file:com.jzboy.couchdb.http.CouchHttpClient.java
/** * Sends a PUT request to the specified CouchDB endpoint. * @param uri CouchDB API endpoint/*w w w .j a va 2 s . c o m*/ * @param data request data * @return the JSON tree parsed form the response body * @throws IOException if the HttpClient throws an IOException * @throws CouchDBException if CouchDB returns an error - response code >= 300. The response details are * encapsulated in the exception. */ public JsonNode put(URI uri, String data) throws IOException, CouchDBException { HttpPut req = new HttpPut(uri); if (data != null) req.setEntity(new StringEntity(data)); return execRequest(req); }
From source file:org.infinispan.server.test.rest.security.RESTCertSecurityTest.java
private HttpResponse put(CloseableHttpClient httpClient, String uri, int expectedCode) throws Exception { HttpResponse response;//www. ja va 2 s. co m HttpPut put = new HttpPut(uri); put.setEntity(new StringEntity("data", "UTF-8")); response = httpClient.execute(put); assertEquals(expectedCode, response.getStatusLine().getStatusCode()); return response; }