IGNITE-2749 - Fixed web session clustering in WebLogic
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/52c134d4 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/52c134d4 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/52c134d4 Branch: refs/heads/ignite-2801 Commit: 52c134d489a4bd431a37bfd8c93e19c6a54e1c5f Parents: 8b4b7b2 Author: Valentin Kulichenko <[email protected]> Authored: Wed Mar 9 20:16:49 2016 -0800 Committer: Valentin Kulichenko <[email protected]> Committed: Wed Mar 9 20:19:57 2016 -0800 ---------------------------------------------------------------------- modules/web/ignite-weblogic-test/pom.xml | 100 +++++++++++++++++++ .../webapp/META-INF/config/default-config.xml | 20 ++++ .../src/main/webapp/WEB-INF/web.xml | 69 +++++++++++++ .../src/main/webapp/index.jsp | 53 ++++++++++ .../ignite/cache/websession/WebSession.java | 28 ++---- .../cache/websession/WebSessionFilter.java | 19 ++-- .../cache/websession/WebSessionListener.java | 8 +- pom.xml | 1 + 8 files changed, 269 insertions(+), 29 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/52c134d4/modules/web/ignite-weblogic-test/pom.xml ---------------------------------------------------------------------- diff --git a/modules/web/ignite-weblogic-test/pom.xml b/modules/web/ignite-weblogic-test/pom.xml new file mode 100644 index 0000000..4746f1f --- /dev/null +++ b/modules/web/ignite-weblogic-test/pom.xml @@ -0,0 +1,100 @@ +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one or more + ~ contributor license agreements. See the NOTICE file distributed with + ~ this work for additional information regarding copyright ownership. + ~ The ASF licenses this file to You under the Apache License, Version 2.0 + ~ (the "License"); you may not use this file except in compliance with + ~ the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> + +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one or more + ~ contributor license agreements. See the NOTICE file distributed with + ~ this work for additional information regarding copyright ownership. + ~ The ASF licenses this file to You under the Apache License, Version 2.0 + ~ (the "License"); you may not use this file except in compliance with + ~ the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> + +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<!-- + POM file. +--> +<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/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>org.apache.ignite</groupId> + <artifactId>ignite-weblogic-test</artifactId> + <packaging>war</packaging> + <version>1.0-SNAPSHOT</version> + <name>ignite-weblogic-test Maven Webapp</name> + <url>http://maven.apache.org</url> + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.apache.ignite</groupId> + <artifactId>ignite-core</artifactId> + <version>1.6.0-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.ignite</groupId> + <artifactId>ignite-web</artifactId> + <version>1.6.0-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.ignite</groupId> + <artifactId>ignite-log4j</artifactId> + <version>1.6.0-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.ignite</groupId> + <artifactId>ignite-spring</artifactId> + <version>1.6.0-SNAPSHOT</version> + </dependency> + </dependencies> + + <build> + <finalName>ignite-weblogic-test</finalName> + </build> +</project> http://git-wip-us.apache.org/repos/asf/ignite/blob/52c134d4/modules/web/ignite-weblogic-test/src/main/webapp/META-INF/config/default-config.xml ---------------------------------------------------------------------- diff --git a/modules/web/ignite-weblogic-test/src/main/webapp/META-INF/config/default-config.xml b/modules/web/ignite-weblogic-test/src/main/webapp/META-INF/config/default-config.xml new file mode 100644 index 0000000..daa466d --- /dev/null +++ b/modules/web/ignite-weblogic-test/src/main/webapp/META-INF/config/default-config.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans.xsd"> + <bean class="org.apache.ignite.configuration.IgniteConfiguration"> + <property name="cacheConfiguration"> + <list> + <bean class="org.apache.ignite.configuration.CacheConfiguration"> + <property name="name" value="atomic"/> + + <property name="cacheMode" value="PARTITIONED"/> + + <property name="atomicityMode" value="ATOMIC"/> + </bean> + </list> + </property> + </bean> +</beans> http://git-wip-us.apache.org/repos/asf/ignite/blob/52c134d4/modules/web/ignite-weblogic-test/src/main/webapp/WEB-INF/web.xml ---------------------------------------------------------------------- diff --git a/modules/web/ignite-weblogic-test/src/main/webapp/WEB-INF/web.xml b/modules/web/ignite-weblogic-test/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..054eab4 --- /dev/null +++ b/modules/web/ignite-weblogic-test/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,69 @@ +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one or more + ~ contributor license agreements. See the NOTICE file distributed with + ~ this work for additional information regarding copyright ownership. + ~ The ASF licenses this file to You under the Apache License, Version 2.0 + ~ (the "License"); you may not use this file except in compliance with + ~ the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> + +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one or more + ~ contributor license agreements. See the NOTICE file distributed with + ~ this work for additional information regarding copyright ownership. + ~ The ASF licenses this file to You under the Apache License, Version 2.0 + ~ (the "License"); you may not use this file except in compliance with + ~ the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> + +<!DOCTYPE web-app PUBLIC + "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" + "http://java.sun.com/dtd/web-app_2_3.dtd" > + +<web-app> + <display-name>Archetype Created Web Application</display-name> + + <listener> + <listener-class>org.apache.ignite.startup.servlet.ServletContextListenerStartup</listener-class> + </listener> + + <filter> + <filter-name>IgniteWebSessionsFilter</filter-name> + <filter-class>org.apache.ignite.cache.websession.WebSessionFilter</filter-class> + </filter> + + <!-- You can also specify a custom URL pattern. --> + <filter-mapping> + <filter-name>IgniteWebSessionsFilter</filter-name> + <url-pattern>/*</url-pattern> + </filter-mapping> + + <!-- Specify Ignite configuration (relative to META-INF folder or Ignite_HOME). --> + <context-param> + <param-name>IgniteConfigurationFilePath</param-name> + <param-value>config/default-config.xml </param-value> + </context-param> + + <!-- Specify the name of Ignite cache for web sessions. --> + <context-param> + <param-name>IgniteWebSessionsCacheName</param-name> + <param-value>atomic</param-value> + </context-param> + +</web-app> http://git-wip-us.apache.org/repos/asf/ignite/blob/52c134d4/modules/web/ignite-weblogic-test/src/main/webapp/index.jsp ---------------------------------------------------------------------- diff --git a/modules/web/ignite-weblogic-test/src/main/webapp/index.jsp b/modules/web/ignite-weblogic-test/src/main/webapp/index.jsp new file mode 100644 index 0000000..0cc090d --- /dev/null +++ b/modules/web/ignite-weblogic-test/src/main/webapp/index.jsp @@ -0,0 +1,53 @@ +<%-- + ~ Licensed to the Apache Software Foundation (ASF) under one or more + ~ contributor license agreements. See the NOTICE file distributed with + ~ this work for additional information regarding copyright ownership. + ~ The ASF licenses this file to You under the Apache License, Version 2.0 + ~ (the "License"); you may not use this file except in compliance with + ~ the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --%> + +<%-- + ~ Licensed to the Apache Software Foundation (ASF) under one or more + ~ contributor license agreements. See the NOTICE file distributed with + ~ this work for additional information regarding copyright ownership. + ~ The ASF licenses this file to You under the Apache License, Version 2.0 + ~ (the "License"); you may not use this file except in compliance with + ~ the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --%> + +<%@ page import="org.apache.ignite.Ignition" %> +<%@ page import="java.util.UUID" %> +<html> +<body> +<h2>Session ID</h2> +<%= request.getSession().getId() %> +<h2>Session content</h2> +<%= Ignition.ignite().cache("atomic").get(request.getSession().getId()) %> +<h2>Cache size</h2> +<%= Ignition.ignite().cache("atomic").size() %> + +<% + HttpSession ses = request.getSession(); + + ses.setAttribute(UUID.randomUUID().toString(), "Value"); +%> + +</body> +</html> http://git-wip-us.apache.org/repos/asf/ignite/blob/52c134d4/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSession.java ---------------------------------------------------------------------- diff --git a/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSession.java b/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSession.java index 496600a..05ecc36 100644 --- a/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSession.java +++ b/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSession.java @@ -94,12 +94,15 @@ class WebSession implements HttpSession, Externalizable { } /** + * @param id Session ID. * @param ses Session. */ - WebSession(HttpSession ses) { + WebSession(String id, HttpSession ses) { + assert id != null; assert ses != null; - id = ses.getId(); + this.id = id; + createTime = ses.getCreationTime(); accessTime = ses.getLastAccessedTime(); maxInactiveInterval = ses.getMaxInactiveInterval(); @@ -117,23 +120,17 @@ class WebSession implements HttpSession, Externalizable { } /** + * @param id Session ID. * @param ses Session. * @param isNew Is new flag. */ - WebSession(HttpSession ses, boolean isNew) { - this(ses); + WebSession(String id, HttpSession ses, boolean isNew) { + this(id, ses); this.isNew = isNew; } /** - * @param accessTime Last access time. - */ - void accessTime(long accessTime) { - this.accessTime = accessTime; - } - - /** * @param ctx Servlet context. */ public void servletContext(ServletContext ctx) { @@ -254,13 +251,6 @@ class WebSession implements HttpSession, Externalizable { lsnr.destroySession(id); } - /** - * @param isNew New session flag. - */ - void setNew(boolean isNew) { - this.isNew = isNew; - } - /** {@inheritDoc} */ @Override public boolean isNew() { return isNew; @@ -293,4 +283,4 @@ class WebSession implements HttpSession, Externalizable { @Override public String toString() { return S.toString(WebSession.class, this); } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/ignite/blob/52c134d4/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSessionFilter.java ---------------------------------------------------------------------- diff --git a/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSessionFilter.java b/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSessionFilter.java index 4a84931..bd2f25f 100644 --- a/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSessionFilter.java +++ b/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSessionFilter.java @@ -166,7 +166,7 @@ public class WebSessionFilter implements Filter { /** Web sessions caching cache name parameter name. */ public static final String WEB_SES_CACHE_NAME_PARAM = "IgniteWebSessionsCacheName"; - /** Web sessions caching retry on fail parameter name (valid for ATOMIC */ + /** Web sessions caching retry on fail parameter name (valid for ATOMIC cache only). */ public static final String WEB_SES_MAX_RETRIES_ON_FAIL_NAME_PARAM = "IgniteWebSessionsMaximumRetriesOnFail"; /** Default retry on fail flag value. */ @@ -338,6 +338,9 @@ public class WebSessionFilter implements Filter { String sesId = httpReq.getRequestedSessionId(); if (sesId != null) { + if (sesIdTransformer != null) + sesId = sesIdTransformer.apply(sesId); + cached = cache.get(sesId); if (cached != null) { @@ -345,7 +348,7 @@ public class WebSessionFilter implements Filter { log.debug("Using cached session for ID: " + sesId); if (cached.isNew()) - cached = new WebSession(cached, false); + cached = new WebSession(cached.getId(), cached, false); } else { if (log.isDebugEnabled()) @@ -386,8 +389,10 @@ public class WebSessionFilter implements Filter { if (ses != null && ses instanceof WebSession) { Collection<T2<String, Object>> updates = ((WebSession)ses).updates(); - if (updates != null) - lsnr.updateAttributes(ses.getId(), updates, ses.getMaxInactiveInterval()); + if (updates != null) { + lsnr.updateAttributes(sesIdTransformer != null ? sesIdTransformer.apply(ses.getId()) : ses.getId(), + updates, ses.getMaxInactiveInterval()); + } } return sesId; @@ -406,7 +411,7 @@ public class WebSessionFilter implements Filter { if (log.isDebugEnabled()) log.debug("Session created: " + sesId); - WebSession cached = new WebSession(ses, true); + WebSession cached = new WebSession(sesId, ses, true); for (int i = 0; i < retries; i++) { try { @@ -428,7 +433,7 @@ public class WebSessionFilter implements Filter { cached = old; if (cached.isNew()) - cached = new WebSession(cached, false); + cached = new WebSession(cached.getId(), cached, false); } break; @@ -502,4 +507,4 @@ public class WebSessionFilter implements Filter { return ses; } } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/ignite/blob/52c134d4/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSessionListener.java ---------------------------------------------------------------------- diff --git a/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSessionListener.java b/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSessionListener.java index b826031..0d7c44e 100644 --- a/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSessionListener.java +++ b/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSessionListener.java @@ -46,7 +46,7 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS; */ class WebSessionListener { /** */ - private static final long RETRY_DELAY = 1; + private static final long RETRY_DELAY = 1000; /** Cache. */ private final IgniteCache<String, WebSession> cache; @@ -186,7 +186,9 @@ class WebSessionListener { if (!entry.exists()) return null; - WebSession ses = new WebSession(entry.getValue()); + WebSession ses0 = entry.getValue(); + + WebSession ses = new WebSession(ses0.getId(), ses0); for (T2<String, Object> update : updates) { String name = update.get1(); @@ -216,4 +218,4 @@ class WebSessionListener { updates = U.readCollection(in); } } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/ignite/blob/52c134d4/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 4a3ae12..b8aaa5f 100644 --- a/pom.xml +++ b/pom.xml @@ -83,6 +83,7 @@ <module>modules/osgi-paxlogging</module> <module>modules/osgi-karaf</module> <module>modules/osgi</module> + <module>modules/web/ignite-weblogic-test</module> </modules> <profiles>
