List of usage examples for org.apache.http.client.methods HttpPut HttpPut
public HttpPut(final String uri)
From source file:com.google.appengine.tck.endpoints.support.EndPointClient.java
public String doPut(URL url) throws Exception { return doRequest(new HttpPut(url.toURI())); }
From source file:com.aliyun.android.oss.task.UploadPartTask.java
/** * HttpPut//ww w .j a v a 2s . c o m */ protected HttpUriRequest generateHttpRequest() { String requestUri = this.getOSSEndPoint() + httpTool.generateCanonicalizedResource("/" + OSSHttpTool.encodeUri(objectKey)); HttpPut httpPut = new HttpPut(requestUri); String resource = httpTool.generateCanonicalizedResource("/" + bucketName + "/" + objectKey); String dateStr = Helper.getGMTDate(); String authorization = OSSHttpTool.generateAuthorization(accessId, accessKey, httpMethod.toString(), "", "", dateStr, "", resource); httpPut.setHeader(AUTHORIZATION, authorization); httpPut.setHeader(DATE, dateStr); httpPut.setHeader(UPLOAD_ID, httpTool.getUploadId()); httpPut.setHeader(PART_NUMBER, Integer.toString(httpTool.getPartNumber())); InputStreamEntity entity = new InputStreamEntity(part.getStream(), part.getSize()); httpPut.setEntity(entity); return httpPut; }
From source file:org.deviceconnect.android.profile.restful.test.FailServiceDiscoveryProfileTestCase.java
/** * PUT???.//from w w w . j a v a 2 s .com * * <pre> * ?HTTP * Method: PUT * Path: /servicediscovery * </pre> * * <pre> * ?? * result?1??????? * </pre> */ @Test public void testGetServices002() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(ServiceDiscoveryProfileConstants.PROFILE_NAME); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpPut(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.NOT_SUPPORT_ATTRIBUTE.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } }
From source file:org.apache.sling.discovery.base.connectors.ping.TopologyRequestValidatorTest.java
@Test public void testTrustRequest() throws IOException { final HttpPut method = new HttpPut("/TestUri"); String clearMessage = "TestMessage"; final String message = topologyRequestValidator.encodeMessage(clearMessage); Assert.assertNotNull(message);// w ww. ja v a2s . c o m Assert.assertNotEquals(message, clearMessage); topologyRequestValidator.trustMessage(method, message); Assert.assertNotNull(method.getFirstHeader(TopologyRequestValidator.HASH_HEADER)); Assert.assertNotNull(method.getFirstHeader(TopologyRequestValidator.HASH_HEADER).getValue()); Assert.assertTrue(method.getFirstHeader(TopologyRequestValidator.HASH_HEADER).getValue().length() > 0); Assert.assertNotNull(method.getFirstHeader(TopologyRequestValidator.SIG_HEADER)); Assert.assertNotNull(method.getFirstHeader(TopologyRequestValidator.SIG_HEADER).getValue()); Assert.assertTrue(method.getFirstHeader(TopologyRequestValidator.SIG_HEADER).getValue().length() > 0); final HttpServletRequest request = context.mock(HttpServletRequest.class); context.checking(new Expectations() { { allowing(request).getHeader(with(TopologyRequestValidator.HASH_HEADER)); will(returnValue(method.getFirstHeader(TopologyRequestValidator.HASH_HEADER).getValue())); allowing(request).getHeader(with(TopologyRequestValidator.SIG_HEADER)); will(returnValue(method.getFirstHeader(TopologyRequestValidator.SIG_HEADER).getValue())); allowing(request).getHeader(with("Content-Encoding")); will(returnValue("")); allowing(request).getRequestURI(); will(returnValue(method.getURI().getPath())); allowing(request).getReader(); will(returnValue(new BufferedReader(new StringReader(message)))); } }); Assert.assertTrue(topologyRequestValidator.isTrusted(request)); Assert.assertEquals(clearMessage, topologyRequestValidator.decodeMessage(request)); }
From source file:org.fcrepo.it.BasicIT.java
private static void putDummyDatastream(final String path, final String mimeType) throws IOException { final HttpPut put = new HttpPut(getURIForPid(path)); put.setHeader("Content-type", mimeType); put.setEntity(new StringEntity(content1)); Assert.assertEquals(201, getStatusCode(put)); }
From source file:com.srotya.tau.nucleus.qa.QACountingAggregationRules.java
@Test public void testACountingAggregations() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException, IOException, InterruptedException { CloseableHttpClient client = null;//from w ww . j a v a2 s . c o m // Create a template for alerting and upload it client = Utils.buildClient("http://localhost:8080/commands/templates", 2000, 2000); HttpPut templateUpload = new HttpPut("http://localhost:8080/commands/templates"); String template = AlertTemplateSerializer.serialize(new AlertTemplate((short) 12, "test_template", "alertAggregation@srotya.com", "mail", "aggregation", "aggregation", 30, 1), false); templateUpload.addHeader("content-type", "application/json"); templateUpload.setEntity(new StringEntity(new Gson().toJson(new TemplateCommand("all", false, template)))); CloseableHttpResponse response = client.execute(templateUpload); response.close(); assertTrue( response.getStatusLine().getStatusCode() >= 200 && response.getStatusLine().getStatusCode() < 300); // Create aggregation rule and upload it HttpPut ruleUpload = null; String rule = null; client = Utils.buildClient("http://localhost:8080/commands/rules", 2000, 2000); ruleUpload = new HttpPut("http://localhost:8080/commands/rules"); ruleUpload.addHeader("content-type", "application/json"); rule = RuleSerializer .serializeRuleToJSONString( new SimpleRule((short) 13, "SimpleAggregationRule", true, new EqualsCondition("value", 8.0), new Action[] { new FineCountingAggregationAction((short) 0, "host", "clientip", 10) }), false); ruleUpload.setEntity(new StringEntity( new Gson().toJson(new RuleCommand(StatelessRulesEngine.ALL_RULEGROUP, false, rule)))); response = client.execute(ruleUpload); response.close(); assertTrue(response.getStatusLine().getReasonPhrase(), response.getStatusLine().getStatusCode() >= 200 && response.getStatusLine().getStatusCode() < 300); // Create alert rule for aggregation rule's output and upload it client = Utils.buildClient("http://localhost:8080/commands/rules", 2000, 2000); ruleUpload = new HttpPut("http://localhost:8080/commands/rules"); rule = RuleSerializer.serializeRuleToJSONString(new SimpleRule((short) 15, "SimpleAlertRule", true, new AndCondition(Arrays.asList(new EqualsCondition(Constants.FIELD_RULE_ID, 13), new EqualsCondition(Constants.FIELD_ACTION_ID, 0))), new Action[] { new TemplatedAlertAction((short) 0, (short) 12) }), false); ruleUpload.addHeader("content-type", "application/json"); ruleUpload.setEntity(new StringEntity( new Gson().toJson(new RuleCommand(StatelessRulesEngine.ALL_RULEGROUP, false, rule)))); response = client.execute(ruleUpload); response.close(); assertTrue( response.getStatusLine().getStatusCode() >= 200 && response.getStatusLine().getStatusCode() < 300); for (int i = 0; i < 5; i++) { client = Utils.buildClient("http://localhost:8080/events", 2000, 2000); Map<String, Object> eventHeaders = new HashMap<>(); eventHeaders.put("clientip", i); eventHeaders.put("host", "host1"); eventHeaders.put("value", 8.0); eventHeaders.put("@timestamp", "2014-04-23T13:40:2" + i + ".000Z"); eventHeaders.put(Constants.FIELD_EVENT_ID, 1200 + i); HttpPost eventUpload = new HttpPost("http://localhost:8080/events"); eventUpload.addHeader("content-type", "application/json"); eventUpload.setEntity(new StringEntity(new Gson().toJson(eventHeaders))); response = client.execute(eventUpload); response.close(); assertTrue(response.getStatusLine().getReasonPhrase(), response.getStatusLine().getStatusCode() >= 200 && response.getStatusLine().getStatusCode() < 300); } int size = 0; while ((size = AllQATests.getSmtpServer().getReceivedEmailSize()) <= 3) { System.out.println("Waiting on aggregation window to close; email count:" + size); Thread.sleep(10000); } assertEquals(4, size); }
From source file:com.google.api.client.apache.ApacheHttpTransport.java
@Override public ApacheHttpRequest buildPutRequest(String url) { return new ApacheHttpRequest(this.httpClient, new HttpPut(url)); }
From source file:tools.devnull.boteco.client.rest.impl.DefaultRestClient.java
@Override public RestConfiguration put(String url) { return execute(new HttpPut(url)); }
From source file:org.hl7.fhir.client.ClientUtils.java
public static <T extends Resource> ResourceRequest<T> issuePutRequest(URI resourceUri, byte[] payload, String resourceFormat, List<Header> headers, HttpHost proxy) { HttpPut httpPut = new HttpPut(resourceUri); return issueResourceRequest(resourceFormat, httpPut, payload, headers, proxy); }
From source file:com.flipkart.phantom.http.impl.HttpProxy.java
/** * Creates a HttpRequestBase object understood by the apache http library * @param method HTTP request method/*from w w w . j av a2 s . co m*/ * @param uri HTTP request URI * @param data HTTP request data * @return * @throws Exception */ private HttpRequestBase createRequest(String method, String uri, byte[] data) throws Exception { // get if ("GET".equals(method)) { HttpGet r = new HttpGet(pool.constructUrl(uri)); return r; // put } else if ("PUT".equals(method)) { HttpPut r = new HttpPut(pool.constructUrl(uri)); r.setEntity(new ByteArrayEntity(data)); return r; // post } else if ("POST".equals(method)) { HttpPost r = new HttpPost(pool.constructUrl(uri)); r.setEntity(new ByteArrayEntity(data)); return r; // delete } else if ("DELETE".equals(method)) { HttpDelete r = new HttpDelete(pool.constructUrl(uri)); return r; // invalid } else { return null; } }