From 8f50f512ac48fe8be9660b4c78e99a55a7a41ae2 Mon Sep 17 00:00:00 2001 From: Nusrat Shakarov Date: Wed, 22 May 2024 07:19:09 +0200 Subject: [PATCH] IGNITE-22077 Add spring 6 support to spring session extension (#262) --- .../bin/include/jvmdefaults.sh | 2 +- modules/spring-session-ext/pom.xml | 28 ++++-- .../IgniteHttpSessionConfiguration.java | 14 ++- .../IgniteIndexedSessionRepository.java | 29 +++++- .../IgniteHttpSessionConfigurationTest.java | 3 +- parent-internal/pom.xml | 97 +++++++++++++++++++ pom.xml | 10 +- 7 files changed, 165 insertions(+), 18 deletions(-) diff --git a/modules/performance-statistics-ext/bin/include/jvmdefaults.sh b/modules/performance-statistics-ext/bin/include/jvmdefaults.sh index d30fe005a..94c0cadf0 100644 --- a/modules/performance-statistics-ext/bin/include/jvmdefaults.sh +++ b/modules/performance-statistics-ext/bin/include/jvmdefaults.sh @@ -144,7 +144,7 @@ getJavaSpecificOpts() { --add-opens=java.base/java.time=ALL-UNNAMED \ --add-opens=java.base/java.text=ALL-UNNAMED \ --add-opens=java.management/sun.management=ALL-UNNAMED \ - --add-opens java.desktop/java.awt.font=ALL-UNNAMED \ + --add-opens=java.desktop/java.awt.font=ALL-UNNAMED \ ${current_value}" fi diff --git a/modules/spring-session-ext/pom.xml b/modules/spring-session-ext/pom.xml index 72f725ce3..4be5e346c 100644 --- a/modules/spring-session-ext/pom.xml +++ b/modules/spring-session-ext/pom.xml @@ -30,15 +30,17 @@ ignite-spring-session-ext - 1.1.0-SNAPSHOT + 2.0.0-SNAPSHOT https://ignite.apache.org - 2.5.0 - 5.5.0 - 1.3.2 + 17 + + 3.2.2 + 6.2.4 + 3.0.0 3.20.0 - 5.7.2 + 5.10.2 3.0.1 @@ -48,7 +50,7 @@ org.springframework spring-framework-bom - ${spring53.version} + ${spring61.version} pom import @@ -99,9 +101,9 @@ - javax.annotation - javax.annotation-api - ${javax.annotation.version} + jakarta.annotation + jakarta.annotation-api + ${jakarta.annotation.version} @@ -151,8 +153,14 @@ ${mockito.version} test - + + + jakarta.servlet + jakarta.servlet-api + 6.0.0 + + diff --git a/modules/spring-session-ext/src/main/java/org/apache/ignite/spring/sessions/IgniteHttpSessionConfiguration.java b/modules/spring-session-ext/src/main/java/org/apache/ignite/spring/sessions/IgniteHttpSessionConfiguration.java index 61f1fa37f..a06006bb0 100644 --- a/modules/spring-session-ext/src/main/java/org/apache/ignite/spring/sessions/IgniteHttpSessionConfiguration.java +++ b/modules/spring-session-ext/src/main/java/org/apache/ignite/spring/sessions/IgniteHttpSessionConfiguration.java @@ -21,6 +21,7 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import jakarta.annotation.PostConstruct; import org.apache.ignite.Ignite; import org.apache.ignite.cache.query.SqlFieldsQuery; import org.apache.ignite.client.IgniteClient; @@ -79,6 +80,9 @@ public class IgniteHttpSessionConfiguration extends SpringHttpSessionConfigurati /** */ private List> sesRepoCustomizers; + /** */ + private Object connObj; + /** * @return Session repository. */ @@ -134,7 +138,15 @@ public void setSessions( if (connObj == null) connObj = cli.getIfAvailable(); - this.sessions = createSessionProxy(connObj); + this.connObj = connObj; + } + + /** + * Init sessions. + */ + @PostConstruct + public void initSessions() { + this.sessions = createSessionProxy(this.connObj); } /** diff --git a/modules/spring-session-ext/src/main/java/org/apache/ignite/spring/sessions/IgniteIndexedSessionRepository.java b/modules/spring-session-ext/src/main/java/org/apache/ignite/spring/sessions/IgniteIndexedSessionRepository.java index 25a3e3155..c7857b1e5 100644 --- a/modules/spring-session-ext/src/main/java/org/apache/ignite/spring/sessions/IgniteIndexedSessionRepository.java +++ b/modules/spring-session-ext/src/main/java/org/apache/ignite/spring/sessions/IgniteIndexedSessionRepository.java @@ -22,7 +22,7 @@ import java.util.Map; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; -import javax.annotation.PreDestroy; +import jakarta.annotation.PreDestroy; import javax.cache.configuration.CacheEntryListenerConfiguration; import javax.cache.configuration.Factory; import javax.cache.event.CacheEntryCreatedListener; @@ -47,6 +47,8 @@ import org.springframework.session.PrincipalNameIndexResolver; import org.springframework.session.SaveMode; import org.springframework.session.Session; +import org.springframework.session.SessionIdGenerator; +import org.springframework.session.UuidSessionIdGenerator; import org.springframework.session.events.AbstractSessionEvent; import org.springframework.session.events.SessionCreatedEvent; import org.springframework.session.events.SessionDeletedEvent; @@ -121,6 +123,9 @@ public class IgniteIndexedSessionRepository /** The index resolver. */ private IndexResolver idxResolver = new DelegatingIndexResolver<>(new PrincipalNameIndexResolver<>()); + /** Session id generator. */ + private SessionIdGenerator sessionIdGenerator = UuidSessionIdGenerator.getInstance(); + /** Sessions cache proxy. */ private final SessionProxy sessions; @@ -216,6 +221,15 @@ public void setSaveMode(SaveMode saveMode) { this.saveMode = saveMode; } + /** + * Set session id generator. + * @param sesIdGenerator Session id generator. + */ + public void setSessionIdGenerator(SessionIdGenerator sesIdGenerator) { + Assert.notNull(sesIdGenerator, "sessionIdGenerator cannot be null"); + this.sessionIdGenerator = sesIdGenerator; + } + /** {@inheritDoc} */ @Override public IgniteSession createSession() { MapSession cached = new MapSession(); @@ -223,11 +237,15 @@ public void setSaveMode(SaveMode saveMode) { if (this.dfltMaxInactiveInterval != null) cached.setMaxInactiveInterval(Duration.ofSeconds(this.dfltMaxInactiveInterval)); + cached.setSessionIdGenerator(this.sessionIdGenerator); + return new IgniteSession(cached, idxResolver, true, saveMode, this::flushImmediateIfNecessary); } /** {@inheritDoc} */ @Override public void save(IgniteSession ses) { + ses.getDelegate().setSessionIdGenerator(this.sessionIdGenerator); + if (ses.isNew()) ttlSessions(ses.getMaxInactiveInterval()).put(ses.getId(), ses); else { @@ -263,7 +281,10 @@ else if (ses.hasChanges()) { return null; } - return new IgniteSession(saved.getDelegate(), idxResolver, false, saveMode, this::flushImmediateIfNecessary); + MapSession mapSession = saved.getDelegate(); + mapSession.setSessionIdGenerator(this.sessionIdGenerator); + + return new IgniteSession(mapSession, idxResolver, false, saveMode, this::flushImmediateIfNecessary); } /** {@inheritDoc} */ @@ -389,7 +410,7 @@ private void updatePartial(IgniteSession ses) { if (oldSes == null) break; - updatedSes = new IgniteSession(oldSes.getDelegate(), idxResolver, false, saveMode, this::flushImmediateIfNecessary); + updatedSes = new IgniteSession(new MapSession(oldSes.getDelegate()), idxResolver, false, saveMode, this::flushImmediateIfNecessary); copyChanges(updatedSes, ses); if (attempt > MAX_UPDATE_ATTEMPT) { @@ -399,6 +420,6 @@ private void updatePartial(IgniteSession ses) { ttlSessions(ses.getMaxInactiveInterval()).replace(ses.getId(), updatedSes); break; } - } while (ttlSessions(ses.getMaxInactiveInterval()).replace(ses.getId(), oldSes, updatedSes)); + } while (!ttlSessions(ses.getMaxInactiveInterval()).replace(ses.getId(), oldSes, updatedSes)); } } diff --git a/modules/spring-session-ext/src/test/java/org/apache/ignite/spring/sessions/IgniteHttpSessionConfigurationTest.java b/modules/spring-session-ext/src/test/java/org/apache/ignite/spring/sessions/IgniteHttpSessionConfigurationTest.java index a6b2f185d..fd7ea137a 100644 --- a/modules/spring-session-ext/src/test/java/org/apache/ignite/spring/sessions/IgniteHttpSessionConfigurationTest.java +++ b/modules/spring-session-ext/src/test/java/org/apache/ignite/spring/sessions/IgniteHttpSessionConfigurationTest.java @@ -217,7 +217,7 @@ void namedIgniteConfiguration() { void multipleIgniteConfiguration() { assertThatExceptionOfType(BeanCreationException.class) .isThrownBy(() -> registerAndRefresh(MultipleIgniteConfiguration.class)) - .withMessageContaining("expected single matching bean but found 2"); + .withStackTraceContaining("expected single matching bean but found 2"); } /** */ @@ -410,6 +410,7 @@ static class NamedIgniteConfiguration extends BaseConfiguration { /** */ @Bean + @Primary Ignite ignite() { return mockedIgnite(igniteSessions); } diff --git a/parent-internal/pom.xml b/parent-internal/pom.xml index f00f5c7a5..bd2d1e17f 100644 --- a/parent-internal/pom.xml +++ b/parent-internal/pom.xml @@ -38,6 +38,7 @@ 2.2.13.RELEASE 2.2.13.RELEASE 5.3.19 + 6.1.6 + false + + + org.apache.maven.plugins + maven-surefire-plugin + + 1 + + --add-opens=java.base/jdk.internal.access=ALL-UNNAMED + --add-opens=java.base/jdk.internal.misc=ALL-UNNAMED + --add-opens=java.base/jdk.internal.ref=ALL-UNNAMED + --add-opens=java.base/jdk.internal.loader=ALL-UNNAMED + --add-opens=java.base/sun.nio.ch=ALL-UNNAMED + --add-opens=java.management/com.sun.jmx.mbeanserver=ALL-UNNAMED + --add-opens=jdk.internal.jvmstat/sun.jvmstat.monitor=ALL-UNNAMED + --add-opens=java.base/sun.reflect.generics.reflectiveObjects=ALL-UNNAMED + --add-opens=jdk.management/com.sun.management.internal=ALL-UNNAMED + --add-opens=java.base/java.io=ALL-UNNAMED + --add-opens=java.base/java.net=ALL-UNNAMED + --add-opens=java.base/java.nio=ALL-UNNAMED + --add-opens=java.base/java.security.cert=ALL-UNNAMED + --add-opens=java.base/java.util=ALL-UNNAMED + --add-opens=java.base/java.util.concurrent=ALL-UNNAMED + --add-opens=java.base/java.util.concurrent.locks=ALL-UNNAMED + --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED + --add-opens=java.base/java.lang=ALL-UNNAMED + --add-opens=java.base/java.lang.invoke=ALL-UNNAMED + --add-opens=java.base/java.time=ALL-UNNAMED + --add-opens=java.base/sun.security.ssl=ALL-UNNAMED + --add-opens=java.base/sun.security.x509=ALL-UNNAMED + --add-opens=java.base/sun.net.util=ALL-UNNAMED + --add-opens=java.sql/java.sql=ALL-UNNAMED + --add-opens=java.base/java.lang.reflect=ALL-UNNAMED + --add-opens=java.base/java.text=ALL-UNNAMED + --add-opens=java.desktop/java.awt.font=ALL-UNNAMED + + + + + io.gatling + gatling-maven-plugin + + + --add-opens=java.base/jdk.internal.access=ALL-UNNAMED + --add-opens=java.base/jdk.internal.misc=ALL-UNNAMED + --add-opens=java.base/jdk.internal.ref=ALL-UNNAMED + --add-opens=java.base/jdk.internal.loader=ALL-UNNAMED + --add-opens=java.base/sun.nio.ch=ALL-UNNAMED + --add-opens=java.management/com.sun.jmx.mbeanserver=ALL-UNNAMED + --add-opens=jdk.internal.jvmstat/sun.jvmstat.monitor=ALL-UNNAMED + --add-opens=java.base/sun.reflect.generics.reflectiveObjects=ALL-UNNAMED + --add-opens=jdk.management/com.sun.management.internal=ALL-UNNAMED + --add-opens=java.base/java.io=ALL-UNNAMED + --add-opens=java.base/java.net=ALL-UNNAMED + --add-opens=java.base/java.nio=ALL-UNNAMED + --add-opens=java.base/java.security.cert=ALL-UNNAMED + --add-opens=java.base/java.util=ALL-UNNAMED + --add-opens=java.base/java.util.concurrent=ALL-UNNAMED + --add-opens=java.base/java.util.concurrent.locks=ALL-UNNAMED + --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED + --add-opens=java.base/java.lang=ALL-UNNAMED + --add-opens=java.base/java.lang.invoke=ALL-UNNAMED + --add-opens=java.base/java.time=ALL-UNNAMED + --add-opens=java.base/sun.security.ssl=ALL-UNNAMED + --add-opens=java.base/sun.security.x509=ALL-UNNAMED + --add-opens=java.base/sun.net.util=ALL-UNNAMED + --add-opens=java.sql/java.sql=ALL-UNNAMED + --add-opens=java.base/java.lang.reflect=ALL-UNNAMED + --add-opens=java.base/java.text=ALL-UNNAMED + --add-opens=java.desktop/java.awt.font=ALL-UNNAMED + + + + + + diff --git a/pom.xml b/pom.xml index cebf14799..33710bdbe 100644 --- a/pom.xml +++ b/pom.xml @@ -47,7 +47,6 @@ modules/performance-statistics-ext modules/spring-tx-ext modules/spring-cache-ext - modules/spring-session-ext modules/cdc-ext modules/aws-ext modules/azure-ext @@ -74,6 +73,15 @@ ../ignite + + java-17+ + + [17,) + + + modules/spring-session-ext + +