Package org.apache.commons.httpclient

Examples of org.apache.commons.httpclient.Header


    try {
      method = session.newMethodHead(url);

      doConnect(method);

      Header head = method.getResponseHeader("Accept-Ranges");
      if (head == null) {
        needtest = true; // header is optional - need more testing

      } else if (head.getValue().equalsIgnoreCase("bytes")) {
        needtest = false;

      } else if (head.getValue().equalsIgnoreCase("none")) {
        throw new IOException("Server does not support byte Ranges");
      }

      head = method.getResponseHeader("Content-Length");
      if (head == null) {
        throw new IOException("Server does not support Content-Length");
      }

      try {
        total_length = Long.parseLong(head.getValue());
      } catch (NumberFormatException e) {
        throw new IOException("Server has malformed Content-Length header");
      }

    } finally {
View Full Code Here


    fLink = link;
    fMethod = method;
    fMonitor = monitor;

    /* Keep some important Headers */
    Header headerLastModified = method.getResponseHeader(HEADER_RESPONSE_LAST_MODIFIED);
    if (headerLastModified != null)
      setIfModifiedSince(headerLastModified.getValue());

    Header headerETag = method.getResponseHeader(HEADER_RESPONSE_ETAG);
    if (headerETag != null)
      setIfNoneMatch(headerETag.getValue());
  }
View Full Code Here

  /**
   * @return the content length of the content served by this stream or -1 if
   * not available.
   */
  public int getContentLength() {
    Header header = fMethod.getResponseHeader(HEADER_RESPONSE_CONTENT_LENGTH);
    if (header != null) {
      String value = header.getValue();
      try {
        return Integer.parseInt(value);
      } catch (NumberFormatException e) {
        return -1;
      }
View Full Code Here

  /**
   * @return the content type of the content served by this stream or null if
   * not available.
   */
  public String getContentType() {
    Header header = fMethod.getResponseHeader(HEADER_RESPONSE_CONTENT_TYPE);
    if (header != null)
      return header.getValue();

    return null;
  }
View Full Code Here

        if (status == HttpStatus.SC_MOVED_PERMANENTLY
            || status == HttpStatus.SC_MOVED_TEMPORARILY
            || status == HttpStatus.SC_SEE_OTHER
            || status == HttpStatus.SC_TEMPORARY_REDIRECT) {
          String redirectLocation;
          Header locationHeader = gMethod
              .getResponseHeader("location");
          if (locationHeader != null) {
            redirectLocation = locationHeader.getValue();
            gMethod = new GetMethod(redirectLocation);
            status = hClient.executeMethod(gMethod);
            if (status != HttpStatus.SC_OK) {
              throw new NetworkException(gMethod.getStatusLine()
                  .getReasonPhrase());
View Full Code Here

          if (status == HttpStatus.SC_MOVED_PERMANENTLY
              || status == HttpStatus.SC_MOVED_TEMPORARILY
              || status == HttpStatus.SC_SEE_OTHER
              || status == HttpStatus.SC_TEMPORARY_REDIRECT) {
            String redirectLocation;
            Header locationHeader = gMethod
                .getResponseHeader("location");
            if (locationHeader != null) {
              redirectLocation = locationHeader.getValue();

              gMethod = new GetMethod(redirectLocation);
              status = hClient.executeMethod(gMethod);
              if (status != HttpStatus.SC_OK) {
                throw new NetworkException(gMethod
View Full Code Here

        if (status == HttpStatus.SC_MOVED_PERMANENTLY
            || status == HttpStatus.SC_MOVED_TEMPORARILY
            || status == HttpStatus.SC_SEE_OTHER
            || status == HttpStatus.SC_TEMPORARY_REDIRECT) {
          String redirectLocation;
          Header locationHeader = hMethod
              .getResponseHeader("location");
          if (locationHeader != null) {
            redirectLocation = locationHeader.getValue();
            hMethod = new HeadMethod(redirectLocation);
            status = hClient.executeMethod(hMethod);
            if (status != HttpStatus.SC_OK) {
              throw new NetworkException(hMethod.getStatusLine()
                  .getReasonPhrase());
View Full Code Here

   * @param method
   *            HttpMethodBase
   * @return NetHEADInfo
   */
  private static HTTPHEADInfo getHeadInfo(HttpMethodBase method) {
    Header header;

    String lastModifiedDate = null;
    String contentType = null;
    String contentLength = "0";
    String date = null;

    Header[] lHeaders = method.getResponseHeaders();
    for (int i = 0; i < lHeaders.length; i++) {
      Header lHeader = lHeaders[i];
      String lValue = lHeader.getValue();
      // if (Debug.WITH_DEV_DEBUG && lValue != null && lValue.length() >
      // 0) {
      // sLog.debug(lHeader.getName() + ":" + lValue);
      // }
    }
View Full Code Here

          case HttpStatus.SC_TEMPORARY_REDIRECT: {
            lRedirect = true;
            // The redirection code fails for
            // localhost, use IP address as a workaround.
            String redirectLocation;
            Header locationHeader = gMethod
                .getResponseHeader("location");

            if (locationHeader != null) {
              redirectLocation = locationHeader.getValue();
              gMethod.setFollowRedirects(true);
              lUrl = new URL(redirectLocation);
            } else {

            }
          }
            break;
          case HttpStatus.SC_PARTIAL_CONTENT:
            // sLog.info("(1) Partial download granted for: "
            // + pUrl.toExternalForm());
            // sLog.info("(2) Start at byte: "
            // + gMethod.getRequestHeader("Range")
            // .getValue());
            lContinue = false;
            break;
          case HttpStatus.SC_REQUESTED_RANGE_NOT_SATISFIABLE: {
            // 28-07-2006, Duh? OK let's try again without
            // Range.
            // sLog.warn("(1) Partial download denied for: "
            // + pUrl.toExternalForm());

            Header lRHeader = gMethod
                .getResponseHeader("Content-Range");
            if (lRHeader != null) {
              // sLog.warn("(2) The content-range is: "
              // + lRHeader.getValue());
            }

            // sLog.warn(gMethod.getResponseBodyAsString());

            Header h = gMethod.getRequestHeader("Range");
            gMethod.removeRequestHeader(h);
            append = false;
          }
            break;
          case HttpStatus.SC_UNAUTHORIZED: {
View Full Code Here

    int fileLen = new Long(encl.getFile().length()).intValue();
    String contentRange = "bytes=" + new Integer((fileLen)).toString()
        + "-";

    Header head = new Header();
    head.setName("Range");
    head.setValue(contentRange);
    gMethod.addRequestHeader(head);
  }
View Full Code Here

TOP

Related Classes of org.apache.commons.httpclient.Header

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.