Refactor all Spring Session, Apache Geode Samples using Spring Boot to switch from Thymeleaf to FreeMarker.

Convert Thymelead templates to FreeMarker templates.

Remove the use of WebJars.

Refactor all Sample application code.
This commit is contained in:
John Blum
2021-12-02 23:33:57 -08:00
parent 0040b9a37e
commit 39ff983567
11 changed files with 45 additions and 43 deletions

View File

@@ -6,7 +6,7 @@ dependencies {
implementation project(':spring-session-data-geode') implementation project(':spring-session-data-geode')
implementation("org.springframework.boot:spring-boot-starter-thymeleaf") { implementation("org.springframework.boot:spring-boot-starter-freemarker") {
exclude group: "org.apache.logging.log4j", module: "log4j-to-slf4j" exclude group: "org.apache.logging.log4j", module: "log4j-to-slf4j"
} }
@@ -16,8 +16,6 @@ dependencies {
implementation "jakarta.servlet:jakarta.servlet-api" implementation "jakarta.servlet:jakarta.servlet-api"
implementation "org.springframework.data:spring-data-geode-test" implementation "org.springframework.data:spring-data-geode-test"
implementation "org.webjars:bootstrap"
implementation "org.webjars:webjars-locator"
runtimeOnly "org.springframework.shell:spring-shell" runtimeOnly "org.springframework.shell:spring-shell"

View File

@@ -102,6 +102,7 @@ public class Application {
// end::class[] // end::class[]
@SuppressWarnings("all")
HttpSession updateRequestCount(HttpSession session) { HttpSession updateRequestCount(HttpSession session) {
synchronized (session) { synchronized (session) {

View File

@@ -1,5 +1,4 @@
<!DOCTYPE html SYSTEM "https://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-3.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="https://www.thymeleaf.org">
<head> <head>
<title>Session Attributes</title> <title>Session Attributes</title>
<style type="text/css"> <style type="text/css">
@@ -19,7 +18,7 @@
<h1>Try it</h1> <h1>Try it</h1>
<form class="form-inline" role="form" action="./session" method="post"> <form role="form" action="./session" method="post">
<label for="attributeName">Attribute Name</label> <label for="attributeName">Attribute Name</label>
<input id="attributeName" type="text" name="attributeName"/> <input id="attributeName" type="text" name="attributeName"/>
<label for="attributeValue">Attribute Value</label> <label for="attributeValue">Attribute Value</label>
@@ -29,7 +28,7 @@
<hr/> <hr/>
<table class="table table-striped"> <table>
<thead> <thead>
<tr> <tr>
<th>Attribute Name</th> <th>Attribute Name</th>
@@ -37,10 +36,15 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr th:each="attribute: ${sessionAttributes}"> <#attempt>
<td th:text="${attribute.key}">name</td> <#list sessionAttributes as attributeName, attributeValue>
<td th:text="${attribute.value}">value</td> <tr>
<td>${attributeName}</td>
<td>${attributeValue}</td>
</tr> </tr>
</#list>
<#recover>
</#attempt>
</tbody> </tbody>
</table> </table>
</div> </div>

View File

@@ -5,7 +5,7 @@ dependencies {
implementation project(':spring-session-data-geode') implementation project(':spring-session-data-geode')
implementation("org.springframework.boot:spring-boot-starter-thymeleaf") { implementation("org.springframework.boot:spring-boot-starter-freemarker") {
exclude group: "org.apache.logging.log4j", module: "log4j-to-slf4j" exclude group: "org.apache.logging.log4j", module: "log4j-to-slf4j"
} }
@@ -15,8 +15,6 @@ dependencies {
implementation "jakarta.servlet:jakarta.servlet-api" implementation "jakarta.servlet:jakarta.servlet-api"
implementation "org.springframework.data:spring-data-geode-test" implementation "org.springframework.data:spring-data-geode-test"
implementation "org.webjars:bootstrap"
implementation "org.webjars:webjars-locator"
runtimeOnly "org.springframework.shell:spring-shell" runtimeOnly "org.springframework.shell:spring-shell"

View File

@@ -31,8 +31,7 @@ import org.springframework.session.data.gemfire.config.annotation.web.http.Enabl
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@@ -67,7 +66,7 @@ public class Application {
SpringApplication.run(Application.class, args); SpringApplication.run(Application.class, args);
} }
@ClientCacheApplication(name = "SpringSessionDataGeodeBootSampleWithScopedProxiesClient", logLevel = "error", @ClientCacheApplication(name = "SpringSessionDataGeodeBootSampleWithScopedProxiesClient",
readTimeout = 15000, retryAttempts = 1, subscriptionEnabled = true) // <3> readTimeout = 15000, retryAttempts = 1, subscriptionEnabled = true) // <3>
@EnableGemFireHttpSession(poolName = "DEFAULT") // <4> @EnableGemFireHttpSession(poolName = "DEFAULT") // <4>
static class ClientCacheConfiguration { } static class ClientCacheConfiguration { }
@@ -102,13 +101,13 @@ public class Application {
return writer.toString(); return writer.toString();
} }
@RequestMapping(method = RequestMethod.GET, path = "/ping") @GetMapping(path = "/ping")
@ResponseBody @ResponseBody
public String ping() { public String ping() {
return PING_RESPONSE; return PING_RESPONSE;
} }
@RequestMapping(method = RequestMethod.GET, path = "/counts") @GetMapping(path = "/counts")
public String requestAndSessionInstanceCount(HttpServletRequest request, HttpSession session, Model model) { // <6> public String requestAndSessionInstanceCount(HttpServletRequest request, HttpSession session, Model model) { // <6>
model.addAttribute("sessionId", session.getId()); model.addAttribute("sessionId", session.getId());

View File

@@ -1,5 +1,4 @@
<!DOCTYPE html SYSTEM "https://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-3.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="https://www.thymeleaf.org">
<head> <head>
<title>Request and Session Counts</title> <title>Request and Session Counts</title>
<style type="text/css"> <style type="text/css">
@@ -16,7 +15,7 @@
in the context of Spring Session when GemFire is used to back the HTTP Session. in the context of Spring Session when GemFire is used to back the HTTP Session.
</p> </p>
<table class="table table-striped"> <table>
<thead> <thead>
<tr> <tr>
<th> * </th> <th> * </th>
@@ -26,12 +25,15 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<#attempt>
<tr> <tr>
<td><b>count</b></td> <td><b>count</b></td>
<td th:text="${sessionId}">?</td> <td>${sessionId}</td>
<td th:text="${sessionCount}">0</td> <td>${sessionCount}</td>
<td th:text="${requestCount}">0</td> <td>${requestCount}/></td>
</tr> </tr>
<#recover>
</#attempt>
</tbody> </tbody>
</table> </table>
</div> </div>

View File

@@ -6,7 +6,7 @@ dependencies {
implementation project(':spring-session-data-geode') implementation project(':spring-session-data-geode')
implementation("org.springframework.boot:spring-boot-starter-thymeleaf") { implementation("org.springframework.boot:spring-boot-starter-freemarker") {
exclude group: "org.apache.logging.log4j", module: "log4j-to-slf4j" exclude group: "org.apache.logging.log4j", module: "log4j-to-slf4j"
} }
@@ -16,8 +16,6 @@ dependencies {
implementation "jakarta.servlet:jakarta.servlet-api" implementation "jakarta.servlet:jakarta.servlet-api"
implementation "org.springframework.data:spring-data-geode-test" implementation "org.springframework.data:spring-data-geode-test"
implementation "org.webjars:bootstrap"
implementation "org.webjars:webjars-locator"
runtimeOnly "org.springframework.shell:spring-shell" runtimeOnly "org.springframework.shell:spring-shell"

View File

@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package sample; package sample;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package sample.pages; package sample.pages;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -39,8 +39,8 @@ import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap; import org.springframework.ui.ModelMap;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
@@ -74,7 +74,7 @@ public class Application {
SpringApplication.run(Application.class, args); SpringApplication.run(Application.class, args);
} }
@ClientCacheApplication(name = "SpringSessionDataGeodeBootSampleClient", logLevel = "error", @ClientCacheApplication(name = "SpringSessionDataGeodeBootSampleClient",
readTimeout = 15000, retryAttempts = 1, subscriptionEnabled = true) // <3> readTimeout = 15000, retryAttempts = 1, subscriptionEnabled = true) // <3>
@EnableGemFireHttpSession(poolName = "DEFAULT") // <4> @EnableGemFireHttpSession(poolName = "DEFAULT") // <4>
static class ClientCacheConfiguration extends ClientServerIntegrationTestsSupport { static class ClientCacheConfiguration extends ClientServerIntegrationTestsSupport {
@@ -111,18 +111,18 @@ public class Application {
return writer.toString(); return writer.toString();
} }
@RequestMapping(method = RequestMethod.GET, path = "/ping") @GetMapping(path = "/ping")
@ResponseBody @ResponseBody
public String ping() { public String ping() {
return PING_RESPONSE; return PING_RESPONSE;
} }
@RequestMapping(method = RequestMethod.POST, path = "/session") @PostMapping(path = "/session")
public String session(HttpSession session, ModelMap modelMap, public String session(HttpSession session, ModelMap model,
@RequestParam(name = "attributeName", required = false) String name, @RequestParam(name = "attributeName", required = false) String name,
@RequestParam(name = "attributeValue", required = false) String value) { // <7> @RequestParam(name = "attributeValue", required = false) String value) { // <7>
modelMap.addAttribute("sessionAttributes", model.addAttribute("sessionAttributes",
attributes(setAttribute(updateRequestCount(session), name, value))); attributes(setAttribute(updateRequestCount(session), name, value)));
return INDEX_TEMPLATE_VIEW_NAME; return INDEX_TEMPLATE_VIEW_NAME;

View File

@@ -1,5 +1,4 @@
<!DOCTYPE html SYSTEM "https://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-3.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="https://www.thymeleaf.org">
<head> <head>
<title>Session Attributes</title> <title>Session Attributes</title>
<style type="text/css"> <style type="text/css">
@@ -19,7 +18,7 @@
<h1>Try it</h1> <h1>Try it</h1>
<form class="form-inline" role="form" action="./session" method="post"> <form role="form" action="./session" method="post">
<label for="attributeName">Attribute Name</label> <label for="attributeName">Attribute Name</label>
<input id="attributeName" type="text" name="attributeName"/> <input id="attributeName" type="text" name="attributeName"/>
<label for="attributeValue">Attribute Value</label> <label for="attributeValue">Attribute Value</label>
@@ -29,7 +28,7 @@
<hr/> <hr/>
<table class="table table-striped"> <table>
<thead> <thead>
<tr> <tr>
<th>Attribute Name</th> <th>Attribute Name</th>
@@ -37,10 +36,15 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr th:each="attribute: ${sessionAttributes}"> <#attempt>
<td th:text="${attribute.key}">name</td> <#list sessionAttributes as attributeName, attributeValue>
<td th:text="${attribute.value}">value</td> <tr>
<td>${attributeName}</td>
<td>${attributeValue}</td>
</tr> </tr>
</#list>
<#recover>
</#attempt>
</tbody> </tbody>
</table> </table>
</div> </div>