List of usage examples for org.apache.http.client.methods HttpPut setEntity
public void setEntity(final HttpEntity entity)
From source file:org.activiti.rest.service.api.repository.ModelResourceSourceTest.java
public void testSetModelEditorSource() throws Exception { Model model = null;/*from ww w . j ava 2 s. c om*/ try { model = repositoryService.newModel(); model.setName("Model name"); repositoryService.saveModel(model); HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_SOURCE, model.getId())); httpPut.setEntity(HttpMultipartHelper.getMultiPartEntity("sourcefile", "application/octet-stream", new ByteArrayInputStream("This is the new editor source".getBytes()), null)); closeResponse(executeBinaryRequest(httpPut, HttpStatus.SC_NO_CONTENT)); assertEquals("This is the new editor source", new String(repositoryService.getModelEditorSource(model.getId()))); } finally { try { repositoryService.deleteModel(model.getId()); } catch (Throwable ignore) { // Ignore, model might not be created } } }
From source file:org.droidparts.http.RESTClient.java
public String put(String uri, String contentEncoding, String data) throws HTTPException { L.d("PUT on " + uri + ", data: " + data); // TODO useHttpURLConnection() HttpPut req = new HttpPut(uri); try {/*w w w .ja v a 2 s . c o m*/ StringEntity entity = new StringEntity(data, UTF8); entity.setContentType(contentEncoding); req.setEntity(entity); } catch (UnsupportedEncodingException e) { throw new HTTPException(e); } DefaultHttpClientWrapper wrapper = getLegacy(); HttpResponse resp = wrapper.getResponse(req); Header loc = resp.getLastHeader("Location"); DefaultHttpClientWrapper.consumeResponse(resp); if (loc != null) { String[] parts = loc.getValue().split("/"); String location = parts[parts.length - 1]; L.d("location: " + location); return location; } else { return null; } }
From source file:de.damdi.fitness.activity.settings.sync.RestClient.java
/** * Sends a HTTP-PUT-Request to the path <code>path</code> with * <code>data</code> as body * //ww w. j a v a 2 s .c o m * @param path * the path of the resource * @param data * the data that has been sent * @return the response body * @throws IOException */ public String put(String path, String data) throws IOException { if (path == null) throw new IllegalArgumentException("path cannot be null"); if (data == null) throw new IllegalArgumentException("data cannot be null"); HttpPut req = new HttpPut(createUri(path)); req.setEntity(new StringEntity(data)); HttpResponse resp = execute(req); return readResponseBody(resp); }
From source file:com.swisscom.refimpl.boundary.MIB2Client.java
public HttpResponse modifySubscription(String merchantId, String subscriptionId, List<HttpPut> out, String status) throws IOException, HttpException { HttpPut request = new HttpPut(MIB2Client.SUBSCRIPTIONS_URL + "/" + subscriptionId); String entity = "{\"operation\": \"" + status + "\"}"; request.setEntity(new StringEntity(entity, ContentType.create("application/vnd.ch.swisscom.easypay.subscription+json", "utf-8"))); if (out != null) { out.add(request);/*ww w . j a va2 s. co m*/ } addSignature(request, "PUT", "/subscriptions/" + subscriptionId, merchantId, "application/vnd.ch.swisscom.easypay.subscription+json", entity.getBytes("UTF-8")); return httpClient.execute(request); }
From source file:org.activiti.rest.service.api.repository.ModelResourceSourceTest.java
public void testSetModelEditorSourceExtra() throws Exception { Model model = null;/*ww w .j a va2 s.c o m*/ try { model = repositoryService.newModel(); model.setName("Model name"); repositoryService.saveModel(model); HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_SOURCE_EXTRA, model.getId())); httpPut.setEntity(HttpMultipartHelper.getMultiPartEntity("sourcefile", "application/octet-stream", new ByteArrayInputStream("This is the new extra editor source".getBytes()), null)); closeResponse(executeBinaryRequest(httpPut, HttpStatus.SC_NO_CONTENT)); assertEquals("This is the new extra editor source", new String(repositoryService.getModelEditorSourceExtra(model.getId()))); } finally { try { repositoryService.deleteModel(model.getId()); } catch (Throwable ignore) { // Ignore, model might not be created } } }
From source file:retsys.client.http.HttpHelper.java
public HttpPut getHttpPutObj(String operation, String body) throws IOException { HttpPut put = null; put = new HttpPut(getHttpUrl(hostName, hostPort, context) + "/" + operation); StringEntity se = new StringEntity(body); se.setContentEncoding("UTF-8"); se.setContentType("application/json"); put.setEntity(se); return put;/*from w ww . j a v a 2s .c o m*/ }
From source file:org.activiti.rest.service.api.identity.GroupResourceTest.java
/** * Test updating an unexisting group./*from w w w .j a v a 2 s. c o m*/ */ public void testUpdateUnexistingGroup() throws Exception { HttpPut httpPut = new HttpPut( SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP, "unexisting")); httpPut.setEntity(new StringEntity(objectMapper.createObjectNode().toString())); closeResponse(executeRequest(httpPut, HttpStatus.SC_NOT_FOUND)); }
From source file:com.example.h156252.connected_cars.CarGrid.java
public String GETval(String url) { InputStream inputStream = null; JSONObject res = new JSONObject(); String result = ""; String brand = session.KEY_BRAND; try {// w w w . j a v a 2s . c o m JSONObject owner = new JSONObject(); owner.put("id", receiver_id); owner.put("text", brand); owner.put("Message", message_to_be_sent); owner.put("isDone", false); // owner.put("cartext", cartext); HttpClient client = new DefaultHttpClient(); URI website = new URI(url); HttpPut request = new HttpPut(); request.setEntity(new StringEntity(owner.toString())); request.addHeader("content-type", "application/json"); request.setURI(website); HttpResponse response = client.execute(request); inputStream = response.getEntity().getContent(); if (inputStream != null) result = convertInputStreamToString(inputStream); else result = "Did not work!"; /* String data = null; JSONArray jsonResponse = null; data = EntityUtils.toString(entity); //verify //Toast.makeText(getApplicationContext(),data,Toast.LENGTH_SHORT); //jsonResponse = new JSONArray(data);*/ } catch (Exception e) { } return result; }
From source file:com.drillster.api.Api.java
private String sendRequestInternal(String url, HttpEntity content, HttpMethod method, ContentType ct) throws ApiException { String target = url + ct.extension; this.log.debug("Sending request to " + target + ". Content:\n" + content); HttpRequest request;// w w w. ja va 2 s. co m if (method == HttpMethod.GET) { request = new HttpGet(target); } else { if (method == HttpMethod.PUT) { HttpPut put = new HttpPut(target); put.setEntity(content); request = put; } else if (method == HttpMethod.POST) { HttpPost post = new HttpPost(target); post.setEntity(content); request = post; } else { throw new IllegalArgumentException(); } } return sendRequestInternal(request); }
From source file:com.graphaware.test.util.TestHttpClient.java
/** * Issue an HTTP PUT and assert the response status code. * * @param url to POST to. * @param json request body. * @param headers request headers as map. * @param expectedStatusCode expected status code. * @return the body of the response./*from w w w .j a va 2 s .c o m*/ */ public String put(String url, String json, Map<String, String> headers, final int expectedStatusCode) { HttpPut put = new HttpPut(url); if (json != null) { put.setEntity(new StringEntity(json, ContentType.APPLICATION_JSON)); } setHeaders(put, headers); return method(put, expectedStatusCode); }