List of usage examples for org.apache.http.client.methods HttpPut setEntity
public void setEntity(final HttpEntity entity)
From source file:org.elasticsearch.querydoge.helper.HttpHelper.java
public String putAndReturnBody(String path, String message) throws ClientProtocolException, IOException { HttpPut httpPut = new HttpPut(baseUrl + path); StringEntity entity = new StringEntity(message, HTTP.UTF_8); entity.setContentType("application/x-www-form-urlencoded"); httpPut.setEntity(entity); System.out.println(httpPut);/*from w w w .j a v a 2s .c om*/ System.out.println(message); return httpclient.execute(httpPut, responseHandler); }
From source file:org.jfrog.build.client.ArtifactoryHttpClient.java
public ArtifactoryUploadResponse upload(HttpPut httpPut, HttpEntity fileEntity) throws IOException { httpPut.setEntity(fileEntity); return execute(httpPut); }
From source file:com.aperigeek.dropvault.dav.DAVClient.java
public void put(String uri, File file) throws DAVException { try {/*from w w w. j a va 2 s . c o m*/ HttpPut put = new HttpPut(uri); put.setEntity(new UnknownTypeFileEntity(file)); HttpResponse response = client.execute(put); response.getEntity().consumeContent(); if (response.getStatusLine().getStatusCode() != 200) { throw new DAVException("Invalid status code:" + response.getStatusLine().getStatusCode() + " " + response.getStatusLine().getReasonPhrase()); } } catch (IOException ex) { throw new DAVException(ex); } }
From source file:org.apache.reef.runtime.hdinsight.client.yarnrest.HDInsightInstance.java
/** * Issues a YARN kill command to the application. * * @param applicationId//from w w w. j a va 2s .c o m */ public void killApplication(final String applicationId) throws IOException { final String url = this.getApplicationURL(applicationId) + "/state"; final HttpPut put = preparePut(url); put.setEntity(new StringEntity(APPLICATION_KILL_MESSAGE, ContentType.APPLICATION_JSON)); this.httpClient.execute(put, this.httpClientContext); }
From source file:com.temenos.useragent.generic.http.DefaultHttpClient.java
@Override public HttpResponse put(String url, HttpRequest request) { logHttpRequest(url, request);/* w ww. ja va 2s . c om*/ CloseableHttpClient client = HttpClientBuilder.create() .setDefaultCredentialsProvider(DefaultHttpClientHelper.getBasicCredentialProvider()).build(); HttpPut putRequest = new HttpPut(url); DefaultHttpClientHelper.buildRequestHeaders(request, putRequest); putRequest.setEntity(new StringEntity(request.payload(), "UTF-8")); try { CloseableHttpResponse httpResponse = client.execute(putRequest); HttpEntity responseEntity = httpResponse.getEntity(); return handleResponse(httpResponse, responseEntity); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.jboss.aerogear.unifiedpush.quickstart.util.WebClient.java
private Boolean updateContact(Contact contact) { try {/*from ww w .j a v a2s. co m*/ String updateURL = Constants.BASE_URL + "/rest/contacts/" + String.valueOf(contact.getId()); HttpPut put = new HttpPut(updateURL); put.setEntity(new StringEntity(new Gson().toJson(contact))); put.setHeader("Accept", "application/json"); put.setHeader("Content-type", "application/json"); HttpResponse response = httpClient.execute(put); if (isStatusCodeOk(response)) { return true; } else { return false; } } catch (Exception e) { Log.e(TAG, e.getMessage()); return false; } }
From source file:org.fashiontec.bodyapps.sync.Sync.java
/** * Manages put requests//from ww w .j a v a 2 s . c o m * * @param url * @param json * @param conTimeOut * @param socTimeOut * @return */ public HttpResponse put(String url, String json, int conTimeOut, int socTimeOut) { HttpResponse response = null; try { HttpParams httpParameters = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParameters, conTimeOut); HttpConnectionParams.setSoTimeout(httpParameters, socTimeOut); HttpClient client = new DefaultHttpClient(httpParameters); HttpPut request = new HttpPut(url); StringEntity se = new StringEntity(json); request.setEntity(se); request.setHeader("Accept", "application/json"); request.setHeader("Content-type", "application/json"); response = client.execute(request); } catch (Exception e) { Log.e(TAG, e.getMessage()); } return response; }
From source file:org.apache.geode.rest.internal.web.GeodeRestClient.java
public HttpResponse doPut(String query, String username, String password, String body) throws Exception { 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:com.amazonaws.http.ApacheHttpClient.java
private HttpUriRequest createHttpRequest(HttpRequest request) { HttpUriRequest httpRequest;/*w ww .j av a 2 s . c o m*/ String method = request.getMethod(); if (method.equals("POST")) { HttpPost postRequest = new HttpPost(request.getUri()); if (request.getContent() != null) { postRequest.setEntity(new InputStreamEntity(request.getContent(), request.getContentLength())); } httpRequest = postRequest; } else if (method.equals("GET")) { httpRequest = new HttpGet(request.getUri()); } else if (method.equals("PUT")) { HttpPut putRequest = new HttpPut(request.getUri()); if (request.getContent() != null) { putRequest.setEntity(new InputStreamEntity(request.getContent(), request.getContentLength())); } httpRequest = putRequest; } else if (method.equals("DELETE")) { httpRequest = new HttpDelete(request.getUri()); } else if (method.equals("HEAD")) { httpRequest = new HttpHead(request.getUri()); } else { throw new UnsupportedOperationException("Unsupported method: " + method); } if (request.getHeaders() != null && !request.getHeaders().isEmpty()) { for (Map.Entry<String, String> header : request.getHeaders().entrySet()) { String key = header.getKey(); /* * HttpClient4 fills in the Content-Length header and complains * if it's already present, so we skip it here. We also skip the * Host header to avoid sending it twice, which will interfere * with some signing schemes. */ if (key.equals(HttpHeader.CONTENT_LENGTH) || key.equals(HttpHeader.HOST)) { continue; } httpRequest.addHeader(header.getKey(), header.getValue()); } } // disable redirect if (params == null) { params = new BasicHttpParams(); params.setParameter(ClientPNames.HANDLE_REDIRECTS, false); } httpRequest.setParams(params); return httpRequest; }
From source file:org.talend.librariesmanager.deploy.ArtifactsDeployer.java
private void installToRemote(HttpEntity entity, URL targetURL) throws BusinessException { DefaultHttpClient httpClient = new DefaultHttpClient(); try {// w ww. j a va2 s .co m httpClient.getCredentialsProvider().setCredentials( new AuthScope(targetURL.getHost(), targetURL.getPort()), new UsernamePasswordCredentials(nexusServer.getUserName(), nexusServer.getPassword())); HttpPut httpPut = new HttpPut(targetURL.toString()); httpPut.setEntity(entity); HttpResponse response = httpClient.execute(httpPut); StatusLine statusLine = response.getStatusLine(); int responseCode = statusLine.getStatusCode(); EntityUtils.consume(entity); if (responseCode > 399) { if (responseCode == 401) { throw new BusinessException("Authrity failed"); } else { throw new BusinessException( "Deploy failed: " + responseCode + ' ' + statusLine.getReasonPhrase()); } } } catch (Exception e) { throw new BusinessException("softwareupdate.error.cannotupload", e.getMessage()); } finally { httpClient.getConnectionManager().shutdown(); } }