List of usage examples for org.apache.http.client.methods HttpPut HttpPut
public HttpPut(final String uri)
From source file:com.evrythng.java.wrapper.util.FileUtils.java
/** * Uploads text as a file content with PRIVATE read access. * * @param uri upload {@link URI}//from ww w . j a va 2s . co m * @param contentTypeString content type * @param contentString text content * @throws IOException */ public static void uploadPrivateContent(final URI uri, final String contentTypeString, final String contentString) throws IOException { LOGGER.info("uploadPrivateContent START: uri: [{}]; content type: [{}], content length: [{}]", new Object[] { uri, contentTypeString, contentString.length() }); CloseableHttpClient closeableHttpClient = HttpClients.createDefault(); HttpPut httpPut = new HttpPut(uri); httpPut.addHeader(HttpHeaders.CONTENT_TYPE, contentTypeString); httpPut.addHeader(FileUtils.X_AMZ_ACL_HEADER_NAME, FileUtils.X_AMZ_ACL_HEADER_VALUE_PRIVATE); ContentType contentType = ContentType.create(contentTypeString); StringEntity stringEntity = new StringEntity(contentString, contentType); httpPut.setEntity(stringEntity); CloseableHttpResponse response = closeableHttpClient.execute(httpPut); StatusLine statusLine = response.getStatusLine(); if (!(statusLine.getStatusCode() == HttpStatus.SC_OK)) { throw new IOException(String.format("An error occurred while trying to upload private file - %d: %s", statusLine.getStatusCode(), statusLine.getReasonPhrase())); } LOGGER.info("uploadPrivateContent END: uri: [{}]; content type: [{}], content length: [{}]", new Object[] { uri, contentTypeString, contentString.length() }); }
From source file:com.feedeo.rest.client.AbstractRestClient.java
protected ClientHttpRequestFactory createClientHttpRequestFactory(HttpClient httpClient) { return new HttpComponentsClientHttpRequestFactory(httpClient) { @Override/*from ww w.j av a 2 s .c om*/ protected HttpUriRequest createHttpUriRequest(HttpMethod httpMethod, URI uri) { switch (httpMethod) { case GET: return new HttpGet(uri); case DELETE: return new HttpEntityEnclosingDeleteRequest(uri); case HEAD: return new HttpHead(uri); case OPTIONS: return new HttpOptions(uri); case POST: return new HttpPost(uri); case PUT: return new HttpPut(uri); case TRACE: return new HttpTrace(uri); case PATCH: return new HttpPatch(uri); default: throw new IllegalArgumentException("Invalid HTTP method: " + httpMethod); } } }; }
From source file:org.deviceconnect.android.profile.restful.test.FailSystemProfileTestCase.java
/** * PUT?????.//from w ww . j a va2 s . c om * <pre> * ?HTTP * Method: PUT * Path: /system/device?deviceId=123456789&deviceId=xxxx * </pre> * <pre> * ?? * result?1??????? * </pre> */ public void testGetSystemInvalidMethodPut() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(SystemProfileConstants.PROFILE_NAME); try { HttpUriRequest request = new HttpPut(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.NOT_SUPPORT_ACTION.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } }
From source file:com.urbancode.ud.client.ApplicationClient.java
public void addApplicationToTeam(String application, String team, String type) throws IOException { String uri = url + "/cli/application/teams?team=" + encodePath(team) + "&type=" + encodePath(type) + "&application=" + encodePath(application); HttpPut method = new HttpPut(uri); invokeMethod(method);/*www . ja va2 s . co m*/ }
From source file:org.craftercms.deployer.impl.processors.HttpMethodCallProcessor.java
protected HttpUriRequest createRequest() { if (method.equalsIgnoreCase("get")) { return new HttpGet(url); } else if (method.equalsIgnoreCase("post")) { return new HttpPost(url); } else if (method.equalsIgnoreCase("put")) { return new HttpPut(url); } else if (method.equalsIgnoreCase("delete")) { return new HttpDelete(url); } else if (method.equalsIgnoreCase("head")) { return new HttpHead(url); } else if (method.equalsIgnoreCase("options")) { return new HttpOptions(url); } else if (method.equalsIgnoreCase("trace")) { return new HttpTrace(url); } else {/*w w w. j a v a2s . c o m*/ throw new DeploymentException("HTTP method '" + method + " not recognized"); } }
From source file:org.keycloak.client.registration.HttpUtil.java
InputStream doPut(String content, String contentType, Charset charset, String acceptType, String... path) throws ClientRegistrationException { try {/* www. ja v a 2 s . c o m*/ HttpPut request = new HttpPut(getUrl(baseUri, path)); request.setHeader(HttpHeaders.CONTENT_TYPE, contentType(contentType, charset)); request.setHeader(HttpHeaders.ACCEPT, acceptType); request.setEntity(new StringEntity(content, charset)); addAuth(request); HttpResponse response = httpClient.execute(request); InputStream responseStream = null; if (response.getEntity() != null) { responseStream = response.getEntity().getContent(); } if (response.getStatusLine().getStatusCode() == 200) { return responseStream; } else { throw httpErrorException(response, responseStream); } } catch (IOException e) { throw new ClientRegistrationException("Failed to send request", e); } }
From source file:io.logspace.agent.hq.HqClient.java
public void uploadEvents(Collection<Event> events) throws IOException { String eventsUrl = this.baseUrl + "/api/events"; HttpPut httpPut = new HttpPut(eventsUrl); httpPut.setEntity(toJsonEntity(events)); httpPut.addHeader("logspace.space-token", this.spaceToken); this.logger.info("Uploading {} event(s) using space-token '{}' to {}", events.size(), this.spaceToken, eventsUrl);/*from ww w .j av a 2 s .com*/ this.httpClient.execute(httpPut, new UploadEventsResponseHandler()); }
From source file:functionaltests.RestSchedulerJobPaginationTest.java
@Test public void testJobsPagination() throws Exception { Assert.assertEquals("Test expects only one node", 1, RestFuncTHelper.DEFAULT_NUMBER_OF_NODES); JobId jobId1 = getScheduler().submit(createJob(NonTerminatingJob.class)); waitJobState(jobId1, JobStatus.RUNNING, 30000); JobId jobId2 = submitDefaultJob();//from w w w . j a v a 2 s . c om JobId jobId3 = submitDefaultJob(); checkPagingRequests1(); // check 'jobsinfo' and 'revisionjobsinfo' provide job's attributes JSONObject page; JSONArray jobs; page = getRequestJSONObject(getResourceUrl("jobsinfo")); jobs = (JSONArray) page.get("list"); checkJob((JSONObject) jobs.get(2), JobStatus.RUNNING, 1, 0); page = getRequestJSONObject(getResourceUrl("revisionjobsinfo")); JSONObject map = (JSONObject) page.get("map"); Assert.assertEquals(1, map.keySet().size()); jobs = (JSONArray) map.get(map.keySet().iterator().next()); checkJob((JSONObject) jobs.get(2), JobStatus.RUNNING, 1, 0); checkFiltering1(); String resource = "jobs/" + jobId1.value() + "/kill"; String schedulerUrl = getResourceUrl(resource); HttpPut httpPut = new HttpPut(schedulerUrl); setSessionHeader(httpPut); HttpResponse response = executeUriRequest(httpPut); assertHttpStatusOK(response); waitJobState(jobId1, JobStatus.KILLED, 30000); waitJobState(jobId2, JobStatus.FINISHED, 30000); waitJobState(jobId3, JobStatus.FINISHED, 30000); checkFiltering2(); // check 'jobsinfo' and 'revisionjobsinfo' provide updated job's attributes JSONObject job = null; page = getRequestJSONObject(getResourceUrl("jobsinfo")); jobs = (JSONArray) page.get("list"); checkJob(findJob("1", jobs), JobStatus.KILLED, 0, 0); page = getRequestJSONObject(getResourceUrl("revisionjobsinfo")); map = (JSONObject) page.get("map"); Assert.assertEquals(1, map.keySet().size()); jobs = (JSONArray) map.get(map.keySet().iterator().next()); checkJob(findJob("1", jobs), JobStatus.KILLED, 0, 0); checkPagingRequests2(); }
From source file:com.intel.cosbench.client.http.HttpClientUtil.java
public static HttpPut makeHttpPut(String url) { return new HttpPut(url); }
From source file:com.urbancode.ud.client.PropertyClient.java
public JSONArray updatePropDefs(String propSheetDefPath, JSONArray propDefs, boolean deleteExtraProps) throws IOException, JSONException { JSONArray result = null;/* w w w .j a v a 2s .c o m*/ String uri = url + "/property/propSheetDef/" + encodePath(propSheetDefPath) + ".-1/propDefs/update/" + String.valueOf(deleteExtraProps); HttpPut method = new HttpPut(uri); method.setEntity(getStringEntity(propDefs)); HttpResponse response = invokeMethod(method); String body = getBody(response); result = new JSONArray(body); return result; }