List of usage examples for org.apache.commons.httpclient.methods HeadMethod HeadMethod
public HeadMethod(String paramString)
From source file:com.sittinglittleduck.DirBuster.workGenerators.BruteForceWorkGenerator.java
public void run() { boolean recursive = true; // checks if the server surports heads requests if (manager.getAuto()) { try {// w w w . j ava 2 s.c o m 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 } } while ((!dirQueue.isEmpty() || !workQueue.isEmpty()) && recursive) { recursive = manager.isRecursive(); // 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(); } started = currentDir; if (manager.getDoDirs()) { doingDirs = true; String baseCase = null; // store for the basecase object set to null; BaseCase baseCaseObj = null; URL failurl = null; try { // get fail responce code for a dir test baseCaseObj = GenBaseCase.genBaseCase(manager, firstPart + currentDir, true, null); } 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 if (failcode != 200) { makeList(minLen, maxLen, null, baseCaseObj); } else { makeList(minLen, maxLen, baseCase, baseCaseObj); } } // end of doing the dirs // brute force files names if (manager.getDoFiles()) { doingDirs = false; String baseCase = null; BaseCase baseCaseObj = null; URL failurl = null; for (int b = 0; b < extToCheck.size(); b++) { ExtToCheck tempExt = (ExtToCheck) extToCheck.elementAt(b); if (tempExt.toCheck()) { fileExtention = ""; if (tempExt.getName().equals(ExtToCheck.BLANK_EXT)) { fileExtention = ""; } else { fileExtention = "." + tempExt.getName(); } try { // deal with the files baseCaseObj = GenBaseCase.genBaseCase(manager, firstPart + currentDir, false, fileExtention); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } // call function to generate the brute force if (failcode != 200) { makeList(minLen, maxLen, null, baseCaseObj); } else { makeList(minLen, maxLen, baseCase, baseCaseObj); } } } } finished = started; } manager.youAreFinished(); }
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;/*from www . ja va 2 s. c o m*/ 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:com.wandisco.s3hdfs.rewrite.redirect.Redirect.java
HttpMethod getHttpMethod(String scheme, String host, int port, String op, String userName, String uri, HTTP_METHOD method) {//w w w . j a v a 2 s . c o m if (!uri.startsWith(WEBHDFS_PREFIX)) uri = ADD_WEBHDFS(uri); String url = scheme + "://" + host + ":" + port + uri + "?user.name=" + userName + "&op=" + op; switch (method) { case GET: return new GetMethod(url); case PUT: return new PutMethod(url); case POST: return new PostMethod(url); case DELETE: return new DeleteMethod(url); case HEAD: return new HeadMethod(url); default: return null; } }
From source file:net.sf.ufsc.http.HttpFile.java
/** * @see net.sf.ufsc.File#lastModified()/*from w ww. j a v a 2 s. 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.cerema.cloud2.lib.resources.files.ExistenceCheckRemoteOperation.java
@Override protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result = null; HeadMethod head = null;/*from w w w . ja v a 2s . co m*/ boolean previousFollowRedirects = client.getFollowRedirects(); try { head = new HeadMethod(client.getWebdavUri() + WebdavUtils.encodePath(mPath)); client.setFollowRedirects(false); int status = client.executeMethod(head, TIMEOUT, TIMEOUT); if (previousFollowRedirects) { mRedirectionPath = client.followRedirection(head); status = mRedirectionPath.getLastStatus(); } 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(); client.setFollowRedirects(previousFollowRedirects); } return result; }
From source file:fr.dutra.confluence2wordpress.util.UrlUtils.java
private static URI followRedirectsInternal(URI url, int maxRedirections) { URI response = url;//from ww w. j a va 2 s . com HttpClient client = new HttpClient(); DefaultHttpMethodRetryHandler handler = new DefaultHttpMethodRetryHandler(1, false); client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, handler); HttpMethod method = new HeadMethod(url.toASCIIString()); //method.setRequestHeader("Accept-Language", locale.getLanguage() + ",en"); method.setFollowRedirects(false); try { int statusCode = client.executeMethod(method); if ((statusCode == HttpStatus.SC_MOVED_PERMANENTLY) | (statusCode == HttpStatus.SC_MOVED_TEMPORARILY)) { if (maxRedirections > 0) { Header location = method.getResponseHeader("Location"); if (!location.getValue().equals("")) { // recursively check URL until it's not redirected any more // locations can be relative to previous URL URI target = url.resolve(location.getValue()); response = followRedirectsInternal(target, maxRedirections - 1); } } } } catch (Exception e) { //HttpClient can also throw IllegalArgumentException when URLs are malformed } return response; }
From source file:net.sf.ufsc.http.HttpFile.java
/** * @see net.sf.ufsc.File#length()// w w w. ja v a 2s. co m */ 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:com.moss.bdbadmin.client.service.BdbClient.java
public void head(IdProof assertion, String path) throws ServiceException { try {/*from w w w.j ava2 s. c om*/ HeadMethod method = new HeadMethod(baseUrl + "/" + path); method.setRequestHeader(AuthenticationHeader.HEADER_NAME, AuthenticationHeader.encode(assertion)); int result = httpClient.executeMethod(method); if (result != 200) { throw new ServiceException(result); } } catch (IOException ex) { throw new ServiceFailure(ex); } }
From source file:com.noelios.restlet.ext.httpclient.HttpMethodCall.java
/** * Constructor.//ww w . j a va 2 s .com * * @param helper * The parent HTTP client helper. * @param method * The method name. * @param requestUri * The request URI. * @param hasEntity * Indicates if the call will have an entity to send to the * server. * @throws IOException */ public HttpMethodCall(HttpClientHelper helper, final String method, String requestUri, boolean hasEntity) throws IOException { super(helper, method, requestUri); this.clientHelper = helper; if (requestUri.startsWith("http")) { if (method.equalsIgnoreCase(Method.GET.getName())) { this.httpMethod = new GetMethod(requestUri); } else if (method.equalsIgnoreCase(Method.POST.getName())) { this.httpMethod = new PostMethod(requestUri); } else if (method.equalsIgnoreCase(Method.PUT.getName())) { this.httpMethod = new PutMethod(requestUri); } else if (method.equalsIgnoreCase(Method.HEAD.getName())) { this.httpMethod = new HeadMethod(requestUri); } else if (method.equalsIgnoreCase(Method.DELETE.getName())) { this.httpMethod = new DeleteMethod(requestUri); } else if (method.equalsIgnoreCase(Method.CONNECT.getName())) { final HostConfiguration host = new HostConfiguration(); host.setHost(new URI(requestUri, false)); this.httpMethod = new ConnectMethod(host); } else if (method.equalsIgnoreCase(Method.OPTIONS.getName())) { this.httpMethod = new OptionsMethod(requestUri); } else if (method.equalsIgnoreCase(Method.TRACE.getName())) { this.httpMethod = new TraceMethod(requestUri); } else { this.httpMethod = new EntityEnclosingMethod(requestUri) { @Override public String getName() { return method; } }; } this.httpMethod.setFollowRedirects(this.clientHelper.isFollowRedirects()); this.httpMethod.setDoAuthentication(false); if (this.clientHelper.getRetryHandler() != null) { try { this.httpMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, Engine.loadClass(this.clientHelper.getRetryHandler()).newInstance()); } catch (Exception e) { this.clientHelper.getLogger().log(Level.WARNING, "An error occurred during the instantiation of the retry handler.", e); } } this.responseHeadersAdded = false; setConfidential(this.httpMethod.getURI().getScheme().equalsIgnoreCase(Protocol.HTTPS.getSchemeName())); } else { throw new IllegalArgumentException("Only HTTP or HTTPS resource URIs are allowed here"); } }
From source file:com.arjuna.qa.junit.HttpUtils.java
public static HttpMethodBase createMethod(URL url, int type) { HttpMethodBase request = null;/*from w w w . jav a 2 s. co m*/ switch (type) { case GET: request = new GetMethod(url.toString()); break; case POST: request = new PostMethod(url.toString()); break; case HEAD: request = new HeadMethod(url.toString()); break; case OPTIONS: request = new OptionsMethod(url.toString()); break; case PUT: request = new PutMethod(url.toString()); break; case DELETE: request = new DeleteMethod(url.toString()); break; case TRACE: request = new TraceMethod(url.toString()); break; } return request; }