Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
<module>clusterexec</module>
<module>streams</module>
<module>remote</module>
<module>remote-secured</module>
<module>scripting</module>
<module>query</module>
<module>listen</module>
Expand Down
45 changes: 45 additions & 0 deletions remote-secured/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>infinispan-simple-tutorials-remote-secured</artifactId>
<parent>
<relativePath>../pom.xml</relativePath>
<version>1.0.0-SNAPSHOT</version>
<groupId>org.infinispan.tutorial.simple</groupId>
<artifactId>infinispan-simple-tutorials</artifactId>
</parent>
<name>Infinispan Simple Tutorials: Remote Secured</name>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable>
<arguments>
<argument>-Djava.net.preferIPv4Stack=true</argument>
<argument>-Djava.util.logging.config.file=src/main/resources/logging.properties</argument>
<argument>-classpath</argument>
<classpath />
<argument>org.infinispan.tutorial.simple.remote.InfinispanRemoteSecured</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-client-hotrod</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.infinispan.tutorial.simple.remote;

import org.infinispan.client.hotrod.RemoteCache;
import org.infinispan.client.hotrod.RemoteCacheManager;
import org.infinispan.client.hotrod.configuration.ClientIntelligence;
import org.infinispan.client.hotrod.configuration.ConfigurationBuilder;
import org.infinispan.client.hotrod.impl.ConfigurationProperties;
import org.infinispan.commons.api.CacheContainerAdmin;

/**
* Run the Infinispan Server using the Docker Image
*
* docker run -it -p 11222:11222 -e USER="Titus Bramble" -e PASS="Shambles" infinispan/server:latest
*/
public class InfinispanRemoteSecured {

public static void main(String[] args) {
// Create a configuration for a locally-running server
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.addServer().host("127.0.0.1").port(ConfigurationProperties.DEFAULT_HOTROD_PORT);
// Workaround for docker 4 mac
builder.clientIntelligence(ClientIntelligence.BASIC);

//Configure the security properties
builder.security().authentication()
.username("Titus Bramble")
.password("Shambles")
.saslMechanism("PLAIN")
.realm("default")
.serverName("infinispan");

// Connect to the server
RemoteCacheManager cacheManager = new RemoteCacheManager(builder.build());
// Create test cache, if such does not exist
cacheManager.administration().withFlags(CacheContainerAdmin.AdminFlag.VOLATILE).getOrCreateCache("test", "org.infinispan.DIST_SYNC");
// Obtain the remote cache
RemoteCache<String, String> cache = cacheManager.getCache("test");
/// Store a value
cache.put("key", "value");
// Retrieve the value and print it out
System.out.printf("key = %s\n", cache.get("key"));
// Stop the cache manager and release all resources
cacheManager.stop();
}

}