Search in sources :

Example 1 with RestServerHelper

use of org.infinispan.rest.helper.RestServerHelper 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;
}
Also used : GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) RestServerHelper(org.infinispan.rest.helper.RestServerHelper)

Example 2 with RestServerHelper

use of org.infinispan.rest.helper.RestServerHelper in project infinispan by infinispan.

the class XSiteResourceTest method startServers.

@BeforeClass
public void startServers() {
    sites.forEach(site -> {
        String siteName = site.getSiteName();
        EmbeddedCacheManager cm = site.cacheManagers().iterator().next();
        RestServerHelper restServerHelper = new RestServerHelper(cm);
        restServerHelper.start(TestResourceTracker.getCurrentTestShortName());
        restServerPerSite.put(siteName, restServerHelper);
        RestClientConfiguration clientConfig = new RestClientConfigurationBuilder().addServer().host("127.0.0.1").port(restServerHelper.getPort()).build();
        RestClient client = RestClient.forConfiguration(clientConfig);
        clientPerSite.put(siteName, client);
    });
}
Also used : RestClientConfiguration(org.infinispan.client.rest.configuration.RestClientConfiguration) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) RestClient(org.infinispan.client.rest.RestClient) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) RestServerHelper(org.infinispan.rest.helper.RestServerHelper) BeforeClass(org.testng.annotations.BeforeClass)

Example 3 with RestServerHelper

use of org.infinispan.rest.helper.RestServerHelper in project infinispan by infinispan.

the class RestAccessLoggingTest method setup.

@Override
protected void setup() throws Exception {
    super.setup();
    testShortName = TestResourceTracker.getCurrentTestShortName();
    logAppender = new StringLogAppender("org.infinispan.REST_ACCESS_LOG", Level.TRACE, t -> t.getName().startsWith("non-blocking-thread-" + testShortName), PatternLayout.newBuilder().withPattern(LOG_FORMAT).build());
    logAppender.install();
    restServer = new RestServerHelper(cacheManager);
    restServer.start(TestResourceTracker.getCurrentTestShortName());
    RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder();
    builder.addServer().host(restServer.getHost()).port(restServer.getPort());
    restClient = RestClient.forConfiguration(builder.create());
    cacheClient = restClient.cache("default");
}
Also used : CompletionStages.join(org.infinispan.util.concurrent.CompletionStages.join) SingleCacheManagerTest(org.infinispan.test.SingleCacheManagerTest) TestResourceTracker(org.infinispan.commons.test.TestResourceTracker) Level(org.apache.logging.log4j.Level) RestClient(org.infinispan.client.rest.RestClient) Test(org.testng.annotations.Test) AssertJUnit.assertTrue(org.testng.AssertJUnit.assertTrue) RestCacheClient(org.infinispan.client.rest.RestCacheClient) RestServerHelper(org.infinispan.rest.helper.RestServerHelper) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) TestCacheManagerFactory(org.infinispan.test.fwk.TestCacheManagerFactory) PatternLayout(org.apache.logging.log4j.core.layout.PatternLayout) StringLogAppender(org.infinispan.commons.test.skip.StringLogAppender) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) StringLogAppender(org.infinispan.commons.test.skip.StringLogAppender) RestServerHelper(org.infinispan.rest.helper.RestServerHelper)

Example 4 with RestServerHelper

use of org.infinispan.rest.helper.RestServerHelper in project infinispan by infinispan.

the class CacheResourceTest method testCORSAllOrigins.

@Test
public void testCORSAllOrigins() throws IOException {
    RestServerHelper restServerHelper = null;
    RestClient client = null;
    try {
        RestServerConfigurationBuilder restBuilder = new RestServerConfigurationBuilder();
        restBuilder.cors().addNewRule().allowOrigins(new String[] { "*" });
        restBuilder.host("localhost").port(0);
        restServerHelper = RestServerHelper.defaultRestServer();
        RestServerConfiguration build = restBuilder.build();
        restServerHelper.withConfiguration(build).start("test");
        client = restServerHelper.createClient();
        RestResponse response = join(client.cache("default").get("test", singletonMap(ORIGIN.toString(), "http://host.example.com:5576")));
        assertThat(response).containsAllHeaders("access-control-allow-origin");
    } finally {
        client.close();
        if (restServerHelper != null)
            restServerHelper.stop();
    }
}
Also used : RestServerConfigurationBuilder(org.infinispan.rest.configuration.RestServerConfigurationBuilder) RestResponse(org.infinispan.client.rest.RestResponse) RestClient(org.infinispan.client.rest.RestClient) RestServerConfiguration(org.infinispan.rest.configuration.RestServerConfiguration) RestServerHelper(org.infinispan.rest.helper.RestServerHelper) Test(org.testng.annotations.Test)

Example 5 with RestServerHelper

use of org.infinispan.rest.helper.RestServerHelper in project infinispan by infinispan.

the class AbstractRestResourceTest method createCacheManagers.

@Override
protected void createCacheManagers() throws Exception {
    Security.doAs(ADMIN, () -> {
        for (int i = 0; i < NUM_SERVERS; i++) {
            GlobalConfigurationBuilder configForNode = getGlobalConfigForNode(i);
            addClusterEnabledCacheManager(new GlobalConfigurationBuilder().read(configForNode.build()), getDefaultCacheBuilder(), TransportFlags.minimalXsiteFlags());
        }
        cacheManagers.forEach(this::defineCaches);
        cacheManagers.forEach(cm -> cm.defineConfiguration("invalid", getDefaultCacheBuilder().encoding().mediaType(APPLICATION_OBJECT_TYPE).indexing().enabled(true).addIndexedEntities("invalid").build()));
        serverStateManager = new DummyServerStateManager();
        for (EmbeddedCacheManager cm : cacheManagers) {
            BasicComponentRegistry bcr = SecurityActions.getGlobalComponentRegistry(cm).getComponent(BasicComponentRegistry.class.getName());
            bcr.registerComponent(ServerStateManager.class, serverStateManager, false);
            cm.getClassAllowList().addClasses(TestClass.class);
            waitForClusterToForm(cm.getCacheNames().stream().filter(name -> {
                try {
                    cm.getCache(name);
                    return true;
                } catch (CacheConfigurationException ignored) {
                    return false;
                }
            }).toArray(String[]::new));
            RestServerHelper restServerHelper = new RestServerHelper(cm);
            if (isSecurityEnabled()) {
                BasicAuthenticator basicAuthenticator = new BasicAuthenticator(new SimpleSecurityDomain(ADMIN, USER), REALM);
                restServerHelper.withAuthenticator(basicAuthenticator);
            }
            if (ssl) {
                restServerHelper.withKeyStore(SERVER_KEY_STORE, STORE_PASSWORD, STORE_TYPE).withTrustStore(SERVER_KEY_STORE, STORE_PASSWORD, STORE_TYPE);
            }
            restServerHelper.start(TestResourceTracker.getCurrentTestShortName());
            restServers.add(restServerHelper);
        }
    });
    adminClient = RestClient.forConfiguration(getClientConfig("admin", "admin").build());
    client = RestClient.forConfiguration(getClientConfig("user", "user").build());
}
Also used : PrivateGlobalConfigurationBuilder(org.infinispan.configuration.internal.PrivateGlobalConfigurationBuilder) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) DummyServerStateManager(org.infinispan.server.core.DummyServerStateManager) BasicComponentRegistry(org.infinispan.factories.impl.BasicComponentRegistry) BasicAuthenticator(org.infinispan.rest.authentication.impl.BasicAuthenticator) CacheConfigurationException(org.infinispan.commons.CacheConfigurationException) SimpleSecurityDomain(org.infinispan.rest.resources.security.SimpleSecurityDomain) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) RestServerHelper(org.infinispan.rest.helper.RestServerHelper)

Aggregations

RestServerHelper (org.infinispan.rest.helper.RestServerHelper)7 RestClientConfigurationBuilder (org.infinispan.client.rest.configuration.RestClientConfigurationBuilder)5 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)4 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)4 RestClient (org.infinispan.client.rest.RestClient)3 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)2 Test (org.testng.annotations.Test)2 Level (org.apache.logging.log4j.Level)1 PatternLayout (org.apache.logging.log4j.core.layout.PatternLayout)1 RestCacheClient (org.infinispan.client.rest.RestCacheClient)1 RestResponse (org.infinispan.client.rest.RestResponse)1 RestClientConfiguration (org.infinispan.client.rest.configuration.RestClientConfiguration)1 CacheConfigurationException (org.infinispan.commons.CacheConfigurationException)1 TestResourceTracker (org.infinispan.commons.test.TestResourceTracker)1 StringLogAppender (org.infinispan.commons.test.skip.StringLogAppender)1 PrivateGlobalConfigurationBuilder (org.infinispan.configuration.internal.PrivateGlobalConfigurationBuilder)1 BasicComponentRegistry (org.infinispan.factories.impl.BasicComponentRegistry)1 BasicAuthenticator (org.infinispan.rest.authentication.impl.BasicAuthenticator)1 RestServerConfiguration (org.infinispan.rest.configuration.RestServerConfiguration)1 RestServerConfigurationBuilder (org.infinispan.rest.configuration.RestServerConfigurationBuilder)1