Skip to content

Commit 7ba995b

Browse files
author
Jean Deruelle
committed
Merge branch 'Issue-3' into github-master
2 parents ab879bd + faf4c00 commit 7ba995b

13 files changed

Lines changed: 237 additions & 121 deletions

containers/sip-servlets-as8-drop-in/jboss-as-mobicents/pom.xml

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -106,46 +106,36 @@
106106
<dependency>
107107
<groupId>org.wildfly</groupId>
108108
<artifactId>wildfly-undertow</artifactId>
109-
<version>8.2.0.Final</version>
109+
<version>8.2.1.Final</version>
110110
<scope>provided</scope>
111-
<!-- exclusions>
112-
<exclusion>
113-
<groupId>io.undertow</groupId>
114-
<artifactId>undertow-core</artifactId>
115-
</exclusion>
116-
<exclusion>
117-
<groupId>io.undertow</groupId>
118-
<artifactId>undertow-servlet</artifactId>
119-
</exclusion>
120-
</exclusions -->
121111
</dependency>
122112
<dependency>
123113
<groupId>org.wildfly</groupId>
124114
<artifactId>wildfly-naming</artifactId>
125-
<version>8.2.0.Final</version>
115+
<version>8.2.1.Final</version>
126116
<scope>provided</scope>
127117
</dependency>
128118
<dependency>
129119
<groupId>org.wildfly</groupId>
130120
<artifactId>wildfly-web</artifactId>
131-
<version>8.2.0.Final</version>
121+
<version>8.2.1.Final</version>
132122
<scope>provided</scope>
133123
</dependency>
134124
<dependency>
135125
<groupId>org.wildfly</groupId>
136126
<artifactId>wildfly-web-common</artifactId>
137-
<version>8.2.0.Final</version>
127+
<version>8.2.1.Final</version>
138128
<scope>provided</scope>
139129
</dependency>
140130
<dependency>
141131
<groupId>io.undertow</groupId>
142132
<artifactId>undertow-core</artifactId>
143-
<version>1.1.0.Final</version>
133+
<version>1.1.8.Final</version>
144134
</dependency>
145135
<dependency>
146136
<groupId>io.undertow</groupId>
147137
<artifactId>undertow-servlet</artifactId>
148-
<version>1.1.0.Final</version>
138+
<version>1.1.8.Final</version>
149139
</dependency>
150140

151141
<dependency>

containers/sip-servlets-as8/pom.xml

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,40 +21,30 @@
2121
<dependency>
2222
<groupId>org.wildfly</groupId>
2323
<artifactId>wildfly-undertow</artifactId>
24-
<version>8.2.0.Final</version>
24+
<version>8.2.1.Final</version>
2525
<scope>provided</scope>
26-
<!-- exclusions>
27-
<exclusion>
28-
<groupId>io.undertow</groupId>
29-
<artifactId>undertow-core</artifactId>
30-
</exclusion>
31-
<exclusion>
32-
<groupId>io.undertow</groupId>
33-
<artifactId>undertow-servlet</artifactId>
34-
</exclusion>
35-
</exclusions -->
3626
</dependency>
3727
<dependency>
3828
<groupId>org.wildfly</groupId>
3929
<artifactId>wildfly-web</artifactId>
40-
<version>8.2.0.Final</version>
30+
<version>8.2.1.Final</version>
4131
<scope>provided</scope>
4232
</dependency>
4333
<dependency>
4434
<groupId>org.wildfly</groupId>
4535
<artifactId>wildfly-web-common</artifactId>
46-
<version>8.2.0.Final</version>
36+
<version>8.2.1.Final</version>
4737
<scope>provided</scope>
4838
</dependency>
4939
<dependency>
5040
<groupId>io.undertow</groupId>
5141
<artifactId>undertow-core</artifactId>
52-
<version>1.1.0.Final</version>
42+
<version>1.1.8.Final</version>
5343
</dependency>
5444
<dependency>
5545
<groupId>io.undertow</groupId>
5646
<artifactId>undertow-servlet</artifactId>
57-
<version>1.1.0.Final</version>
47+
<version>1.1.8.Final</version>
5848
</dependency>
5949
<!--dependency>
6050
<groupId>org.jboss.security</groupId>

containers/sip-servlets-as8/src/main/java/org/mobicents/io/undertow/server/session/ConvergedInMemorySessionManager.java

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public void stop() {
103103
}
104104

105105
@Override
106-
public Session createSession(HttpServerExchange serverExchange, SessionConfig sessionCookieConfig) {
106+
public Session createSession(final HttpServerExchange serverExchange, final SessionConfig config) {
107107
if (evictionQueue != null) {
108108
while (sessions.size() >= maxSize && !evictionQueue.isEmpty()) {
109109
String key = evictionQueue.poll();
@@ -114,10 +114,10 @@ public Session createSession(HttpServerExchange serverExchange, SessionConfig se
114114
}
115115
}
116116
}
117-
if (sessionCookieConfig == null) {
117+
if (config == null) {
118118
throw UndertowMessages.MESSAGES.couldNotFindSessionCookieConfig();
119119
}
120-
String sessionID = sessionCookieConfig.findSessionId(serverExchange);
120+
String sessionID = config.findSessionId(serverExchange);
121121
int count = 0;
122122
while (sessionID == null) {
123123
sessionID = sessionIdGenerator.createSessionId();
@@ -136,10 +136,10 @@ public Session createSession(HttpServerExchange serverExchange, SessionConfig se
136136
} else {
137137
evictionToken = null;
138138
}
139-
final ConvergedSessionImpl session = new ConvergedSessionImpl(this, sessionID, sessionCookieConfig, serverExchange.getIoThread(), serverExchange.getConnection().getWorker(), evictionToken);
139+
final ConvergedSessionImpl session = new ConvergedSessionImpl(this, sessionID, config, serverExchange.getIoThread(), serverExchange.getConnection().getWorker(), evictionToken);
140140
ConvergedInMemorySession im = new ConvergedInMemorySession(session, defaultSessionTimeout);
141141
sessions.put(sessionID, im);
142-
sessionCookieConfig.setSessionId(serverExchange, session.getId());
142+
config.setSessionId(serverExchange, session.getId());
143143
im.lastAccessed = System.currentTimeMillis();
144144
session.bumpTimeout();
145145
sessionListeners.sessionCreated(session, serverExchange);
@@ -158,7 +158,7 @@ public void addConvergedSessionDeletegateToSession(SessionConfig sessionCookieCo
158158
}
159159

160160
@Override
161-
public Session getSession(HttpServerExchange serverExchange, SessionConfig sessionCookieConfig) {
161+
public Session getSession(final HttpServerExchange serverExchange, final SessionConfig sessionCookieConfig) {
162162
String sessionId = sessionCookieConfig.findSessionId(serverExchange);
163163
return getSession(sessionId);
164164
}
@@ -182,12 +182,12 @@ public void registerSessionListener(SessionListener listener) {
182182
}
183183

184184
@Override
185-
public void removeSessionListener(SessionListener listener) {
185+
public synchronized void removeSessionListener(final SessionListener listener) {
186186
sessionListeners.removeSessionListener(listener);
187187
}
188188

189189
@Override
190-
public void setDefaultSessionTimeout(int timeout) {
190+
public void setDefaultSessionTimeout(final int timeout) {
191191
defaultSessionTimeout = timeout;
192192
}
193193

@@ -206,6 +206,23 @@ public Set<String> getAllSessions() {
206206
return new HashSet<>(sessions.keySet());
207207
}
208208

209+
@Override
210+
public boolean equals(Object object) {
211+
if (!(object instanceof SessionManager)) return false;
212+
SessionManager manager = (SessionManager) object;
213+
return this.deploymentName.equals(manager.getDeploymentName());
214+
}
215+
216+
@Override
217+
public int hashCode() {
218+
return this.deploymentName.hashCode();
219+
}
220+
221+
@Override
222+
public String toString() {
223+
return this.deploymentName;
224+
}
225+
209226
/**
210227
* session implementation for the in memory session manager
211228
*/
@@ -235,6 +252,7 @@ private static AtomicReferenceFieldUpdater<ConvergedSessionImpl, Object> createT
235252
private volatile Object evictionToken;
236253
private final SessionConfig sessionCookieConfig;
237254
private volatile long expireTime = -1;
255+
private volatile boolean invalidationStarted = false;
238256

239257
final XnioExecutor executor;
240258
final XnioWorker worker;
@@ -268,9 +286,13 @@ private ConvergedSessionImpl(ConvergedInMemorySessionManager sessionManager, fin
268286
}
269287

270288
synchronized void bumpTimeout() {
289+
if(invalidationStarted) {
290+
return;
291+
}
292+
271293
final int maxInactiveInterval = getMaxInactiveInterval();
272294
if (maxInactiveInterval > 0) {
273-
long newExpireTime = System.currentTimeMillis() + (maxInactiveInterval * 1000);
295+
long newExpireTime = System.currentTimeMillis() + (maxInactiveInterval * 1000L);
274296
if(timerCancelKey != null && (newExpireTime < expireTime)) {
275297
// We have to re-schedule as the new maxInactiveInterval is lower than the old one
276298
if (!timerCancelKey.remove()) {
@@ -283,7 +305,7 @@ synchronized void bumpTimeout() {
283305
//+1 second, to make sure that the time has actually expired
284306
//we don't re-schedule every time, as it is expensive
285307
//instead when it expires we check if the timeout has been bumped, and if so we re-schedule
286-
timerCancelKey = executor.executeAfter(cancelTask, (maxInactiveInterval * 1000) + 1, TimeUnit.MILLISECONDS);
308+
timerCancelKey = executor.executeAfter(cancelTask, (maxInactiveInterval * 1000L) + 1, TimeUnit.MILLISECONDS);
287309
}
288310
}
289311
if (evictionToken != null) {
@@ -405,22 +427,27 @@ public void invalidate(final HttpServerExchange exchange) {
405427
invalidate(exchange, SessionListener.SessionDestroyedReason.INVALIDATED);
406428
}
407429

408-
synchronized void invalidate(final HttpServerExchange exchange, SessionListener.SessionDestroyedReason reason) {
409-
if (timerCancelKey != null) {
410-
timerCancelKey.remove();
411-
}
412-
ConvergedInMemorySession sess = sessionManager.sessions.get(sessionId);
413-
if (sess == null) {
414-
if (reason == SessionListener.SessionDestroyedReason.INVALIDATED) {
415-
throw UndertowMessages.MESSAGES.sessionAlreadyInvalidated();
430+
void invalidate(final HttpServerExchange exchange, SessionListener.SessionDestroyedReason reason) {
431+
synchronized(ConvergedSessionImpl.this) {
432+
if (timerCancelKey != null) {
433+
timerCancelKey.remove();
416434
}
417-
return;
435+
ConvergedInMemorySession sess = sessionManager.sessions.get(sessionId);
436+
if (sess == null) {
437+
if (reason == SessionListener.SessionDestroyedReason.INVALIDATED) {
438+
throw UndertowMessages.MESSAGES.sessionAlreadyInvalidated();
439+
}
440+
return;
441+
}
442+
invalidationStarted = true;
418443
}
419-
sessionManager.sessionListeners.sessionDestroyed(sess.session, exchange, reason);
444+
sessionManager.sessionListeners.sessionDestroyed(this, exchange, reason);
445+
420446
sessionManager.sessions.remove(sessionId);
421447
if (exchange != null) {
422448
sessionCookieConfig.clearSession(exchange, this.getId());
423449
}
450+
424451
}
425452

426453
@Override

containers/sip-servlets-as8/src/main/java/org/mobicents/io/undertow/servlet/core/ConvergedDeploymentManagerImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ public void deploy() {
185185
}
186186

187187
final List<ThreadSetupAction> setup = new ArrayList<>();
188+
setup.add(ServletRequestContextThreadSetupAction.INSTANCE);
188189
setup.add(new ContextClassLoaderSetupAction(deploymentInfo.getClassLoader()));
189190
setup.addAll(deploymentInfo.getThreadSetupActions());
190191
final CompositeThreadSetupAction threadSetupAction = new CompositeThreadSetupAction(setup);

containers/sip-servlets-as8/src/main/java/org/mobicents/io/undertow/servlet/core/ConvergedSessionListenerBridge.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ public class ConvergedSessionListenerBridge extends SessionListenerBridge{
4646
private final ServletContext servletContext;
4747
private final SessionManager manager;
4848

49-
public ConvergedSessionListenerBridge(ThreadSetupAction threadSetup, ApplicationListeners applicationListeners,
50-
ServletContext servletContext, SessionManager manager) {
49+
public ConvergedSessionListenerBridge(final ThreadSetupAction threadSetup, final ApplicationListeners applicationListeners,
50+
final ServletContext servletContext, final SessionManager manager) {
5151
super(threadSetup, applicationListeners, servletContext);
5252
this.threadSetup = threadSetup;
5353
this.applicationListeners = applicationListeners;

containers/sip-servlets-as8/src/main/java/org/mobicents/io/undertow/servlet/core/SecurityActions.java

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@
4343
*/
4444
class SecurityActions {
4545

46+
static String getSystemProperty(final String prop) {
47+
if (System.getSecurityManager() == null) {
48+
return System.getProperty(prop);
49+
} else {
50+
return (String) AccessController.doPrivileged(new PrivilegedAction<Object>() {
51+
public Object run() {
52+
return System.getProperty(prop);
53+
}
54+
});
55+
}
56+
}
57+
4658
static HttpSession forSession(final Session session, final ServletContext servletContext, final boolean newSession, final SessionManager manager) {
4759
if (System.getSecurityManager() == null) {
4860
return ConvergedHttpSessionFacade.forConvergedSession(session, servletContext, newSession, manager);
@@ -69,18 +81,34 @@ public ServletRequestContext run() {
6981
}
7082
}
7183

72-
static String getSystemProperty(final String prop) {
84+
static void setCurrentRequestContext(final ServletRequestContext servletRequestContext) {
7385
if (System.getSecurityManager() == null) {
74-
return System.getProperty(prop);
86+
ServletRequestContext.setCurrentRequestContext(servletRequestContext);
7587
} else {
76-
return (String) AccessController.doPrivileged(new PrivilegedAction<Object>() {
88+
AccessController.doPrivileged(new PrivilegedAction<Object>() {
89+
@Override
7790
public Object run() {
78-
return System.getProperty(prop);
91+
ServletRequestContext.setCurrentRequestContext(servletRequestContext);
92+
return null;
7993
}
8094
});
8195
}
8296
}
8397

98+
static void clearCurrentServletAttachments() {
99+
if (System.getSecurityManager() == null) {
100+
ServletRequestContext.clearCurrentServletAttachments();
101+
} else {
102+
AccessController.doPrivileged(new PrivilegedAction<Object>() {
103+
@Override
104+
public Object run() {
105+
ServletRequestContext.clearCurrentServletAttachments();
106+
return null;
107+
}
108+
});
109+
}
110+
}
111+
84112
static ServletInitialHandler createServletInitialHandler(final ServletPathMatches paths, final HttpHandler next, final CompositeThreadSetupAction setupAction, final ServletContext servletContext) {
85113
if (System.getSecurityManager() == null) {
86114
return new ConvergedServletInitialHandler(paths, next, setupAction, /*TODO*/(ConvergedServletContextImpl) servletContext);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* TeleStax, Open Source Cloud Communications
3+
* Copyright 2011-2015, Telestax Inc and individual contributors
4+
* by the @authors tag.
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* under the terms of the GNU Affero General Public License as
8+
* published by the Free Software Foundation; either version 3 of
9+
* the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Affero General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Affero General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>
18+
*/
19+
package org.mobicents.io.undertow.servlet.core;
20+
21+
import io.undertow.server.HttpServerExchange;
22+
import io.undertow.servlet.api.ThreadSetupAction;
23+
import io.undertow.servlet.handlers.ServletRequestContext;
24+
25+
/**
26+
* This class is based on protected class io.undertow.servlet.core.ServletRequestContextThreadSetupAction.
27+
*
28+
* @author kakonyi.istvan@alerant.hu
29+
*/
30+
class ServletRequestContextThreadSetupAction implements ThreadSetupAction {
31+
32+
static final ServletRequestContextThreadSetupAction INSTANCE = new ServletRequestContextThreadSetupAction();
33+
34+
private ServletRequestContextThreadSetupAction() {
35+
36+
}
37+
38+
private static final Handle HANDLE = new Handle() {
39+
@Override
40+
public void tearDown() {
41+
SecurityActions.clearCurrentServletAttachments();
42+
}
43+
};
44+
45+
@Override
46+
public Handle setup(HttpServerExchange exchange) {
47+
if(exchange == null) {
48+
return null;
49+
}
50+
ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
51+
SecurityActions.setCurrentRequestContext(servletRequestContext);
52+
return HANDLE;
53+
}
54+
}

0 commit comments

Comments
 (0)