List of usage examples for org.apache.http.client.methods HttpDelete HttpDelete
public HttpDelete(final String uri)
From source file:co.uk.alt236.restclient4android.net.Connection.java
private HttpRequestBase setupHttpRequest(NetworkRequest request, URI uri) { String method = request.getAction().toUpperCase(); String body = request.getRequestBody(); HttpRequestBase httpReq = null;//from w ww. jav a 2s . c o m HttpEntity entity = null; if (body != null) { body = body.trim(); if (body.length() > 0) { entity = new ByteArrayEntity(body.getBytes()); } } if ("GET".equals(method)) { httpReq = new HttpGet(uri); } else if ("POST".equals(method)) { httpReq = new HttpPost(uri); if (entity != null) { ((HttpPost) httpReq).setEntity(entity); } } else if ("PUT".equals(method)) { httpReq = new HttpPut(uri); if (entity != null) { ((HttpPut) httpReq).setEntity(entity); } } else if ("DELETE".equals(method)) { httpReq = new HttpDelete(uri); } else if ("HEAD".equals(method)) { httpReq = new HttpHead(uri); } else if ("TRACE".equals(method)) { httpReq = new HttpTrace(uri); } else if ("OPTIONS".equals(method)) { httpReq = new HttpOptions(uri); } setAuthentication(httpReq, request); setHeaders(httpReq, request); return httpReq; }
From source file:net.lamp.support.HttpManager.java
/** * ? URL ?? * //from w w w.j ava2 s . co m * @param url ?? * @param method "GET" or "POST" * @param params ?? * @param file ?????? SdCard ? * * @return ? * @throws WeiboException ? */ public static String openUrl(String url, String method, WeiboParameters params, String file) throws WeiboException { String result = ""; try { HttpClient client = getNewHttpClient(); HttpUriRequest request = null; ByteArrayOutputStream bos = null; client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, NetStateManager.getAPN()); if (method.equals(HTTPMETHOD_GET)) { url = url + "?" + Utility.encodeUrl(params); HttpGet get = new HttpGet(url); request = get; } else if (method.equals(HTTPMETHOD_POST)) { HttpPost post = new HttpPost(url); request = post; byte[] data = null; String _contentType = params.getValue("content-type"); bos = new ByteArrayOutputStream(); if (!TextUtils.isEmpty(file)) { paramToUpload(bos, params); post.setHeader("Content-Type", MULTIPART_FORM_DATA + "; boundary=" + BOUNDARY); // ? // Utility.UploadImageUtils.revitionPostImageSize(file); imageContentToUpload(bos, file); } else { if (_contentType != null) { params.remove("content-type"); post.setHeader("Content-Type", _contentType); } else { post.setHeader("Content-Type", "application/x-www-form-urlencoded"); } String postParam = Utility.encodeParameters(params); data = postParam.getBytes("UTF-8"); bos.write(data); } data = bos.toByteArray(); bos.close(); ByteArrayEntity formEntity = new ByteArrayEntity(data); post.setEntity(formEntity); } else if (method.equals("DELETE")) { request = new HttpDelete(url); } HttpResponse response = client.execute(request); StatusLine status = response.getStatusLine(); int statusCode = status.getStatusCode(); if (statusCode != 200) { result = readHttpResponse(response); // throw new WeiboHttpException(result, statusCode); } result = readHttpResponse(response); return result; } catch (IOException e) { throw new WeiboException(e); } }
From source file:com.precioustech.fxtrading.oanda.restapi.position.OandaPositionManagementProvider.java
@Override public boolean closePosition(Long accountId, TradeableInstrument<String> instrument) { CloseableHttpClient httpClient = getHttpClient(); try {//from www . j av a 2 s .c om HttpDelete httpDelete = new HttpDelete(getPositionForInstrumentUrl(accountId, instrument)); httpDelete.setHeader(authHeader); LOG.info(TradingUtils.executingRequestMsg(httpDelete)); HttpResponse resp = httpClient.execute(httpDelete); int httpCode = resp.getStatusLine().getStatusCode(); if (httpCode == HttpStatus.SC_OK) { LOG.info(String.format("Position successfully closed for instrument %s and account %d", instrument.getInstrument(), accountId)); return true; } else { LOG.warn(String.format( "Position for instrument %s and account %d not closed. Encountered error code=%d", instrument.getInstrument(), accountId, httpCode)); } } catch (Exception ex) { LOG.error(String.format("error encountered whilst closing position for instrument %s and account %d", instrument.getInstrument(), accountId), ex); } finally { TradingUtils.closeSilently(httpClient); } return false; }
From source file:com.gooddata.http.client.LoginSSTRetrievalStrategy.java
@Override public void logout(final HttpClient httpClient, final HttpHost httpHost, final String url, final String sst, final String tt) throws IOException, GoodDataLogoutException { notNull(httpClient, "client can't be null"); notNull(httpHost, "host can't be null"); notEmpty(url, "url can't be empty"); notEmpty(sst, "SST can't be empty"); notEmpty(tt, "TT can't be empty"); log.debug("performing logout"); final HttpDelete request = new HttpDelete(url); try {// w ww.java2s . co m request.setHeader(SST_HEADER, sst); request.setHeader(TT_HEADER, tt); final HttpResponse response = httpClient.execute(httpHost, request); final StatusLine statusLine = response.getStatusLine(); if (statusLine.getStatusCode() != HttpStatus.SC_NO_CONTENT) { throw new GoodDataLogoutException("Logout unsuccessful using http", statusLine.getStatusCode(), statusLine.getReasonPhrase()); } } finally { request.reset(); } }
From source file:org.apache.stratos.metadata.client.rest.DefaultRestClient.java
public HttpResponse doDelete(String resourcePath) throws RestClientException { HttpDelete delete = new HttpDelete(resourcePath); setAuthHeader(delete);//from ww w .ja va 2 s . c o m try { return httpClient.execute(delete); } catch (IOException e) { String errorMsg = "Error while executing DELETE statement"; log.error(errorMsg, e); throw new RestClientException(errorMsg, e); } finally { delete.releaseConnection(); } }
From source file:com.vmware.photon.controller.nsxclient.RestClient.java
/** * Creates a HTTP request object./*from w ww . j ava 2 s . c o m*/ */ private HttpUriRequest getHttpRequest(final Method method, final String path, final HttpEntity payload) throws IOException { String uri = target + path; HttpUriRequest request; switch (method) { case GET: request = new HttpGet(uri); break; case PUT: request = new HttpPut(uri); ((HttpPut) request).setEntity(payload); break; case POST: request = new HttpPost(uri); ((HttpPost) request).setEntity(payload); break; case DELETE: request = new HttpDelete(uri); break; default: throw new RuntimeException("Unknown method: " + method); } return request; }
From source file:com.indoqa.httpproxy.HttpClientProxy.java
private HttpUriRequest createProxyRequest(String method, String url) { switch (method) { case METHOD_GET: return new HttpGet(url); case METHOD_POST: return new HttpPost(url); case METHOD_PUT: return new HttpPut(url); case METHOD_DELETE: return new HttpDelete(url); default://from www . j av a 2s . co m throw new IllegalArgumentException("Proxy doesn't support method: " + method); } }
From source file:org.esxx.js.protocol.HTTPHandler.java
@Override public Object remove(Context cx, Scriptable thisObj, ContentType recv_ct) throws Exception { Result result = sendRequest(cx, thisObj, recv_ct, new HttpDelete(jsuri.getURI())); if (result.status < 200 || result.status >= 300) { throw new JavaScriptException(makeJSResponse(cx, thisObj, result), null, 0); }//w w w . ja v a 2 s .co m return result.object; }
From source file:org.fashiontec.bodyapps.sync.Sync.java
/** * Manages delete requests./* ww w .j a va 2 s.c om*/ * * @param url * @param conTimeOut * @param socTimeOut * @return */ public HttpResponse DELETE(String url, int conTimeOut, int socTimeOut) { HttpResponse response = null; try { HttpParams httpParameters = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParameters, conTimeOut); HttpConnectionParams.setSoTimeout(httpParameters, socTimeOut); HttpClient client = new DefaultHttpClient(httpParameters); HttpDelete request = new HttpDelete(url); request.setHeader("Accept", "application/json"); response = client.execute(request); } catch (Exception e) { Log.e(TAG, e.getMessage()); } return response; }
From source file:org.deviceconnect.android.profile.restful.test.NormalLightProfileTestCase.java
/** * ????./* ww w .j ava 2 s . c o m*/ * <pre> * ?HTTP * Method: DELETE * Path: /light?serviceId=xxxx&lightId=xxx * </pre> * <pre> * ?? * result?0??????? * </pre> */ @Test public void testDeleteLight() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(LightProfile.PROFILE_NAME); builder.addParameter(AuthorizationProfile.PARAM_ACCESS_TOKEN, getAccessToken()); builder.addParameter(DConnectProfileConstants.PARAM_SERVICE_ID, getServiceId()); builder.addParameter(LightProfile.PARAM_LIGHT_ID, LIGHT_ID); try { HttpUriRequest request = new HttpDelete(builder.toString()); JSONObject response = sendRequest(request); assertResultOK(response); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } }