List of usage examples for org.apache.http.client.methods HttpPut HttpPut
public HttpPut(final String uri)
From source file:org.elasticsearch.querydoge.helper.HttpHelper.java
public String putAndReturnBody(String path, String message) throws ClientProtocolException, IOException { HttpPut httpPut = new HttpPut(baseUrl + path); StringEntity entity = new StringEntity(message, HTTP.UTF_8); entity.setContentType("application/x-www-form-urlencoded"); httpPut.setEntity(entity);/*from www . j a va 2s . c o m*/ System.out.println(httpPut); System.out.println(message); return httpclient.execute(httpPut, responseHandler); }
From source file:net.gcolin.httpquery.HttpHandlerImpl.java
@Override public Request put(String uri, InputStream inStream) { HttpPut put = new HttpPut(uri); put.setEntity(new InputStreamEntity(inStream, -1)); return new RequestImpl(put); }
From source file:com.srotya.tau.nucleus.qa.QAStateAggregationRules.java
@Test public void testAStateAggregations() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException, IOException, InterruptedException { CloseableHttpClient client = null;//w w w . j a va2 s . com // 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) 22, "test_template", "alertAggregation@srotya.com", "mail", "state tracking", "state tracking", 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) 23, "SimpleStateTrackingRule", true, new EqualsCondition("value", 9.0), new Action[] { new StateAggregationAction((short) 0, "host", 10, new EqualsCondition("value", 9.0)) }), 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) 25, "SimpleStateAlertRule", true, new AndCondition(Arrays.asList(new EqualsCondition(Constants.FIELD_RULE_ID, 23), new EqualsCondition(Constants.FIELD_ACTION_ID, 0))), new Action[] { new TemplatedAlertAction((short) 0, (short) 22) }), 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", 9.0); eventHeaders.put("@timestamp", "2014-04-23T13:40:2" + i + ".000Z"); eventHeaders.put(Constants.FIELD_EVENT_ID, 1300 + 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()) <= 4) { System.out.println("Waiting on aggregation window to close; email count:" + size); Thread.sleep(10000); } assertEquals(5, size); }
From source file:org.apache.camel.component.cxf.jaxrs.CxfRsConsumerWithBeanTest.java
private void sendPutRequest(String uri) throws Exception { HttpPut put = new HttpPut(uri); StringEntity entity = new StringEntity("string"); entity.setContentType("text/plain"); put.setEntity(entity);// w ww .java2s. c o m CloseableHttpClient httpclient = HttpClientBuilder.create().build(); try { HttpResponse response = httpclient.execute(put); assertEquals(200, response.getStatusLine().getStatusCode()); assertEquals("c20string", EntityUtils.toString(response.getEntity())); } finally { httpclient.close(); } }
From source file:org.lightcouch.CouchDbContext.java
/** * Creates a new Database, if it does not already exist. * @param dbName The Database name/* w ww . ja va 2 s . co m*/ */ public void createDB(String dbName) { assertNotEmpty(dbName, "Database name"); HttpResponse headresp = null; HttpResponse putresp = null; URI uri = builder(dbc.getBaseUri()).path(dbName).build(); try { headresp = dbc.head(uri); } catch (NoDocumentException e) { // db doesn't exist HttpPut put = new HttpPut(uri); putresp = dbc.executeRequest(put); log.info(String.format("Database: '%s' is created.", dbName)); } finally { close(headresp); close(putresp); } }
From source file:org.codegist.crest.io.http.HttpClientHttpChannelFactory.java
/** * @inheritDoc//from w w w .j a v a 2 s .co m */ public HttpChannel open(MethodType methodType, String url, Charset charset) { HttpUriRequest request; switch (methodType) { case GET: request = new HttpGet(url); break; case POST: request = new HttpPost(url); break; case PUT: request = new HttpPut(url); break; case DELETE: request = new HttpDelete(url); break; case OPTIONS: request = new HttpOptions(url); break; case HEAD: request = new HttpHead(url); break; default: throw new IllegalArgumentException("Method " + methodType + " not supported"); } HttpProtocolParams.setContentCharset(request.getParams(), charset.displayName()); return new HttpClientHttpChannel(client, request); }
From source file:org.fcrepo.integration.api.AbstractResourceIT.java
protected static HttpPut putDSMethod(final String pid, final String ds) { return new HttpPut(serverAddress + "objects/" + pid + "/datastreams/" + ds); }
From source file:io.openkit.OKHTTPClient.java
public static void putJSON(String relativeUrl, JSONObject requestParams, AsyncHttpResponseHandler responseHandler) { StringEntity sEntity = getJSONString(requestParams); HttpPut request = new HttpPut(getAbsoluteUrl(relativeUrl)); if (sEntity == null) { responseHandler.onFailure(new Throwable("JSON encoding error"), "JSON encoding error"); } else {/*from w ww. j a v a 2 s . co m*/ request.setEntity(sEntity); sign(request); client.put(request, "application/json", responseHandler); } }
From source file:com.urbancode.ud.client.SystemClient.java
public void addGroupToTeam(String group, String team, String type) throws IOException { String uri = url + "/cli/teamsecurity/groups?group=" + encodePath(group) + "&team=" + encodePath(team) + "&type=" + encodePath(type); HttpPut method = new HttpPut(uri); invokeMethod(method);/*from w w w .ja v a2s . c om*/ }