Package org.apache.commons.httpclient.methods

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


     */
    protected FileType doGetType()
        throws Exception
    {
        // Use the HEAD method to probe the file.
        method = new HeadMethod();
        setupMethod(method);
        final HttpClient client = fileSystem.getClient();
        final int status = client.executeMethod(method);
        method.releaseConnection();
        if (status == HttpURLConnection.HTTP_OK)
View Full Code Here


                final UsernamePasswordCredentials creds =
                    new UsernamePasswordCredentials(username, password);
                client.getState().setCredentials(null, hostname, creds);
            }

            client.executeMethod(new HeadMethod());
        }
        catch (final Exception exc)
        {
            throw new FileSystemException("vfs.provider.http/connect.error", new Object[]{hostname}, exc);
        }
View Full Code Here

  }

  public static Integer detectMIMEType(String url) {
    try {
      HttpClient httpClient = new HttpClient();
      HeadMethod method = new HeadMethod(url);
      method.getParams().setIntParameter("http.socket.timeout",5000);
      int code = httpClient.executeMethod(method);
      if (code == 200) {
        Header h = method.getResponseHeader("Content-Type");
        if (h != null) {
          HeaderElement[] headElm = h.getElements();
          if(headElm != null & headElm.length > 0){
            String mimeType = headElm[0].getValue();
            if(mimeType == null){
View Full Code Here

    HttpClient hClient = new HttpClient();
    hClient.getParams().setSoTimeout(25000);
    // hClient.setTimeout(5000); deprecated in 3.0 client
    HostConfiguration hc = hClient.getHostConfiguration();
    hc = setProxySetttings(hClient, hc);
    HeadMethod hMethod = null;
    try {
      hMethod = new HeadMethod(url.toString());
      hMethod.setRequestHeader("cache-control", "no-cache");
      int status = hClient.executeMethod(hMethod);

      if (status != HttpStatus.SC_OK) {
        // Check for redirection.
        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());
            }
          } else {
            // The response is invalid and did not provide the
            // new
            // location for
            // the resource. Report an error or possibly handle
            // the
            // response
            // like a 404 Not Found error.
          }
        } else {
          if (status == HttpStatus.SC_UNAUTHORIZED) {
            // Retry with password.
            hc = hClient.getHostConfiguration();
            try {

              hClient.getState().setCredentials(
                  new AuthScope(AuthScope.ANY_HOST,
                      AuthScope.ANY_PORT,
                      AuthScope.ANY_REALM),
                  getCredentials(feed)

              );
            } catch (Exception e) {
              throw new NetworkException(e.getMessage());
            }
            hMethod = new HeadMethod(url.toString());
            hMethod.setDoAuthentication(true);
            status = hClient.executeMethod(hMethod);
            if (status != HttpStatus.SC_OK) {
              throw new NetworkException(hMethod.getStatusLine()
                  .getReasonPhrase());
            }
          } else {
            throw new NetworkException(hMethod.getStatusLine()
                .getReasonPhrase());
          }
        }
      }
      head = getHeadInfo(hMethod);
    } catch (HttpException he) {
      // Received Illegal redirect exception on some URLs
      throw new NetworkException(he.getMessage(), he);
    } catch (IOException ioe) {
      throw new NetworkException(ioe.getMessage(), ioe);
    } catch (java.lang.IllegalArgumentException iae) {
      throw new NetworkException(iae.getMessage(), iae);
    } finally {
      if (hMethod != null) {
        hMethod.releaseConnection();
      }
    }
    return head;
  }
View Full Code Here

            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:
View Full Code Here

            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:
View Full Code Here

            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:
View Full Code Here

    */
   @Test
   public void testHead() throws Exception
   {
      HttpClient client = new HttpClient();
      HeadMethod method = new HeadMethod(TestPortProvider.generateURL("/GetTest"));
      method.addRequestHeader("Accept", "text/plain");
      int status = client.executeMethod(method);
      Assert.assertEquals(200, status);
      Header header = method.getResponseHeader("CTS-HEAD");
      Assert.assertNotNull(header);
      Assert.assertEquals("text-plain", header.getValue());
   }
View Full Code Here

    */
   @Test
   public void testHead2() throws Exception
   {
      HttpClient client = new HttpClient();
      HeadMethod method = new HeadMethod(TestPortProvider.generateURL("/GetTest"));
      method.addRequestHeader("Accept", "text/html");
      int status = client.executeMethod(method);
      Assert.assertEquals(200, status);
      Header header = method.getResponseHeader("CTS-HEAD");
      Assert.assertNotNull(header);
      Assert.assertEquals("text-html", header.getValue());
   }
View Full Code Here

    */
   @Test
   public void testHeadSubresource() throws Exception
   {
      HttpClient client = new HttpClient();
      HeadMethod method = new HeadMethod(TestPortProvider.generateURL("/GetTest/sub"));
      method.addRequestHeader("Accept", "text/plain");
      int status = client.executeMethod(method);
      Assert.assertEquals(200, status);
      Header header = method.getResponseHeader("CTS-HEAD");
      Assert.assertNotNull(header);
      Assert.assertEquals("sub-text-plain", header.getValue());
   }
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.