List of usage examples for org.apache.http.client.methods HttpRequestBase abort
public void abort()
From source file:Main.java
private static void abortConnection(final HttpRequestBase httpRequestBase, final HttpClient httpclient) { if (httpRequestBase != null) { httpRequestBase.abort(); }//from w ww . j a v a2 s .c o m if (httpclient != null) { httpclient.getConnectionManager().shutdown(); } }
From source file:org.eclipse.mylyn.commons.repositories.http.core.HttpUtil.java
public static HttpResponse execute(final AbstractHttpClient client, final HttpHost host, final HttpContext context, final HttpRequestBase method, final IProgressMonitor progress) throws IOException { Assert.isNotNull(client);/*from ww w .j a va 2 s.c om*/ Assert.isNotNull(method); final IOperationMonitor monitor = OperationUtil.convert(progress); ICancellableOperation operation = new ICancellableOperation() { @Override public void abort() { method.abort(); } @Override public boolean isCanceled() { return monitor.isCanceled(); } }; CancellableOperationMonitorThread thread = null; if (context != null) { thread = (CancellableOperationMonitorThread) context.getAttribute(CONTEXT_KEY_MONITOR_THREAD); } if (thread != null) { thread.addOperation(operation); } try { return client.execute(host, method, context); } catch (InterruptedIOException e) { if (monitor.isCanceled()) { throw new OperationCanceledException(); } throw e; } finally { if (thread != null) { thread.removeOperation(operation); } } }
From source file:bixo.fetcher.SimpleHttpFetcher.java
private static void safeAbort(boolean needAbort, HttpRequestBase request) { if (needAbort && (request != null)) { try {//from w ww .j a va 2 s . c om request.abort(); } catch (Throwable t) { // Ignore any errors } } }
From source file:org.apache.tuscany.sca.binding.atom.provider.AtomBindingInvoker.java
private static void release(HttpRequestBase request, HttpResponse response) { if (response != null) { HttpEntity entity = response.getEntity(); if (entity != null) { try { entity.consumeContent(); } catch (IOException e) { if (request != null) { request.abort(); }// w w w . java2s . com } } } }
From source file:org.eclipse.mylyn.commons.http.HttpUtil.java
public static HttpResponse execute(final AbstractHttpClient client, final HttpHost host, final HttpContext context, final HttpRequestBase method, IProgressMonitor monitor) throws IOException { Assert.isNotNull(client);// ww w . j a v a2 s . co m Assert.isNotNull(method); monitor = Policy.monitorFor(monitor); MonitoredRequest<HttpResponse> executor = new MonitoredRequest<HttpResponse>(monitor) { @Override public void abort() { super.abort(); method.abort(); } @Override public HttpResponse execute() throws Exception { return client.execute(host, method, context); } }; return executeInternal(monitor, executor); }
From source file:net.java.sip.communicator.service.httputil.HttpUtils.java
/** * Executes the method and return the result. Handle ask for password * when hitting password protected site. * Keep asking for password till user clicks cancel or enters correct * password. When 'remember password' is checked password is saved, if this * password and username are not correct clear them, if there are correct * they stay saved.// w w w. j a va 2s . co m * @param httpClient the configured http client to use. * @param req the request for now it is get or post. * @param redirectHandler handles redirection, should we redirect and * the actual redirect. * @param parameters if we are redirecting we can use already filled * username and password in order to avoid asking the user twice. * * @return the result http entity. */ private static HttpEntity executeMethod(DefaultHttpClient httpClient, HttpRequestBase req, RedirectHandler redirectHandler, List<NameValuePair> parameters) throws Throwable { // do it when response (first execution) or till we are unauthorized HttpResponse response = null; int redirects = 0; while (response == null || response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED || response.getStatusLine().getStatusCode() == HttpStatus.SC_FORBIDDEN) { // if we were unauthorized, lets clear the method and recreate it // for new connection with new credentials. if (response != null && (response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED || response.getStatusLine().getStatusCode() == HttpStatus.SC_FORBIDDEN)) { if (logger.isDebugEnabled()) logger.debug("Will retry http connect and " + "credentials input as latest are not correct!"); throw new AuthenticationException("Authorization needed"); } else response = httpClient.execute(req); // if user click cancel no need to retry, stop trying if (!((HTTPCredentialsProvider) httpClient.getCredentialsProvider()).retry()) { if (logger.isDebugEnabled()) logger.debug("User canceled credentials input."); break; } // check for post redirect as post redirects are not handled // automatically // RFC2616 (10.3 Redirection 3xx). // The second request (forwarded method) can only be a GET or HEAD. Header locationHeader = response.getFirstHeader("location"); if (locationHeader != null && req instanceof HttpPost && (response.getStatusLine().getStatusCode() == HttpStatus.SC_MOVED_PERMANENTLY || response.getStatusLine().getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY || response.getStatusLine().getStatusCode() == HttpStatus.SC_SEE_OTHER) && redirects < MAX_REDIRECTS) { HttpRequestBase oldreq = req; oldreq.abort(); String newLocation = locationHeader.getValue(); // lets ask redirection handler if any if (redirectHandler != null && redirectHandler.handleRedirect(newLocation, parameters)) { return null; } req = new HttpGet(newLocation); req.setParams(oldreq.getParams()); req.setHeaders(oldreq.getAllHeaders()); redirects++; response = httpClient.execute(req); } } // if we finally managed to login return the result. if (response != null && response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { return response.getEntity(); } // is user has canceled no result needed. return null; }
From source file:org.commonjava.couch.io.CouchHttpClient.java
public void cleanup(final HttpRequestBase request) { request.abort(); client.getConnectionManager().closeExpiredConnections(); client.getConnectionManager().closeIdleConnections(2, TimeUnit.SECONDS); }
From source file:com.twotoasters.android.hoot.HootTransportHttpClient.java
@Override public void cancel(HootRequest request) { synchronized (mRequestBaseMap) { HttpRequestBase requestBase = mRequestBaseMap.get(request); if (requestBase != null) { requestBase.abort(); }/* w w w . j a v a 2 s .c o m*/ } }
From source file:com.woonoz.proxy.servlet.HttpRequestHandler.java
private void handleException(HttpRequestBase httpCommand, Exception e) { logger.error("Exception handling httpCommand: {}", (httpCommand != null ? httpCommand.getURI() : "(missing)"), e); if (httpCommand != null) { httpCommand.abort(); }/*from ww w. j a v a 2s . c om*/ }
From source file:ee.ria.xroad.common.util.HttpSender.java
private void doRequest(HttpRequestBase request) throws Exception { this.request = request; addAdditionalHeaders();//from w ww. j a v a 2 s . c o m try { HttpResponse response = client.execute(request, context); handleResponse(response); } catch (Exception ex) { log.debug("Request failed", ex); request.abort(); throw ex; } }