Skip to content

Commit

Permalink
LDEV-5144 change request scope sync to be per instance
Browse files Browse the repository at this point in the history
  • Loading branch information
zspitzer committed Dec 27, 2024
1 parent ea302fa commit fb06afd
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 79 deletions.
162 changes: 85 additions & 77 deletions core/src/main/java/lucee/runtime/net/http/HTTPServletRequestWrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,29 +217,35 @@ public RequestDispatcher getOriginalRequestDispatcher(String realpath) {
}

@Override
public synchronized void removeAttribute(String name) {
if (disconnected) disconnectData.attributes.remove(name);
else req.removeAttribute(name);
public void removeAttribute(String name) {
synchronized (this) {
if (disconnected) disconnectData.attributes.remove(name);
else req.removeAttribute(name);
}
}

@Override
public synchronized void setAttribute(String name, Object value) {
if (disconnected) disconnectData.attributes.put(name, value);
else req.setAttribute(name, value);
public void setAttribute(String name, Object value) {
synchronized (this) {
if (disconnected) disconnectData.attributes.put(name, value);
else req.setAttribute(name, value);
}
}

@Override
public synchronized Object getAttribute(String name) {
if (disconnected) return disconnectData.attributes.get(name);
return req.getAttribute(name);
public Object getAttribute(String name) {
synchronized (this) {
if (disconnected) return disconnectData.attributes.get(name);
return req.getAttribute(name);
}
}

@Override
public synchronized Enumeration getAttributeNames() {
if (disconnected) {
return new EnumerationWrapper(disconnectData.attributes.keySet().toArray());
public Enumeration getAttributeNames() {
synchronized (this) {
if (disconnected) return new EnumerationWrapper(disconnectData.attributes.keySet().toArray());
return req.getAttributeNames();
}
return req.getAttributeNames();
}

@Override
Expand Down Expand Up @@ -379,79 +385,81 @@ public HttpServletRequest getOriginalRequest() {
return req;
}

public synchronized void disconnect(PageContextImpl pc) {
if (disconnected) return;
disconnectData = new DisconnectData();
public void disconnect(PageContextImpl pc) {
synchronized (this){
if (disconnected) return;
disconnectData = new DisconnectData();

// attributes
{
Iterator<String> it = ListUtil.toIterator(req.getAttributeNames());
disconnectData.attributes = MapFactory.getConcurrentMap();
String k;
while (it.hasNext()) {
k = it.next();
if (!StringUtil.isEmpty(k)) disconnectData.attributes.put(k, req.getAttribute(k));
// attributes
{
Iterator<String> it = ListUtil.toIterator(req.getAttributeNames());
disconnectData.attributes = MapFactory.getConcurrentMap();
String k;
while (it.hasNext()) {
k = it.next();
if (!StringUtil.isEmpty(k)) disconnectData.attributes.put(k, req.getAttribute(k));
}
}
}

// headers
{
Enumeration<String> headerNames = req.getHeaderNames();
disconnectData.headers = MapFactory.getConcurrentMap();// new ConcurrentHashMap<Collection.Key, LinkedList<String>>();
// headers
{
Enumeration<String> headerNames = req.getHeaderNames();
disconnectData.headers = MapFactory.getConcurrentMap();// new ConcurrentHashMap<Collection.Key, LinkedList<String>>();

String k;
Enumeration<String> e;
while (headerNames.hasMoreElements()) {
k = headerNames.nextElement().toString();
e = req.getHeaders(k);
LinkedList<String> list = new LinkedList<String>();
while (e.hasMoreElements()) {
list.add(e.nextElement().toString());
}
if (!StringUtil.isEmpty(k)) disconnectData.headers.put(KeyImpl.init(k), list);
}
}

String k;
Enumeration<String> e;
while (headerNames.hasMoreElements()) {
k = headerNames.nextElement().toString();
e = req.getHeaders(k);
LinkedList<String> list = new LinkedList<String>();
while (e.hasMoreElements()) {
list.add(e.nextElement().toString());
// cookies
{
Cookie[] _cookies = req.getCookies();
if (!ArrayUtil.isEmpty(_cookies)) {
disconnectData.cookies = new Cookie[_cookies.length];
for (int i = 0; i < _cookies.length; i++)
disconnectData.cookies[i] = _cookies[i];
}
if (!StringUtil.isEmpty(k)) disconnectData.headers.put(KeyImpl.init(k), list);
else disconnectData.cookies = SerializableCookie.COOKIES0;
}
}

// cookies
{
Cookie[] _cookies = req.getCookies();
if (!ArrayUtil.isEmpty(_cookies)) {
disconnectData.cookies = new Cookie[_cookies.length];
for (int i = 0; i < _cookies.length; i++)
disconnectData.cookies[i] = _cookies[i];
disconnectData.authType = req.getAuthType();
disconnectData.method = req.getMethod();
disconnectData.pathTranslated = req.getPathTranslated();
disconnectData.remoteUser = req.getRemoteUser();
disconnectData.requestedSessionId = req.getRequestedSessionId();
disconnectData.requestedSessionIdFromCookie = req.isRequestedSessionIdFromCookie();
disconnectData.requestedSessionIdFromURL = req.isRequestedSessionIdFromURL();
disconnectData.secure = req.isSecure();
disconnectData.requestedSessionIdValid = req.isRequestedSessionIdValid();
disconnectData.characterEncoding = req.getCharacterEncoding();
disconnectData.contentLength = req.getContentLength();
disconnectData.contentType = req.getContentType();
disconnectData.serverPort = req.getServerPort();
disconnectData.serverName = req.getServerName();
disconnectData.scheme = req.getScheme();
disconnectData.remoteHost = req.getRemoteHost();
disconnectData.remoteAddr = req.getRemoteAddr();
disconnectData.protocol = req.getProtocol();
disconnectData.locale = req.getLocale();
// only store it when j2ee sessions are enabled
if (pc.getSessionType() == Config.SESSION_TYPE_JEE) disconnectData.session = req.getSession(true); // create if necessary

disconnectData.userPrincipal = req.getUserPrincipal();

if (bytes == null || file == null) {
storeEL();
}
else disconnectData.cookies = SerializableCookie.COOKIES0;
}

disconnectData.authType = req.getAuthType();
disconnectData.method = req.getMethod();
disconnectData.pathTranslated = req.getPathTranslated();
disconnectData.remoteUser = req.getRemoteUser();
disconnectData.requestedSessionId = req.getRequestedSessionId();
disconnectData.requestedSessionIdFromCookie = req.isRequestedSessionIdFromCookie();
disconnectData.requestedSessionIdFromURL = req.isRequestedSessionIdFromURL();
disconnectData.secure = req.isSecure();
disconnectData.requestedSessionIdValid = req.isRequestedSessionIdValid();
disconnectData.characterEncoding = req.getCharacterEncoding();
disconnectData.contentLength = req.getContentLength();
disconnectData.contentType = req.getContentType();
disconnectData.serverPort = req.getServerPort();
disconnectData.serverName = req.getServerName();
disconnectData.scheme = req.getScheme();
disconnectData.remoteHost = req.getRemoteHost();
disconnectData.remoteAddr = req.getRemoteAddr();
disconnectData.protocol = req.getProtocol();
disconnectData.locale = req.getLocale();
// only store it when j2ee sessions are enabled
if (pc.getSessionType() == Config.SESSION_TYPE_JEE) disconnectData.session = req.getSession(true); // create if necessary

disconnectData.userPrincipal = req.getUserPrincipal();

if (bytes == null || file == null) {
storeEL();
disconnected = true;
// req=null;
}
disconnected = true;
// req=null;
}

static class ArrayEnum<E> implements Enumeration<E> {
Expand Down
2 changes: 1 addition & 1 deletion loader/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<project default="core" basedir="." name="Lucee"
xmlns:resolver="antlib:org.apache.maven.resolver.ant">

<property name="version" value="6.2.0.263-SNAPSHOT"/>
<property name="version" value="6.2.0.264-SNAPSHOT"/>

<taskdef uri="antlib:org.apache.maven.resolver.ant" resource="org/apache/maven/resolver/ant/antlib.xml">
<classpath>
Expand Down
2 changes: 1 addition & 1 deletion loader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.lucee</groupId>
<artifactId>lucee</artifactId>
<version>6.2.0.263-SNAPSHOT</version>
<version>6.2.0.264-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Lucee Loader Build</name>
Expand Down

0 comments on commit fb06afd

Please sign in to comment.