Skip to content

Commit de1147e

Browse files
authored
Merge pull request #6392 from duncdrum/dp-fix-jetty-cont
jetty fixes II
2 parents ff7e385 + 2239330 commit de1147e

35 files changed

Lines changed: 1410 additions & 356 deletions

File tree

exist-core/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,7 @@ The BaseX Team. The original license statement is also included below.]]></pream
12031203
<jetty.home>${project.basedir}/../exist-jetty-config/target/classes/org/exist/jetty</jetty.home>
12041204
<exist.configurationFile>${project.build.testOutputDirectory}/conf.xml</exist.configurationFile>
12051205
<exist.jetty.standalone.webapp.dir>${project.build.testOutputDirectory}/standalone-webapp</exist.jetty.standalone.webapp.dir>
1206+
<exist.jetty.portal.dir>${project.basedir}/../exist-jetty-config/src/main/resources/org/exist/jetty/etc/webapps/portal</exist.jetty.portal.dir>
12061207
<log4j.configurationFile>${project.build.testOutputDirectory}/log4j2.xml</log4j.configurationFile>
12071208
</systemPropertyVariables>
12081209

@@ -1229,6 +1230,7 @@ The BaseX Team. The original license statement is also included below.]]></pream
12291230
<jetty.home>${project.basedir}/../exist-jetty-config/target/classes/org/exist/jetty</jetty.home>
12301231
<exist.configurationFile>${project.build.testOutputDirectory}/conf.xml</exist.configurationFile>
12311232
<exist.jetty.standalone.webapp.dir>${project.build.testOutputDirectory}/standalone-webapp</exist.jetty.standalone.webapp.dir>
1233+
<exist.jetty.portal.dir>${project.basedir}/../exist-jetty-config/src/main/resources/org/exist/jetty/etc/webapps/portal</exist.jetty.portal.dir>
12321234
<log4j.configurationFile>${project.build.testOutputDirectory}/log4j2.xml</log4j.configurationFile>
12331235
</systemPropertyVariables>
12341236
</configuration>

exist-core/src/main/java/org/exist/http/servlets/HttpResponseWrapper.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,25 @@ public void addCookie(final String name, final String value, final int maxAge, b
7878
final Cookie cookie = new Cookie(name, encode(value));
7979
cookie.setMaxAge(maxAge);
8080
cookie.setSecure( secure );
81-
if (domain != null) {
81+
if (domain != null && !domain.isEmpty()) {
8282
cookie.setDomain(domain);
8383
}
84-
if (path != null) {
84+
setCookiePath(cookie, path);
85+
response.addCookie(cookie);
86+
}
87+
88+
/**
89+
* Apply a cookie path only when it is a non-empty string.
90+
* <p>
91+
* Standalone Jetty deployments use a root context ({@code getContextPath()} returns {@code ""}).
92+
* Passing that empty string as an explicit Path makes many HTTP clients (including Apache HttpClient
93+
* used in integration tests) reject the cookie entirely. Omitting Path lets the container apply
94+
* the RFC 6265 default for the request URI.
95+
*/
96+
private static void setCookiePath(final Cookie cookie, final String path) {
97+
if (path != null && !path.isEmpty()) {
8598
cookie.setPath(path);
8699
}
87-
response.addCookie(cookie);
88100
}
89101

90102
@Override

exist-core/src/main/java/org/exist/indexing/IndexController.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@
4040
import org.w3c.dom.NodeList;
4141

4242
import java.util.ArrayList;
43+
import java.util.Comparator;
4344
import java.util.HashMap;
45+
import java.util.LinkedHashMap;
4446
import java.util.List;
4547
import java.util.Map;
4648
import org.exist.security.PermissionDeniedException;
@@ -56,7 +58,14 @@ public enum CollectionIndexRemovalMode {
5658
CONFIG_ONLY_REINDEX
5759
}
5860

59-
private final Map<String, IndexWorker> indexWorkers = new HashMap<>();
61+
/**
62+
* Stable iteration order for listener chains and {@link #flush()}.
63+
*/
64+
private static final Comparator<IndexWorker> INDEX_WORKER_ORDER = Comparator
65+
.comparingInt(IndexWorker::getChainPriority)
66+
.thenComparing(IndexWorker::getIndexId);
67+
68+
private final Map<String, IndexWorker> indexWorkers = new LinkedHashMap<>();
6069

6170
private final DBBroker broker;
6271
private StreamListener listener = null;
@@ -68,9 +77,9 @@ public enum CollectionIndexRemovalMode {
6877
public IndexController(final DBBroker broker) {
6978
this.broker = broker;
7079
final List<IndexWorker> workers = broker.getBrokerPool().getIndexManager().getWorkers(broker);
71-
for (final IndexWorker worker : workers) {
72-
indexWorkers.put(worker.getIndexId(), worker);
73-
}
80+
workers.stream()
81+
.sorted(INDEX_WORKER_ORDER)
82+
.forEach(worker -> indexWorkers.put(worker.getIndexId(), worker));
7483
}
7584

7685
/**

exist-core/src/main/java/org/exist/indexing/IndexWorker.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,24 @@ public interface IndexWorker {
5353
*/
5454
public static final String VALUE_COUNT = "value_count";
5555

56+
/**
57+
* Lower values run earlier in {@link IndexController} listener chains and {@link #flush()}.
58+
* Gaps reserve room for future workers: {@code 0} structural, {@code 1–99} pre-statistics,
59+
* {@code 100–999} pre-Lucene, {@code 1000+} Lucene and later; unranked workers use
60+
* {@link Integer#MAX_VALUE}.
61+
*/
62+
int CHAIN_PRIORITY_STRUCTURAL = 0;
63+
int CHAIN_PRIORITY_STATISTICS = 100;
64+
int CHAIN_PRIORITY_LUCENE = 1000;
65+
66+
/**
67+
* Chain-order priority for {@link IndexController}. Default {@link Integer#MAX_VALUE} preserves
68+
* legacy ordering among workers that do not override.
69+
*/
70+
default int getChainPriority() {
71+
return Integer.MAX_VALUE;
72+
}
73+
5674
/**
5775
* Returns an ID which uniquely identifies this worker's index.
5876
* @return a unique name identifying this worker's index.

0 commit comments

Comments
 (0)