Re-organize all client/server sample code to separate client and server classes into client and server packages, respectively.
Rename sample.ServerConfig class to sample.server.GemFireServer and apply the GemFireServer Gradle Plugin. Change all 'spring.session.data.gemfire.*' and 'spring.session.data.geode.*' properties to use the SDG property prefixed with 'spring.data.gemfire.*'.
This commit is contained in:
@@ -23,7 +23,7 @@ class GemFireServerPlugin implements Plugin<Project> {
|
||||
project.gretty {
|
||||
jvmArgs = [
|
||||
"-Dspring.data.gemfire.cache.server.port=${project.tasks.gemfireServer.port}",
|
||||
"-Dspring.data.gemfire.pool.servers=localhost[${project.tasks.gemfireServer.port}]",
|
||||
"-Dspring.data.gemfire.pool.servers=localhost[${project.tasks.gemfireServer.port}]"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,14 +84,14 @@ Add the following Spring configuration:
|
||||
|
||||
[source,java]
|
||||
----
|
||||
include::{samples-dir}javaconfig/gemfire-clientserver/src/main/java/sample/ClientConfig.java[tags=class]
|
||||
include::{samples-dir}javaconfig/gemfire-clientserver/src/main/java/sample/client/ClientConfig.java[tags=class]
|
||||
----
|
||||
|
||||
<1> First, we declare our Web application to be an Apache Geode cache client by annotating our `ClientConfig` class
|
||||
with `@ClientCacheApplication`. Additionally, we adjust a few basic, "DEFAULT" `Pool` settings (e.g. `readTimeout`).
|
||||
<2> `@EnableGemFireHttpSession` creates a Spring bean named `springSessionRepositoryFilter` that implements
|
||||
`javax.servlet.Filter`. The filter replaces the `HttpSession` with an implementation provided by Spring Session
|
||||
and backed by Apache Geode. Additionall, the configuration will also create the necessary client-side `Region`
|
||||
and backed by Apache Geode. Additionally, the configuration will also create the necessary client-side `Region`
|
||||
(by default, "ClusteredSpringSessions`, which is a `PROXY` `Region`) corresponding to the same server-side `Region`
|
||||
by name. All session state is sent from the client to the server through `Region` data access operations.
|
||||
The client-side `Region` use the "DEFAULT" `Pool`.
|
||||
@@ -142,12 +142,12 @@ In this sample, we will use the following Java configuration to configure and ru
|
||||
|
||||
[source,java]
|
||||
----
|
||||
include::{samples-dir}javaconfig/gemfire-clientserver/src/main/java/sample/ServerConfig.java[tags=class]
|
||||
include::{samples-dir}javaconfig/gemfire-clientserver/src/main/java/sample/server/GemFireServer.java[tags=class]
|
||||
----
|
||||
|
||||
<1> First, we use the `@CacheServerApplication` annotation to simplify the creation of a peer cache instance
|
||||
containing with a `CacheServer` for cache clients to connect.
|
||||
<2> (Optional) Then, the `ServerConfig` class is annotated with `@EnableGemFireHttpSession` to create the necessary
|
||||
<2> (Optional) Then, the `GemFireServer` class is annotated with `@EnableGemFireHttpSession` to create the necessary
|
||||
server-side `Region` (by default, "_ClusteredSpringSessions_") used to store `HttpSession` state. This step is
|
||||
optional since the Session `Region` could be created manually, perhaps using external means.
|
||||
Using `@EnableGemFireHttpSession` is convenient and quick.
|
||||
|
||||
@@ -133,7 +133,7 @@ The Apache Geode Server gets bootstrapped with the following:
|
||||
|
||||
[source,java]
|
||||
----
|
||||
include::{samples-dir}xml/gemfire-clientserver/src/main/java/sample/ServerConfig.java[tags=class]
|
||||
include::{samples-dir}xml/gemfire-clientserver/src/main/java/sample/server/GemFireServer.java[tags=class]
|
||||
----
|
||||
|
||||
TIP: Rather than defining a simple Java class with a `main` method, you might consider using Spring Boot instead.
|
||||
|
||||
@@ -26,12 +26,9 @@ dependencies {
|
||||
testCompile("org.springframework.boot:spring-boot-starter-test") {
|
||||
exclude group: "org.springframework.boot", module: "spring-boot-starter-logging"
|
||||
}
|
||||
|
||||
testCompile seleniumDependencies
|
||||
|
||||
// integrationTestCompile seleniumDependencies
|
||||
|
||||
// integrationTestRuntime "org.springframework.shell:spring-shell"
|
||||
|
||||
}
|
||||
|
||||
mainClassName = 'sample.client.Application'
|
||||
@@ -45,61 +42,3 @@ run {
|
||||
mainClassName = 'sample.server.GemFireServer'
|
||||
}
|
||||
}
|
||||
|
||||
task runGemFireServer() {
|
||||
doLast {
|
||||
ext.port = reservePort()
|
||||
|
||||
println "Starting Apache Geode Server on port [$port] ..."
|
||||
|
||||
def out = new StringBuilder()
|
||||
def err = new StringBuilder()
|
||||
|
||||
String classpath = sourceSets.main.runtimeClasspath.collect { it }.join(File.pathSeparator)
|
||||
|
||||
String[] commandLine = [
|
||||
'java', '-server', '-ea', '-classpath', classpath,
|
||||
//"-Dgemfire.log-file=gemfire-server.log",
|
||||
//"-Dgemfire.log-level=config",
|
||||
"-Dspring.data.gemifre.cache.server.port=$port",
|
||||
'sample.server.GemFireServer'
|
||||
]
|
||||
|
||||
//println commandLine
|
||||
|
||||
ext.process = commandLine.execute()
|
||||
//ext.process = new ProcessBuilder().command(commandLine).redirectErrorStream(true).start();
|
||||
|
||||
ext.process.consumeProcessOutput(out, err)
|
||||
|
||||
//println 'OUT: ' + out
|
||||
//println 'ERR: ' + err
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*integrationTest {
|
||||
dependsOn runGemFireServer
|
||||
doFirst {
|
||||
def port = reservePort()
|
||||
//systemProperties['gemfire.log-file'] = "gemfire-client.log"
|
||||
//systemProperties['gemfire.log-level'] = "config"
|
||||
systemProperties['management.port'] = 0
|
||||
systemProperties['server.port'] = port
|
||||
systemProperties['spring.data.gemfire.cache.server.port'] = runGemFireServer.port
|
||||
systemProperties['spring.data.gemfire.pool.servers'] = "localhost[" + runGemFireServer.port + "]"
|
||||
}
|
||||
doLast {
|
||||
println 'Stopping Apache Geode Server...'
|
||||
runGemFireServer.process?.destroy()
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
def reservePort() {
|
||||
def socket = new ServerSocket(0)
|
||||
def result = socket.localPort
|
||||
socket.close()
|
||||
result
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
apply plugin: 'io.spring.convention.spring-sample-boot'
|
||||
apply plugin: "gemfire-server"
|
||||
apply plugin: "application"
|
||||
|
||||
repositories {
|
||||
@@ -46,61 +47,3 @@ run {
|
||||
mainClassName = 'sample.server.GemFireServer'
|
||||
}
|
||||
}
|
||||
|
||||
task runGemFireServer() {
|
||||
doLast {
|
||||
ext.port = reservePort()
|
||||
|
||||
println "Starting Apache Geode Server on port [$port] ..."
|
||||
|
||||
def out = new StringBuilder()
|
||||
def err = new StringBuilder()
|
||||
|
||||
String classpath = project.sourceSets.main.runtimeClasspath.collect { it }.join(File.pathSeparator)
|
||||
|
||||
String[] commandLine = [
|
||||
'java', '-server', '-ea', '-classpath', classpath,
|
||||
//"-Dgemfire.log-file=gemfire-server.log",
|
||||
//"-Dgemfire.log-level=config",
|
||||
"-Dspring.data.gemfire.cache.server.port=$port",
|
||||
'sample.server.GemFireServer'
|
||||
]
|
||||
|
||||
//println commandLine
|
||||
|
||||
ext.process = commandLine.execute()
|
||||
//ext.process = new ProcessBuilder().command(commandLine).redirectErrorStream(true).start();
|
||||
|
||||
ext.process.consumeProcessOutput(out, err)
|
||||
|
||||
//println 'OUT: ' + out
|
||||
//println 'ERR: ' + err
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
integrationTest {
|
||||
dependsOn runGemFireServer
|
||||
doFirst {
|
||||
def port = reservePort()
|
||||
//systemProperties['gemfire.log-file'] = "gemfire-client.log"
|
||||
//systemProperties['gemfire.log-level'] = "config"
|
||||
systemProperties['management.port'] = 0
|
||||
systemProperties['server.port'] = port
|
||||
systemProperties['spring.data.gemfire.cache.server.port'] = runGemFireServer.port
|
||||
systemProperties['spring.data.gemfire.pool.servers'] = "localhost[${runGemFireServer.port}]"
|
||||
}
|
||||
doLast {
|
||||
println 'Stopping Apache Geode Server...'
|
||||
runGemFireServer.process?.destroy()
|
||||
// runGemFireServer.process?.destroyForcibly()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def reservePort() {
|
||||
def socket = new ServerSocket(0)
|
||||
def result = socket.localPort
|
||||
socket.close()
|
||||
result
|
||||
}
|
||||
|
||||
@@ -26,4 +26,4 @@ dependencies {
|
||||
|
||||
}
|
||||
|
||||
mainClassName = "sample.ServerConfig"
|
||||
mainClassName = "sample.server.GemFireServer"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
* Copyright 2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
package sample.client;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
* Copyright 2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
package sample.client;
|
||||
|
||||
import org.springframework.session.web.context.AbstractHttpSessionApplicationInitializer;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
* Copyright 2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
package sample.client;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
* Copyright 2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
package sample.server;
|
||||
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.data.gemfire.config.annotation.CacheServerApplication;
|
||||
@@ -23,11 +23,11 @@ import org.springframework.session.data.gemfire.config.annotation.web.http.Enabl
|
||||
// tag::class[]
|
||||
@CacheServerApplication(name = "SpringSessionDataGeodeJavaConfigSampleServer", logLevel = "error") // <1>
|
||||
@EnableGemFireHttpSession(maxInactiveIntervalInSeconds = 30) // <2>
|
||||
public class ServerConfig {
|
||||
public class GemFireServer {
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
public static void main(String[] args) {
|
||||
new AnnotationConfigApplicationContext(ServerConfig.class).registerShutdownHook();
|
||||
new AnnotationConfigApplicationContext(GemFireServer.class).registerShutdownHook();
|
||||
}
|
||||
}
|
||||
// end::class[]
|
||||
@@ -26,4 +26,4 @@ dependencies {
|
||||
|
||||
}
|
||||
|
||||
mainClassName = "sample.ServerConfig"
|
||||
mainClassName = "sample.server.GemFireServer"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
* Copyright 2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
package sample.client;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
* Copyright 2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
package sample.client;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
* Copyright 2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
package sample.server;
|
||||
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -23,10 +23,10 @@ import org.springframework.context.annotation.ImportResource;
|
||||
// tag::class[]
|
||||
@Configuration // <1>
|
||||
@ImportResource("META-INF/spring/session-server.xml") // <2>
|
||||
public class ServerConfig {
|
||||
public class GemFireServer {
|
||||
|
||||
public static void main(String[] args) {
|
||||
new AnnotationConfigApplicationContext(ServerConfig.class).registerShutdownHook();
|
||||
new AnnotationConfigApplicationContext(GemFireServer.class).registerShutdownHook();
|
||||
}
|
||||
}
|
||||
// tag::end[]
|
||||
@@ -20,17 +20,14 @@
|
||||
<!--1-->
|
||||
<util:properties id="gemfireProperties">
|
||||
<prop key="name">SpringSessionDataGeodeSampleXmlServer</prop>
|
||||
<prop key="log-level">${spring.session.data.geode.log-level:error}</prop>
|
||||
<prop key="log-level">${spring.data.gemfire.cache.log-level:error}</prop>
|
||||
</util:properties>
|
||||
|
||||
<!--2-->
|
||||
<gfe:cache properties-ref="gemfireProperties"/>
|
||||
|
||||
<!--3-->
|
||||
<gfe:cache-server auto-startup="true"
|
||||
bind-address="${spring.session.data.geode.cache.server.host:localhost}"
|
||||
host-name-for-clients="${spring.session.data.geode.cache.server.hostname-for-clients:${spring.data.gemfire.cache.server.hostname-for-clients:localhost}}"
|
||||
port="${spring.session.data.geode.cache.server.port:${spring.data.gemfire.cache.server.port:40404}}"/>
|
||||
<gfe:cache-server port="${spring.data.gemfire.cache.server.port:40404}"/>
|
||||
|
||||
<!--4-->
|
||||
<bean class="org.springframework.session.data.gemfire.config.annotation.web.http.GemFireHttpSessionConfiguration"
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
|
||||
<context:property-placeholder/>
|
||||
|
||||
<bean class="sample.ClientServerReadyBeanPostProcessor"/>
|
||||
<bean class="sample.client.ClientServerReadyBeanPostProcessor"/>
|
||||
|
||||
<!--1-->
|
||||
<util:properties id="gemfireProperties">
|
||||
<prop key="log-level">${spring.session.data.geode.log-level:error}</prop>
|
||||
<prop key="log-level">${spring.data.gemfire.cache.log-level:error}</prop>
|
||||
</util:properties>
|
||||
|
||||
<!--2-->
|
||||
@@ -29,8 +29,7 @@
|
||||
|
||||
<!--3-->
|
||||
<gfe:pool read-timeout="15000" retry-attempts="1" subscription-enabled="true">
|
||||
<gfe:server host="${spring.session.data.geode.cache.server.host:localhost}"
|
||||
port="${spring.session.data.geode.cache.server.port:${spring.data.gemfire.cache.server.port:40404}}"/>
|
||||
<gfe:server host="localhost" port="${spring.data.gemfire.cache.server.port:40404}"/>
|
||||
</gfe:pool>
|
||||
|
||||
<!--4-->
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
|
||||
<servlet>
|
||||
<servlet-name>session</servlet-name>
|
||||
<servlet-class>sample.SessionServlet</servlet-class>
|
||||
<servlet-class>sample.client.SessionServlet</servlet-class>
|
||||
</servlet>
|
||||
|
||||
<servlet-mapping>
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
<!--1-->
|
||||
<util:properties id="gemfireProperties">
|
||||
<prop key="name">SpringSessionDataGeodeXmlP2pSample</prop>
|
||||
<prop key="log-level">${spring.session.data.geode.log-level:error}</prop>
|
||||
<prop key="log-level">${spring.data.gemfire.cache.log-level:error}</prop>
|
||||
</util:properties>
|
||||
|
||||
<!--2-->
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
|
||||
<servlet>
|
||||
<servlet-name>session</servlet-name>
|
||||
<servlet-class>sample.SessionServlet</servlet-class>
|
||||
<servlet-class>sample.client.SessionServlet</servlet-class>
|
||||
</servlet>
|
||||
|
||||
<servlet-mapping>
|
||||
|
||||
Reference in New Issue
Block a user