Search in sources :

Example 6 with RestServerConfigurationBuilder

use of org.infinispan.rest.configuration.RestServerConfigurationBuilder in project infinispan by infinispan.

the class BaseJsonTest method setup.

@BeforeClass
protected void setup() throws Exception {
    cacheManager = TestCacheManagerFactory.createServerModeCacheManager(EndpointITSCI.INSTANCE, new ConfigurationBuilder());
    cacheManager.getClassWhiteList().addRegexps(".*");
    cacheManager.defineConfiguration(CACHE_NAME, getIndexCacheConfiguration().build());
    RestServerConfigurationBuilder builder = new RestServerConfigurationBuilder();
    int restPort = findFreePort();
    builder.port(restPort);
    restServer = new RestServer();
    restServer.setServerManagement(new DummyServerManagement(), true);
    restServer.start(builder.build(), cacheManager);
    restClient = RestClient.forConfiguration(new RestClientConfigurationBuilder().addServer().host(restServer.getHost()).port(restServer.getPort()).build());
    restCacheClient = restClient.cache(CACHE_NAME);
    hotRodServer = startHotRodServer(cacheManager);
    remoteCacheManager = createRemoteCacheManager();
    remoteCache = remoteCacheManager.getCache(CACHE_NAME);
}
Also used : RestServer(org.infinispan.rest.RestServer) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) RestServerConfigurationBuilder(org.infinispan.rest.configuration.RestServerConfigurationBuilder) RestServerConfigurationBuilder(org.infinispan.rest.configuration.RestServerConfigurationBuilder) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) DummyServerManagement(org.infinispan.server.core.DummyServerManagement) BeforeClass(org.testng.annotations.BeforeClass)

Example 7 with RestServerConfigurationBuilder

use of org.infinispan.rest.configuration.RestServerConfigurationBuilder in project infinispan by infinispan.

the class ServerConfigurationParser method configureDefaultEndpoint.

private void configureDefaultEndpoint(ConfigurationReader reader, String socketBinding, EndpointConfigurationBuilder endpoint) {
    if (endpoint.connectors().isEmpty()) {
        endpoint.addConnector(HotRodServerConfigurationBuilder.class).implicitConnector(true).startTransport(false).socketBinding(socketBinding);
        RestServerConfigurationBuilder rest = endpoint.addConnector(RestServerConfigurationBuilder.class).implicitConnector(true).startTransport(false).socketBinding(socketBinding);
        configureEndpoint(reader.getProperties(), endpoint, rest);
    }
}
Also used : RestServerConfigurationBuilder(org.infinispan.rest.configuration.RestServerConfigurationBuilder) HotRodServerConfigurationBuilder(org.infinispan.server.hotrod.configuration.HotRodServerConfigurationBuilder)

Example 8 with RestServerConfigurationBuilder

use of org.infinispan.rest.configuration.RestServerConfigurationBuilder 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 9 with RestServerConfigurationBuilder

use of org.infinispan.rest.configuration.RestServerConfigurationBuilder in project infinispan by infinispan.

the class RestTestingUtil method createDefaultRestConfiguration.

public static RestServerConfigurationBuilder createDefaultRestConfiguration() {
    RestServerConfigurationBuilder builder = new RestServerConfigurationBuilder();
    builder.startTransport(false);
    return builder;
}
Also used : RestServerConfigurationBuilder(org.infinispan.rest.configuration.RestServerConfigurationBuilder)

Example 10 with RestServerConfigurationBuilder

use of org.infinispan.rest.configuration.RestServerConfigurationBuilder in project infinispan by infinispan.

the class EndpointConfigurationBuilder method create.

public EndpointConfiguration create(SocketBindingsConfiguration bindingsConfiguration, SecurityConfiguration securityConfiguration) {
    boolean implicitSecurity = implicitConnectorSecurity && securityRealm() != null;
    bindingsConfiguration.applySocketBinding(attributes.attribute(EndpointConfiguration.SOCKET_BINDING).get(), singlePortBuilder, singlePortBuilder);
    List<ProtocolServerConfiguration> connectors = new ArrayList<>(connectorBuilders.size());
    for (ProtocolServerConfigurationBuilder<?, ?> builder : connectorBuilders) {
        bindingsConfiguration.applySocketBinding(builder.socketBinding(), builder, singlePortBuilder);
        if (implicitSecurity) {
            if (builder instanceof HotRodServerConfigurationBuilder) {
                enableImplicitAuthentication(securityConfiguration, securityRealm(), (HotRodServerConfigurationBuilder) builder);
            } else if (builder instanceof RestServerConfigurationBuilder) {
                enableImplicitAuthentication(securityConfiguration, securityRealm(), (RestServerConfigurationBuilder) builder);
            } else if (builder instanceof RespServerConfigurationBuilder) {
                enableImplicitAuthentication(securityConfiguration, securityRealm(), (RespServerConfigurationBuilder) builder);
            }
        }
        connectors.add(builder.create());
    }
    if (implicitSecurity) {
        RealmConfiguration realm = securityConfiguration.realms().getRealm(securityRealm());
        if (realm.hasFeature(ServerSecurityRealm.Feature.ENCRYPT)) {
            singlePortBuilder.ssl().enable().sslContext(realm.serverSSLContext());
        }
    }
    return new EndpointConfiguration(attributes.protect(), connectors, singlePortBuilder.create());
}
Also used : RestServerConfigurationBuilder(org.infinispan.rest.configuration.RestServerConfigurationBuilder) RespServerConfigurationBuilder(org.infinispan.server.resp.configuration.RespServerConfigurationBuilder) RealmConfiguration(org.infinispan.server.configuration.security.RealmConfiguration) ProtocolServerConfiguration(org.infinispan.server.core.configuration.ProtocolServerConfiguration) ArrayList(java.util.ArrayList) HotRodServerConfigurationBuilder(org.infinispan.server.hotrod.configuration.HotRodServerConfigurationBuilder)

Aggregations

RestServerConfigurationBuilder (org.infinispan.rest.configuration.RestServerConfigurationBuilder)10 RestServer (org.infinispan.rest.RestServer)5 HotRodServerConfigurationBuilder (org.infinispan.server.hotrod.configuration.HotRodServerConfigurationBuilder)5 RestClientConfigurationBuilder (org.infinispan.client.rest.configuration.RestClientConfigurationBuilder)4 DummyServerManagement (org.infinispan.server.core.DummyServerManagement)4 RestResponse (org.infinispan.client.rest.RestResponse)2 UTF8StringMarshaller (org.infinispan.commons.marshall.UTF8StringMarshaller)2 Route (org.infinispan.server.router.routes.Route)2 HotRodServerRouteDestination (org.infinispan.server.router.routes.hotrod.HotRodServerRouteDestination)2 RestServerRouteDestination (org.infinispan.server.router.routes.rest.RestServerRouteDestination)2 SinglePortRouteSource (org.infinispan.server.router.routes.singleport.SinglePortRouteSource)2 BeforeClass (org.testng.annotations.BeforeClass)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 RemoteCacheManager (org.infinispan.client.hotrod.RemoteCacheManager)1 ConfigurationBuilder (org.infinispan.client.hotrod.configuration.ConfigurationBuilder)1 RestClient (org.infinispan.client.rest.RestClient)1 RestClientConfiguration (org.infinispan.client.rest.configuration.RestClientConfiguration)1 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)1 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)1