use of org.apache.commons.httpclient.methods.HeadMethod in project intellij-community by JetBrains.
the class PythonDocumentationProvider method pageExists.
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;
}
use of org.apache.commons.httpclient.methods.HeadMethod in project zm-mailbox by Zimbra.
the class TritonIncomingBlob method getRemoteSize.
@Override
protected long getRemoteSize() throws IOException {
outStream.flush();
HttpClient client = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient();
HeadMethod head = new HeadMethod(baseUrl + uploadUrl);
ZimbraLog.store.info("heading %s", head.getURI());
try {
head.addRequestHeader(TritonHeaders.SERVER_TOKEN, serverToken.getToken());
int statusCode = HttpClientUtil.executeMethod(client, head);
if (statusCode == HttpStatus.SC_OK) {
String contentLength = head.getResponseHeader(TritonHeaders.CONTENT_LENGTH).getValue();
long remoteSize = -1;
try {
remoteSize = Long.valueOf(contentLength);
} catch (NumberFormatException nfe) {
throw new IOException("Content length can't be parsed to Long", nfe);
}
return remoteSize;
} else {
ZimbraLog.store.error("failed with code %d response: %s", statusCode, head.getResponseBodyAsString());
throw new IOException("unable to head blob " + statusCode + ":" + head.getStatusText(), null);
}
} finally {
head.releaseConnection();
}
}
use of org.apache.commons.httpclient.methods.HeadMethod in project alfresco-remote-api by Alfresco.
the class PublicApiHttpClient method head.
public HttpResponse head(final RequestContext rq, Binding cmisBinding, String version, String cmisOperation) throws IOException {
RestApiEndpoint endpoint = new RestApiEndpoint(rq.getNetworkId(), cmisBinding, version, cmisOperation, null);
String url = endpoint.getUrl();
HeadMethod req = new HeadMethod(url.toString());
return submitRequest(req, rq);
}
use of org.apache.commons.httpclient.methods.HeadMethod in project sling by apache.
the class HeadServletTest method nonexistentHead.
@Test
public void nonexistentHead() throws IOException {
final HeadMethod head = new HeadMethod(NONEXISTENT_URL);
assertEquals(404, H.getHttpClient().executeMethod(head));
}
use of org.apache.commons.httpclient.methods.HeadMethod in project ecf by eclipse.
the class TestBasicAuth method testHeadBasicAuthentication.
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());
}
Aggregations