Package org.apache.commons.httpclient.methods

Examples of org.apache.commons.httpclient.methods.HeadMethod


      if (method.equals(POST)) {
          httpMethod = new PostMethod(urlStr);
      } else if (method.equals(PUT)){
          httpMethod = new PutMethod(urlStr);
      } else if (method.equals(HEAD)){
          httpMethod = new HeadMethod(urlStr);
      } else if (method.equals(TRACE)){
          httpMethod = new TraceMethod(urlStr);
      } else if (method.equals(OPTIONS)){
          httpMethod = new OptionsMethod(urlStr);
      } else if (method.equals(DELETE)){
View Full Code Here


    public URLInfo getURLInfo(URL url) {
        return getURLInfo(url, 0);
    }

    public URLInfo getURLInfo(URL url, int timeout) {
        HeadMethod head = null;
        try {
            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;
    }
View Full Code Here

    private HeadMethod doHead(URL url, int timeout) throws IOException {
        HttpClient client = getClient(url);
        client.setTimeout(timeout);

        HeadMethod head = new HeadMethod(url.toExternalForm());
        head.setDoAuthentication(useAuthentication(url) || useProxyAuthentication());
        client.executeMethod(head);
        return head;
    }
View Full Code Here

            if (method.equals(HTTPConstants.POST)) {
                httpMethod = new PostMethod(urlStr);
            } else if (method.equals(HTTPConstants.PUT)){
                httpMethod = new PutMethod(urlStr);
            } else if (method.equals(HTTPConstants.HEAD)){
                httpMethod = new HeadMethod(urlStr);
            } else if (method.equals(HTTPConstants.TRACE)){
                httpMethod = new TraceMethod(urlStr);
            } else if (method.equals(HTTPConstants.OPTIONS)){
                httpMethod = new OptionsMethod(urlStr);
            } else if (method.equals(HTTPConstants.DELETE)){
View Full Code Here

      case GET:
        return new GetMethod(uri);
      case DELETE:
        return new DeleteMethod(uri);
      case HEAD:
        return new HeadMethod(uri);
      case OPTIONS:
        return new OptionsMethod(uri);
      case POST:
        return new PostMethod(uri);
      case PUT:
View Full Code Here

      case GET:
        return new GetMethod(uri);
      case DELETE:
        return new DeleteMethod(uri);
      case HEAD:
        return new HeadMethod(uri);
      case OPTIONS:
        return new OptionsMethod(uri);
      case POST:
        return new PostMethod(uri);
      case PUT:
View Full Code Here

            if (method.equals(POST)) {
                httpMethod = new PostMethod(urlStr);
            } else if (method.equals(PUT)){
                httpMethod = new PutMethod(urlStr);
            } else if (method.equals(HEAD)){
                httpMethod = new HeadMethod(urlStr);
            } else if (method.equals(TRACE)){
                httpMethod = new TraceMethod(urlStr);
            } else if (method.equals(OPTIONS)){
                httpMethod = new OptionsMethod(urlStr);
            } else if (method.equals(DELETE)){
View Full Code Here

    } else if (method.equalsIgnoreCase(DELETE)) {
      httpMethod = new DeleteMethod();
    } else if (method.equalsIgnoreCase(PUT)) {
      httpMethod = new PutMethod();
    } else if (method.equalsIgnoreCase(HEAD)) {
      httpMethod = new HeadMethod();
    } else if (method.equalsIgnoreCase(OPTIONS)) {
      httpMethod = new OptionsMethod();
    } else if (method.equalsIgnoreCase(TRACE)) {
      httpMethod = new TraceMethod(uri.toString());
    } else {
View Full Code Here

    private HeadMethod doHead(URL url, int timeout) throws IOException {
        HttpClient client = getClient();
        client.setTimeout(timeout);

        HeadMethod head = new HeadMethod(normalizeToString(url));
        head.setDoAuthentication(useAuthentication(url) || useProxyAuthentication());
        client.executeMethod(head);
        return head;
    }
View Full Code Here

    public URLInfo getURLInfo(URL url) {
        return getURLInfo(url, 0);
    }

    public URLInfo getURLInfo(URL url, int timeout) {
        HeadMethod head = null;
        try {
            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;
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.httpclient.methods.HeadMethod

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.