List of usage examples for org.apache.http.client.methods HttpPut HttpPut
public HttpPut(final String uri)
From source file:web.restful.ClientTest.java
public static void main(String[] args) throws ClientProtocolException, IOException { HttpClient client = new DefaultHttpClient(); HttpPut put = new HttpPut("http://localhost:8080/ss16-lab-web/resources/outliers/session"); put.setEntity(new StringEntity("upenkwbq"));// session ID client.execute(put);/*from ww w . j a va 2 s.c o m*/ put.releaseConnection(); put = new HttpPut("http://localhost:8080/ss16-lab-web/resources/outliers/bucket"); put.setEntity(new StringEntity("Level1/Level1_Bin_1.txt")); // bucket name client.execute(put); put.releaseConnection(); put = new HttpPut("http://localhost:8080/ss16-lab-web/resources/outliers/method"); put.setEntity(new StringEntity("chauvenet")); // method name client.execute(put); put.releaseConnection(); HttpGet get = new HttpGet("http://localhost:8080/ss16-lab-web/resources/outliers"); HttpResponse response = client.execute(get); HttpEntity en = response.getEntity(); InputStreamReader i = new InputStreamReader(en.getContent()); BufferedReader rd = new BufferedReader(i); String line = ""; while ((line = rd.readLine()) != null) { System.out.println(line); } }
From source file:com.javaquery.apache.httpclient.HttpPutExample.java
public static void main(String[] args) { /* Create object of CloseableHttpClient */ CloseableHttpClient httpClient = HttpClients.createDefault(); /* Prepare put request */ HttpPut httpPut = new HttpPut("http://www.example.com/api/customer"); /* Add headers to get request */ httpPut.addHeader("Authorization", "value"); /* Prepare StringEntity from JSON */ StringEntity jsonData = new StringEntity("{\"id\":\"123\", \"name\":\"Vicky Thakor\"}", "UTF-8"); /* Body of request */ httpPut.setEntity(jsonData);// ww w . java 2 s .c o m /* Response handler for after request execution */ ResponseHandler<String> responseHandler = new ResponseHandler<String>() { @Override public String handleResponse(HttpResponse httpResponse) throws ClientProtocolException, IOException { /* Get status code */ int httpResponseCode = httpResponse.getStatusLine().getStatusCode(); System.out.println("Response code: " + httpResponseCode); if (httpResponseCode >= 200 && httpResponseCode < 300) { /* Convert response to String */ HttpEntity entity = httpResponse.getEntity(); return entity != null ? EntityUtils.toString(entity) : null; } else { return null; /* throw new ClientProtocolException("Unexpected response status: " + httpResponseCode); */ } } }; try { /* Execute URL and attach after execution response handler */ String strResponse = httpClient.execute(httpPut, responseHandler); /* Print the response */ System.out.println("Response: " + strResponse); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:edu.ucsd.ccdb.cil.xml2json.ElasticsearchClient.java
public static void main(String[] args) throws Exception { try {/* w w w . j av a 2 s .c o m*/ DefaultHttpClient httpClient = new DefaultHttpClient(); //HttpPut put = new HttpPut("http://localhost:9200/customer/user/john@smith.com"); //-X PUT //put.setEntity(new FileEntity(new File("/Users/ncmir/NetBeansProjects/MyTest/web/customer.json"), "application/json")); //@ - absolute path HttpPut put = new HttpPut("http://localhost:9200/ccdb/data/1"); //-X PUT put.setEntity( new FileEntity(new File("/Users/ncmir/Documents/CCDB/ccdbJson/1.json"), "application/json")); //@ - absolute path BasicResponseHandler responseHandler = new BasicResponseHandler(); String o = httpClient.execute(put, responseHandler); System.out.println(o); } catch (Exception e) { //-f, fail silently e.printStackTrace(); } }
From source file:org.jboss.pnc.mavenrepositorymanager.ArtifactUploadUtils.java
public static boolean put(CloseableHttpClient client, String url, String content) throws IOException { HttpPut put = new HttpPut(url); put.setEntity(new StringEntity(content)); return client.execute(put, response -> { try {// www . ja va 2s . c om return response.getStatusLine().getStatusCode() == 201; } finally { if (response instanceof CloseableHttpResponse) { IOUtils.closeQuietly((CloseableHttpResponse) response); } } }); }
From source file:org.opencastproject.remotetest.server.resource.SchedulerResources.java
public static HttpResponse addEvent(TrustedHttpClient client, String event) throws Exception { HttpPut put = new HttpPut(getServiceUrl() + "event"); List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>(); params.add(new BasicNameValuePair("event", event)); put.setEntity(new UrlEncodedFormEntity(params)); return client.execute(put); }
From source file:com.spokenpic.net.RestClientPut.java
@Override protected RestResult doPost() { HttpPut httpPut = new HttpPut(getSchemeServer() + this.uri); setupHttp(httpPut);/* ww w. j av a 2 s . c o m*/ try { StringEntity data = new StringEntity(this.data, "UTF-8"); data.setChunked(false); httpPut.setEntity(data); httpPut.setHeader("Content-type", "application/json"); HttpResponse httpResponse = HttpManager.execute(httpPut); return returnResponse(httpResponse); } catch (Exception e) { Log.d("RestClientFilePUT", "Error doPost: " + e.toString()); return errorResponse("Fatal error during PUT"); } }
From source file:coolmapplugin.util.HTTPRequestUtil.java
public static boolean executePut(String targetURL, String jsonBody) { try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) { HttpPut request = new HttpPut(targetURL); if (jsonBody != null && !jsonBody.isEmpty()) { StringEntity params = new StringEntity(jsonBody); request.addHeader("content-type", "application/json"); request.setEntity(params);//from w w w. j a v a 2 s. c o m } HttpResponse result = httpClient.execute(request); if (result.getStatusLine().getStatusCode() == 412 || result.getStatusLine().getStatusCode() == 500) { return false; } } catch (IOException e) { return false; } return true; }
From source file:edu.ucsd.ccdb.cil.xml2json.ElasticsearchClient.java
public void xputElastic(String index, String type, String ID, File f) throws Exception { DefaultHttpClient httpClient = new DefaultHttpClient(); String url = "http://localhost:9200/" + index + "/" + type + "/" + ID; System.out.println(url);/* w w w . java2s . co m*/ HttpPut put = new HttpPut(url); //-X PUT put.setEntity(new FileEntity(f, "application/json")); //@ - absolute path BasicResponseHandler responseHandler = new BasicResponseHandler(); String o = httpClient.execute(put, responseHandler); /* System.err.println("----------"+o+"----------"); if(o == null || o.trim().length() == 0) { System.err.println(o); System.exit(1); } */ }
From source file:com.starbucks.apps.HttpUtils.java
public static HttpInvocationContext doPut(final String payload, String contentType, String url) throws IOException { HttpUriRequest request = new HttpPut(url); return invoke(request, payload, contentType); }
From source file:io.kahu.hawaii.util.call.http.PutRequest.java
public PutRequest(RequestPrototype<HttpResponse, T> prototype, URI uri) { super(prototype, new HttpPut(uri)); }