List of usage examples for org.apache.http.client.methods HttpPut HttpPut
public HttpPut(final String uri)
From source file:com.arrow.acn.client.api.DeviceStateApi.java
public StatusModel transReceived(String deviceHid, String transHid) { String method = "transReceived"; try {//ww w . j a va 2s . c o m URI uri = buildUri(String.format(TRANS_RECEIVED_URL, deviceHid, transHid)); StatusModel result = execute(new HttpPut(uri), StatusModel.class); log(method, result); return result; } catch (Throwable e) { logError(method, e); throw new AcnClientException(method, e); } }
From source file:org.sharetask.controller.WorkspaceControllerIT.java
@Test public void testChangeOwnerWorkspace() throws IOException { //given//from ww w. j a v a 2 s . c o m final HttpPut httpPut = new HttpPut(URL_WORKSPACE); httpPut.addHeader(new BasicHeader("Content-Type", "application/json")); final StringEntity httpEntity = new StringEntity( "{\"id\":3," + "\"title\":\"Test Title\"," + "\"owner\":{\"username\":\"dev2@shareta.sk\"}" + "}"); httpPut.setEntity(httpEntity); //when final HttpResponse response = getClient().execute(httpPut); //then Assert.assertEquals(HttpStatus.OK.value(), response.getStatusLine().getStatusCode()); final String responseData = EntityUtils.toString(response.getEntity()); Assert.assertTrue(responseData.contains("\"username\":\"dev2@shareta.sk\"")); }
From source file:com.connectsdk.service.command.ServiceCommand.java
public HttpRequestBase getRequest() { if (target == null) { throw new IllegalStateException("ServiceCommand has no target url"); }/*from ww w . j av a2 s. c o m*/ if (this.httpMethod.equalsIgnoreCase(TYPE_GET)) { return new HttpGet(target); } else if (this.httpMethod.equalsIgnoreCase(TYPE_POST)) { return new HttpPost(target); } else if (this.httpMethod.equalsIgnoreCase(TYPE_DEL)) { return new HttpDelete(target); } else if (this.httpMethod.equalsIgnoreCase(TYPE_PUT)) { return new HttpPut(target); } else { return null; } }
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:com.teradata.tempto.internal.hadoop.hdfs.WebHDFSClient.java
@Override public void createDirectory(String path, String username) { // TODO: reconsider permission=777 HttpPut mkdirRequest = new HttpPut(buildUri(path, username, "MKDIRS", Pair.of("permission", "777"))); try (CloseableHttpResponse response = httpClient.execute(mkdirRequest)) { if (response.getStatusLine().getStatusCode() != SC_OK) { throw invalidStatusException("MKDIRS", path, username, mkdirRequest, response); }/*w ww .j a va 2s. co m*/ logger.debug("Created directory {} - username: {}", path, username); } catch (IOException e) { throw new RuntimeException("Could not create directory " + path + " in hdfs, user: " + username, e); } }
From source file:org.deviceconnect.android.profile.restful.test.NormalConnectProfileTestCase.java
/** * WiFi?.//from www .j a va 2 s. c om * <pre> * ?HTTP * Method: PUT * Path: /connect/wifi?deviceid=xxxx * </pre> * <pre> * ?? * result?0??????? * </pre> */ public void testPutWifi() { StringBuilder builder = new StringBuilder(); builder.append(DCONNECT_MANAGER_URI); builder.append("/" + ConnectProfileConstants.PROFILE_NAME); builder.append("/" + ConnectProfileConstants.ATTRIBUTE_WIFI); builder.append("?"); builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId()); builder.append("&"); builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken()); try { HttpUriRequest request = new HttpPut(builder.toString()); JSONObject root = sendRequest(request); Assert.assertNotNull("root is null.", root); Assert.assertEquals(DConnectMessage.RESULT_OK, root.getInt(DConnectMessage.EXTRA_RESULT)); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } }
From source file:org.sensapp.android.sensappdroid.restrequests.RestRequest.java
public static String putData(Uri uri, String data) throws RequestErrorException { URI target;// ww w . j a v a 2s . c om try { target = new URI(uri.toString() + DISPATCHER_PATH); } catch (URISyntaxException e1) { e1.printStackTrace(); throw new RequestErrorException(e1.getMessage()); } HttpClient client = new DefaultHttpClient(); HttpPut request = new HttpPut(target); request.setHeader("Content-type", "application/json"); String response = null; try { StringEntity seContent = new StringEntity(data); seContent.setContentType("text/json"); request.setEntity(seContent); response = resolveResponse(client.execute(request)); } catch (Exception e) { throw new RequestErrorException(e.getMessage()); } if (response.trim().length() > 2) { throw new RequestErrorException("Sensor not registred: " + response); } return response; }
From source file:com.volley.android.toolbox.HttpClientStack.java
/** * Creates the appropriate subclass of HttpUriRequest for passed in request. *///from w ww .ja v a 2s. co m @SuppressWarnings("deprecation") /* protected */ static HttpUriRequest createHttpRequest(Request<?> request, Map<String, String> additionalHeaders) throws AuthFailureError { switch (request.getMethod()) { case Request.Method.DEPRECATED_GET_OR_POST: { // This is the deprecated way that needs to be handled for backwards compatibility. // If the request's post body is null, then the assumption is that the request is // GET. Otherwise, it is assumed that the request is a POST. byte[] postBody = request.getPostBody(); if (postBody != null) { HttpPost postRequest = new HttpPost(request.getUrl()); postRequest.addHeader(HEADER_CONTENT_TYPE, request.getPostBodyContentType()); HttpEntity entity; entity = new ByteArrayEntity(postBody); postRequest.setEntity(entity); return postRequest; } else { return new HttpGet(request.getUrl()); } } case Request.Method.GET: return new HttpGet(request.getUrl()); case Request.Method.DELETE: return new HttpDelete(request.getUrl()); case Request.Method.POST: { HttpPost postRequest = new HttpPost(request.getUrl()); postRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(postRequest, request); return postRequest; } case Request.Method.PUT: { HttpPut putRequest = new HttpPut(request.getUrl()); putRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(putRequest, request); return putRequest; } default: throw new IllegalStateException("Unknown request method."); } }
From source file:com.mr.http.toolbox.MR_HttpClientStack.java
/** * Creates the appropriate subclass of HttpUriRequest for passed in request. *//*from w ww .j a v a 2 s . co m*/ @SuppressWarnings("deprecation") /* protected */ static HttpUriRequest createHttpRequest(MR_Request<?> request, Map<String, String> additionalHeaders) throws MR_AuthFailureError { switch (request.getMethod()) { case Method.DEPRECATED_GET_OR_POST: { // This is the deprecated way that needs to be handled for backwards compatibility. // If the request's post body is null, then the assumption is that the request is // GET. Otherwise, it is assumed that the request is a POST. byte[] postBody = request.getPostBody(); if (postBody != null) { HttpPost postRequest = new HttpPost(request.getUrl()); postRequest.addHeader(HEADER_CONTENT_TYPE, request.getPostBodyContentType()); HttpEntity entity; entity = new ByteArrayEntity(postBody); postRequest.setEntity(entity); return postRequest; } else { return new HttpGet(request.getUrl()); } } case Method.GET: return new HttpGet(request.getUrl()); case Method.DELETE: return new HttpDelete(request.getUrl()); case Method.POST: { HttpPost postRequest = new HttpPost(request.getUrl()); postRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(postRequest, request); return postRequest; } case Method.PUT: { HttpPut putRequest = new HttpPut(request.getUrl()); putRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(putRequest, request); return putRequest; } default: throw new IllegalStateException("Unknown request method."); } }