List of usage examples for org.apache.commons.httpclient.methods DeleteMethod DeleteMethod
public DeleteMethod(String paramString)
From source file:com.cloud.network.bigswitch.BigSwitchVnsApi.java
protected HttpMethod createMethod(String type, String uri, int port) throws BigSwitchVnsApiException { String url;/* ww w . j av a 2s . c om*/ try { url = new URL(s_protocol, _host, port, uri).toString(); } catch (MalformedURLException e) { s_logger.error("Unable to build BigSwitch API URL", e); throw new BigSwitchVnsApiException("Unable to build v API URL", e); } if ("post".equalsIgnoreCase(type)) { return new PostMethod(url); } else if ("get".equalsIgnoreCase(type)) { return new GetMethod(url); } else if ("delete".equalsIgnoreCase(type)) { return new DeleteMethod(url); } else if ("put".equalsIgnoreCase(type)) { return new PutMethod(url); } else { throw new BigSwitchVnsApiException("Requesting unknown method type"); } }
From source file:lucee.commons.net.http.httpclient3.HTTPEngine3Impl.java
public static HTTPResponse delete(URL url, String username, String password, int timeout, int maxRedirect, String charset, String useragent, ProxyData proxy, Header[] headers) throws IOException { return _invoke(new DeleteMethod(url.toExternalForm()), url, username, password, timeout, maxRedirect, charset, useragent, proxy, headers, null, null); }
From source file:com.progress.codeshare.esbservice.http.HTTPService.java
public void service(final XQServiceContext ctx) throws XQServiceException { try {/* w ww. j a v a 2 s. co m*/ final XQMessageFactory factory = ctx.getMessageFactory(); final XQParameters params = ctx.getParameters(); final int messagePart = params.getIntParameter(PARAM_MESSAGE_PART, XQConstants.PARAM_STRING); final String method = params.getParameter(PARAM_METHOD, XQConstants.PARAM_STRING); final String uri = params.getParameter(PARAM_URI, XQConstants.PARAM_STRING); while (ctx.hasNextIncoming()) { final XQEnvelope env = ctx.getNextIncoming(); final XQMessage origMsg = env.getMessage(); final XQMessage newMsg = factory.createMessage(); final HttpClient client = new HttpClient(); final Iterator headerIterator = origMsg.getHeaderNames(); if (METHOD_DELETE.equals(method)) { final HttpMethodBase req = new DeleteMethod(uri); /* * Copy all XQ headers and extract HTTP headers and * parameters */ while (headerIterator.hasNext()) { final String header = (String) headerIterator.next(); newMsg.setHeaderValue(header, origMsg.getHeaderValue(header)); final Matcher matcher = PATTERN_HEADER.matcher(header); if (matcher.find()) req.addRequestHeader(matcher.group(1), (String) origMsg.getHeaderValue(matcher.group())); } client.executeMethod(req); /* Transform all HTTP to XQ headers */ final Header[] headers = req.getResponseHeaders(); for (int i = 0; i < headers.length; i++) newMsg.setHeaderValue(PREFIX_HEADER + headers[i].getName(), headers[i].getValue()); final XQPart newPart = newMsg.createPart(); newPart.setContentId("Result"); newPart.setContent(new String(req.getResponseBody()), req.getResponseHeader("Content-Type").getValue()); newMsg.addPart(newPart); } else if (METHOD_GET.equals(method)) { final HttpMethodBase req = new GetMethod(); final List paramList = new ArrayList(); /* * Copy all XQ headers and extract HTTP headers and * parameters */ while (headerIterator.hasNext()) { final String header = (String) headerIterator.next(); newMsg.setHeaderValue(header, origMsg.getHeaderValue(header)); final Matcher headerMatcher = PATTERN_HEADER.matcher(header); if (headerMatcher.find()) { req.addRequestHeader(headerMatcher.group(1), (String) origMsg.getHeaderValue(headerMatcher.group())); continue; } final Matcher paramMatcher = PATTERN_PARAM.matcher(header); if (paramMatcher.find()) paramList.add(new NameValuePair(paramMatcher.group(1), (String) origMsg.getHeaderValue(paramMatcher.group()))); } req.setQueryString((NameValuePair[]) paramList.toArray(new NameValuePair[] {})); client.executeMethod(req); /* Transform all HTTP to XQ headers */ final Header[] headers = req.getResponseHeaders(); for (int i = 0; i < headers.length; i++) newMsg.setHeaderValue(PREFIX_HEADER + headers[i].getName(), headers[i].getValue()); final XQPart newPart = newMsg.createPart(); newPart.setContentId("Result"); newPart.setContent(new String(req.getResponseBody()), req.getResponseHeader("Content-Type").getValue()); newMsg.addPart(newPart); } else if (METHOD_POST.equals(method)) { final PostMethod req = new PostMethod(uri); /* * Copy all XQ headers and extract HTTP headers and * parameters */ while (headerIterator.hasNext()) { final String header = (String) headerIterator.next(); newMsg.setHeaderValue(header, origMsg.getHeaderValue(header)); final Matcher headerMatcher = PATTERN_HEADER.matcher(header); if (headerMatcher.find()) { req.addRequestHeader(headerMatcher.group(1), (String) origMsg.getHeaderValue(headerMatcher.group())); continue; } final Matcher paramMatcher = PATTERN_PARAM.matcher(header); if (paramMatcher.find()) req.addParameter(new NameValuePair(paramMatcher.group(1), (String) origMsg.getHeaderValue(paramMatcher.group()))); } final XQPart origPart = origMsg.getPart(messagePart); req.setRequestEntity(new StringRequestEntity((String) origPart.getContent(), origPart.getContentType(), null)); client.executeMethod(req); /* Transform all HTTP to XQ headers */ final Header[] headers = req.getResponseHeaders(); for (int i = 0; i < headers.length; i++) newMsg.setHeaderValue(PREFIX_HEADER + headers[i].getName(), headers[i].getValue()); final XQPart newPart = newMsg.createPart(); newPart.setContentId("Result"); newPart.setContent(new String(req.getResponseBody()), req.getResponseHeader("Content-Type").getValue()); newMsg.addPart(newPart); } else if (METHOD_PUT.equals(method)) { final EntityEnclosingMethod req = new PutMethod(uri); /* Copy all XQ headers and extract HTTP headers */ while (headerIterator.hasNext()) { final String header = (String) headerIterator.next(); newMsg.setHeaderValue(header, origMsg.getHeaderValue(header)); final Matcher matcher = PATTERN_HEADER.matcher(header); if (matcher.find()) req.addRequestHeader(matcher.group(1), (String) origMsg.getHeaderValue(matcher.group())); } final XQPart origPart = origMsg.getPart(messagePart); req.setRequestEntity(new StringRequestEntity((String) origPart.getContent(), origPart.getContentType(), null)); client.executeMethod(req); /* Transform all HTTP to XQ headers */ final Header[] headers = req.getResponseHeaders(); for (int i = 0; i < headers.length; i++) newMsg.setHeaderValue(PREFIX_HEADER + headers[i].getName(), headers[i].getValue()); final XQPart newPart = newMsg.createPart(); newPart.setContentId("Result"); newPart.setContent(new String(req.getResponseBody()), req.getResponseHeader("Content-Type").getValue()); newMsg.addPart(newPart); } env.setMessage(newMsg); final Iterator addressIterator = env.getAddresses(); if (addressIterator.hasNext()) ctx.addOutgoing(env); } } catch (final Exception e) { throw new XQServiceException(e); } }
From source file:demo.jaxrs.client.Client.java
public void deleteCustomerInfo(String name, String password, int id) throws Exception { System.out.println("HTTP DELETE to update customer info, user : " + name + ", password : " + password); System.out.println("Confirming a customer with id " + id + " exists first"); getCustomerInfo(name, password, id); System.out.println("Deleting now..."); DeleteMethod del = new DeleteMethod("http://localhost:9002/customerservice/customers/" + id); setMethodHeaders(del, name, password); handleHttpMethod(del);/*from w w w . j ava 2 s. com*/ System.out.println("Confirming a customer with id " + id + " does not exist anymore"); getCustomerInfo(name, password, id); }
From source file:com.zimbra.cs.store.http.HttpStoreManager.java
@Override public boolean deleteFromStore(String locator, Mailbox mbox) throws IOException { HttpClient client = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient(); DeleteMethod delete = new DeleteMethod(getDeleteUrl(mbox, locator)); try {/*from w ww .ja va 2 s . c o m*/ int statusCode = HttpClientUtil.executeMethod(client, delete); if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_NO_CONTENT) { return true; } else if (statusCode == HttpStatus.SC_NOT_FOUND) { return false; } else { throw new IOException("unexpected return code during blob DELETE: " + delete.getStatusText()); } } finally { delete.releaseConnection(); } }
From source file:com.noelios.restlet.ext.httpclient.HttpMethodCall.java
/** * Constructor.//from w w w .jav a2s . co m * * @param helper * The parent HTTP client helper. * @param method * The method name. * @param requestUri * The request URI. * @param hasEntity * Indicates if the call will have an entity to send to the * server. * @throws IOException */ public HttpMethodCall(HttpClientHelper helper, final String method, String requestUri, boolean hasEntity) throws IOException { super(helper, method, requestUri); this.clientHelper = helper; if (requestUri.startsWith("http")) { if (method.equalsIgnoreCase(Method.GET.getName())) { this.httpMethod = new GetMethod(requestUri); } else if (method.equalsIgnoreCase(Method.POST.getName())) { this.httpMethod = new PostMethod(requestUri); } else if (method.equalsIgnoreCase(Method.PUT.getName())) { this.httpMethod = new PutMethod(requestUri); } else if (method.equalsIgnoreCase(Method.HEAD.getName())) { this.httpMethod = new HeadMethod(requestUri); } else if (method.equalsIgnoreCase(Method.DELETE.getName())) { this.httpMethod = new DeleteMethod(requestUri); } else if (method.equalsIgnoreCase(Method.CONNECT.getName())) { final HostConfiguration host = new HostConfiguration(); host.setHost(new URI(requestUri, false)); this.httpMethod = new ConnectMethod(host); } else if (method.equalsIgnoreCase(Method.OPTIONS.getName())) { this.httpMethod = new OptionsMethod(requestUri); } else if (method.equalsIgnoreCase(Method.TRACE.getName())) { this.httpMethod = new TraceMethod(requestUri); } else { this.httpMethod = new EntityEnclosingMethod(requestUri) { @Override public String getName() { return method; } }; } this.httpMethod.setFollowRedirects(this.clientHelper.isFollowRedirects()); this.httpMethod.setDoAuthentication(false); if (this.clientHelper.getRetryHandler() != null) { try { this.httpMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, Engine.loadClass(this.clientHelper.getRetryHandler()).newInstance()); } catch (Exception e) { this.clientHelper.getLogger().log(Level.WARNING, "An error occurred during the instantiation of the retry handler.", e); } } this.responseHeadersAdded = false; setConfidential(this.httpMethod.getURI().getScheme().equalsIgnoreCase(Protocol.HTTPS.getSchemeName())); } else { throw new IllegalArgumentException("Only HTTP or HTTPS resource URIs are allowed here"); } }
From source file:com.jivesoftware.os.jive.utils.http.client.ApacheHttpClient31BackedHttpClient.java
@Override public HttpStreamResponse getStream(String path, int timeoutMillis) throws HttpClientException { return executeMethodStream(new DeleteMethod(path), timeoutMillis); }
From source file:jails.http.client.CommonsClientHttpRequestFactory.java
/** * Create a Commons HttpMethodBase object for the given HTTP method * and URI specification.//from w w w . j a va 2s . c o m * @param httpMethod the HTTP method * @param uri the URI * @return the Commons HttpMethodBase object */ protected HttpMethodBase createCommonsHttpMethod(HttpMethod httpMethod, String uri) { switch (httpMethod) { case GET: return new GetMethod(uri); case DELETE: return new DeleteMethod(uri); case HEAD: return new HeadMethod(uri); case OPTIONS: return new OptionsMethod(uri); case POST: return new PostMethod(uri); case PUT: return new PutMethod(uri); case TRACE: return new TraceMethod(uri); default: throw new IllegalArgumentException("Invalid HTTP method: " + httpMethod); } }
From source file:com.arjuna.qa.junit.HttpUtils.java
public static HttpMethodBase createMethod(URL url, int type) { HttpMethodBase request = null;/* w w w . j a va2s . com*/ switch (type) { case GET: request = new GetMethod(url.toString()); break; case POST: request = new PostMethod(url.toString()); break; case HEAD: request = new HeadMethod(url.toString()); break; case OPTIONS: request = new OptionsMethod(url.toString()); break; case PUT: request = new PutMethod(url.toString()); break; case DELETE: request = new DeleteMethod(url.toString()); break; case TRACE: request = new TraceMethod(url.toString()); break; } return request; }
From source file:com.cloud.network.bigswitch.BigSwitchBcfApi.java
protected HttpMethod createMethod(final String type, final String uri, final int port) throws BigSwitchBcfApiException { String url;// ww w. j av a2s . c o m try { url = new URL(S_PROTOCOL, host, port, uri).toString(); } catch (MalformedURLException e) { S_LOGGER.error("Unable to build Big Switch API URL", e); throw new BigSwitchBcfApiException("Unable to build Big Switch API URL", e); } if ("post".equalsIgnoreCase(type)) { return new PostMethod(url); } else if ("get".equalsIgnoreCase(type)) { return new GetMethod(url); } else if ("delete".equalsIgnoreCase(type)) { return new DeleteMethod(url); } else if ("put".equalsIgnoreCase(type)) { return new PutMethod(url); } else { throw new BigSwitchBcfApiException("Requesting unknown method type"); } }