use of org.apache.http.client.fluent.Executor in project redisson by redisson.
the class RedissonSessionManagerTest method testInvalidate.
@Test
public void testInvalidate() throws Exception {
File f = Paths.get("").toAbsolutePath().resolve("src/test/webapp/WEB-INF/redisson.yaml").toFile();
Config config = Config.fromYAML(f);
RedissonClient r = Redisson.create(config);
r.getKeys().flushall();
// start the server at http://localhost:8080/myapp
TomcatServer server = new TomcatServer("myapp", 8080, "src/test/");
server.start();
Executor executor = Executor.newInstance();
BasicCookieStore cookieStore = new BasicCookieStore();
executor.use(cookieStore);
write(8080, executor, "test", "1234");
Cookie cookie = cookieStore.getCookies().get(0);
invalidate(executor);
Executor.closeIdleConnections();
executor = Executor.newInstance();
cookieStore = new BasicCookieStore();
cookieStore.addCookie(cookie);
executor.use(cookieStore);
read(8080, executor, "test", "null");
invalidate(executor);
Executor.closeIdleConnections();
server.stop();
TimeUnit.SECONDS.sleep(60);
Assert.assertEquals(0, r.getKeys().count());
}
use of org.apache.http.client.fluent.Executor in project redisson by redisson.
the class RedissonSessionManagerTest method testUpdateTwoServers.
@Test
public void testUpdateTwoServers() 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);
write(8080, executor, "test", "1234");
read(8081, executor, "test", "1234");
read(8080, executor, "test", "1234");
write(8080, executor, "test", "324");
read(8081, executor, "test", "324");
Executor.closeIdleConnections();
server1.stop();
server2.stop();
}
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(8080, executor, "test", "1234");
read(8080, 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 testRecreate.
@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();
}
use of org.apache.http.client.fluent.Executor in project streamsx.topology by IBMStreams.
the class ICP4DAuthenticator method config.
public JsonObject config(boolean verify, boolean forceRecreate) throws IOException {
if (cfg != null && !forceRecreate)
return cfg;
this.verify = verify;
Executor executor = RestUtils.createExecutor(!verify);
JsonObject namepwd = new JsonObject();
String[] userPwd = Util.getDefaultUserPassword(user, password);
namepwd.addProperty("username", userPwd[0]);
namepwd.addProperty("password", userPwd[1]);
Request post = Request.Post(authorizeUrl.toExternalForm()).bodyString(namepwd.toString(), ContentType.APPLICATION_JSON);
JsonObject resp = RestUtils.requestGsonResponse(executor, post);
String icp4dToken = GsonUtilities.jstring(resp, "token");
// these tokens have ~ 12 hours lifetime, with 11 hours from now as expected expiry time we are comfortable
expire = System.currentTimeMillis() + 11l * 3600l * MS;
String icpdAuth = RestUtils.createBearerAuth(icp4dToken);
String serviceId = null;
JsonObject sci = null;
JsonObject sca = null;
// Occasionally see null for connection-info.
for (int i = 0; i < 5; i++) {
resp = RestUtils.getGsonResponse(executor, icpdAuth, detailsUrl);
JsonObject sro = object(resp, "requestObj");
serviceId = jstring(sro, "ID");
sca = object(sro, "CreateArguments");
sci = object(sca, "connection-info");
if (sci != null && !sci.entrySet().isEmpty())
break;
sci = null;
try {
Thread.sleep(5);
} catch (InterruptedException e) {
break;
}
}
if (sci == null)
throw new IllegalStateException("Unable to retrieve connection details for Streams instance: " + instanceName);
this.serviceAuth = RestUtils.createBearerAuth(icp4dToken);
JsonObject connInfo = new JsonObject();
final String externalBuildPoolsEndpoint = jstring(sci, "externalBuildPoolsEndpoint");
if (externalBuildPoolsEndpoint != null) {
URL buildPoolsUrl = urlFromEndPoint(externalBuildPoolsEndpoint);
connInfo.addProperty("serviceBuildPoolsEndpoint", buildPoolsUrl.toExternalForm());
}
final String externalBuildEndpoint = jstring(sci, "externalBuildEndpoint");
URL buildUrl = urlFromEndPoint(externalBuildEndpoint);
final String externalRestResourceEndpoint = jstring(sci, "externalRestResourceEndpoint");
if (externalRestResourceEndpoint != null) {
URL restResourceUrl = urlFromEndPoint(externalRestResourceEndpoint);
connInfo.addProperty(StreamsKeys.STREAMS_REST_RESOURCES_ENDPOINT, restResourceUrl.toExternalForm());
}
final String externalRestEndpoint = jstring(sci, "externalRestEndpoint");
URL streamsUrl = urlFromEndPoint(externalRestEndpoint);
JsonObject instance = object(sca, "metadata", "instance");
String serviceName = jstring(instance, "id");
// Return object matches one created in Python.
connInfo.addProperty("serviceRestEndpoint", streamsUrl.toExternalForm());
connInfo.addProperty("serviceBuildEndpoint", buildUrl.toExternalForm());
JsonObject cfg = new JsonObject();
cfg.addProperty("type", "streams");
cfg.addProperty("externalClient", true);
cfg.add("connection_info", connInfo);
cfg.addProperty("service_token", icp4dToken);
cfg.addProperty("service_token_expire", expire);
cfg.addProperty("user_token", icp4dToken);
cfg.addProperty("service_name", serviceName);
cfg.addProperty("cluster_ip", icpdUrl.getHost());
cfg.addProperty("cluster_port", icpdUrl.getPort());
cfg.addProperty("service_id", serviceId);
this.cfg = cfg;
return cfg;
}
Aggregations