use of org.infinispan.server.router.routes.rest.RestServerRouteDestination in project keycloak by keycloak.
the class HotRodUtils method createHotRodMapStoreServer.
/**
* Not suitable for a production usage. Only for development and test purposes.
* Also do not use in clustered environment.
* @param hotRodServer HotRodServer
* @param hotRodCacheManager DefaultCacheManager
* @param embeddedPort int
*/
public static void createHotRodMapStoreServer(HotRodServer hotRodServer, DefaultCacheManager hotRodCacheManager, int embeddedPort) {
HotRodServerConfigurationBuilder hotRodServerConfigurationBuilder = new HotRodServerConfigurationBuilder();
hotRodServerConfigurationBuilder.startTransport(false);
hotRodServerConfigurationBuilder.port(embeddedPort);
hotRodServer.start(hotRodServerConfigurationBuilder.build(), hotRodCacheManager);
RestServerConfigurationBuilder restServerConfigurationBuilder = new RestServerConfigurationBuilder();
restServerConfigurationBuilder.startTransport(false);
restServerConfigurationBuilder.port(embeddedPort);
RestServer restServer = new RestServer();
restServer.start(restServerConfigurationBuilder.build(), hotRodCacheManager);
SinglePortRouteSource routeSource = new SinglePortRouteSource();
Set<Route<? extends RouteSource, ? extends RouteDestination>> routes = new HashSet<>();
routes.add(new Route<>(routeSource, new HotRodServerRouteDestination("hotrod", hotRodServer)));
routes.add(new Route<>(routeSource, new RestServerRouteDestination("rest", restServer)));
SinglePortRouterConfiguration singlePortRouter = new SinglePortServerConfigurationBuilder().port(embeddedPort).build();
SinglePortEndpointRouter endpointServer = new SinglePortEndpointRouter(singlePortRouter);
endpointServer.start(new RoutingTable(routes));
}
use of org.infinispan.server.router.routes.rest.RestServerRouteDestination in project infinispan by infinispan.
the class SinglePortTest method shouldUpgradeToHotRodThroughALPN.
@Test
public void shouldUpgradeToHotRodThroughALPN() {
checkForOpenSSL();
// given
hotrodServer = HotRodTestingUtil.startHotRodServerWithoutTransport("default");
restServer = RestTestingUtil.createDefaultRestServer("rest", "default");
HotRodServerRouteDestination hotrodDestination = new HotRodServerRouteDestination("hotrod", hotrodServer);
RestServerRouteDestination restDestination = new RestServerRouteDestination("rest", restServer);
SinglePortRouteSource singlePortSource = new SinglePortRouteSource();
Route<SinglePortRouteSource, RestServerRouteDestination> routeToRest = new Route<>(singlePortSource, restDestination);
Route<SinglePortRouteSource, HotRodServerRouteDestination> routeToHotRod = new Route<>(singlePortSource, hotrodDestination);
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).add(routeToHotRod);
router = new Router(routerConfigurationBuilder.build());
router.start();
EndpointRouter endpointRouter = router.getRouter(EndpointRouter.Protocol.SINGLE_PORT).get();
// when
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.addServer().host(endpointRouter.getIp().getHostAddress()).port(endpointRouter.getPort());
builder.security().ssl().trustStoreFileName(TRUST_STORE_PATH).trustStorePassword(TRUST_STORE_PASSWORD.toCharArray());
hotRodClient = new RemoteCacheManager(builder.build());
hotRodClient.getCache("default").put("test", "test");
}
use of org.infinispan.server.router.routes.rest.RestServerRouteDestination in project infinispan by infinispan.
the class SinglePortTest method shouldUpgradeToHotRodThroughHTTP11UpgradeHeaders.
@Test
public void shouldUpgradeToHotRodThroughHTTP11UpgradeHeaders() {
// given
EmbeddedCacheManager cacheManager = TestCacheManagerFactory.createCacheManager(hotRodCacheConfiguration());
// Initialize a transport-less Hot Rod server
HotRodServerConfigurationBuilder hotRodServerBuilder = new HotRodServerConfigurationBuilder();
hotRodServerBuilder.startTransport(false);
hotRodServerBuilder.name(TestResourceTracker.getCurrentTestName());
hotrodServer = HotRodClientTestingUtil.startHotRodServer(cacheManager, hotRodServerBuilder);
// Initialize a transport-less REST server
restServer = new RestServer();
RestServerConfigurationBuilder restServerConfigurationBuilder = new RestServerConfigurationBuilder();
restServerConfigurationBuilder.startTransport(false);
restServerConfigurationBuilder.name(TestResourceTracker.getCurrentTestName());
restServer.setServerManagement(new DummyServerManagement(), true);
restServer.start(restServerConfigurationBuilder.build(), cacheManager);
// Initialize a Single Port server with routes to the Hot Rod and REST servers
HotRodServerRouteDestination hotrodDestination = new HotRodServerRouteDestination("hotrod", hotrodServer);
RestServerRouteDestination restDestination = new RestServerRouteDestination("rest", restServer);
SinglePortRouteSource singlePortSource = new SinglePortRouteSource();
Route<SinglePortRouteSource, HotRodServerRouteDestination> routeToHotRod = new Route<>(singlePortSource, hotrodDestination);
Route<SinglePortRouteSource, RestServerRouteDestination> routeToRest = new Route<>(singlePortSource, restDestination);
RouterConfigurationBuilder routerConfigurationBuilder = new RouterConfigurationBuilder();
routerConfigurationBuilder.singlePort().port(0).ip(InetAddress.getLoopbackAddress()).routing().add(routeToRest).add(routeToHotRod);
router = new Router(routerConfigurationBuilder.build());
router.start();
EndpointRouter endpointRouter = router.getRouter(EndpointRouter.Protocol.SINGLE_PORT).get();
String host = endpointRouter.getHost();
int port = endpointRouter.getPort();
// First off we verify that the HTTP side of things works
RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder();
builder.addServer().host(host).port(port).protocol(Protocol.HTTP_11);
httpClient = RestClient.forConfiguration(builder.build());
CompletionStage<RestResponse> response = httpClient.cache(cacheManager.getCacheManagerConfiguration().defaultCacheName().get()).post("key", VALUE);
ResponseAssertion.assertThat(response).hasNoContent();
Assertions.assertThat(restServer.getCacheManager().getCache().size()).isEqualTo(1);
// Next up, the RemoteCacheManager
ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
configurationBuilder.marshaller(new UTF8StringMarshaller());
configurationBuilder.addServer().host(host).port(port);
hotRodClient = new RemoteCacheManager(configurationBuilder.build());
Object value = hotRodClient.getCache().withDataFormat(DataFormat.builder().keyType(TEXT_PLAIN).valueType(TEXT_PLAIN).build()).get("key");
Assertions.assertThat(value).isEqualTo("test");
}
Aggregations