Search in sources :

Example 46 with RestClientConfigurationBuilder

use of org.infinispan.client.rest.configuration.RestClientConfigurationBuilder in project infinispan by infinispan.

the class HotRodCacheQueries method testQueryViaRest.

@Test
public void testQueryViaRest() throws IOException {
    RemoteCache<Integer, User> remoteCache = ClusteredIT.createQueryableCache(SERVER_TEST, indexed);
    remoteCache.put(1, createUser1());
    remoteCache.put(2, createUser2());
    String query = "FROM sample_bank_account.User WHERE name='Adrian'";
    RestClient restClient = SERVER_TEST.newRestClient(new RestClientConfigurationBuilder());
    RestResponse response = sync(restClient.cache(SERVER_TEST.getMethodName()).query(query));
    Json results = Json.read(response.getBody());
    assertEquals(1, results.at("total_results").asInteger());
}
Also used : RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) User(org.infinispan.protostream.sampledomain.User) RestResponse(org.infinispan.client.rest.RestResponse) RestClient(org.infinispan.client.rest.RestClient) Json(org.infinispan.commons.dataconversion.internal.Json) Test(org.junit.Test)

Example 47 with RestClientConfigurationBuilder

use of org.infinispan.client.rest.configuration.RestClientConfigurationBuilder in project infinispan by infinispan.

the class BaseRestSearchTest method createCacheManagers.

@Override
protected void createCacheManagers() throws Exception {
    // global config
    GlobalConfigurationBuilder globalCfg = GlobalConfigurationBuilder.defaultClusteredBuilder();
    globalCfg.serialization().addContextInitializer(RestTestSCI.INSTANCE);
    // test cache config
    ConfigurationBuilder builder = getConfigBuilder();
    builder.statistics().enabled(true);
    // create a 'default' config which is not indexed
    ConfigurationBuilder defaultBuilder = new ConfigurationBuilder();
    // start cache managers + default cache
    createClusteredCaches(getNumNodes(), globalCfg, defaultBuilder, isServerMode(), "default");
    // start rest sever for each cache manager
    cacheManagers.forEach(cm -> {
        RestServerHelper restServer = new RestServerHelper(cm);
        restServer.start(TestResourceTracker.getCurrentTestShortName());
        restServers.add(restServer);
        RestClientConfigurationBuilder clientConfigurationBuilder = new RestClientConfigurationBuilder();
        clientConfigurationBuilder.addServer().host(restServer.getHost()).port(restServer.getPort());
        clients.add(RestClient.forConfiguration(clientConfigurationBuilder.build()));
    });
    client = clients.get(0);
    cacheClient = client.cache(CACHE_NAME);
    // register protobuf schema
    String protoFileContents = Util.getResourceAsString(PROTO_FILE_NAME, getClass().getClassLoader());
    registerProtobuf(protoFileContents);
    // start indexed test cache that depends on the protobuf schema
    cacheManagers.forEach(cm -> {
        cm.defineConfiguration(CACHE_NAME, builder.build());
        cm.getCache(CACHE_NAME);
    });
}
Also used : GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) RestServerHelper(org.infinispan.rest.helper.RestServerHelper)

Example 48 with RestClientConfigurationBuilder

use of org.infinispan.client.rest.configuration.RestClientConfigurationBuilder in project infinispan by infinispan.

the class MultiNodeRestTest method createCacheManagers.

@Override
protected void createCacheManagers() throws Throwable {
    createClusteredCaches(getMembers(), GlobalConfigurationBuilder.defaultClusteredBuilder(), new ConfigurationBuilder(), true);
    cacheManagers.forEach(cm -> {
        RestServerHelper restServer = new RestServerHelper(cm);
        restServer.start(TestResourceTracker.getCurrentTestShortName());
        restServers.add(restServer);
    });
    RestClientConfigurationBuilder clientConfigurationBuilder = new RestClientConfigurationBuilder();
    restServers.forEach(s -> clientConfigurationBuilder.addServer().host(s.getHost()).port(s.getPort()));
    this.client = RestClient.forConfiguration(clientConfigurationBuilder.build());
    // Register the proto schema before starting the caches
    String protoFileContents = Util.getResourceAsString(getProtoFile(), getClass().getClassLoader());
    registerProtobuf(protoFileContents);
    cacheManagers.forEach(cm -> {
        getCacheConfigs().forEach((name, configBuilder) -> cm.createCache(name, configBuilder.build()));
    });
    cacheClients = getCacheConfigs().keySet().stream().collect(Collectors.toMap(Function.identity(), client::cache));
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) RestServerHelper(org.infinispan.rest.helper.RestServerHelper)

Example 49 with RestClientConfigurationBuilder

use of org.infinispan.client.rest.configuration.RestClientConfigurationBuilder 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");
}
Also used : RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) HotRodServerConfigurationBuilder(org.infinispan.server.hotrod.configuration.HotRodServerConfigurationBuilder) ConfigurationBuilder(org.infinispan.client.hotrod.configuration.ConfigurationBuilder) RestServerConfigurationBuilder(org.infinispan.rest.configuration.RestServerConfigurationBuilder) RouterConfigurationBuilder(org.infinispan.server.router.configuration.builder.RouterConfigurationBuilder) SinglePortRouteSource(org.infinispan.server.router.routes.singleport.SinglePortRouteSource) RestResponse(org.infinispan.client.rest.RestResponse) UTF8StringMarshaller(org.infinispan.commons.marshall.UTF8StringMarshaller) Router(org.infinispan.server.router.Router) EndpointRouter(org.infinispan.server.router.router.EndpointRouter) DummyServerManagement(org.infinispan.server.core.DummyServerManagement) RestServerRouteDestination(org.infinispan.server.router.routes.rest.RestServerRouteDestination) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) RouterConfigurationBuilder(org.infinispan.server.router.configuration.builder.RouterConfigurationBuilder) HotRodServerRouteDestination(org.infinispan.server.router.routes.hotrod.HotRodServerRouteDestination) RestServer(org.infinispan.rest.RestServer) RestServerConfigurationBuilder(org.infinispan.rest.configuration.RestServerConfigurationBuilder) RemoteCacheManager(org.infinispan.client.hotrod.RemoteCacheManager) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) HotRodServerConfigurationBuilder(org.infinispan.server.hotrod.configuration.HotRodServerConfigurationBuilder) EndpointRouter(org.infinispan.server.router.router.EndpointRouter) Route(org.infinispan.server.router.routes.Route) Test(org.junit.Test)

Example 50 with RestClientConfigurationBuilder

use of org.infinispan.client.rest.configuration.RestClientConfigurationBuilder in project infinispan by infinispan.

the class RestAuthentication method testStaticResourcesAnonymously.

@Test
public void testStaticResourcesAnonymously() {
    InfinispanServerDriver serverDriver = SERVERS.getServerDriver();
    InetSocketAddress serverAddress = serverDriver.getServerSocket(0, 11222);
    RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder().followRedirects(false);
    builder.addServer().host(serverAddress.getHostName()).port(serverAddress.getPort());
    RestClient restClient = RestClient.forConfiguration(builder.build());
    RestResponse response = sync(restClient.raw().get("/"));
    // The root resource redirects to the console
    assertEquals(307, response.getStatus());
}
Also used : RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) InetSocketAddress(java.net.InetSocketAddress) RestResponse(org.infinispan.client.rest.RestResponse) RestClient(org.infinispan.client.rest.RestClient) InfinispanServerDriver(org.infinispan.server.test.core.InfinispanServerDriver) Test(org.junit.Test)

Aggregations

RestClientConfigurationBuilder (org.infinispan.client.rest.configuration.RestClientConfigurationBuilder)56 Test (org.junit.Test)26 RestClient (org.infinispan.client.rest.RestClient)25 RestResponse (org.infinispan.client.rest.RestResponse)22 RestClientConfiguration (org.infinispan.client.rest.configuration.RestClientConfiguration)8 RestServerHelper (org.infinispan.rest.helper.RestServerHelper)6 ConfigurationBuilder (org.infinispan.client.hotrod.configuration.ConfigurationBuilder)5 InetSocketAddress (java.net.InetSocketAddress)4 RestCacheClient (org.infinispan.client.rest.RestCacheClient)4 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)4 RestServer (org.infinispan.rest.RestServer)4 RestServerConfigurationBuilder (org.infinispan.rest.configuration.RestServerConfigurationBuilder)4 AbstractRestResourceTest (org.infinispan.rest.resources.AbstractRestResourceTest)4 DummyServerManagement (org.infinispan.server.core.DummyServerManagement)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 RestEntity (org.infinispan.client.rest.RestEntity)3 Json (org.infinispan.commons.dataconversion.internal.Json)3 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)3 Router (org.infinispan.server.router.Router)3