You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2015/05/05 09:50:10 UTC
[1/3] tomee git commit: TOMEE-1576 removing cached session in the
request - adapted from struberg work in a fb
Repository: tomee
Updated Branches:
refs/heads/master 1767d4804 -> 98029f737
TOMEE-1576 removing cached session in the request - adapted from struberg work in a fb
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/64febe30
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/64febe30
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/64febe30
Branch: refs/heads/master
Commit: 64febe3099597077df9472469654ce8033e81ceb
Parents: 1767d48
Author: Romain Manni-Bucau <rm...@apache.org>
Authored: Tue May 5 09:43:03 2015 +0200
Committer: Romain Manni-Bucau <rm...@apache.org>
Committed: Tue May 5 09:43:03 2015 +0200
----------------------------------------------------------------------
.../org/apache/openejb/server/httpd/HttpRequestImpl.java | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/64febe30/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpRequestImpl.java
----------------------------------------------------------------------
diff --git a/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpRequestImpl.java b/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpRequestImpl.java
index eaf420f..7b9d612 100644
--- a/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpRequestImpl.java
+++ b/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpRequestImpl.java
@@ -887,7 +887,13 @@ public class HttpRequestImpl implements HttpRequest {
}
}
- final HttpSessionImpl impl = new HttpSessionImpl(contextPath, timeout);
+ final HttpSessionImpl impl = new HttpSessionImpl(contextPath, timeout) {
+ @Override
+ public void invalidate() {
+ super.invalidate();
+ HttpRequestImpl.this.session = null;
+ }
+ };
session = impl;
if (begin != null) {
begin.sessionCreated(new HttpSessionEvent(session));
[3/3] tomee git commit: tests for 2 previous commits
Posted by rm...@apache.org.
tests for 2 previous commits
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/98029f73
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/98029f73
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/98029f73
Branch: refs/heads/master
Commit: 98029f7374edea604347e1c0a5f598fb793a65e6
Parents: 10280fa
Author: Romain Manni-Bucau <rm...@apache.org>
Authored: Tue May 5 09:50:02 2015 +0200
Committer: Romain Manni-Bucau <rm...@apache.org>
Committed: Tue May 5 09:50:02 2015 +0200
----------------------------------------------------------------------
.../server/httpd/HttpRequestImplTest.java | 50 ++++++++++++++
.../server/httpd/HttpSessionImplTest.java | 68 ++++++++++++++++++++
2 files changed, 118 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/98029f73/server/openejb-http/src/test/java/org/apache/openejb/server/httpd/HttpRequestImplTest.java
----------------------------------------------------------------------
diff --git a/server/openejb-http/src/test/java/org/apache/openejb/server/httpd/HttpRequestImplTest.java b/server/openejb-http/src/test/java/org/apache/openejb/server/httpd/HttpRequestImplTest.java
new file mode 100644
index 0000000..54b7373
--- /dev/null
+++ b/server/openejb-http/src/test/java/org/apache/openejb/server/httpd/HttpRequestImplTest.java
@@ -0,0 +1,50 @@
+/**
+ * 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.
+ */
+package org.apache.openejb.server.httpd;
+
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.server.httpd.session.SessionManager;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+public class HttpRequestImplTest {
+ @Before
+ public void init() {
+ SystemInstance.get().setComponent(SessionManager.class, new SessionManager());
+ }
+
+ @After
+ public void reset() {
+ SystemInstance.reset();
+ }
+
+ @Test
+ public void run() throws URISyntaxException {
+ final HttpRequest req = new HttpRequestImpl(new URI("http://localhost:1234/foo"));
+ final javax.servlet.http.HttpSession session = req.getSession();
+ assertNotNull(session);
+ session.invalidate();
+ assertNull(req.getSession(false));
+ }
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/98029f73/server/openejb-http/src/test/java/org/apache/openejb/server/httpd/HttpSessionImplTest.java
----------------------------------------------------------------------
diff --git a/server/openejb-http/src/test/java/org/apache/openejb/server/httpd/HttpSessionImplTest.java b/server/openejb-http/src/test/java/org/apache/openejb/server/httpd/HttpSessionImplTest.java
new file mode 100644
index 0000000..990d48e
--- /dev/null
+++ b/server/openejb-http/src/test/java/org/apache/openejb/server/httpd/HttpSessionImplTest.java
@@ -0,0 +1,68 @@
+/*
+ * 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.
+ */
+package org.apache.openejb.server.httpd;
+
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.server.httpd.session.SessionManager;
+import org.apache.openejb.util.reflection.Reflections;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Collections;
+import javax.servlet.http.HttpSessionEvent;
+import javax.servlet.http.HttpSessionListener;
+
+import static org.junit.Assert.assertEquals;
+
+public class HttpSessionImplTest {
+ @Before
+ public void init() {
+ SystemInstance.get().setComponent(SessionManager.class, new SessionManager());
+ }
+
+ @After
+ public void reset() {
+ SystemInstance.reset();
+ }
+
+ @Test
+ public void run() throws URISyntaxException {
+ final HttpRequest req = new HttpRequestImpl(new URI("http://localhost:1234/foo"));
+ final javax.servlet.http.HttpSession session = req.getSession();
+ Reflections.set(session, "listeners", Collections.<Object>singletonList(new HttpSessionListener() {
+ private int count = 0;
+
+ @Override
+ public void sessionCreated(final HttpSessionEvent se) {
+ // no-op
+ }
+
+ @Override
+ public void sessionDestroyed(final HttpSessionEvent se) {
+ se.getSession().setAttribute("seen", ++count);
+ }
+ }));
+ session.invalidate();
+ final long c1 = Integer.class.cast(session.getAttribute("seen"));
+ session.invalidate();
+ final long c2 = Integer.class.cast(session.getAttribute("seen"));
+ assertEquals(c1, c2);
+ }
+}
[2/3] tomee git commit: TOMEE-1577 synchronizing httpsessionimpl
invalidate
Posted by rm...@apache.org.
TOMEE-1577 synchronizing httpsessionimpl invalidate
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/10280fab
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/10280fab
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/10280fab
Branch: refs/heads/master
Commit: 10280fab2fdf8b452bf44db81d1b7bdeb9096571
Parents: 64febe3
Author: Romain Manni-Bucau <rm...@apache.org>
Authored: Tue May 5 09:49:47 2015 +0200
Committer: Romain Manni-Bucau <rm...@apache.org>
Committed: Tue May 5 09:49:47 2015 +0200
----------------------------------------------------------------------
.../openejb/server/httpd/HttpSessionImpl.java | 34 +++++++++++++-------
1 file changed, 23 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/10280fab/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpSessionImpl.java
----------------------------------------------------------------------
diff --git a/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpSessionImpl.java b/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpSessionImpl.java
index f82b7bf..104deb5 100644
--- a/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpSessionImpl.java
+++ b/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpSessionImpl.java
@@ -40,6 +40,7 @@ public class HttpSessionImpl implements HttpSession {
private final long created = System.currentTimeMillis();
private volatile long timeout;
private volatile long lastAccessed = created;
+ private volatile boolean valid = true;
public HttpSessionImpl(final String contextPath, final long timeout) {
this.timeout = timeout;
@@ -91,20 +92,31 @@ public class HttpSessionImpl implements HttpSession {
@Override
public void invalidate() {
- if (!listeners.isEmpty()) {
- final HttpSessionEvent event = new HttpSessionEvent(this);
- for (final HttpSessionListener o : listeners) {
- try {
- HttpSessionListener.class.cast(o).sessionDestroyed(event);
- } catch (final Throwable th) {
- // ignore, may be undeployed
+ if (!valid) {
+ return;
+ }
+
+ synchronized (this) {
+ if (!valid) {
+ return;
+ }
+
+ if (!listeners.isEmpty()) {
+ final HttpSessionEvent event = new HttpSessionEvent(this);
+ for (final HttpSessionListener o : listeners) {
+ try {
+ HttpSessionListener.class.cast(o).sessionDestroyed(event);
+ } catch (final Throwable th) {
+ // ignore, may be undeployed
+ }
}
}
- }
- final SessionManager sessionManager = SystemInstance.get().getComponent(SessionManager.class);
- if (sessionManager != null) {
- sessionManager.removeSession(sessionId);
+ final SessionManager sessionManager = SystemInstance.get().getComponent(SessionManager.class);
+ if (sessionManager != null) {
+ sessionManager.removeSession(sessionId);
+ }
+ valid = false;
}
}