Search in sources :

Example 21 with Executor

use of org.apache.http.client.fluent.Executor in project redisson by redisson.

the class RedissonSessionManagerTest method testWriteReadRemove.

@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();
}
Also used : Executor(org.apache.http.client.fluent.Executor) Test(org.junit.jupiter.api.Test)

Example 22 with Executor

use of org.apache.http.client.fluent.Executor in project redisson by redisson.

the class RedissonSessionManagerTest method testInvalidate.

@Test
public void testInvalidate() throws Exception {
    // start the server at http://localhost:8080/myapp
    TomcatServer server = new TomcatServer("myapp", 8080, "src/test/");
    server.start();
    WebApplicationContext wa = WebApplicationContextUtils.getRequiredWebApplicationContext(server.getServletContext());
    SessionEventsListener listener = wa.getBean(SessionEventsListener.class);
    Executor executor = Executor.newInstance();
    BasicCookieStore cookieStore = new BasicCookieStore();
    executor.use(cookieStore);
    write(executor, "test", "1234");
    Cookie cookie = cookieStore.getCookies().get(0);
    Thread.sleep(50);
    Assertions.assertEquals(1, listener.getSessionCreatedEvents());
    Assertions.assertEquals(0, listener.getSessionDeletedEvents());
    invalidate(executor);
    Assertions.assertEquals(1, listener.getSessionCreatedEvents());
    Assertions.assertEquals(1, listener.getSessionDeletedEvents());
    Executor.closeIdleConnections();
    executor = Executor.newInstance();
    cookieStore = new BasicCookieStore();
    cookieStore.addCookie(cookie);
    executor.use(cookieStore);
    read(executor, "test", "null");
    Executor.closeIdleConnections();
    server.stop();
}
Also used : Cookie(org.apache.http.cookie.Cookie) BasicCookieStore(org.apache.http.impl.client.BasicCookieStore) Executor(org.apache.http.client.fluent.Executor) WebApplicationContext(org.springframework.web.context.WebApplicationContext) Test(org.junit.jupiter.api.Test)

Example 23 with Executor

use of org.apache.http.client.fluent.Executor in project redisson by redisson.

the class RedissonSessionManagerTest method testExpire.

@Test
public void testExpire() throws Exception {
    HttpInitializer.CONFIG_CLASS = HttpConfigTimeout.class;
    // start the server at http://localhost:8080/myapp
    TomcatServer server = new TomcatServer("myapp", 8080, "src/test/");
    server.start();
    WebApplicationContext wa = WebApplicationContextUtils.getRequiredWebApplicationContext(server.getServletContext());
    SessionEventsListener listener = wa.getBean(SessionEventsListener.class);
    Executor executor = Executor.newInstance();
    BasicCookieStore cookieStore = new BasicCookieStore();
    executor.use(cookieStore);
    write(executor, "test", "1234");
    Cookie cookie = cookieStore.getCookies().get(0);
    Thread.sleep(50);
    Assertions.assertEquals(1, listener.getSessionCreatedEvents());
    Assertions.assertEquals(0, listener.getSessionExpiredEvents());
    Executor.closeIdleConnections();
    Thread.sleep(6000);
    Assertions.assertEquals(1, listener.getSessionCreatedEvents());
    Assertions.assertEquals(1, listener.getSessionExpiredEvents());
    executor = Executor.newInstance();
    cookieStore = new BasicCookieStore();
    cookieStore.addCookie(cookie);
    executor.use(cookieStore);
    read(executor, "test", "null");
    Thread.sleep(50);
    Assertions.assertEquals(2, listener.getSessionCreatedEvents());
    write(executor, "test", "1234");
    Thread.sleep(3000);
    read(executor, "test", "1234");
    Thread.sleep(3000);
    Assertions.assertEquals(1, listener.getSessionExpiredEvents());
    Thread.sleep(1000);
    Assertions.assertEquals(1, listener.getSessionExpiredEvents());
    Thread.sleep(3000);
    Assertions.assertEquals(2, listener.getSessionExpiredEvents());
    Executor.closeIdleConnections();
    server.stop();
}
Also used : Cookie(org.apache.http.cookie.Cookie) BasicCookieStore(org.apache.http.impl.client.BasicCookieStore) Executor(org.apache.http.client.fluent.Executor) WebApplicationContext(org.springframework.web.context.WebApplicationContext) Test(org.junit.jupiter.api.Test)

Example 24 with Executor

use of org.apache.http.client.fluent.Executor in project gerrit by GerritCodeReview.

the class CorsIT method crossDomainPutTopic.

@Test
public void crossDomainPutTopic() throws Exception {
    // Setting cookies with HttpOnly requires Servlet API 3+ which not all deployments might have
    // available.
    assume().that(cookieHasSetHttpOnlyMethod()).isTrue();
    Result change = createChange();
    BasicCookieStore cookies = new BasicCookieStore();
    Executor http = Executor.newInstance().use(cookies);
    Request req = Request.Get(canonicalWebUrl.get() + "/login/?account_id=" + admin.id().get());
    http.execute(req);
    String auth = null;
    for (Cookie c : cookies.getCookies()) {
        if ("GerritAccount".equals(c.getName())) {
            auth = c.getValue();
        }
    }
    assertWithMessage("GerritAccount cookie").that(auth).isNotNull();
    cookies.clear();
    UrlEncoded url = new UrlEncoded(canonicalWebUrl.get() + "/changes/" + change.getChangeId() + "/topic");
    url.put("$m", "PUT");
    url.put("$ct", "application/json; charset=US-ASCII");
    url.put("access_token", auth);
    String origin = "http://example.com";
    req = Request.Post(url.toString());
    req.setHeader(CONTENT_TYPE, "text/plain");
    req.setHeader(ORIGIN, origin);
    req.bodyByteArray("{\"topic\":\"test-xd\"}".getBytes(StandardCharsets.US_ASCII));
    HttpResponse r = http.execute(req).returnResponse();
    assertThat(r.getStatusLine().getStatusCode()).isEqualTo(200);
    Header vary = r.getFirstHeader(VARY);
    assertWithMessage(VARY).that(vary).isNotNull();
    assertWithMessage(VARY).that(Splitter.on(", ").splitToList(vary.getValue())).contains(ORIGIN);
    Header allowOrigin = r.getFirstHeader(ACCESS_CONTROL_ALLOW_ORIGIN);
    assertWithMessage(ACCESS_CONTROL_ALLOW_ORIGIN).that(allowOrigin).isNotNull();
    assertWithMessage(ACCESS_CONTROL_ALLOW_ORIGIN).that(allowOrigin.getValue()).isEqualTo(origin);
    Header allowAuth = r.getFirstHeader(ACCESS_CONTROL_ALLOW_CREDENTIALS);
    assertWithMessage(ACCESS_CONTROL_ALLOW_CREDENTIALS).that(allowAuth).isNotNull();
    assertWithMessage(ACCESS_CONTROL_ALLOW_CREDENTIALS).that(allowAuth.getValue()).isEqualTo("true");
    checkTopic(change, "test-xd");
}
Also used : Cookie(org.apache.http.cookie.Cookie) BasicCookieStore(org.apache.http.impl.client.BasicCookieStore) Executor(org.apache.http.client.fluent.Executor) Header(org.apache.http.Header) BasicHeader(org.apache.http.message.BasicHeader) Request(org.apache.http.client.fluent.Request) HttpResponse(org.apache.http.HttpResponse) UrlEncoded(com.google.gerrit.server.UrlEncoded) Result(com.google.gerrit.acceptance.PushOneCommit.Result) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 25 with Executor

use of org.apache.http.client.fluent.Executor in project streamsx.topology by IBMStreams.

the class RemoteDistributedStreamsContext method setSubmissionInstance.

static void setSubmissionInstance(AppEntity entity) throws IOException {
    Instance cfgInstance = getConfigInstance(entity);
    if (cfgInstance != null) {
        StreamsConnection sc = cfgInstance.getStreamsConnection();
        boolean verify = cfgInstance.getStreamsConnection().isVerify();
        JsonObject deploy = deploy(entity.submission);
        Function<Executor, String> authenticatorO = sc.getAuthenticator();
        deploy.addProperty(ContextProperties.SSL_VERIFY, verify);
        JsonObject service;
        if (authenticatorO instanceof ICP4DAuthenticator) {
            ICP4DAuthenticator authenticator = (ICP4DAuthenticator) authenticatorO;
            service = authenticator.config(verify);
        } else if (authenticatorO instanceof StandaloneAuthenticator) {
            StandaloneAuthenticator authenticator = (StandaloneAuthenticator) authenticatorO;
            service = authenticator.config(verify);
            String buildServiceUrl = getConfigBuildServiceUrl(entity);
            if (buildServiceUrl == null) {
                buildServiceUrl = System.getenv(Util.STREAMS_BUILD_URL);
            }
            if (buildServiceUrl != null) {
                // Copy so we don't affect instance. Version of gson we
                // use lacks deepCopy() so we serialize / parse to copy.
                String json = service.toString();
                service = new JsonParser().parse(json).getAsJsonObject();
                JsonObject connInfo = service.getAsJsonObject(CONNECTION_INFO);
                if (connInfo.has(SERVICE_BUILD_ENDPOINT)) {
                    connInfo.remove(SERVICE_BUILD_ENDPOINT);
                }
                connInfo.addProperty(SERVICE_BUILD_ENDPOINT, buildServiceUrl);
            }
        } else {
            throw new IllegalStateException("Invalid Instance for Streams V5: " + cfgInstance);
        }
        deploy.add(StreamsKeys.SERVICE_DEFINITION, service);
    }
}
Also used : ICP4DAuthenticator(com.ibm.streamsx.rest.internal.ICP4DAuthenticator) Executor(org.apache.http.client.fluent.Executor) Instance(com.ibm.streamsx.rest.Instance) JsonObject(com.google.gson.JsonObject) StreamsConnection(com.ibm.streamsx.rest.StreamsConnection) StandaloneAuthenticator(com.ibm.streamsx.rest.internal.StandaloneAuthenticator) JsonParser(com.google.gson.JsonParser)

Aggregations

Executor (org.apache.http.client.fluent.Executor)46 Test (org.junit.Test)26 Request (org.apache.http.client.fluent.Request)12 BasicCookieStore (org.apache.http.impl.client.BasicCookieStore)11 HttpResponse (org.apache.http.HttpResponse)6 Response (org.apache.http.client.fluent.Response)6 URI (java.net.URI)5 Cookie (org.apache.http.cookie.Cookie)5 Test (org.junit.jupiter.api.Test)5 JsonObject (com.google.gson.JsonObject)4 InputStream (java.io.InputStream)4 DistributionTransportSecret (org.apache.sling.distribution.transport.DistributionTransportSecret)4 StreamsConnection (com.ibm.streamsx.rest.StreamsConnection)3 HashMap (java.util.HashMap)3 DistributionRequest (org.apache.sling.distribution.DistributionRequest)3 JsonParser (com.google.gson.JsonParser)2 Instance (com.ibm.streamsx.rest.Instance)2 ICP4DAuthenticator (com.ibm.streamsx.rest.internal.ICP4DAuthenticator)2 StandaloneAuthenticator (com.ibm.streamsx.rest.internal.StandaloneAuthenticator)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2