Search in sources :

Example 1 with HeadMethod

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;
}
Also used : HeadMethod(org.apache.commons.httpclient.methods.HeadMethod) HttpConnectionManagerParams(org.apache.commons.httpclient.params.HttpConnectionManagerParams) HttpClient(org.apache.commons.httpclient.HttpClient) IOException(java.io.IOException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 2 with HeadMethod

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();
    }
}
Also used : HeadMethod(org.apache.commons.httpclient.methods.HeadMethod) HttpClient(org.apache.commons.httpclient.HttpClient) IOException(java.io.IOException)

Example 3 with HeadMethod

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);
}
Also used : HeadMethod(org.apache.commons.httpclient.methods.HeadMethod)

Example 4 with HeadMethod

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));
}
Also used : HeadMethod(org.apache.commons.httpclient.methods.HeadMethod) HttpTest(org.apache.sling.commons.testing.integration.HttpTest) Test(org.junit.Test)

Example 5 with HeadMethod

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());
}
Also used : HeadMethod(org.apache.commons.httpclient.methods.HeadMethod) Header(org.apache.commons.httpclient.Header) HttpServiceHandler(org.apache.commons.httpclient.server.HttpServiceHandler) FeedbackService(org.apache.commons.httpclient.FeedbackService) HttpRequestHandlerChain(org.apache.commons.httpclient.server.HttpRequestHandlerChain) HttpState(org.apache.commons.httpclient.HttpState) AuthRequestHandler(org.apache.commons.httpclient.server.AuthRequestHandler) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials)

Aggregations

HeadMethod (org.apache.commons.httpclient.methods.HeadMethod)13 IOException (java.io.IOException)7 HttpClient (org.apache.commons.httpclient.HttpClient)7 Header (org.apache.commons.httpclient.Header)3 HttpTest (org.apache.sling.commons.testing.integration.HttpTest)3 Test (org.junit.Test)3 HttpException (org.apache.commons.httpclient.HttpException)2 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)2 HttpConnectionManagerParams (org.apache.commons.httpclient.params.HttpConnectionManagerParams)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Callable (java.util.concurrent.Callable)1 ExecutorService (java.util.concurrent.ExecutorService)1 FeedbackService (org.apache.commons.httpclient.FeedbackService)1 HostConfiguration (org.apache.commons.httpclient.HostConfiguration)1 HttpMethodBase (org.apache.commons.httpclient.HttpMethodBase)1 HttpState (org.apache.commons.httpclient.HttpState)1