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();
}
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();
}
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();
}
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");
}
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);
}
}
Aggregations