Search in sources :

Example 1 with RestServerConfigurationBuilder

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

the class RestServerConfigurationParser method parseRest.

private void parseRest(ConfigurationReader reader, ServerConfigurationBuilder serverBuilder) {
    boolean dedicatedSocketBinding = false;
    String securityRealm = null;
    EndpointConfigurationBuilder endpoint = serverBuilder.endpoints().current();
    RestServerConfigurationBuilder builder = endpoint.addConnector(RestServerConfigurationBuilder.class);
    ServerConfigurationParser.configureEndpoint(reader.getProperties(), endpoint, builder);
    for (int i = 0; i < reader.getAttributeCount(); i++) {
        ParseUtils.requireNoNamespaceAttribute(reader, i);
        String value = replaceProperties(reader.getAttributeValue(i));
        Attribute attribute = Attribute.forName(reader.getAttributeName(i));
        switch(attribute) {
            case CONTEXT_PATH:
                {
                    builder.contextPath(value);
                    break;
                }
            case EXTENDED_HEADERS:
                {
                    builder.extendedHeaders(ExtendedHeaders.valueOf(value));
                    break;
                }
            case NAME:
                {
                    builder.name(value);
                    break;
                }
            case MAX_CONTENT_LENGTH:
                {
                    builder.maxContentLength(Integer.parseInt(value));
                    break;
                }
            case COMPRESSION_LEVEL:
                {
                    builder.compressionLevel(Integer.parseInt(value));
                    break;
                }
            case SOCKET_BINDING:
                {
                    builder.socketBinding(value);
                    builder.startTransport(true);
                    dedicatedSocketBinding = true;
                    break;
                }
            case SECURITY_REALM:
                {
                    securityRealm = value;
                }
            default:
                {
                    ServerConfigurationParser.parseCommonConnectorAttributes(reader, i, serverBuilder, builder);
                }
        }
    }
    if (!dedicatedSocketBinding) {
        builder.socketBinding(endpoint.singlePort().socketBinding()).startTransport(false);
    }
    while (reader.inTag()) {
        Element element = Element.forName(reader.getLocalName());
        switch(element) {
            case AUTHENTICATION:
                {
                    parseAuthentication(reader, serverBuilder, builder.authentication().enable(), securityRealm);
                    break;
                }
            case ENCRYPTION:
                {
                    if (!dedicatedSocketBinding) {
                        throw Server.log.cannotConfigureProtocolEncryptionUnderSinglePort();
                    }
                    parseEncryption(reader, serverBuilder, builder.encryption(), securityRealm);
                    break;
                }
            case CORS_RULES:
                {
                    parseCorsRules(reader, builder);
                    break;
                }
            default:
                {
                    ServerConfigurationParser.parseCommonConnectorElements(reader, builder);
                }
        }
    }
}
Also used : RestServerConfigurationBuilder(org.infinispan.rest.configuration.RestServerConfigurationBuilder) EndpointConfigurationBuilder(org.infinispan.server.configuration.endpoint.EndpointConfigurationBuilder)

Example 2 with RestServerConfigurationBuilder

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

use of org.infinispan.rest.configuration.RestServerConfigurationBuilder 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));
}
Also used : SinglePortRouteSource(org.infinispan.server.router.routes.singleport.SinglePortRouteSource) RestServerRouteDestination(org.infinispan.server.router.routes.rest.RestServerRouteDestination) HotRodServerRouteDestination(org.infinispan.server.router.routes.hotrod.HotRodServerRouteDestination) SinglePortRouterConfiguration(org.infinispan.server.router.configuration.SinglePortRouterConfiguration) RestServer(org.infinispan.rest.RestServer) RestServerConfigurationBuilder(org.infinispan.rest.configuration.RestServerConfigurationBuilder) RoutingTable(org.infinispan.server.router.RoutingTable) RouteSource(org.infinispan.server.router.routes.RouteSource) SinglePortRouteSource(org.infinispan.server.router.routes.singleport.SinglePortRouteSource) SinglePortEndpointRouter(org.infinispan.server.router.router.impl.singleport.SinglePortEndpointRouter) HotRodServerConfigurationBuilder(org.infinispan.server.hotrod.configuration.HotRodServerConfigurationBuilder) HotRodServerRouteDestination(org.infinispan.server.router.routes.hotrod.HotRodServerRouteDestination) RouteDestination(org.infinispan.server.router.routes.RouteDestination) RestServerRouteDestination(org.infinispan.server.router.routes.rest.RestServerRouteDestination) SinglePortServerConfigurationBuilder(org.infinispan.server.configuration.endpoint.SinglePortServerConfigurationBuilder) Route(org.infinispan.server.router.routes.Route) HashSet(java.util.HashSet)

Example 4 with RestServerConfigurationBuilder

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

the class EndpointInteroperabilityTest method setup.

@BeforeClass
protected void setup() throws Exception {
    cacheManager = TestCacheManagerFactory.createServerModeCacheManager();
    cacheManager.defineConfiguration(DEFAULT_CACHE_NAME, getDefaultCacheConfiguration().build());
    cacheManager.defineConfiguration(MARSHALLED_CACHE_NAME, getMarshalledCacheConfiguration().build());
    cacheManager.defineConfiguration(STRING_CACHE_NAME, getStringsCacheConfiguration().build());
    RestServerConfigurationBuilder builder = new RestServerConfigurationBuilder();
    builder.port(findFreePort());
    restServer = new RestServer();
    restServer.setServerManagement(new DummyServerManagement(), true);
    restServer.start(builder.build(), cacheManager);
    RestClientConfigurationBuilder clientBuilder = new RestClientConfigurationBuilder();
    RestClientConfiguration configuration = clientBuilder.addServer().host(restServer.getHost()).port(restServer.getPort()).build();
    restClient = RestClient.forConfiguration(configuration);
    HotRodServerConfigurationBuilder serverBuilder = new HotRodServerConfigurationBuilder();
    serverBuilder.adminOperationsHandler(new EmbeddedServerAdminOperationHandler());
    hotRodServer = startHotRodServer(cacheManager, serverBuilder);
    defaultRemoteCache = createRemoteCacheManager(IdentityMarshaller.INSTANCE).getCache(DEFAULT_CACHE_NAME);
    defaultMarshalledRemoteCache = createRemoteCacheManager(null).getCache(MARSHALLED_CACHE_NAME);
    stringRemoteCache = createRemoteCacheManager(new UTF8StringMarshaller()).getCache(STRING_CACHE_NAME);
}
Also used : RestServer(org.infinispan.rest.RestServer) RestServerConfigurationBuilder(org.infinispan.rest.configuration.RestServerConfigurationBuilder) RestClientConfiguration(org.infinispan.client.rest.configuration.RestClientConfiguration) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) EmbeddedServerAdminOperationHandler(org.infinispan.server.core.admin.embeddedserver.EmbeddedServerAdminOperationHandler) UTF8StringMarshaller(org.infinispan.commons.marshall.UTF8StringMarshaller) DummyServerManagement(org.infinispan.server.core.DummyServerManagement) HotRodServerConfigurationBuilder(org.infinispan.server.hotrod.configuration.HotRodServerConfigurationBuilder) BeforeClass(org.testng.annotations.BeforeClass)

Example 5 with RestServerConfigurationBuilder

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

the class EndpointsCacheFactory method createRestCache.

private void createRestCache() {
    RestServer restServer = startProtocolServer(findFreePort(), p -> {
        RestServerConfigurationBuilder builder = new RestServerConfigurationBuilder();
        builder.port(p);
        rest = new RestServer();
        rest.setServerManagement(new DummyServerManagement(), true);
        rest.start(builder.build(), cacheManager);
        return rest;
    });
    RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder();
    builder.addServer().host(restServer.getHost()).port(restServer.getPort());
    restClient = RestClient.forConfiguration(builder.build());
    restCacheClient = restClient.cache(cacheName);
}
Also used : RestServer(org.infinispan.rest.RestServer) RestServerConfigurationBuilder(org.infinispan.rest.configuration.RestServerConfigurationBuilder) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) DummyServerManagement(org.infinispan.server.core.DummyServerManagement)

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