List of usage examples for org.apache.commons.httpclient.methods HeadMethod HeadMethod
public HeadMethod(String paramString)
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();/*from w w w .j a v a2 s .c om*/ return method; }
From source file:ir.keloud.android.lib.test_project.test.KeloudClientTest.java
public void testExecuteMethodWithTimeouts() throws HttpException, IOException { KeloudClient client = new KeloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager()); int connectionTimeout = client.getConnectionTimeout(); int readTimeout = client.getDataTimeout(); HeadMethod head = new HeadMethod(client.getWebdavUri() + "/"); try {/*from w w w .ja va 2 s . c o m*/ client.executeMethod(head, 1, 1000); throw new AssertionFailedError("Completed HEAD with impossible read timeout"); } catch (Exception e) { Log.e("KeloudClientTest", "EXCEPTION", e); assertTrue("Unexcepted exception " + e.getLocalizedMessage(), (e instanceof ConnectTimeoutException) || (e instanceof SocketTimeoutException)); } finally { head.releaseConnection(); } assertEquals("Connection timeout was changed for future requests", connectionTimeout, client.getConnectionTimeout()); assertEquals("Read timeout was changed for future requests", readTimeout, client.getDataTimeout()); try { client.executeMethod(head, 1000, 1); throw new AssertionFailedError("Completed HEAD with impossible connection timeout"); } catch (Exception e) { Log.e("KeloudClientTest", "EXCEPTION", e); assertTrue("Unexcepted exception " + e.getLocalizedMessage(), (e instanceof ConnectTimeoutException) || (e instanceof SocketTimeoutException)); } finally { head.releaseConnection(); } assertEquals("Connection timeout was changed for future requests", connectionTimeout, client.getConnectionTimeout()); assertEquals("Read timeout was changed for future requests", readTimeout, client.getDataTimeout()); }
From source file:com.owncloud.android.lib.test_project.test.OwnCloudClientTest.java
public void testExecuteMethodWithTimeouts() throws HttpException, IOException { OwnCloudClient client = new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager()); int connectionTimeout = client.getConnectionTimeout(); int readTimeout = client.getDataTimeout(); HeadMethod head = new HeadMethod(client.getWebdavUri() + "/"); try {//from w w w .j a v a 2 s.c o m client.executeMethod(head, 1, 1000); throw new AssertionFailedError("Completed HEAD with impossible read timeout"); } catch (Exception e) { Log.e("OwnCloudClientTest", "EXCEPTION", e); assertTrue("Unexcepted exception " + e.getLocalizedMessage(), (e instanceof ConnectTimeoutException) || (e instanceof SocketTimeoutException)); } finally { head.releaseConnection(); } assertEquals("Connection timeout was changed for future requests", connectionTimeout, client.getConnectionTimeout()); assertEquals("Read timeout was changed for future requests", readTimeout, client.getDataTimeout()); try { client.executeMethod(head, 1000, 1); throw new AssertionFailedError("Completed HEAD with impossible connection timeout"); } catch (Exception e) { Log.e("OwnCloudClientTest", "EXCEPTION", e); assertTrue("Unexcepted exception " + e.getLocalizedMessage(), (e instanceof ConnectTimeoutException) || (e instanceof SocketTimeoutException)); } finally { head.releaseConnection(); } assertEquals("Connection timeout was changed for future requests", connectionTimeout, client.getConnectionTimeout()); assertEquals("Read timeout was changed for future requests", readTimeout, client.getDataTimeout()); }
From source file:com.cerema.cloud2.lib.common.OwnCloudClient.java
/** * Check if a file exists in the OC server * //from www. j a v a 2 s. c o m * @deprecated Use ExistenceCheckOperation instead * * @return 'true' if the file exists; 'false' it doesn't exist * @throws Exception When the existence could not be determined */ @Deprecated public boolean existsFile(String path) throws IOException, HttpException { HeadMethod head = new HeadMethod(getWebdavUri() + 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.smartitengineering.util.rest.client.jersey.cache.CustomApacheHttpClientResponseResolver.java
/** * Determines the HttpClient's request method from the HTTPMethod enum. * * @param method the HTTPCache enum that determines * @param requestURI the request URI./* w ww . jav a 2 s . c o m*/ * @return a new HttpMethod subclass. */ protected HttpMethod getMethod(HTTPMethod method, URI requestURI) { if (CONNECT.equals(method)) { HostConfiguration config = new HostConfiguration(); config.setHost(requestURI.getHost(), requestURI.getPort(), requestURI.getScheme()); return new ConnectMethod(config); } else if (DELETE.equals(method)) { return new CustomHttpMethod(HTTPMethod.DELETE.name(), requestURI.toString()); } else if (GET.equals(method)) { return new GetMethod(requestURI.toString()); } else if (HEAD.equals(method)) { return new HeadMethod(requestURI.toString()); } else if (OPTIONS.equals(method)) { return new OptionsMethod(requestURI.toString()); } else if (POST.equals(method)) { return new PostMethod(requestURI.toString()); } else if (PUT.equals(method)) { return new PutMethod(requestURI.toString()); } else if (TRACE.equals(method)) { return new TraceMethod(requestURI.toString()); } else { return new CustomHttpMethod(method.name(), requestURI.toString()); } }
From source file:com.gisgraphy.domain.geoloc.importer.ImporterHelper.java
/** * @param URL the HTTP URL/*from w ww .j av a 2 s . co 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:fr.jayasoft.ivy.url.HttpClientHandler.java
private HeadMethod doHead(URL url, int timeout) throws IOException, HttpException { HttpClient client = getClient(url);/* w w w.ja va 2 s.co m*/ client.setTimeout(timeout); HeadMethod head = new HeadMethod(url.toExternalForm()); head.setDoAuthentication(useAuthentication(url) || useProxyAuthentication()); client.executeMethod(head); return head; }
From source file:net.sf.ehcache.constructs.web.filter.SimpleCachingHeadersPageCachingFilterTest.java
/** * HEAD methods return an empty response body. If a HEAD request populates * a cache and then a GET follorws, a blank page will result. * This test ensures that the SimplePageCachingFilter implements calculateKey * properly to avoid this problem./*from www. j a v a2s .c o m*/ */ @Test public void testHeadThenGetOnCachedPage() throws Exception { HttpClient httpClient = new HttpClient(); HttpMethod httpMethod = new HeadMethod(buildUrl(cachedPageUrl)); int responseCode = httpClient.executeMethod(httpMethod); //httpclient follows redirects, so gets the home page. assertEquals(HttpURLConnection.HTTP_OK, responseCode); String responseBody = httpMethod.getResponseBodyAsString(); assertNull(responseBody); assertNull(httpMethod.getResponseHeader("Content-Encoding")); httpMethod = new GetMethod(buildUrl(cachedPageUrl)); responseCode = httpClient.executeMethod(httpMethod); responseBody = httpMethod.getResponseBodyAsString(); assertNotNull(responseBody); }
From source file:ir.keloud.android.lib.test_project.test.KeloudClientTest.java
public void testExecuteMethod() { KeloudClient client = new KeloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager()); HeadMethod head = new HeadMethod(client.getWebdavUri() + "/"); int status = -1; try {// ww w . ja v a 2s . co m status = client.executeMethod(head); assertTrue("Wrong status code returned: " + status, status > 99 && status < 600); } catch (IOException e) { Log.e(TAG, "Exception in HEAD method execution", e); // TODO - make it fail? ; try several times, and make it fail if none // is right? } finally { head.releaseConnection(); } }
From source file:com.owncloud.android.lib.test_project.test.OwnCloudClientTest.java
public void testExecuteMethod() { OwnCloudClient client = new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager()); HeadMethod head = new HeadMethod(client.getWebdavUri() + "/"); int status = -1; try {//from ww w . ja v a 2 s.c om status = client.executeMethod(head); assertTrue("Wrong status code returned: " + status, status > 99 && status < 600); } catch (IOException e) { Log.e(TAG, "Exception in HEAD method execution", e); // TODO - make it fail? ; try several times, and make it fail if none // is right? } finally { head.releaseConnection(); } }