List of usage examples for org.apache.commons.httpclient.methods HeadMethod HeadMethod
public HeadMethod(String paramString)
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(/* w w w . j a v a2 s. c om*/ "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:com.edge.media.service.util.HttpUtil.java
public void verifyUrl(String url, String path, String suffix) throws Exception { HttpClient client = new HttpClient(); HttpMethod method = new HeadMethod(url + path + suffix); int statusCode = 0; try {/*w w w . j a v a 2s . c o m*/ statusCode = client.executeMethod(method); } catch (IOException e) { // do nothing } method.releaseConnection(); if (statusCode != HttpStatus.SC_OK) { StringBuilder err = new StringBuilder("Stream does not exist: "); err.append(path); err.append(", "); err.append(statusCode); throw new Exception(err.toString()); } }
From source file:net.sf.j2ep.requesthandlers.BasicRequestHandler.java
/** * Will only set the headers.//from w w w . j ava 2s .c om * @throws HttpException * * @see net.sf.j2ep.model.RequestHandler#process(javax.servlet.http.HttpServletRequest, java.lang.String) */ public HttpMethod process(HttpServletRequest request, String url) throws HttpException { HttpMethodBase method = null; if (request.getMethod().equalsIgnoreCase("GET")) { method = new GetMethod(url); } else if (request.getMethod().equalsIgnoreCase("HEAD")) { method = new HeadMethod(url); } else if (request.getMethod().equalsIgnoreCase("DELETE")) { method = new DeleteMethod(url); } else { return null; } setHeaders(method, request); return method; }
From source file:com.owncloud.android.operations.ExistenceCheckOperation.java
@Override protected RemoteOperationResult run(WebdavClient client) { if (!isOnline()) { return new RemoteOperationResult(RemoteOperationResult.ResultCode.NO_NETWORK_CONNECTION); }//ww w . j a v a 2s.c o m RemoteOperationResult result = null; HeadMethod head = null; try { head = new HeadMethod(client.getBaseUri() + WebdavUtils.encodePath(mPath)); int status = client.executeMethod(head, TIMEOUT, TIMEOUT); client.exhaustResponse(head.getResponseBodyAsStream()); boolean success = (status == HttpStatus.SC_OK && !mSuccessIfAbsent) || (status == HttpStatus.SC_NOT_FOUND && mSuccessIfAbsent); result = new RemoteOperationResult(success, status, head.getResponseHeaders()); Log_OC.d(TAG, "Existence check for " + client.getBaseUri() + WebdavUtils.encodePath(mPath) + " targeting for " + (mSuccessIfAbsent ? " absence " : " existence ") + "finished with HTTP status " + status + (!success ? "(FAIL)" : "")); } catch (Exception e) { result = new RemoteOperationResult(e); Log_OC.e(TAG, "Existence check for " + client.getBaseUri() + WebdavUtils.encodePath(mPath) + " targeting for " + (mSuccessIfAbsent ? " absence " : " existence ") + ": " + result.getLogMessage(), result.getException()); } finally { if (head != null) head.releaseConnection(); } return result; }
From source file:lucee.commons.net.http.httpclient3.HTTPEngine3Impl.java
public static HTTPResponse head(URL url, String username, String password, int timeout, int maxRedirect, String charset, String useragent, ProxyData proxy, Header[] headers) throws IOException { return _invoke(new HeadMethod(url.toExternalForm()), url, username, password, timeout, maxRedirect, charset, useragent, proxy, headers, null, null); }
From source file:net.sf.ehcache.constructs.web.filter.CachingFilterTest.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 w ww . j a v a 2 s.c o m*/ */ 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:net.sf.ufsc.http.HttpFile.java
/** * @see net.sf.ufsc.File#exists()//from w ww. ja va2s . com */ public boolean exists() throws java.io.IOException { HeadMethod method = new HeadMethod(this.uri.toString()); int status = this.client.executeMethod(method); if (status == HttpStatus.SC_OK) { return true; } else if (status == HttpStatus.SC_NOT_FOUND) { return false; } else { throw new IOException(method.getStatusText()); } }
From source file:com.sittinglittleduck.DirBuster.workGenerators.BruteForceURLFuzz.java
public void run() { // checks if the server surports heads requests if (manager.getAuto()) { try {// w w w .j a v a2 s . c om URL headurl = new URL(firstPart); HeadMethod httphead = new HeadMethod(headurl.toString()); // set the custom HTTP headers Vector HTTPheaders = manager.getHTTPHeaders(); for (int a = 0; a < HTTPheaders.size(); a++) { HTTPHeader httpHeader = (HTTPHeader) HTTPheaders.elementAt(a); httphead.setRequestHeader(httpHeader.getHeader(), httpHeader.getValue()); } int responceCode = httpclient.executeMethod(httphead); // if the responce code is method not implemented or fails if (responceCode == 501 || responceCode == 400) { // switch the mode to just GET requests manager.setAuto(false); } } catch (MalformedURLException e) { // TODO deal with error } catch (IOException e) { // TODO deal with error } } // deal with the dirs try { // get item from queue DirToCheck tempDirToCheck = dirQueue.take(); // get dir name currentDir = tempDirToCheck.getName(); // get any extention that need to be checked extToCheck = tempDirToCheck.getExts(); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("Starting fuzz on " + firstPart + urlFuzzStart + "{dir}" + urlFuzzEnd); started = currentDir; String baseCase = null; // store for the basecase object set to null; BaseCase baseCaseObj = null; try { // get fail responce code for a dir test baseCaseObj = GenBaseCase.genURLFuzzBaseCase(manager, firstPart + urlFuzzStart, urlFuzzEnd); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } // baseCaseObj = new BaseCase(null, failcode, true, failurl, baseCase); // call function to generate the brute force makeList(minLen, maxLen, baseCase, baseCaseObj); manager.youAreFinished(); }
From source file:com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation.java
@Override protected RemoteOperationResult run(OwnCloudClient client) { if (!isOnline()) { return new RemoteOperationResult(RemoteOperationResult.ResultCode.NO_NETWORK_CONNECTION); }/* w w w .j a v a 2 s .co m*/ RemoteOperationResult result = null; HeadMethod head = null; try { head = new HeadMethod(client.getWebdavUri() + WebdavUtils.encodePath(mPath)); int status = client.executeMethod(head, TIMEOUT, TIMEOUT); client.exhaustResponse(head.getResponseBodyAsStream()); boolean success = (status == HttpStatus.SC_OK && !mSuccessIfAbsent) || (status == HttpStatus.SC_NOT_FOUND && mSuccessIfAbsent); result = new RemoteOperationResult(success, status, head.getResponseHeaders()); Log_OC.d(TAG, "Existence check for " + client.getWebdavUri() + WebdavUtils.encodePath(mPath) + " targeting for " + (mSuccessIfAbsent ? " absence " : " existence ") + "finished with HTTP status " + status + (!success ? "(FAIL)" : "")); } catch (Exception e) { result = new RemoteOperationResult(e); Log_OC.e(TAG, "Existence check for " + client.getWebdavUri() + WebdavUtils.encodePath(mPath) + " targeting for " + (mSuccessIfAbsent ? " absence " : " existence ") + ": " + result.getLogMessage(), result.getException()); } finally { if (head != null) head.releaseConnection(); } return result; }
From source file:com.zimbra.cs.store.triton.TritonIncomingBlob.java
@Override protected long getRemoteSize() throws IOException { outStream.flush();/*from w w w . ja v a2 s . c o m*/ HttpClient client = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient(); HeadMethod head = new HeadMethod(baseUrl + uploadUrl); ZimbraLog.store.info("heading %s", head.getURI()); try { head.addRequestHeader(TritonHeaders.SERVER_TOKEN, serverToken.getToken()); int statusCode = HttpClientUtil.executeMethod(client, head); if (statusCode == HttpStatus.SC_OK) { String contentLength = head.getResponseHeader(TritonHeaders.CONTENT_LENGTH).getValue(); long remoteSize = -1; try { remoteSize = Long.valueOf(contentLength); } catch (NumberFormatException nfe) { throw new IOException("Content length can't be parsed to Long", nfe); } return remoteSize; } else { ZimbraLog.store.error("failed with code %d response: %s", statusCode, head.getResponseBodyAsString()); throw new IOException("unable to head blob " + statusCode + ":" + head.getStatusText(), null); } } finally { head.releaseConnection(); } }