Java Code Examples for org.apache.http.client.fluent.Executor#newInstance()

The following examples show how to use org.apache.http.client.fluent.Executor#newInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RedissonSessionManagerTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
public void testExpiration() throws Exception {
    TomcatServer server1 = new TomcatServer("myapp", 8080, "src/test/");
    server1.start();

    Executor executor = Executor.newInstance();
    BasicCookieStore cookieStore = new BasicCookieStore();
    executor.use(cookieStore);
    
    write(executor, "test", "1234");

    TomcatServer server2 = new TomcatServer("myapp", 8081, "src/test/");
    server2.start();

    Thread.sleep(30000);
    
    read(8081, executor, "test", "1234");

    Thread.sleep(40000);
    
    executor.use(cookieStore);
    read(executor, "test", "1234");
    
    Executor.closeIdleConnections();
    server1.stop();
    server2.stop();
}
 
Example 2
Source File: RedissonSessionManagerTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdate() throws Exception {
    // start the server at http://localhost:8080/myapp
    TomcatServer server = new TomcatServer("myapp", 8080, "src/test/");
    server.start();

    Executor executor = Executor.newInstance();
    
    write(executor, "test", "1");
    read(executor, "test", "1");
    write(executor, "test", "2");
    read(executor, "test", "2");
    
    Executor.closeIdleConnections();
    server.stop();
}
 
Example 3
Source File: RedissonSessionManagerTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdate() throws Exception {
    // start the server at http://localhost:8080/myapp
    TomcatServer server = new TomcatServer("myapp", 8080, "src/test/");
    server.start();

    Executor executor = Executor.newInstance();
    
    write(executor, "test", "1");
    read(executor, "test", "1");
    write(executor, "test", "2");
    read(executor, "test", "2");
    
    Executor.closeIdleConnections();
    server.stop();
}
 
Example 4
Source File: RedissonSessionManagerTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdate() throws Exception {
    // start the server at http://localhost:8080/myapp
    TomcatServer server = new TomcatServer("myapp", 8080, "src/test/");
    server.start();

    Executor executor = Executor.newInstance();
    
    write(executor, "test", "1");
    read(executor, "test", "1");
    write(executor, "test", "2");
    read(executor, "test", "2");
    
    Executor.closeIdleConnections();
    server.stop();
}
 
Example 5
Source File: RedissonSessionManagerTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateTwoServers() throws Exception {
    TomcatServer server1 = new TomcatServer("myapp", 8080, "src/test/");
    server1.start();

    Executor executor = Executor.newInstance();
    BasicCookieStore cookieStore = new BasicCookieStore();
    executor.use(cookieStore);
    
    write(executor, "test", "1234");

    TomcatServer server2 = new TomcatServer("myapp", 8081, "src/test/");
    server2.start();

    read(8081, executor, "test", "1234");
    read(executor, "test", "1234");
    write(executor, "test", "324");
    read(8081, executor, "test", "324");
    
    Executor.closeIdleConnections();
    server1.stop();
    server2.stop();
}
 
Example 6
Source File: RedissonSessionManagerTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testHttpSessionListener() throws Exception {
    TomcatServer server1 = new TomcatServer("myapp", 8080, "src/test/");
    server1.start();

    TomcatServer server2 = new TomcatServer("myapp", 8081, "src/test/");
    server2.start();

    Executor executor = Executor.newInstance();
    BasicCookieStore cookieStore = new BasicCookieStore();
    executor.use(cookieStore);

    TestHttpSessionListener.CREATED_INVOCATION_COUNTER = 0;
    TestHttpSessionListener.DESTROYED_INVOCATION_COUNTER = 0;

    write(executor, "test", "1234");

    TomcatServer server3 = new TomcatServer("myapp", 8082, "src/test/");
    server3.start();

    invalidate(executor);

    Thread.sleep(500);

    Assert.assertEquals(2, TestHttpSessionListener.CREATED_INVOCATION_COUNTER);
    Assert.assertEquals(3, TestHttpSessionListener.DESTROYED_INVOCATION_COUNTER);

    Executor.closeIdleConnections();
    server1.stop();
    server2.stop();
    server3.stop();
}
 
Example 7
Source File: RedissonSessionManagerTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testWriteReadRemove() throws Exception {
    // start the server at http://localhost:8080/myapp
    TomcatServer server = new TomcatServer("myapp", 8080, "src/test/");
    server.start();

    Executor executor = Executor.newInstance();
    
    write(executor, "test", "1234");
    read(executor, "test", "1234");
    remove(executor, "test", "null");
    
    Executor.closeIdleConnections();
    server.stop();
}
 
Example 8
Source File: RedissonSessionManagerTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testHttpSessionListener() throws Exception {
    TomcatServer server1 = new TomcatServer("myapp", 8080, "src/test/");
    server1.start();

    TomcatServer server2 = new TomcatServer("myapp", 8081, "src/test/");
    server2.start();

    Executor executor = Executor.newInstance();
    BasicCookieStore cookieStore = new BasicCookieStore();
    executor.use(cookieStore);

    TestHttpSessionListener.CREATED_INVOCATION_COUNTER = 0;
    TestHttpSessionListener.DESTROYED_INVOCATION_COUNTER = 0;

    write(executor, "test", "1234");

    TomcatServer server3 = new TomcatServer("myapp", 8082, "src/test/");
    server3.start();

    invalidate(executor);

    Thread.sleep(500);

    Assert.assertEquals(2, TestHttpSessionListener.CREATED_INVOCATION_COUNTER);
    Assert.assertEquals(3, TestHttpSessionListener.DESTROYED_INVOCATION_COUNTER);

    Executor.closeIdleConnections();
    server1.stop();
    server2.stop();
    server3.stop();
}
 
Example 9
Source File: RedissonSessionManagerTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testExpiration() throws Exception {
    TomcatServer server1 = new TomcatServer("myapp", 8080, "src/test/");
    server1.start();

    Executor executor = Executor.newInstance();
    BasicCookieStore cookieStore = new BasicCookieStore();
    executor.use(cookieStore);
    
    write(executor, "test", "1234");

    TomcatServer server2 = new TomcatServer("myapp", 8081, "src/test/");
    server2.start();

    Thread.sleep(30000);
    
    read(8081, executor, "test", "1234");

    Thread.sleep(40000);
    
    executor.use(cookieStore);
    read(executor, "test", "1234");
    
    Executor.closeIdleConnections();
    server1.stop();
    server2.stop();
}
 
Example 10
Source File: RedissonSessionManagerTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testRecreate() throws Exception {
    // start the server at http://localhost:8080/myapp
    TomcatServer server = new TomcatServer("myapp", 8080, "src/test/");
    server.start();

    Executor executor = Executor.newInstance();
    
    write(executor, "test", "1");
    recreate(executor, "test", "2");
    read(executor, "test", "2");
    
    Executor.closeIdleConnections();
    server.stop();
}
 
Example 11
Source File: RedissonSessionManagerTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testWriteReadRemove() throws Exception {
    // start the server at http://localhost:8080/myapp
    TomcatServer server = new TomcatServer("myapp", 8080, "src/test/");
    server.start();

    Executor executor = Executor.newInstance();
    
    write(executor, "test", "1234");
    read(executor, "test", "1234");
    remove(executor, "test", "null");
    
    Executor.closeIdleConnections();
    server.stop();
}
 
Example 12
Source File: RedissonSessionManagerTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testExpiration() throws Exception {
    TomcatServer server1 = new TomcatServer("myapp", 8080, "src/test/");
    server1.start();

    Executor executor = Executor.newInstance();
    BasicCookieStore cookieStore = new BasicCookieStore();
    executor.use(cookieStore);
    
    write(executor, "test", "1234");

    TomcatServer server2 = new TomcatServer("myapp", 8081, "src/test/");
    server2.start();

    Thread.sleep(30000);
    
    read(8081, executor, "test", "1234");

    Thread.sleep(40000);
    
    executor.use(cookieStore);
    read(executor, "test", "1234");
    
    Executor.closeIdleConnections();
    server1.stop();
    server2.stop();
}
 
Example 13
Source File: HttpClientServiceImpl.java    From smockin with Apache License 2.0 5 votes vote down vote up
HttpClientResponseDTO executeRequest(final Request request, final Map<String, String> requestHeaders, final boolean isHttpsCall) throws IOException {


        applyRequestHeaders(request, requestHeaders);

        final HttpResponse httpResponse;

        if (isHttpsCall) {

            try {
                final Executor executor = Executor.newInstance(noSslHttpClient());
                httpResponse = executor.execute(request).returnResponse();
            } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) {
                throw new IOException();
            }

        } else {

            httpResponse = request.execute().returnResponse();
        }

        return new HttpClientResponseDTO(
                httpResponse.getStatusLine().getStatusCode(),
                httpResponse.getEntity().getContentType().getValue(),
                extractResponseHeaders(httpResponse),
                extractResponseBody(httpResponse)
        );
    }
 
Example 14
Source File: RedissonSessionManagerTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testWriteReadRemove() throws Exception {
    // start the server at http://localhost:8080/myapp
    TomcatServer server = new TomcatServer("myapp", 8080, "src/test/");
    server.start();

    Executor executor = Executor.newInstance();
    
    write(executor, "test", "1234");
    read(executor, "test", "1234");
    remove(executor, "test", "null");
    
    Executor.closeIdleConnections();
    server.stop();
}
 
Example 15
Source File: RedissonSessionManagerTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testWriteReadRemove() throws Exception {
    // start the server at http://localhost:8080/myapp
    TomcatServer server = new TomcatServer("myapp", 8080, "src/test/");
    server.start();

    Executor executor = Executor.newInstance();
    
    write(executor, "test", "1234");
    read(executor, "test", "1234");
    remove(executor, "test", "null");
    
    Executor.closeIdleConnections();
    server.stop();
}
 
Example 16
Source File: Rest.java    From components with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor sets schema(http or https), host(google.com) and port number(8080) using one hostPort parameter
 * 
 * @param hostPort URL
 */
public Rest(String hostPort) {
    headers = new LinkedList<>();
    if (!hostPort.endsWith("/")) {
        hostPort = hostPort + "/";
    }
    this.hostPort = hostPort;

    contentType = ContentType.create("application/json", StandardCharsets.UTF_8);

    executor = Executor.newInstance(createHttpClient());
    executor.use(new BasicCookieStore());
}
 
Example 17
Source File: RedissonSessionManagerTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testRecreate() throws Exception {
    // start the server at http://localhost:8080/myapp
    TomcatServer server = new TomcatServer("myapp", 8080, "src/test/");
    server.start();

    Executor executor = Executor.newInstance();
    
    write(executor, "test", "1");
    recreate(executor, "test", "2");
    read(executor, "test", "2");
    
    Executor.closeIdleConnections();
    server.stop();
}
 
Example 18
Source File: GithubHttp.java    From zest-writer with GNU General Public License v3.0 5 votes vote down vote up
public static Content loadManifest(String folder, String owner, String repo) throws IOException {
    String projecUrl = "https://api.github.com/repos/"+owner+"/"+repo;
    String title = null;
    log.debug("Tentative de connexion à l'url : "+projecUrl);
    String githubUser = System.getProperty("zw.github_user");
    String githubToken = System.getProperty("zw.github_token");

    Executor executor;
    if(githubUser != null && !"".equals(githubUser) && githubToken != null && !"".equals(githubToken)) {
        executor = Executor
                .newInstance()
                .auth(new HttpHost("api.github.com"), githubUser, githubToken);
    } else {
        executor = Executor.newInstance();
    }

    String json = executor.execute(Request.Get(projecUrl)).returnContent().asString();
    ObjectMapper mapper = new ObjectMapper();
    Map map = mapper.readValue(json, Map.class);
    if(map.containsKey("description")) {
        title = (String) map.get("description");
    }
    Content current = new Content("container", toSlug(title), title, Constant.DEFAULT_INTRODUCTION_FILENAME, Constant.DEFAULT_CONCLUSION_FILENAME, new ArrayList<>(), 2, "CC-BY", title, "TUTORIAL");
    // read all directory
    current.getChildren ().addAll (loadDirectory (folder.length () + File.separator.length (), new File(folder)));
    current.setBasePath (folder);
    generateMetadataAttributes(current.getFilePath());
    return current;
}
 
Example 19
Source File: RestUtils.java    From streamsx.topology with Apache License 2.0 4 votes vote down vote up
static Executor createExecutor() {
    return Executor.newInstance(createHttpClient(false));
}
 
Example 20
Source File: LoginHandlerTest.java    From substitution-schedule-parser with Mozilla Public License 2.0 4 votes vote down vote up
@NotNull private Executor newExecutor() {
    return Executor.newInstance(HttpClientBuilder.create().build());
}