List of usage examples for org.apache.http.client.methods HttpPut setEntity
public void setEntity(final HttpEntity entity)
From source file:edu.jhu.pha.vospace.protocol.HttpPutProtocolHandler.java
@Override public void invoke(JobDescription job) throws IOException { String putFileUrl = job.getProtocols() .get(SettingsServlet.getConfig().getString("transfers.protocol.httpput")); StorageManager backend = StorageManagerFactory.getStorageManager(job.getUsername()); HttpClient client = MyHttpConnectionPoolProvider.getHttpClient(); InputStream fileInp = backend.getBytes(job.getTargetId().getNodePath()); HttpPut put = new HttpPut(putFileUrl); Node node = NodeFactory.getNode(job.getTargetId(), job.getUsername()); put.setEntity(new InputStreamEntity(fileInp, node.getNodeInfo().getSize())); try {// w w w . j av a2 s. co m HttpResponse response = client.execute(put); response.getEntity().getContent().close(); } catch (IOException ex) { put.abort(); ex.printStackTrace(); throw ex; } finally { try { if (null != fileInp) fileInp.close(); } catch (IOException e) { } } }
From source file:org.droidparts.net.http.RESTClient.java
public HTTPResponse put(String uri, String contentType, String data) throws HTTPException { L.i("PUT on '%s', data: '%s'.", uri, data); HTTPResponse response;//from w w w . j a v a2s . c om if (useHttpURLConnection()) { HttpURLConnection conn = httpURLConnectionWorker.getConnection(uri, Method.PUT); HttpURLConnectionWorker.postOrPut(conn, contentType, data); response = HttpURLConnectionWorker.getReponse(conn, true); } else { HttpPut req = new HttpPut(uri); req.setEntity(HttpClientWorker.buildStringEntity(contentType, data)); response = httpClientWorker.getReponse(req, true); } L.d(response); return response; }
From source file:org.lilyproject.process.test.AbstractRestTest.java
protected ResponseAndContent putUri(String uri, String body) throws Exception { HttpPut put = new HttpPut(uri); put.setEntity(new StringEntity(body, "application/json", "UTF-8")); return processResponseAndContent(put); }
From source file:org.talend.dataprep.api.service.command.dataset.UpdateDataSet.java
private UpdateDataSet(String id, InputStream dataSetContent) { super(GenericCommand.DATASET_GROUP); execute(() -> {//w ww . ja v a 2s . c om final HttpPut put = new HttpPut(datasetServiceUrl + "/datasets/" + id); //$NON-NLS-1$ //$NON-NLS-2$ put.setHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE); put.setEntity(new InputStreamEntity(dataSetContent)); return put; }); on(HttpStatus.NO_CONTENT).then(emptyString()); on(HttpStatus.OK).then(asString()); }
From source file:de.shadowhunt.subversion.internal.UploadOperation.java
@Override protected HttpUriRequest createRequest() { final URI uri = URIUtils.createURI(repository, resource); final HttpPut request = new HttpPut(uri); if (lockToken != null) { request.addHeader("If", "<" + uri + "> (<" + lockToken + ">)"); }//from w w w . j a v a 2 s . com request.setEntity(new InputStreamEntity(content, STREAM_WHOLE_CONTENT)); return request; }
From source file:com.activiti.service.activiti.TaskService.java
public void updateTask(ServerConfig serverConfig, String taskId, JsonNode actionRequest) { if (taskId == null) { throw new IllegalArgumentException("Task id is required"); }/* w ww . ja va2 s . c o m*/ URIBuilder builder = clientUtil.createUriBuilder(MessageFormat.format(RUNTIME_TASK_URL, taskId)); HttpPut put = clientUtil.createPut(builder, serverConfig); put.setEntity(clientUtil.createStringEntity(actionRequest)); clientUtil.executeRequestNoResponseBody(put, serverConfig, HttpStatus.SC_OK); }
From source file:org.matmaul.freeboxos.internal.RestManager.java
public <T extends Response<F>, F> F put(String path, HttpEntity entity, Class<T> beanClass) throws FreeboxException { HttpPut put = new HttpPut(getBaseAddress() + path); put.setEntity(entity); return execute(put, beanClass, true); }
From source file:org.talend.dataprep.api.service.command.preparation.PreparationUpdate.java
private HttpRequestBase onExecute(String id, Preparation preparation) { try {//from w ww .ja va 2 s . com final byte[] preparationJSONValue = objectMapper.writeValueAsBytes(preparation); final HttpPut preparationCreation = new HttpPut(preparationServiceUrl + "/preparations/" + id); preparationCreation.setHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE); preparationCreation.setEntity(new ByteArrayEntity(preparationJSONValue)); return preparationCreation; } catch (JsonProcessingException e) { throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e); } }
From source file:com.urbancode.ud.client.PropertyClient.java
public JSONObject updateResourcePropValues(String propSheetPath, String propSheetVer, JSONObject propDefs) throws IOException, JSONException { JSONObject result = null;/*from w w w . jav a 2 s.c om*/ String uri = url + "/property/propSheet/" + encodePath(propSheetPath) + "." + propSheetVer + "/allPropValuesFromBatch/"; HttpPut method = new HttpPut(uri); method.addHeader("Version", propSheetVer); // Set propsheet version method.setEntity(getStringEntity(propDefs)); HttpResponse response = invokeMethod(method); String body = getBody(response); if (body.length() > 0) result = new JSONObject(body); return result; }
From source file:com.gemstone.gemfire.rest.internal.web.controllers.RestAPIsAndInterOpsDUnitTest.java
public static void doUpdatesUsingRestApis(String restEndpoint) { //UPdate keys using REST calls {//w w w.ja va2 s . c o m try { CloseableHttpClient httpclient = HttpClients.createDefault(); HttpPut put = new HttpPut(restEndpoint + "/People/3,4,5,6,7,8,9,10,11,12"); put.addHeader("Content-Type", "application/json"); put.addHeader("Accept", "application/json"); StringEntity entity = new StringEntity(PERSON_LIST_AS_JSON); put.setEntity(entity); CloseableHttpResponse result = httpclient.execute(put); } catch (Exception e) { throw new RuntimeException("unexpected exception", e); } } //Delete Single keys { try { CloseableHttpClient httpclient = HttpClients.createDefault(); HttpDelete delete = new HttpDelete(restEndpoint + "/People/13"); delete.addHeader("Content-Type", "application/json"); delete.addHeader("Accept", "application/json"); CloseableHttpResponse result = httpclient.execute(delete); } catch (Exception e) { throw new RuntimeException("unexpected exception", e); } } //Delete set of keys { try { CloseableHttpClient httpclient = HttpClients.createDefault(); HttpDelete delete = new HttpDelete(restEndpoint + "/People/14,15,16"); delete.addHeader("Content-Type", "application/json"); delete.addHeader("Accept", "application/json"); CloseableHttpResponse result = httpclient.execute(delete); } catch (Exception e) { throw new RuntimeException("unexpected exception", e); } } //REST put?op=CAS for key 1 /* try { { HttpEntity<Object> entity = new HttpEntity<Object>(PERSON_AS_JSON_CAS, headers); ResponseEntity<String> result = RestTestUtils.getRestTemplate().exchange( restEndpoint + "/People/1?op=cas", HttpMethod.PUT, entity, String.class); } } catch (HttpClientErrorException e) { fail("Caught HttpClientErrorException while doing put with op=cas"); }catch (HttpServerErrorException se) { fail("Caught HttpServerErrorException while doing put with op=cas"); } */ //REST put?op=REPLACE for key 2 { /*HttpEntity<Object> entity = new HttpEntity<Object>(PERSON_AS_JSON_REPLACE, headers); ResponseEntity<String> result = RestTestUtils.getRestTemplate().exchange( restEndpoint + "/People/2?op=replace", HttpMethod.PUT, entity, String.class);*/ try { CloseableHttpClient httpclient = HttpClients.createDefault(); HttpPut put = new HttpPut(restEndpoint + "/People/2?op=replace"); put.addHeader("Content-Type", "application/json"); put.addHeader("Accept", "application/json"); StringEntity entity = new StringEntity(PERSON_AS_JSON_REPLACE); put.setEntity(entity); CloseableHttpResponse result = httpclient.execute(put); } catch (Exception e) { throw new RuntimeException("unexpected exception", e); } } }