use of org.infinispan.client.rest.configuration.RestClientConfigurationBuilder in project infinispan by infinispan.
the class RestEndpointRouterTest method shouldRouteToProperRestServerBasedOnPath.
/**
* In this scenario we create 2 REST servers, each one with different REST Path: <ul> <li>REST1 -
* http://127.0.0.1:8080/rest/rest1</li> <li>REST2 - http://127.0.0.1:8080/rest/rest2</li> </ul>
* <p>
* The router should match requests based on path and redirect them to proper server.
*/
@Test
public void shouldRouteToProperRestServerBasedOnPath() {
// given
restServer1 = RestTestingUtil.createDefaultRestServer("rest1", "default");
restServer2 = RestTestingUtil.createDefaultRestServer("rest2", "default");
RestServerRouteDestination rest1Destination = new RestServerRouteDestination("rest1", restServer1);
RestRouteSource rest1Source = new RestRouteSource("rest1");
Route<RestRouteSource, RestServerRouteDestination> routeToRest1 = new Route<>(rest1Source, rest1Destination);
RestServerRouteDestination rest2Destination = new RestServerRouteDestination("rest2", restServer2);
RestRouteSource rest2Source = new RestRouteSource("rest2");
Route<RestRouteSource, RestServerRouteDestination> routeToRest2 = new Route<>(rest2Source, rest2Destination);
RouterConfigurationBuilder routerConfigurationBuilder = new RouterConfigurationBuilder();
routerConfigurationBuilder.rest().port(8080).ip(InetAddress.getLoopbackAddress()).routing().add(routeToRest1).add(routeToRest2);
router = new Router(routerConfigurationBuilder.build());
router.start();
int port = router.getRouter(EndpointRouter.Protocol.REST).get().getPort();
// when
ServerConfigurationBuilder builder = new RestClientConfigurationBuilder().addServer().host("127.0.0.1").port(port);
restClient = RestClient.forConfiguration(builder.build());
RestRawClient rawClient = restClient.raw();
String path1 = "/rest/rest1/v2/caches/default/test";
String path2 = "/rest/rest2/v2/caches/default/test";
join(rawClient.putValue(path1, emptyMap(), "rest1", TEXT_PLAIN_TYPE));
join(rawClient.putValue(path2, emptyMap(), "rest2", TEXT_PLAIN_TYPE));
String valueReturnedFromRest1 = join(rawClient.get(path1)).getBody();
String valueReturnedFromRest2 = join(rawClient.get(path2)).getBody();
// then
assertThat(valueReturnedFromRest1).isEqualTo("rest1");
assertThat(valueReturnedFromRest2).isEqualTo("rest2");
}
use of org.infinispan.client.rest.configuration.RestClientConfigurationBuilder in project infinispan by infinispan.
the class SinglePortTest method shouldUpgradeThroughALPN.
@Test
public void shouldUpgradeThroughALPN() throws Exception {
checkForOpenSSL();
// given
restServer = RestTestingUtil.createDefaultRestServer("rest", "default");
RestServerRouteDestination restDestination = new RestServerRouteDestination("rest", restServer);
SinglePortRouteSource singlePortSource = new SinglePortRouteSource();
Route<SinglePortRouteSource, RestServerRouteDestination> routeToRest = new Route<>(singlePortSource, restDestination);
SslContextFactory sslContextFactory = new SslContextFactory();
RouterConfigurationBuilder routerConfigurationBuilder = new RouterConfigurationBuilder();
routerConfigurationBuilder.singlePort().sslContext(sslContextFactory.keyStoreFileName(KEY_STORE_PATH).keyStorePassword(KEY_STORE_PASSWORD.toCharArray()).getContext()).port(0).ip(InetAddress.getLoopbackAddress()).routing().add(routeToRest);
router = new Router(routerConfigurationBuilder.build());
router.start();
EndpointRouter singlePortRouter = router.getRouter(EndpointRouter.Protocol.SINGLE_PORT).get();
// when
RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder();
builder.addServer().host(singlePortRouter.getHost()).port(singlePortRouter.getPort()).protocol(Protocol.HTTP_20).security().ssl().trustStoreFileName(TRUST_STORE_PATH).trustStorePassword("secret".toCharArray()).hostnameVerifier((hostname, session) -> true);
httpClient = RestClient.forConfiguration(builder.build());
CompletionStage<RestResponse> response = httpClient.cache("default").post("test", VALUE);
// then
ResponseAssertion.assertThat(response).hasNoContent();
}
use of org.infinispan.client.rest.configuration.RestClientConfigurationBuilder in project infinispan by infinispan.
the class SinglePortTest method shouldUpgradeThroughHTTP11UpgradeHeaders.
@Test
public void shouldUpgradeThroughHTTP11UpgradeHeaders() {
// given
restServer = RestTestingUtil.createDefaultRestServer("rest", "default");
RestServerRouteDestination restDestination = new RestServerRouteDestination("rest1", restServer);
SinglePortRouteSource singlePortSource = new SinglePortRouteSource();
Route<SinglePortRouteSource, RestServerRouteDestination> routeToRest = new Route<>(singlePortSource, restDestination);
RouterConfigurationBuilder routerConfigurationBuilder = new RouterConfigurationBuilder();
routerConfigurationBuilder.singlePort().port(0).ip(InetAddress.getLoopbackAddress()).routing().add(routeToRest);
router = new Router(routerConfigurationBuilder.build());
router.start();
int port = router.getRouter(EndpointRouter.Protocol.SINGLE_PORT).get().getPort();
// when
RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder();
builder.addServer().host("localhost").port(port).protocol(Protocol.HTTP_20);
httpClient = RestClient.forConfiguration(builder.build());
CompletionStage<RestResponse> response = httpClient.cache("default").post("test", VALUE);
// then
ResponseAssertion.assertThat(response).hasNoContent();
}
use of org.infinispan.client.rest.configuration.RestClientConfigurationBuilder in project infinispan by infinispan.
the class IndexedCacheNonIndexedEntityTest method createCacheManager.
@Override
protected EmbeddedCacheManager createCacheManager() {
GlobalConfigurationBuilder gcb = new GlobalConfigurationBuilder().nonClusteredDefault();
EmbeddedCacheManager cm = TestCacheManagerFactory.createCacheManager(gcb, getDefaultStandaloneCacheConfig(false));
restServer = new RestServerHelper(cm);
restServer.start(TestResourceTracker.getCurrentTestShortName() + "-" + cm.getAddress());
RestClientConfigurationBuilder clientConfigurationBuilder = new RestClientConfigurationBuilder();
clientConfigurationBuilder.addServer().host(restServer.getHost()).port(restServer.getPort());
client = RestClient.forConfiguration(clientConfigurationBuilder.build());
return cm;
}
use of org.infinispan.client.rest.configuration.RestClientConfigurationBuilder in project infinispan by infinispan.
the class ForkedInfinispanServerDriver method getRestClient.
private RestClient getRestClient(int server) {
RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder();
// Filter driver properties for REST client configuration properties, e.g. security configuration
// and apply them before applying rest of the dynamically created configuration, e.g. port.
Properties securityConfigurationProperties = new Properties();
configuration.properties().entrySet().stream().filter(entry -> entry.getKey().toString().startsWith("infinispan.client.rest.")).forEach(entry -> securityConfigurationProperties.put(entry.getKey(), entry.getValue()));
builder.withProperties(securityConfigurationProperties);
// Ensure to not print out the *values*!!!
log.debugf("Configured client with the following properties: %s", securityConfigurationProperties.keySet().toString());
builder.addServer().host("localhost").port(getServerPort(server, ForkedServer.DEFAULT_SINGLE_PORT));
return RestClient.forConfiguration(builder.build());
}
Aggregations