List of usage examples for org.apache.http.client.methods HttpPut HttpPut
public HttpPut(final String uri)
From source file:ua.at.tsvetkov.data_processor.requests.PutRequest.java
@Override public InputStream getInputStream() throws IOException { if (!isBuild()) { throw new IllegalArgumentException(REQUEST_IS_NOT_BUILDED); }//from w w w. j a va2 s. c o m startTime = System.currentTimeMillis(); HttpConnectionParams.setConnectionTimeout(httpParameters, configuration.getTimeout()); HttpConnectionParams.setSoTimeout(httpParameters, configuration.getTimeout()); HttpPut httpPost = new HttpPut(toString()); httpPost.setParams(httpParameters); if (header != null) { httpPost.addHeader(header); } printToLogUrl(); return getResponce(httpPost); }
From source file:com.intel.iotkitlib.LibHttp.HttpPutTask.java
private CloudResponse doWork(HttpClient httpClient, String url) { try {/*from w w w . jav a2 s.c om*/ HttpContext localContext = new BasicHttpContext(); HttpPut httpPut = new HttpPut(url); if (httpBody != null) { //setting HTTP body in entity StringEntity bodyEntity = new StringEntity(httpBody, "UTF-8"); httpPut.setEntity(bodyEntity); } //adding headers one by one for (NameValuePair nvp : headerList) { httpPut.addHeader(nvp.getName(), nvp.getValue()); } if (debug) { Log.e(TAG, "URI is : " + httpPut.getURI()); Header[] headers = httpPut.getAllHeaders(); for (int i = 0; i < headers.length; i++) { Log.e(TAG, "Header " + i + " is :" + headers[i].getName() + ":" + headers[i].getValue()); } if (httpBody != null) { BufferedReader reader123 = new BufferedReader( new InputStreamReader(httpPut.getEntity().getContent(), HTTP.UTF_8)); StringBuilder builder123 = new StringBuilder(); for (String line = null; (line = reader123.readLine()) != null;) { builder123.append(line).append("\n"); } Log.e(TAG, "Body is :" + builder123.toString()); } } HttpResponse response = httpClient.execute(httpPut, localContext); if (response != null && response.getStatusLine() != null) { if (debug) Log.d(TAG, "response: " + response.getStatusLine().getStatusCode()); } HttpEntity responseEntity = response != null ? response.getEntity() : null; StringBuilder builder = new StringBuilder(); if (responseEntity != null) { BufferedReader reader = new BufferedReader( new InputStreamReader(responseEntity.getContent(), HTTP.UTF_8)); for (String line = null; (line = reader.readLine()) != null;) { builder.append(line).append("\n"); } if (debug) Log.d(TAG, "Response received is :" + builder.toString()); } CloudResponse cloudResponse = new CloudResponse(); if (response != null) { cloudResponse.code = response.getStatusLine().getStatusCode(); } cloudResponse.response = builder.toString(); return cloudResponse; } catch (java.net.ConnectException cEx) { Log.e(TAG, cEx.getMessage()); return null; } catch (Exception e) { Log.e(TAG, e.toString()); e.printStackTrace(); return null; } }
From source file:net.gcolin.httpquery.HttpHandlerImpl.java
@Override public Request put(String uri, String str) { HttpPut put = new HttpPut(uri); try {//from ww w . j a v a 2s .c o m put.setEntity(new StringEntity(str)); } catch (UnsupportedEncodingException e) { Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, e.getMessage(), e); } return new RequestImpl(put); }
From source file:org.talend.dataprep.api.service.command.preparation.PreparationMove.java
private HttpRequestBase onExecute(String id, String folder, String destination, String newName) { try {/*from w w w. java 2 s. c o m*/ URIBuilder uriBuilder = new URIBuilder(preparationServiceUrl + "/preparations/" + id + "/move"); if (StringUtils.isNotBlank(folder)) { uriBuilder.addParameter("folder", folder); } if (StringUtils.isNotBlank(destination)) { uriBuilder.addParameter("destination", destination); } if (StringUtils.isNotBlank(newName)) { uriBuilder.addParameter("newName", newName); } return new HttpPut(uriBuilder.build()); } catch (URISyntaxException e) { throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e); } }
From source file:pl.psnc.synat.wrdz.zmkd.invocation.RestServiceCallerUtils.java
/** * Construct request URI and headers of the service based upon passed information. * /*from w w w.j a v a2 s.c o m*/ * @param execHopInfo * info how to execute a REST service * @return request URI and headers of the service * @throws URISyntaxException * when correct URI cannot be constructed */ public static HttpRequestBase constructServiceRequestBase(ExecutionInfo execHopInfo) throws URISyntaxException { switch (execHopInfo.getMethod()) { case GET: return new HttpGet(constructServiceURI(execHopInfo.getAddress(), execHopInfo.getTemplateParams(), execHopInfo.getQueryParams())); case POST: return new HttpPost(constructServiceURI(execHopInfo.getAddress(), execHopInfo.getTemplateParams(), execHopInfo.getQueryParams())); case PUT: return new HttpPut(constructServiceURI(execHopInfo.getAddress(), execHopInfo.getTemplateParams(), execHopInfo.getQueryParams())); default: throw new WrdzRuntimeException("Not yet implemented HTTP method: " + execHopInfo.getMethod()); } }
From source file:com.digitalarx.android.syncadapter.ContactSyncAdapter.java
@Override public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {/*from w w w .jav a2 s . c o m*/ setAccount(account); setContentProviderClient(provider); Cursor c = getLocalContacts(false); if (c.moveToFirst()) { do { String lookup = c.getString(c.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY)); String a = getAddressBookUri(); String uri = a + lookup + ".vcf"; FileInputStream f; try { f = getContactVcard(lookup); HttpPut query = new HttpPut(uri); byte[] b = new byte[f.available()]; f.read(b); query.setEntity(new ByteArrayEntity(b)); fireRawRequest(query); } catch (IOException e) { e.printStackTrace(); return; } catch (OperationCanceledException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (AuthenticatorException e) { // TODO Auto-generated catch block e.printStackTrace(); } } while (c.moveToNext()); // } while (c.moveToNext()); } }
From source file:at.ac.tuwien.dsg.elasticdaasclient.testing.RestfulWSClient.java
public String callPutMethod(String xmlString) { String rs = ""; try {/* w ww . ja v a 2s .c o m*/ //HttpGet method = new HttpGet(url); StringEntity inputKeyspace = new StringEntity(xmlString); Logger.getLogger(RestfulWSClient.class.getName()).log(Level.INFO, "Connection .. " + url); HttpPut request = new HttpPut(url); request.addHeader("content-type", "application/xml; charset=utf-8"); request.addHeader("Accept", "application/xml, multipart/related"); request.setEntity(inputKeyspace); HttpResponse methodResponse = this.getHttpClient().execute(request); int statusCode = methodResponse.getStatusLine().getStatusCode(); Logger.getLogger(RestfulWSClient.class.getName()).log(Level.INFO, "Status Code: " + statusCode); BufferedReader rd = new BufferedReader(new InputStreamReader(methodResponse.getEntity().getContent())); StringBuilder result = new StringBuilder(); String line; while ((line = rd.readLine()) != null) { result.append(line); } rs = result.toString(); // System.out.println("Response String: " + result.toString()); } catch (Exception ex) { } return rs; }
From source file:org.deviceconnect.android.profile.restful.test.FailProximityProfileTestCase.java
/** * deviceId???ondeviceproximity???.// ww w . j a va2s . c o m * <pre> * ?HTTP * Method: PUT * Path: /proximity/ondeviceproximity?sessionKey=xxxx * </pre> * <pre> * ?? * result?1??????? * </pre> */ public void testPutOnDeviceProximityChangeNoDeviceId() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(ProximityProfileConstants.PROFILE_NAME); builder.setAttribute(ProximityProfileConstants.ATTRIBUTE_ON_DEVICE_PROXIMITY); builder.addParameter(DConnectMessage.EXTRA_SESSION_KEY, getClientId()); builder.addParameter(DConnectMessage.EXTRA_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpPut(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.EMPTY_DEVICE_ID.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } }
From source file:com.vmware.content.samples.client.util.HttpUtil.java
/** * Uploads a file from local storage to a given HTTP URI. * * @param localFile local storage path to the file to upload. * @param uploadUri HTTP URI where the file needs to be uploaded. * @throws java.security.NoSuchAlgorithmException * @throws java.security.KeyStoreException * @throws java.security.KeyManagementException * @throws java.io.IOException/*from www . j a va2 s . c o m*/ */ public static void uploadFileToUri(File localFile, URI uploadUri) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException, IOException { CloseableHttpClient httpClient = getCloseableHttpClient(); HttpPut request = new HttpPut(uploadUri); HttpEntity content = new FileEntity(localFile); request.setEntity(content); HttpResponse response = httpClient.execute(request); EntityUtils.consumeQuietly(response.getEntity()); }
From source file:com.mber.client.HTTParty.java
public static Call put(final String url, final File file) throws IOException { FileEntity entity = new FileEntity(file); entity.setContentType("application/octet-stream"); HttpPut request = new HttpPut(url); request.setEntity(entity);/*from w w w . j av a 2s . c om*/ return execute(request); }