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);
}
}
}
}
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();
}
}
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));
}
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);
}
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);
}
Aggregations