@Override public Header[] extractResult(HttpHead req, HttpResponse resp) throws IOException { if (resp.getStatusLine().getStatusCode() == SC_NOT_FOUND) { throw new FileNotFoundException("Not Found " + req.getURI()); } return resp.getAllHeaders(); }
public static Deque<URI> expand(String uri) { try { HttpHead head = new HttpHead(uri); SpyStrategy spy = new SpyStrategy(head.getURI()); DefaultHttpClient client = new DefaultHttpClient(); client.setRedirectStrategy(spy); // FIXME: the following completely ignores HTTP errors: client.execute(head); return spy.history; } catch (IOException e) { throw new RuntimeException(e); } }
private int pingUrl() { final HttpHead httpHead = new HttpHead( getWebappUrl() ); try { final HttpResponse response = httpClient.execute( httpHead ); return response.getStatusLine().getStatusCode(); } catch ( IOException e ) { logger.debug( "Ignoring exception while pinging URL " + httpHead.getURI(), e ); return -1; } }
@Override public HttpResponse doHead(HttpHead httpget) throws HttpException { // return immediately if we are shutting down and no longer active if (!active.get()) { return null; } try { HttpResponse response = httpClient.execute(httpget); StatusLine status = response.getStatusLine(); int statusCode = status.getStatusCode(); if (statusCode >= 400) { throw new HttpException(statusCode, httpget.getURI()+":"+status.getReasonPhrase()); } return response; } catch (HttpException he) { throw he; } catch (Exception e) { LOG.error("Error getting url: " + httpget.getURI(), e); httpget.abort(); throw new HttpException(e); } }
/** * Uses the HTTP HEAD Method to check if the connection is possible. * @param httpClient HTTPClient to make the request * @return StatusCode * @throws CalDAV4JException when Status is not {@link CalDAVStatus#SC_OK} */ public int testConnection(HttpClient httpClient) throws CalDAV4JException { HttpHead method = new HttpHead(getCalendarCollectionRoot()); HttpResponse response = null; try { response = httpClient.execute(getDefaultHttpHost(method.getURI()), method); } catch (Exception e) { throw new CalDAV4JException(e.getMessage(), new Throwable(e.getCause())); } switch (response.getStatusLine().getStatusCode()) { case CalDAVStatus.SC_OK: break; default: throw new BadStatusException(response.getStatusLine().getStatusCode(), method.getMethod(), getCalendarCollectionRoot()); } return response.getStatusLine().getStatusCode(); }
requestOptions.getMaxRedirects(), head.getURI().toString(), httpResponse.getAllHeaders(), null);
requestOptions.getMaxRedirects(), head.getURI().toString(), httpResponse.getAllHeaders(), null);
requestOptions.getMaxRedirects(), head.getURI().toString(), httpResponse.getAllHeaders(), null);
requestOptions.getMaxRedirects(), head.getURI().toString(), httpResponse.getAllHeaders(), null);