List of usage examples for org.apache.http.client.methods HttpPut HttpPut
public HttpPut(final String uri)
From source file:com.googlesource.gerrit.plugins.hooks.rtc.network.Transport.java
public <T> T put(final String path, final Type typeOrClass, JsonObject data, String etag) throws IOException { HttpPut request = new HttpPut(toUri(path)); if (log.isDebugEnabled()) log.debug("Preparing PUT against " + request.getURI() + " using etag " + etag + " and data " + data); request.setEntity(new StringEntity(data.toString(), HTTP.UTF_8)); if (etag != null) request.addHeader("If-Match", etag); return invoke(request, typeOrClass, APP_OSLC, APP_OSLC); }
From source file:org.deviceconnect.android.uiapp.fragment.profile.VibrationProfileFragment.java
/** * Vibration???./* w ww . j a va 2s .com*/ * @param pattern ? */ private void sendVibration(final CharSequence pattern) { (new AsyncTask<Void, Void, DConnectMessage>() { public DConnectMessage doInBackground(final Void... args) { String p = null; if (pattern != null && pattern.length() > 0) { p = pattern.toString(); } try { URIBuilder builder = new URIBuilder(); builder.setProfile(VibrationProfileConstants.PROFILE_NAME); builder.setAttribute(VibrationProfileConstants.ATTRIBUTE_VIBRATE); builder.addParameter(DConnectMessage.EXTRA_DEVICE_ID, getSmartDevice().getId()); if (p != null) { builder.addParameter(VibrationProfileConstants.PARAM_PATTERN, p); } builder.addParameter(DConnectMessage.EXTRA_ACCESS_TOKEN, getAccessToken()); HttpResponse response = getDConnectClient().execute(getDefaultHost(), new HttpPut(builder.build())); return (new HttpMessageFactory()).newDConnectMessage(response); } catch (URISyntaxException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; } @Override protected void onPostExecute(final DConnectMessage result) { if (getActivity().isFinishing()) { return; } TextView tv = (TextView) getView().findViewById(R.id.fragment_vibration_result); if (result == null) { tv.setText("failed"); } else { tv.setText(result.toString()); } } }).execute(); }
From source file:org.mobisocial.corral.CorralS3Connector.java
public void uploadToServer(String ticket, final EncRslt rslt, String datestr, String objName, final UploadProgressCallback callback) throws ClientProtocolException, IOException { callback.onProgress(UploadState.PREPARING_UPLOAD, 0); Log.d(TAG, "-----UPLOAD START-----"); Log.d(TAG, "URI: " + rslt.uri.toString()); Log.d(TAG, "length: " + rslt.length); Log.d(TAG, "ticket: " + ticket); Log.d(TAG, SERVER_URL + objName); Log.d(TAG, "Authorization: AWS " + ticket); Log.d(TAG, "Content-Md5: " + rslt.md5); Log.d(TAG, "Content-Type: " + CONTENT_TYPE); Log.d(TAG, "Date: " + datestr); InputStream in = mContext.getContentResolver().openInputStream(rslt.uri); final int contentLength = in.available(); HttpClient http = new DefaultHttpClient(); HttpPut put = new HttpPut(SERVER_URL + objName); put.setHeader("Authorization", "AWS " + ticket); put.setHeader("Content-Md5", rslt.md5); put.setHeader("Content-Type", CONTENT_TYPE); put.setHeader("Date", datestr); HttpEntity progress = new ProgressEntity(callback, rslt, contentLength); put.setEntity(progress);/*from w w w .ja v a 2s. c om*/ HttpResponse response = http.execute(put); final int responseCode = response.getStatusLine().getStatusCode(); // FOR DEBUG if (responseCode != HttpURLConnection.HTTP_OK) { throw new RuntimeException("invalid response code, " + responseCode); } }
From source file:org.bibimbap.shortcutlink.RestClient.java
/** * Execute the REST subtasks//www. j a va 2 s . co m */ protected RestClientRequest[] doInBackground(RestClientRequest... params) { // HttpClient that is configured with reasonable default settings and registered schemes for Android final AndroidHttpClient httpClient = AndroidHttpClient.newInstance(RestClient.class.getSimpleName()); for (int index = 0; index < params.length; index++) { RestClientRequest rcr = params[index]; HttpUriRequest httprequest = null; try { HttpResponse httpresponse = null; HttpEntity httpentity = null; // initiating publishProgress(params.length, index, RestfulState.DS_INITIATING); switch (rcr.getHttpRequestType()) { case HTTP_PUT: httprequest = new HttpPut(rcr.getURI()); break; case HTTP_POST: httprequest = new HttpPost(rcr.getURI()); break; case HTTP_DELETE: httprequest = new HttpDelete(rcr.getURI()); break; case HTTP_GET: default: // default to HTTP_GET httprequest = new HttpGet(rcr.getURI()); break; } // resting publishProgress(params.length, index, RestfulState.DS_ONGOING); if ((httpresponse = httpClient.execute(httprequest)) != null) { if ((httpentity = httpresponse.getEntity()) != null) { rcr.setResponse(EntityUtils.toByteArray(httpentity)); } } // success publishProgress(params.length, index, RestfulState.DS_SUCCESS); } catch (Exception ioe) { Log.i(TAG, ioe.getClass().getSimpleName()); // clear out the response rcr.setResponse(null); // abort the request on failure httprequest.abort(); // failed publishProgress(params.length, index, RestfulState.DS_FAILED); } } // close the connection if (httpClient != null) httpClient.close(); return params; }
From source file:com.hoccer.tools.HttpHelper.java
public static HttpResponse putUrlEncoded(String pUrl, Map<String, String> pData) throws IOException, HttpClientException, HttpServerException { HttpPut put = new HttpPut(pUrl); String body = urlEncodeKeysAndValues(pData); insertUrlEncodedAcceptingJson(body, put); return executeHTTPMethod(put, PUT_TIMEOUT); }
From source file:com.sparkplatform.api.core.ConnectionApacheHttp.java
@Override public Response put(String path, String body, Map<String, String> options) throws SparkAPIClientException { HttpPut r = new HttpPut(path); setHeaders(r);/*from www. j a v a2s .c o m*/ setData(r, body); return request(r); }
From source file:com.intel.iotkitlib.http.HttpPutTask.java
public CloudResponse doSync(final String url) { HttpClient httpClient = new DefaultHttpClient(); try {//from w w w. j a va 2 s .c o m 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 new CloudResponse(false, cEx.getMessage()); } catch (Exception e) { Log.e(TAG, e.toString()); e.printStackTrace(); return new CloudResponse(false, e.getMessage()); } }
From source file:dk.i2m.drupal.resource.NodeResource.java
public NodeMessage update(Long id, UrlEncodedFormEntity uefe) throws HttpResponseException, IOException { URLBuilder builder = new URLBuilder(getDc().getHostname()); builder.add(getDc().getEndpoint());/*from w w w.jav a 2 s . com*/ builder.add(getAlias()); builder.add(id); HttpPut method = new HttpPut(builder.toURI()); method.setEntity(uefe); ResponseHandler<String> handler = new BasicResponseHandler(); String response = getDc().getHttpClient().execute(method, handler); return new Gson().fromJson(response, NodeMessage.class); }
From source file:com.servioticy.restclient.RestClient.java
public FutureRestResponse restRequest(String url, String body, int method, Map<String, String> headers) throws RestClientException, RestClientErrorCodeException { HttpRequestBase httpMethod;/* ww w . jav a 2s . co m*/ StringEntity input; switch (method) { case POST: try { input = new StringEntity(body); } catch (UnsupportedEncodingException e) { logger.error(e.getMessage()); throw new RestClientException(e.getMessage()); } input.setContentType("application/json"); HttpPost httpPost = new HttpPost(url); httpPost.setEntity(input); httpMethod = httpPost; break; case PUT: try { input = new StringEntity(body); } catch (UnsupportedEncodingException e) { logger.error(e.getMessage()); throw new RestClientException(e.getMessage()); } input.setContentType("application/json"); HttpPut httpPut = new HttpPut(url); httpPut.setEntity(input); httpMethod = httpPut; break; case DELETE: httpMethod = new HttpDelete(url); break; case GET: httpMethod = new HttpGet(url); break; default: return null; } if (headers != null) { for (Map.Entry<String, String> header : headers.entrySet()) { httpMethod.addHeader(header.getKey(), header.getValue()); } } Future<HttpResponse> response; try { response = httpClient.execute(httpMethod, null); } catch (Exception e) { logger.error(e.getMessage()); throw new RestClientException(e.getMessage()); } // TODO Check the errors nicely FutureRestResponse rr = new FutureRestResponse(response); return rr; }
From source file:eu.betaas.betaasandroidapp.rest.RestClient.java
public String[] putResource(String path, Map<HeaderType, String> headers) { HttpHost target = new HttpHost(endpointUrl, port); String result[];/*from ww w . j av a2 s . c o m*/ try { // specify the get request HttpPut putRequest = new HttpPut(path); for (HeaderType header : headers.keySet()) { putRequest.setHeader(HEADERS.get(header), headers.get(header)); } HttpResponse httpResponse = httpclient.execute(target, putRequest); result = getResponse(httpResponse); } catch (Exception e) { result = new String[2]; result[0] = "clientException"; result[1] = e.getMessage(); } return result; }