本文整理汇总了Java中org.apache.commons.httpclient.methods.HeadMethod.releaseConnection方法的典型用法代码示例。如果您正苦于以下问题:Java HeadMethod.releaseConnection方法的具体用法?Java HeadMethod.releaseConnection怎么用?Java HeadMethod.releaseConnection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.httpclient.methods.HeadMethod
的用法示例。
在下文中一共展示了HeadMethod.releaseConnection方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
}
示例2: 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();
}
}
示例3: 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);
}
示例4: 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);
}
}
示例5: 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());
}
}
示例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.
*/
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());
}
}
示例7: testHeadBasicAuthentication
import org.apache.commons.httpclient.methods.HeadMethod; //导入方法依赖的package包/类
public void testHeadBasicAuthentication() throws Exception {
UsernamePasswordCredentials creds =
new UsernamePasswordCredentials("testuser", "testpass");
HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
handlerchain.appendHandler(new AuthRequestHandler(creds));
handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));
HttpState state = new HttpState();
AuthScope authscope = new AuthScope(
this.server.getLocalAddress(),
this.server.getLocalPort(),
"test");
state.setCredentials(authscope, creds);
this.client.setState(state);
this.server.setRequestHandler(handlerchain);
HeadMethod head = new HeadMethod("/test/");
try {
this.client.executeMethod(head);
} finally {
head.releaseConnection();
}
assertNotNull(head.getStatusLine());
assertEquals(HttpStatus.SC_OK, head.getStatusLine().getStatusCode());
Header auth = head.getRequestHeader("Authorization");
assertNotNull(auth);
String expected = "Basic " + EncodingUtil.getAsciiString(
Base64.encodeBase64(EncodingUtil.getAsciiBytes("testuser:testpass")));
assertEquals(expected, auth.getValue());
AuthState authstate = head.getHostAuthState();
assertNotNull(authstate.getAuthScheme());
assertTrue(authstate.getAuthScheme() instanceof BasicScheme);
assertEquals("test", authstate.getRealm());
}
示例8: head
import org.apache.commons.httpclient.methods.HeadMethod; //导入方法依赖的package包/类
/**
* Send a HEAD request
* @param cluster the cluster definition
* @param path the path or URI
* @param headers the HTTP headers to include in the request
* @return a Response object with response detail
* @throws IOException
*/
public Response head(Cluster cluster, String path, Header[] headers)
throws IOException {
HeadMethod method = new HeadMethod();
try {
int code = execute(cluster, method, null, path);
headers = method.getResponseHeaders();
return new Response(code, headers, null);
} finally {
method.releaseConnection();
}
}
示例9: head
import org.apache.commons.httpclient.methods.HeadMethod; //导入方法依赖的package包/类
/**
* Please see list of status codes and their meaning:
* <br><br>
* 204 No Content: URN is in database. No further information asked.<br>
* 301 Moved Permanently: The given URN is replaced with a newer version. This newer version should be used instead.<br>
* 404 Not Found: The given URN is not registered in system.<br>
* 410 Gone: The given URN is registered in system but marked inactive.<br>
*
* @return the status code of the request
*/
public int head(MCRURN urn) {
HeadMethod headMethod = new HeadMethod(getConfiguration().getServiceURL() + urn);
try {
return getHttpClient().executeMethod(headMethod);
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
headMethod.releaseConnection();
}
}
示例10: existsFile
import org.apache.commons.httpclient.methods.HeadMethod; //导入方法依赖的package包/类
/**
* Check if a file exists in the OC server
*
* @deprecated Use ExistenceCheckOperation instead
*
* @return 'true' if the file exists; 'false' it doesn't exist
* @throws Exception When the existence could not be determined
*/
@Deprecated
public boolean existsFile(String path) throws IOException, HttpException {
HeadMethod head = new HeadMethod(getWebdavUri() + WebdavUtils.encodePath(path));
try {
int status = executeMethod(head);
Log_OC.d(TAG, "HEAD to " + path + " finished with HTTP status " + status +
((status != HttpStatus.SC_OK)?"(FAIL)":""));
exhaustResponse(head.getResponseBodyAsStream());
return (status == HttpStatus.SC_OK);
} finally {
head.releaseConnection(); // let the connection available for other methods
}
}