当前位置: 首页>>代码示例>>Java>>正文


Java HeadMethod类代码示例

本文整理汇总了Java中org.apache.commons.httpclient.methods.HeadMethod的典型用法代码示例。如果您正苦于以下问题:Java HeadMethod类的具体用法?Java HeadMethod怎么用?Java HeadMethod使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HeadMethod类属于org.apache.commons.httpclient.methods包,在下文中一共展示了HeadMethod类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: exists

import org.apache.commons.httpclient.methods.HeadMethod; //导入依赖的package包/类
/** {@inheritDoc} */
public boolean exists() throws ResourceException {
    HeadMethod headMethod = new HeadMethod(resourceUrl);
    headMethod.addRequestHeader("Connection", "close");

    try {
        httpClient.executeMethod(headMethod);
        if (headMethod.getStatusCode() != HttpStatus.SC_OK) {
            return false;
        }

        return true;
    } catch (IOException e) {
        throw new ResourceException("Unable to contact resource URL: " + resourceUrl, e);
    } finally {
        headMethod.releaseConnection();
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:HttpResource.java

示例2: pageExists

import org.apache.commons.httpclient.methods.HeadMethod; //导入依赖的package包/类
private static boolean pageExists(@NotNull String url) {
  if (new File(url).exists()) {
    return true;
  }
  final HttpClient client = new HttpClient();
  final HttpConnectionManagerParams params = client.getHttpConnectionManager().getParams();
  params.setSoTimeout(5 * 1000);
  params.setConnectionTimeout(5 * 1000);

  try {
    final HeadMethod method = new HeadMethod(url);
    final int rc = client.executeMethod(method);
    if (rc == 404) {
      return false;
    }
  }
  catch (IllegalArgumentException e) {
    return false;
  }
  catch (IOException ignored) {
  }
  return true;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:PythonDocumentationProvider.java

示例3: testExecuteMethod

import org.apache.commons.httpclient.methods.HeadMethod; //导入依赖的package包/类
public void testExecuteMethod() {
	OwnCloudClient client = 
			new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
       HeadMethod head = new HeadMethod(client.getWebdavUri() + "/");
       int status = -1;
       try {
           status = client.executeMethod(head);
           assertTrue("Wrong status code returned: " + status, 
           		status > 99 && status < 600);
           
       } catch (IOException e) {
       	Log.e(TAG, "Exception in HEAD method execution", e);
       	// TODO - make it fail? ; try several times, and make it fail if none
       	//			is right?
           
       } finally {
           head.releaseConnection();
       }
}
 
开发者ID:PicFrame,项目名称:picframe,代码行数:20,代码来源:OwnCloudClientTest.java

示例4: main

import org.apache.commons.httpclient.methods.HeadMethod; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    String  message = "Hello Ivy!";
    System.out.println("standard message : " + message);
    System.out.println("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);
}
 
开发者ID:apache,项目名称:ant-ivy,代码行数:20,代码来源:HelloIvy.java

示例5: exists

import org.apache.commons.httpclient.methods.HeadMethod; //导入依赖的package包/类
public boolean exists(String filename) throws FileResourceException {
    HeadMethod m = new HeadMethod(contact + '/' + filename);
    try {
        int code = client.executeMethod(m);
        try {
            if (code != HttpStatus.SC_OK) {
                return false;
            }
            else {
                return true;
            }
        }
        finally {
            m.releaseConnection();
        }
    }
    catch (Exception e) {
        throw new FileResourceException(e);
    }
}
 
开发者ID:swift-lang,项目名称:swift-k,代码行数:21,代码来源:FileResourceImpl.java

示例6: doGetType

import org.apache.commons.httpclient.methods.HeadMethod; //导入依赖的package包/类
/**
 * Determines the type of this file.  Must not return null.  The return
 * value of this method is cached, so the implementation can be expensive.
 */
@Override
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)
    {
        return FileType.FILE;
    }
    else if (status == HttpURLConnection.HTTP_NOT_FOUND
        || status == HttpURLConnection.HTTP_GONE)
    {
        return FileType.IMAGINARY;
    }
    else
    {
        throw new FileSystemException("vfs.provider.http/head.error", getName());
    }
}
 
开发者ID:wso2,项目名称:wso2-commons-vfs,代码行数:28,代码来源:HttpFileObject.java

示例7: createCommonsHttpMethod

import org.apache.commons.httpclient.methods.HeadMethod; //导入依赖的package包/类
/**
 * Create a Commons HttpMethodBase object for the given HTTP method
 * and URI specification.
 * @param httpMethod the HTTP method
 * @param uri the URI
 * @return the Commons HttpMethodBase object
 */
protected HttpMethodBase createCommonsHttpMethod(HttpMethod httpMethod, String uri) {
	switch (httpMethod) {
		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:
			return new PutMethod(uri);
		case TRACE:
			return new TraceMethod(uri);
		case PATCH:
			throw new IllegalArgumentException(
					"HTTP method PATCH not available before Apache HttpComponents HttpClient 4.2");
		default:
			throw new IllegalArgumentException("Invalid HTTP method: " + httpMethod);
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:31,代码来源:CommonsClientHttpRequestFactory.java

示例8: checkUrlExistence

import org.apache.commons.httpclient.methods.HeadMethod; //导入依赖的package包/类
public static void checkUrlExistence(String url) {
    if (url.toLowerCase().startsWith("http") || url.toLowerCase().startsWith("https")) {
        HttpClient httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
        HeadMethod httphead = new HeadMethod(url);
        try {
            if (httpClient.executeMethod(httphead) != HttpStatus.SC_OK) {
                throw new IllegalArgumentException("Invalid URL: " + url);
            }
            if (url.endsWith("metalink") && !checkUrlExistenceMetalink(url)) {
                throw new IllegalArgumentException("Invalid URLs defined on metalink: " + url);
            }
        } catch (HttpException hte) {
            throw new IllegalArgumentException("Cannot reach URL: " + url);
        } catch (IOException ioe) {
            throw new IllegalArgumentException("Cannot reach URL: " + url);
        }
    }
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:19,代码来源:UriUtils.java

示例9: testHeadObject

import org.apache.commons.httpclient.methods.HeadMethod; //导入依赖的package包/类
@Test
public void testHeadObject() throws Exception {
    // create bucket and store object
    assertEquals("OK", conn.createBucket(bucketName, null, null).connection.getResponseMessage());
    S3Object object = new S3Object(testData.getBytes(), null);
    assertEquals("OK", conn.put(bucketName, objectName, object, null).connection.getResponseMessage());

    // grant public read access to the bucket
    Map<String, List<String>> headers = new HashMap<String, List<String>>();
    headers.put("x-amz-acl", Arrays.asList(new String[] { "public-read" }));
    assertEquals("OK", conn.createBucket(bucketName, null, headers).connection.getResponseMessage());

    HttpClient httpClient = new HttpClient();
    HeadMethod headMethod = new HeadMethod(objectUri);
    int rc = httpClient.executeMethod(headMethod);
    assertEquals(200, rc);
    System.out.println(FileUtils.readFileToString(new File(String.format("%s/%s/%s%s", BUCKET_ROOT, bucketName, objectName, ObjectMetaData.FILE_SUFFIX))));
    assertEquals(Integer.toString(testData.length()), headMethod.getResponseHeaders(HttpHeaders.CONTENT_LENGTH)[0].getValue());
    assertEquals(ObjectMetaData.DEFAULT_OBJECT_CONTENT_TYPE, headMethod.getResponseHeaders(HttpHeaders.CONTENT_TYPE)[0].getValue());
}
 
开发者ID:barnyard,项目名称:pi,代码行数:21,代码来源:ComplexScenariosTest.java

示例10: acquireLength

import org.apache.commons.httpclient.methods.HeadMethod; //导入依赖的package包/类
private void acquireLength() throws URISyntaxException, HttpException, IOException {
	HttpMethod head = new HeadMethod(url);
	int code = http.executeMethod(head);
	if(code != 200) {
		throw new IOException("Unable to retrieve from " + url);
	}
	Header lengthHeader = head.getResponseHeader(CONTENT_LENGTH);
	if(lengthHeader == null) {
		throw new IOException("No Content-Length header for " + url);
	}
	String val = lengthHeader.getValue();
	try {
		length = Long.parseLong(val);
	} catch(NumberFormatException e) {
		throw new IOException("Bad Content-Length value " +url+ ": " + val);
	}
}
 
开发者ID:iipc,项目名称:webarchive-commons,代码行数:18,代码来源:ApacheHttp31SLR.java

示例11: doGetType

import org.apache.commons.httpclient.methods.HeadMethod; //导入依赖的package包/类
/**
 * Determines the type of this file.  Must not return null.  The return
 * value of this method is cached, so the implementation can be expensive.
 */
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)
    {
        return FileType.FILE;
    }
    else if (status == HttpURLConnection.HTTP_NOT_FOUND
        || status == HttpURLConnection.HTTP_GONE)
    {
        return FileType.IMAGINARY;
    }
    else
    {
        throw new FileSystemException("vfs.provider.http/head.error", getName());
    }
}
 
开发者ID:pentaho,项目名称:pdi-vfs,代码行数:28,代码来源:HttpFileObject.java

示例12: resourceExists

import org.apache.commons.httpclient.methods.HeadMethod; //导入依赖的package包/类
/**
 * Returns <code>true</code> if the resource given as URL does exist.
 * @param client
 * @param httpURL
 * @return <code>true</code>if the resource exists
 * @throws IOException
 * @throws HttpException
 */
public static boolean resourceExists(HttpClient client, HttpURL httpURL)
   throws IOException, HttpException
{
   HeadMethod head = new HeadMethod(httpURL.getURI());
   head.setFollowRedirects(true);
   int status = client.executeMethod(head);
   
   switch (status) {
      case WebdavStatus.SC_OK:
         return true;
      case WebdavStatus.SC_NOT_FOUND:
         return false;
      default:
         HttpException ex = new HttpException();
         ex.setReasonCode(status);
         ex.setReason(head.getStatusText());
         throw ex;
   }
}
 
开发者ID:integrated,项目名称:jakarta-slide-webdavclient,代码行数:28,代码来源:Utils.java

示例13: createResponseHandler

import org.apache.commons.httpclient.methods.HeadMethod; //导入依赖的package包/类
/**
 * Checks the method being received and created a 
 * suitable ResponseHandler for this method.
 * 
 * @param method Method to handle
 * @return The handler for this response
 * @throws MethodNotAllowedException If no method could be choose this exception is thrown
 */
public static ResponseHandler createResponseHandler(HttpMethod method) throws MethodNotAllowedException {
    if (!AllowedMethodHandler.methodAllowed(method)) {
        throw new MethodNotAllowedException("The method " + method.getName() + " is not in the AllowedHeaderHandler's list of allowed methods.", AllowedMethodHandler.getAllowHeader());
    }
    
    ResponseHandler handler = null;
    if (method.getName().equals("OPTIONS")) {
        handler = new OptionsResponseHandler((OptionsMethod) method);
    } else if (method.getName().equals("GET")) {
        handler = new GetResponseHandler((GetMethod) method);
    } else if (method.getName().equals("HEAD")) {
        handler = new HeadResponseHandler((HeadMethod) method);
    } else if (method.getName().equals("POST")) {
        handler = new PostResponseHandler((PostMethod) method);
    } else if (method.getName().equals("PUT")) {
        handler = new PutResponseHandler((PutMethod) method);
    } else if (method.getName().equals("DELETE")) {
        handler = new DeleteResponseHandler((DeleteMethod) method);
    } else if (method.getName().equals("TRACE")) {
        handler = new TraceResponseHandler((TraceMethod) method);
    } else {
        throw new MethodNotAllowedException("The method " + method.getName() + " was allowed by the AllowedMethodHandler, not by the factory.", handledMethods);
    }

    return handler;
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:35,代码来源:ResponseHandlerFactory.java

示例14: htmlHead

import org.apache.commons.httpclient.methods.HeadMethod; //导入依赖的package包/类
@Test
public void htmlHead() throws IOException {
    final HeadMethod head = new HeadMethod(HTML_URL);
    final int status = H.getHttpClient().executeMethod(head);
    assertEquals(200, status);
    assertNull("Expecting null body", head.getResponseBody());
    assertCommonHeaders(head, "text/html");
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:9,代码来源:HeadServletTest.java

示例15: pngHead

import org.apache.commons.httpclient.methods.HeadMethod; //导入依赖的package包/类
@Test
public void pngHead() throws IOException {
    final HeadMethod head = new HeadMethod(PNG_URL);
    final int status = H.getHttpClient().executeMethod(head);
    assertEquals(200, status);
    assertNull("Expecting null body", head.getResponseBody());
    assertCommonHeaders(head, "image/png");
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:9,代码来源:HeadServletTest.java


注:本文中的org.apache.commons.httpclient.methods.HeadMethod类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。