Example usage for org.apache.commons.httpclient HttpClient getHttpConnectionManager

List of usage examples for org.apache.commons.httpclient HttpClient getHttpConnectionManager

Introduction

In this page you can find the example usage for org.apache.commons.httpclient HttpClient getHttpConnectionManager.

Prototype

public HttpConnectionManager getHttpConnectionManager()

Source Link

Usage

From source file:com.google.apphosting.vmruntime.jetty9.VmRuntimeJettyAuthTest.java

public void testAuth_AdminRequiredWithAdmin() throws Exception {
    HttpClient httpClient = new HttpClient();
    httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(30000);
    GetMethod get = new GetMethod(createUrl("/admin/test-auth").toString());
    get.addRequestHeader(VmApiProxyEnvironment.EMAIL_HEADER, "isdal@google.com");
    get.addRequestHeader(VmApiProxyEnvironment.AUTH_DOMAIN_HEADER, "google.com");
    get.addRequestHeader(VmApiProxyEnvironment.IS_ADMIN_HEADER, "1");
    get.setFollowRedirects(false);// w w w . j a v  a2s.c om
    int httpCode = httpClient.executeMethod(get);
    assertEquals(200, httpCode);
    assertEquals("isdal@google.com: isdal@google.com", get.getResponseBodyAsString());
}

From source file:com.google.apphosting.vmruntime.jetty9.VmRuntimeJettyAuthTest.java

public void testAuth_UserRequiredWithAdmin() throws Exception {
    HttpClient httpClient = new HttpClient();
    httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(30000);
    GetMethod get = new GetMethod(createUrl("/user/test-auth").toString());
    get.addRequestHeader(VmApiProxyEnvironment.EMAIL_HEADER, "isdal@google.com");
    get.addRequestHeader(VmApiProxyEnvironment.AUTH_DOMAIN_HEADER, "google.com");
    get.addRequestHeader(VmApiProxyEnvironment.IS_ADMIN_HEADER, "1");

    get.setFollowRedirects(false);//  w w  w.ja v  a 2 s .c  o  m
    int httpCode = httpClient.executeMethod(get);
    assertEquals(200, httpCode);
    assertEquals("isdal@google.com: isdal@google.com", get.getResponseBodyAsString());
}

From source file:com.google.apphosting.vmruntime.jetty9.VmRuntimeJettyAuthTest.java

public void testAuth_TrustedRealIP() throws Exception {
    HttpClient httpClient = new HttpClient();
    httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(30000);
    GetMethod get = new GetMethod(createUrlForHostIP("/admin/test-auth").toString());
    get.addRequestHeader(VmApiProxyEnvironment.REAL_IP_HEADER, "127.0.0.1");
    get.addRequestHeader(VmApiProxyEnvironment.EMAIL_HEADER, "isdal@google.com");
    get.addRequestHeader(VmApiProxyEnvironment.AUTH_DOMAIN_HEADER, "google.com");
    get.addRequestHeader(VmApiProxyEnvironment.IS_ADMIN_HEADER, "1");
    get.setFollowRedirects(false);//  www.  j a  v a 2 s  .co m
    int httpCode = httpClient.executeMethod(get);
    assertEquals(200, httpCode);
    assertEquals("isdal@google.com: isdal@google.com", get.getResponseBodyAsString());
}

From source file:com.google.apphosting.vmruntime.jetty9.VmRuntimeJettyKitchenSink2Test.java

/**
 * Test that the deferredTask handler is installed.
 *//* www .  j a  va2  s  .  c  o  m*/
public void testDeferredTask() throws Exception {
    // Replace the API proxy delegate so we can fake API responses.
    FakeableVmApiProxyDelegate fakeApiProxy = new FakeableVmApiProxyDelegate();
    ApiProxy.setDelegate(fakeApiProxy);

    // Add a api response so the task queue api is happy.
    TaskQueueBulkAddResponse taskAddResponse = new TaskQueueBulkAddResponse();
    TaskResult taskResult = taskAddResponse.addTaskResult();
    taskResult.setResult(ErrorCode.OK.getValue());
    taskResult.setChosenTaskName("abc");
    fakeApiProxy.addApiResponse(taskAddResponse);

    // Issue a deferredTaskRequest with payload.
    String testData = "0987654321acbdefghijklmn";
    String[] lines = fetchUrl(createUrl("/testTaskQueue?deferredTask=1&deferredData=" + testData));
    TaskQueueBulkAddRequest request = new TaskQueueBulkAddRequest();
    request.parseFrom(fakeApiProxy.getLastRequest().requestData);
    assertEquals(1, request.addRequestSize());
    TaskQueueAddRequest addRequest = request.getAddRequest(0);
    assertEquals(TaskQueueAddRequest.RequestMethod.POST.getValue(), addRequest.getMethod());

    // Pull out the request and fire it at the app.
    HttpClient httpClient = new HttpClient();
    httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(30000);
    PostMethod post = new PostMethod(createUrl(addRequest.getUrl()).toString());
    post.getParams().setVersion(HttpVersion.HTTP_1_0);
    // Add the required Task queue header, plus any headers from the request.
    post.addRequestHeader("X-AppEngine-QueueName", "1");
    for (TaskQueueAddRequest.Header header : addRequest.headers()) {
        post.addRequestHeader(header.getKey(), header.getValue());
    }
    post.setRequestEntity(new ByteArrayRequestEntity(addRequest.getBodyAsBytes()));
    int httpCode = httpClient.executeMethod(post);
    assertEquals(HttpURLConnection.HTTP_OK, httpCode);

    // Verify that the task was handled and that the payload is correct.
    lines = fetchUrl(createUrl("/testTaskQueue?getLastPost=1"));
    assertEquals("deferredData:" + testData, lines[lines.length - 1]);
}

From source file:fr.aliasource.webmail.server.calendar.CalendarProxyImpl.java

private HttpClient createHttpClient() {
    HttpClient ret = new HttpClient(new MultiThreadedHttpConnectionManager());
    HttpConnectionManagerParams mp = ret.getHttpConnectionManager().getParams();
    mp.setDefaultMaxConnectionsPerHost(4);
    mp.setMaxTotalConnections(8);/*from   ww  w .j  av a2s . co  m*/
    return ret;
}

From source file:com.google.apphosting.vmruntime.jetty9.VmRuntimeJettyAuthTest.java

public void testAuth_UserRequiredNoUser() throws Exception {
    String loginUrl = "http://login-url?url=http://test-app.googleapp.com/user/test-auth";
    CreateLoginURLResponse loginUrlResponse = new CreateLoginURLResponse();
    loginUrlResponse.setLoginUrl(loginUrl);
    // Fake the expected call to "user/CreateLoginUrl".
    FakeableVmApiProxyDelegate fakeApiProxy = new FakeableVmApiProxyDelegate();
    ApiProxy.setDelegate(fakeApiProxy);//from   www .  j  a va  2  s.  co  m
    fakeApiProxy.addApiResponse(loginUrlResponse);

    HttpClient httpClient = new HttpClient();
    httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(30000);
    GetMethod get = new GetMethod(createUrl("/user/test-auth").toString());
    get.setFollowRedirects(false);
    int httpCode = httpClient.executeMethod(get);
    assertEquals(302, httpCode);
    Header redirUrl = get.getResponseHeader("Location");
    assertEquals(loginUrl, redirUrl.getValue());
}

From source file:com.google.apphosting.vmruntime.jetty9.VmRuntimeJettyAuthTest.java

public void testAuth_AdminRequiredNoUser() throws Exception {
    String loginUrl = "http://login-url?url=http://test-app.googleapp.com/user/test-auth";
    CreateLoginURLResponse loginUrlResponse = new CreateLoginURLResponse();
    loginUrlResponse.setLoginUrl(loginUrl);
    // Fake the expected call to "user/CreateLoginUrl".
    FakeableVmApiProxyDelegate fakeApiProxy = new FakeableVmApiProxyDelegate();
    ApiProxy.setDelegate(fakeApiProxy);//from   w  w w.  j  a  v a 2s .  co  m
    fakeApiProxy.addApiResponse(loginUrlResponse);

    HttpClient httpClient = new HttpClient();
    httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(30000);
    GetMethod get = new GetMethod(createUrl("/admin/test-auth").toString());
    get.setFollowRedirects(false);
    int httpCode = httpClient.executeMethod(get);
    assertEquals(302, httpCode);
    Header redirUrl = get.getResponseHeader("Location");
    assertEquals(loginUrl, redirUrl.getValue());
}

From source file:com.apatar.ui.JHelpDialog.java

private void addListeners() {
    sendButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent arg0) {

            PostMethod filePost = new PostMethod(getUrl());

            // filePost.getParameters().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true);
            try {
                List<File> targetFiles = getAttachFiles();
                Part[] parts;//w  w  w .j a  va  2s  . co m
                if (targetFiles != null) {
                    parts = new Part[targetFiles.size() + 1];
                    int i = 1;
                    for (File targetFile : targetFiles) {
                        parts[i++] = new FilePart("file" + i, targetFile);
                    }
                    ;
                } else
                    parts = new Part[1];

                parts[0] = new StringPart("FeatureRequest", text.getText());

                filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams()));
                HttpClient client = new HttpClient();
                client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
                int status = client.executeMethod(filePost);
                if (status != HttpStatus.SC_OK) {
                    JOptionPane.showMessageDialog(ApatarUiMain.MAIN_FRAME,
                            "Upload failed, response=" + HttpStatus.getStatusText(status));
                }

            } catch (Exception ex) {
                ex.printStackTrace();
            } finally {
                filePost.releaseConnection();
            }

        }

    });
}

From source file:com.yahoo.flowetl.services.http.BaseHttpGenerator.java

@Override
public Pair<HttpClient, HttpMethod> generate(HttpParams in) {
    HttpClient c = new HttpClient();
    c.getState().clear();//  w ww. j a v  a  2s .co  m
    c.getHttpConnectionManager().setParams(getManagerParams(in));
    c.setParams(getClientParams(in));
    HttpMethod toCall = null;
    if (in instanceof HttpService.PostHttpParams) {
        // post??
        toCall = getPostMethod(in);
    } else {
        // otherwise get (support more later??)
        toCall = getGetMethod(in);
    }
    applyCommonProperties(in, toCall);
    return new Pair<HttpClient, HttpMethod>(c, toCall);
}

From source file:HTTPChunkLocator.java

public HTTPChunkLocator(final HttpClient client, URI aUri) {
    final HttpConnectionManagerParams params = client.getHttpConnectionManager().getParams();
    params.setConnectionTimeout(10000);//  w  w w.j av  a 2 s .  c o  m
    params.setTcpNoDelay(true);
    params.setDefaultMaxConnectionsPerHost(10);
    client.getHttpConnectionManager().setParams(params);
    this.client = client;
    this.endpoint = aUri;

}