List of usage examples for org.apache.http.client.methods HttpPut setEntity
public void setEntity(final HttpEntity entity)
From source file:com.jaeksoft.searchlib.remote.UriWriteObject.java
public UriWriteObject(URI uri, Externalizable object) throws IOException { HttpPut httpPut = new HttpPut(uri.toASCIIString()); httpPut.setConfig(requestConfig);/*from w w w .ja v a 2s . co m*/ ByteArrayOutputStream baos = new ByteArrayOutputStream(); swo = new StreamWriteObject(baos); swo.write(object); swo.close(true); swo = null; sro = null; httpPut.setEntity(new ByteArrayEntity(baos.toByteArray())); execute(httpPut); }
From source file:com.collective.celos.CelosClient.java
private void executePut(URI request, HttpEntity entity) throws IOException { HttpPut put = new HttpPut(request); put.setEntity(entity); executeAndConsume(put);/* w ww. ja va 2 s .c o m*/ }
From source file:es.tid.fiware.fiwareconnectors.cygnus.backends.hdfs.HDFSBackendImpl.java
private HttpResponse doHDFSRequest(HttpClient httpClient, String method, String url, ArrayList<Header> headers, StringEntity entity) throws Exception { HttpResponse response = null;/* ww w .j av a2s. c om*/ HttpRequestBase request = null; if (method.equals("PUT")) { HttpPut req = new HttpPut(url); if (entity != null) { req.setEntity(entity); } // if request = req; } else if (method.equals("POST")) { HttpPost req = new HttpPost(url); if (entity != null) { req.setEntity(entity); } // if request = req; } else if (method.equals("GET")) { request = new HttpGet(url); } else { throw new CygnusRuntimeError("HTTP method not supported: " + method); } // if else if (headers != null) { for (Header header : headers) { request.setHeader(header); } // for } // if logger.debug("HDFS request: " + request.toString()); try { response = httpClient.execute(request); } catch (IOException e) { throw new CygnusPersistenceError(e.getMessage()); } // try catch request.releaseConnection(); logger.debug("HDFS response: " + response.getStatusLine().toString()); return response; }
From source file:nl.gridline.zieook.workflow.rest.CollectionImportCompleteTest.java
@Ignore private HttpResponse executePOST(String url, String data) { HttpClient httpclient = new DefaultHttpClient(); httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); HttpPut post = new HttpPut(url); post.setHeader("Accept", "application/json"); try {/*from w w w.j a v a2 s .co m*/ post.setEntity(new StringEntity(data)); return httpclient.execute(post); } catch (ClientProtocolException e) { LOG.error("upload failed", e); fail("upload failed"); } catch (IOException e) { LOG.error("upload failed", e); fail("upload failed"); } return null; }
From source file:at.ac.tuwien.dsg.cloudlyra.utils.RestfulWSClient.java
public void callPutMethod(String xmlString) { try {//from www . ja v a2 s.co m //HttpGet method = new HttpGet(url); StringEntity inputKeyspace = new StringEntity(xmlString); Logger.getLogger(RestfulWSClient.class.getName()).log(Level.INFO, "Connection .. " + url); HttpPut request = new HttpPut(url); request.addHeader("content-type", "application/xml; charset=utf-8"); request.addHeader("Accept", "application/xml, multipart/related"); request.setEntity(inputKeyspace); HttpResponse methodResponse = this.getHttpClient().execute(request); int statusCode = methodResponse.getStatusLine().getStatusCode(); Logger.getLogger(RestfulWSClient.class.getName()).log(Level.INFO, "Status Code: " + statusCode); BufferedReader rd = new BufferedReader(new InputStreamReader(methodResponse.getEntity().getContent())); StringBuilder result = new StringBuilder(); String line; while ((line = rd.readLine()) != null) { result.append(line); } // System.out.println("Response String: " + result.toString()); } catch (Exception ex) { } }
From source file:org.alfresco.provision.BMService.java
@SuppressWarnings("unchecked") public void setTestProperty(String testName, String propertyName, Object propertyValue) throws IOException { JSONObject json = getTestProperty(testName, propertyName); if (json != null) { Long currentVersion = (Long) json.get("version"); CloseableHttpResponse httpResponse = null; try {//from ww w.ja va 2 s .co m String url = "http://" + hostname + ":9080/alfresco-benchmark-server/api/v1/tests/" + testName + "/props/" + propertyName; JSONObject putJson = new JSONObject(); putJson.put("version", currentVersion); putJson.put("value", propertyValue); HttpPut updateProperty = new HttpPut(url); StringEntity content = setMessageBody(putJson); updateProperty.setEntity(content); httpResponse = client.execute(updateProperty); StatusLine status = httpResponse.getStatusLine(); // Expecting "OK" status if (status.getStatusCode() == HttpStatus.SC_NOT_FOUND) { System.err.println("Property does not exist"); } else if (status.getStatusCode() != HttpStatus.SC_OK) { System.err.println("Unexpected response " + httpResponse.toString()); } } finally { httpResponse.close(); } } else { System.err.println("Property " + propertyName + " for test " + testName + " does not exist"); } }
From source file:com.swisscom.refimpl.boundary.MIB3Client.java
public EasypayResponse modifyTransaction(String merchantId, String transactionId, String operation) throws IOException, HttpException { HttpPut method = null; try {// w w w . j a v a 2 s . co m method = new HttpPut(MIB3Client.PAYMENTS_URL + "/" + transactionId); String entity = "{\"operation\": \"" + operation + "\"}"; method.setEntity(new StringEntity(entity, ContentType.create("application/vnd.ch.swisscom.easypay.direct.payment+json", "UTF-8"))); addSignature(method, "PUT", "/payments/" + transactionId, merchantId, "application/vnd.ch.swisscom.easypay.direct.payment+json", entity.getBytes("UTF-8")); HttpResponse response = httpClient.execute(method); return new EasypayResponse(new String(EntityUtils.toByteArray(response.getEntity())), response.getStatusLine().getStatusCode()); } finally { if (method != null) { method.releaseConnection(); } ; } }
From source file:com.github.kristofa.test.http.MockHttpServerTest.java
@Test public void testShouldHandlePutRequests() throws ClientProtocolException, IOException { // Given a mock server configured to respond to a DELETE /test responseProvider.expect(Method.PUT, "/test", "text/plain; charset=UTF-8", "Hello World").respondWith(200, "text/plain", "Welcome"); // When a request for DELETE /test arrives final HttpPut req = new HttpPut(baseUrl + "/test"); req.setEntity(new StringEntity("Hello World", UTF_8)); final HttpResponse response = client.execute(req); final String responseBody = IOUtils.toString(response.getEntity().getContent()); final int statusCode = response.getStatusLine().getStatusCode(); // Then the response status is 204 assertEquals(200, statusCode);/*from w ww .j ava2 s. c o m*/ assertEquals("Welcome", responseBody); }
From source file:org.activiti.rest.service.api.runtime.ExecutionCollectionResourceTest.java
/** * Test signalling all executions with variables *//*from w ww .j av a2s .c o m*/ @Deployment(resources = { "org/activiti/rest/service/api/runtime/ExecutionResourceTest.process-with-signal-event.bpmn20.xml" }) public void testSignalEventExecutionsWithvariables() throws Exception { Execution signalExecution = runtimeService.startProcessInstanceByKey("processOne"); assertNotNull(signalExecution); ArrayNode variables = objectMapper.createArrayNode(); ObjectNode requestNode = objectMapper.createObjectNode(); requestNode.put("action", "signalEventReceived"); requestNode.put("signalName", "alert"); requestNode.put("variables", variables); ObjectNode varNode = objectMapper.createObjectNode(); variables.add(varNode); varNode.put("name", "myVar"); varNode.put("value", "Variable set when signal event is receieved"); Execution waitingExecution = runtimeService.createExecutionQuery().activityId("waitState").singleResult(); assertNotNull(waitingExecution); // Sending signal event causes the execution to end (scope-execution for // the catching event) HttpPut httpPut = new HttpPut( SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION)); httpPut.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeRequest(httpPut, HttpStatus.SC_NO_CONTENT)); // Check if process is moved on to the other wait-state waitingExecution = runtimeService.createExecutionQuery().activityId("anotherWaitState").singleResult(); assertNotNull(waitingExecution); Map<String, Object> vars = runtimeService.getVariables(waitingExecution.getId()); assertEquals(1, vars.size()); assertEquals("Variable set when signal event is receieved", vars.get("myVar")); }
From source file:org.flowable.rest.service.api.runtime.ExecutionCollectionResourceTest.java
/** * Test signalling all executions with variables *///from w w w .j av a 2 s . c om @Deployment(resources = { "org/flowable/rest/service/api/runtime/ExecutionResourceTest.process-with-signal-event.bpmn20.xml" }) public void testSignalEventExecutionsWithvariables() throws Exception { Execution signalExecution = runtimeService.startProcessInstanceByKey("processOne"); assertNotNull(signalExecution); ArrayNode variables = objectMapper.createArrayNode(); ObjectNode requestNode = objectMapper.createObjectNode(); requestNode.put("action", "signalEventReceived"); requestNode.put("signalName", "alert"); requestNode.set("variables", variables); ObjectNode varNode = objectMapper.createObjectNode(); variables.add(varNode); varNode.put("name", "myVar"); varNode.put("value", "Variable set when signal event is received"); Execution waitingExecution = runtimeService.createExecutionQuery().activityId("waitState").singleResult(); assertNotNull(waitingExecution); // Sending signal event causes the execution to end (scope-execution for // the catching event) HttpPut httpPut = new HttpPut( SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION)); httpPut.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeRequest(httpPut, HttpStatus.SC_NO_CONTENT)); // Check if process is moved on to the other wait-state waitingExecution = runtimeService.createExecutionQuery().activityId("anotherWaitState").singleResult(); assertNotNull(waitingExecution); Map<String, Object> vars = runtimeService.getVariables(waitingExecution.getId()); assertEquals(1, vars.size()); assertEquals("Variable set when signal event is received", vars.get("myVar")); }