List of usage examples for org.apache.commons.httpclient.methods HeadMethod releaseConnection
@Override public void releaseConnection()
From source file:example.HelloIvy.java
public static void main(String[] args) throws Exception { String message = "Hello Ivy!"; System.out.println("standard message : " + message); System.out.println(/*from www . ja v a 2 s .com*/ "capitalized by " + WordUtils.class.getName() + " : " + WordUtils.capitalizeFully(message)); HttpClient client = new HttpClient(); HeadMethod head = new HeadMethod("http://www.ibiblio.org/"); client.executeMethod(head); int status = head.getStatusCode(); System.out.println("head status code with httpclient: " + status); head.releaseConnection(); System.out.println("now check if httpclient dependency on commons-logging has been realized"); Class<?> clss = Class.forName("org.apache.commons.logging.Log"); System.out.println("found logging class in classpath: " + clss); }
From source file:jshm.sh.Client.java
public static HeadMethod makeHeadRequest(String url) throws HttpException, IOException { HeadMethod method = new HeadMethod(url); getHttpClient().executeMethod(method); method.releaseConnection(); return method; }
From source file:com.gisgraphy.domain.geoloc.importer.ImporterHelper.java
/** * @param URL the HTTP URL//from w w w . ja v a2 s .c o m * @return The size of the HTTP file using HTTP head method. */ public static long getHttpFileSize(String URL) { HeadMethod headMethod = new HeadMethod(URL); try { client.executeMethod(headMethod); Header[] contentLengthHeaders = headMethod.getResponseHeaders("Content-Length"); if (contentLengthHeaders.length == 1) { logger.error("HTTP file " + URL + " = " + contentLengthHeaders[0].getValue()); return new Long(contentLengthHeaders[0].getValue()); } else if (contentLengthHeaders.length <= 0) { return -1L; } } catch (HttpException e) { logger.error("can not execute head method for " + URL + " : " + e.getMessage(), e); } catch (IOException e) { logger.error("can not execute head method for " + URL + " : " + e.getMessage(), e); } finally { headMethod.releaseConnection(); } return -1; }
From source file:net.sf.ufsc.http.HttpFile.java
/** * @see net.sf.ufsc.File#length()/* w w w .j a va 2 s . com*/ */ public long length() throws java.io.IOException { HeadMethod method = new HeadMethod(this.uri.toString()); try { this.execute(method); return Long.parseLong(method.getResponseHeader(CONTENT_LENGTH).getValue()); } finally { method.releaseConnection(); } }
From source file:fr.jayasoft.ivy.url.HttpClientHandler.java
public URLInfo getURLInfo(URL url, int timeout) { HeadMethod head = null; try {/* w ww .j a v a 2 s. com*/ head = doHead(url, timeout); int status = head.getStatusCode(); head.releaseConnection(); if (status == HttpStatus.SC_OK) { return new URLInfo(true, getResponseContentLength(head), getLastModified(head)); } if (status == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED) { Message.error("Your proxy requires authentication."); } else if (String.valueOf(status).startsWith("4")) { Message.verbose("CLIENT ERROR: " + head.getStatusText() + " url=" + url); } else if (String.valueOf(status).startsWith("5")) { Message.warn("SERVER ERROR: " + head.getStatusText() + " url=" + url); } Message.debug("HTTP response status: " + status + "=" + head.getStatusText() + " url=" + url); } catch (HttpException e) { Message.error("HttpClientHandler: " + e.getMessage() + ":" + e.getReasonCode() + "=" + e.getReason() + " url=" + url); } catch (UnknownHostException e) { Message.warn("Host " + e.getMessage() + " not found. url=" + url); Message.info( "You probably access the destination server through a proxy server that is not well configured."); } catch (IOException e) { Message.error("HttpClientHandler: " + e.getMessage() + " url=" + url); } finally { if (head != null) { head.releaseConnection(); } } return UNAVAILABLE; }
From source file:net.sf.ufsc.http.HttpFile.java
/** * @see net.sf.ufsc.File#lastModified()/*from w ww.j a v a 2s. c o m*/ */ public Date lastModified() throws java.io.IOException { HeadMethod method = new HeadMethod(this.uri.toString()); try { this.execute(method); return DateUtil.parseDate(method.getResponseHeader(LAST_MODIFIED).getValue()); } catch (DateParseException e) { throw new IOException(e.toString()); } finally { method.releaseConnection(); } }
From source file:com.owncloud.android.oc_framework.network.webdav.WebdavClient.java
/** * Check if a file exists in the OC server * //from w w w .jav a 2 s. co m * TODO replace with ExistenceOperation * * @return 'true' if the file exists; 'false' it doesn't exist * @throws Exception When the existence could not be determined */ public boolean existsFile(String path) throws IOException, HttpException { HeadMethod head = new HeadMethod(mUri.toString() + WebdavUtils.encodePath(path)); try { int status = executeMethod(head); Log.d(TAG, "HEAD to " + path + " finished with HTTP status " + status + ((status != HttpStatus.SC_OK) ? "(FAIL)" : "")); exhaustResponse(head.getResponseBodyAsStream()); return (status == HttpStatus.SC_OK); } finally { head.releaseConnection(); // let the connection available for other methods } }
From source file:net.sf.taverna.t2.reference.impl.external.http.HttpReference.java
@Override public String getCharset() throws DereferenceException { if (charsetFetched) return charsetName; charsetFetched = true;/* ww w . ja v a 2s .com*/ if (!httpUrl.getProtocol().equals("http") && !httpUrl.getProtocol().equals("https")) { charsetName = null; return null; } HeadMethod method = new HeadMethod(httpUrl.toExternalForm()); HttpClient httpClient = new HttpClient(); try { httpClient.executeMethod(method); charsetName = method.getResponseCharSet(); return charsetName; } catch (HttpException e) { // throw new DereferenceException(e); } catch (IOException e) { // throw new DereferenceException(e); } finally { method.releaseConnection(); } charsetName = null; return null; }
From source file:eu.alefzero.webdav.WebdavClient.java
/** * Check if a file exists in the OC server * /* w w w . j ava2 s .co m*/ * TODO replace with ExistenceOperation * * @return 'true' if the file exists; 'false' it doesn't exist * @throws Exception When the existence could not be determined */ public boolean existsFile(String path) throws IOException, HttpException { HeadMethod head = new HeadMethod(mUri.toString() + WebdavUtils.encodePath(path)); try { int status = executeMethod(head); Log_OC.d(TAG, "HEAD to " + path + " finished with HTTP status " + status + ((status != HttpStatus.SC_OK) ? "(FAIL)" : "")); exhaustResponse(head.getResponseBodyAsStream()); return (status == HttpStatus.SC_OK); } finally { head.releaseConnection(); // let the connection available for other methods } }
From source file:com.sa.npopa.samples.hbase.rest.client.Client.java
/** * Send a HEAD request // ww w. j a v a2 s . co m * @param cluster the cluster definition * @param path the path or URI * @param headers the HTTP headers to include in the request * @return a Response object with response detail * @throws IOException */ public Response head(Cluster cluster, String path, Header[] headers) throws IOException { HeadMethod method = new HeadMethod(); try { int code = execute(cluster, method, null, path); headers = method.getResponseHeaders(); return new Response(code, headers, null); } finally { method.releaseConnection(); } }