List of usage examples for org.apache.http.client.methods HttpPut HttpPut
public HttpPut(final String uri)
From source file:com.vanillasource.gerec.httpclient.AsyncApacheHttpClient.java
@Override public CompletableFuture<HttpResponse> doPut(URI uri, HttpRequest.HttpRequestChange change) { return execute(new HttpPut(uri), change); }
From source file:com.groupme.sdk.util.HttpUtils.java
public static InputStream openStream(HttpClient client, String url, int method, String body, Bundle params, Bundle headers) throws HttpResponseException { HttpResponse response;/* w ww. j a va 2 s .co m*/ InputStream in = null; Log.v("HttpUtils", "URL = " + url); try { switch (method) { case METHOD_GET: url = url + "?" + encodeParams(params); HttpGet get = new HttpGet(url); if (headers != null && !headers.isEmpty()) { for (String header : headers.keySet()) { get.setHeader(header, headers.getString(header)); } } response = client.execute(get); break; case METHOD_POST: if (body != null) { url = url + "?" + encodeParams(params); } HttpPost post = new HttpPost(url); Log.d(Constants.LOG_TAG, "URL: " + url); if (headers != null && !headers.isEmpty()) { for (String header : headers.keySet()) { post.setHeader(header, headers.getString(header)); } } if (body == null) { List<NameValuePair> pairs = bundleToList(params); post.setEntity(new UrlEncodedFormEntity(pairs, HTTP.UTF_8)); } else { post.setEntity(new StringEntity(body)); } response = client.execute(post); break; case METHOD_PUT: if (body != null) { url = url + "?" + encodeParams(params); } HttpPut put = new HttpPut(url); if (headers != null && !headers.isEmpty()) { for (String header : headers.keySet()) { put.setHeader(header, headers.getString(header)); } } if (body == null) { List<NameValuePair> pairs = bundleToList(params); put.setEntity(new UrlEncodedFormEntity(pairs, HTTP.UTF_8)); } else { put.setEntity(new StringEntity(body)); } response = client.execute(put); break; default: throw new UnsupportedOperationException("Cannot execute HTTP method: " + method); } int statusCode = response.getStatusLine().getStatusCode(); if (statusCode > 400) { throw new HttpResponseException(statusCode, read(response.getEntity().getContent())); } in = response.getEntity().getContent(); } catch (ClientProtocolException e) { Log.e(Constants.LOG_TAG, "Client error: " + e.toString()); } catch (IOException e) { Log.e(Constants.LOG_TAG, "IO error: " + e.toString()); } return in; }
From source file:at.sti2.spark.handler.ImpactoriumHandler.java
@Override public void invoke(Match match) throws SparkwaveHandlerException { /*/*from ww w .j av a 2 s . c om*/ * TODO Remove this. This is an ugly hack to stop Impactorium handler of sending thousands of matches regarding the same event. * ******************************************************/ long timestamp = (new Date()).getTime(); if (timestamp - twoMinutesPause < 120000) return; twoMinutesPause = timestamp; /* *****************************************************/ String baseurl = handlerProperties.getValue("baseurl"); logger.info("Invoking impactorium at base URL " + baseurl); //Define report id value String reportId = "" + (new Date()).getTime(); //HTTP PUT the info-object id HttpClient httpclient = new DefaultHttpClient(); HttpPut httpPut = new HttpPut(baseurl + "/info-object"); try { StringEntity infoObjectEntityRequest = new StringEntity( "<info-object name=\"Report " + reportId + " \"/>", "UTF-8"); httpPut.setEntity(infoObjectEntityRequest); HttpResponse response = httpclient.execute(httpPut); logger.info("[CREATING REPORT] Status code " + response.getStatusLine()); //First invocation succeeded if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { HttpEntity infoObjectEntityResponse = response.getEntity(); //Something has been returned, let's see what is in it if (infoObjectEntityResponse != null) { String infoObjectResponse = EntityUtils.toString(infoObjectEntityResponse); logger.debug("InfoObject response " + infoObjectResponse); //Extract info-object identifier String infoObjectReportId = extractInfoObjectIdentifier(infoObjectResponse); if (infoObjectReportId == null) { logger.error("Info object report id " + infoObjectReportId); } else { logger.info("Info object report id " + infoObjectReportId); //Format the output for the match final List<TripleCondition> conditions = handlerProperties.getTriplePatternGraph() .getConstruct().getConditions(); final String ntriplesOutput = match.outputNTriples(conditions); //HTTP PUT the data httpPut = new HttpPut(baseurl + "/info-object/" + infoObjectReportId + "/data/data.nt"); StringEntity dataEntityRequest = new StringEntity(ntriplesOutput, "UTF-8"); httpPut.setEntity(dataEntityRequest); response = httpclient.execute(httpPut); logger.info("[STORING DATA] Status code " + response.getStatusLine()); //First invocation succeeded if (!(response.getStatusLine().getStatusCode() == HttpStatus.SC_OK)) throw new SparkwaveHandlerException("Could not write data."); } } } } catch (UnsupportedEncodingException e) { logger.error(e.getMessage()); } catch (ClientProtocolException e) { logger.error(e.getMessage()); } catch (IOException e) { logger.error(e.getMessage()); } }
From source file:org.cloudml.connectors.PyHrapiConnector.java
private String invoke(URI uri, String method, String body) throws UnsupportedEncodingException, IOException { HttpUriRequest request = null;/* w w w. j a va 2s . c om*/ if ("GET".equals(method)) { request = new HttpGet(uri); } else if ("POST".equals(method)) { HttpPost post = new HttpPost(uri); if (body != null && !body.isEmpty()) { post.setHeader("Content-type", "application/json"); post.setEntity(new StringEntity(body)); } request = post; } else if ("PUT".equals(method)) { HttpPut put = new HttpPut(uri); if (body != null && !body.isEmpty()) { put.setHeader("Content-type", "application/json"); put.setEntity(new StringEntity(body)); } request = put; } else if ("DELETE".equals(method)) { request = new HttpDelete(uri); } HttpResponse response = httpclient.execute(request); String s = IOUtils.toString(response.getEntity().getContent()); //TODO: will be removed after debug System.out.println(s); return s; }
From source file:org.apache.jena.fuseki.http.DatasetGraphAccessorHTTP.java
private void doPut(String url, Graph data) { HttpUriRequest httpPut = new HttpPut(url); exec(url, data, httpPut, false); }
From source file:io.fabric8.itests.basic.FabricMavenProxyTest.java
@Test public void testUpload() throws Exception { String featureLocation = System.getProperty("feature.location"); System.out.println("Testing with feature from:" + featureLocation); System.err.println(executeCommand("fabric:create -n")); Set<Container> containers = ContainerBuilder.create(2).withName("maven").withProfiles("fabric") .assertProvisioningResult().build(); try {//from ww w . j ava 2s . c om List<String> uploadUrls = new ArrayList<String>(); ServiceProxy<CuratorFramework> curatorProxy = ServiceProxy.createServiceProxy(bundleContext, CuratorFramework.class); try { CuratorFramework curator = curatorProxy.getService(); List<String> children = ZooKeeperUtils.getChildren(curator, ZkPath.MAVEN_PROXY.getPath("upload")); for (String child : children) { String uploadeUrl = ZooKeeperUtils.getSubstitutedPath(curator, ZkPath.MAVEN_PROXY.getPath("upload") + "/" + child); uploadUrls.add(uploadeUrl); } } finally { curatorProxy.close(); } //Pick a random maven proxy from the list. Random random = new Random(); int index = random.nextInt(uploadUrls.size()); String targetUrl = uploadUrls.get(index); String uploadUrl = targetUrl + "itest/itest/1.0/itest-1.0-features.xml"; System.out.println("Using URI: " + uploadUrl); DefaultHttpClient client = new DefaultHttpClient(); HttpPut put = new HttpPut(uploadUrl); client.getCredentialsProvider().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("admin", "admin")); FileNIOEntity entity = new FileNIOEntity(new File(featureLocation), "text/xml"); put.setEntity(entity); HttpResponse response = client.execute(put); System.err.println("Response:" + response.getStatusLine()); Assert.assertTrue(response.getStatusLine().getStatusCode() == 200 || response.getStatusLine().getStatusCode() == 202); System.err.println( executeCommand("fabric:profile-edit --repositories mvn:itest/itest/1.0/xml/features default")); System.err.println(executeCommand("fabric:profile-edit --features example-cbr default")); Provision.containerStatus(containers, PROVISION_TIMEOUT); } finally { ContainerBuilder.destroy(containers); } }
From source file:io.logspace.agent.hq.HqClient.java
public void uploadCapabilities(AgentControllerCapabilities capabilities) throws IOException { HttpPut httpPut = new HttpPut(this.baseUrl + "/api/capabilities/" + this.agentControllerId); httpPut.setEntity(toJSonEntity(capabilities)); httpPut.addHeader("logspace.space-token", this.spaceToken); this.httpClient.execute(httpPut, new UploadCapabilitiesResponseHandler()); }
From source file:com.arrow.acn.client.api.SoftwareReleaseTransApi.java
public StatusModel failed(String hid, String error) { String method = "failed"; try {//w ww. jav a 2s. co m URI uri = buildUri(String.format(FAILED_URL, hid)); StatusModel result = execute(new HttpPut(uri), JsonUtils.toJson(Collections.singletonMap("error", AcsUtils.trimToEmpty(error))), StatusModel.class); log(method, result); return result; } catch (Throwable e) { logError(method, e); throw new AcnClientException(method, e); } }
From source file:com.arrow.acn.client.api.NodeTypeApi.java
/** * Sends PUT request to update existing node type according to {@code model} * passed/*w w w .j a v a 2s .c o m*/ * * @param hid * {@link String} representing {@code hid} of node type to be * updated * @param model * {@link NodeTypeModel} representing node type parameters to be * updated * * @return {@link HidModel} containing {@code hid} of node type updated * * @throws AcnClientException * if request failed */ public HidModel updateExistingNodeType(String hid, NodeTypeModel model) { String method = "updateExistingNodeType"; try { URI uri = buildUri(SPECIFIC_NODE_TYPE_URL.replace("{hid}", hid)); HidModel result = execute(new HttpPut(uri), JsonUtils.toJson(model), HidModel.class); log(method, result); return result; } catch (Throwable e) { logError(method, e); throw new AcnClientException(method, e); } }
From source file:com.portfolio.data.utils.PostForm.java
public static boolean updateResource(String sessionid, String backend, String uuid, String lang, String json) throws Exception { /// Parse and create xml from JSON JSONObject files = (JSONObject) JSONValue.parse(json); JSONArray array = (JSONArray) files.get("files"); if ("".equals(lang) || lang == null) lang = "fr"; JSONObject obj = (JSONObject) array.get(0); String ressource = ""; String attLang = " lang=\"" + lang + "\""; ressource += "<asmResource>" + "<filename" + attLang + ">" + obj.get("name") + "</filename>" + // filename "<size" + attLang + ">" + obj.get("size") + "</size>" + "<type" + attLang + ">" + obj.get("type") + "</type>" + // obj.get("url"); // Backend source, when there is multiple backend "<fileid" + attLang + ">" + obj.get("fileid") + "</fileid>" + "</asmResource>"; /// Send data to resource /// Server + "/resources/resource/file/" + uuid +"?lang="+ lang CloseableHttpClient httpclient = HttpClients.createDefault(); try {//ww w.ja v a 2 s .c o m HttpPut put = new HttpPut("http://" + backend + "/rest/api/resources/resource/" + uuid); put.setHeader("Cookie", "JSESSIONID=" + sessionid); // So that the receiving servlet allow us StringEntity se = new StringEntity(ressource); se.setContentEncoding("application/xml"); put.setEntity(se); CloseableHttpResponse response = httpclient.execute(put); try { HttpEntity resEntity = response.getEntity(); } finally { response.close(); } } finally { httpclient.close(); } return false; }