diff --git a/elemental-api/elemental-expath-pkg-mgmt-api/pom.xml b/elemental-api/elemental-expath-pkg-mgmt-api/pom.xml
new file mode 100644
index 0000000000..6ba22b5814
--- /dev/null
+++ b/elemental-api/elemental-expath-pkg-mgmt-api/pom.xml
@@ -0,0 +1,171 @@
+
+
+
+ 4.0.0
+
+
+ xyz.elemental
+ elemental-api
+ 7.7.1-SNAPSHOT
+ ..
+
+
+ elemental-expath-pkg-mgmt-api
+
+ Elemental EXPath Package Management API
+ HTTP API for managing EXPath Packages in Elemental
+
+
+ scm:git:https://github.com/evolvedbinary/elemental.git
+ scm:git:https://github.com/evolvedbinary/elemental.git
+ scm:git:https://github.com/evolvedbinary/elemental.git
+ HEAD
+
+
+
+
+ jakarta.servlet
+ jakarta.servlet-api
+
+
+
+ xyz.elemental.fork.org.exist-db
+ exist-core
+ ${project.version}
+
+
+
+ xyz.elemental
+ elemental-media-type-api
+ ${project.version}
+
+
+
+ org.expath.packaging
+ pkg-java
+
+
+
+ org.apache.logging.log4j
+ log4j-api
+
+
+
+ com.evolvedbinary.thirdparty.xml-apis
+ xml-apis
+
+
+
+ junit
+ junit
+ test
+
+
+
+ org.apache.httpcomponents
+ fluent-hc
+ test
+
+
+
+ org.apache.httpcomponents
+ httpcore
+ test
+
+
+
+
+ org.eclipse.jetty
+ jetty-deploy
+ test
+
+
+ org.eclipse.jetty
+ jetty-jmx
+ test
+
+
+
+ org.xmlunit
+ xmlunit-core
+ test
+
+
+
+
+
+
+ src/test/resources
+ false
+
+
+ src/test/resources-filtered
+ true
+
+
+
+
+ com.mycila
+ license-maven-plugin
+
+
+
+ ${project.parent.relativePath}/../elemental-parent/FDB-backport-to-EDB-LGPL-21-ONLY-license.template.txt
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+
+ ${project.basedir}/../../exist-jetty-config/target/classes/org/exist/jetty
+ ${project.build.testOutputDirectory}/conf.xml
+ ${project.build.testOutputDirectory}/standalone-webapp
+ ${project.build.testOutputDirectory}/log4j2.xml
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/elemental-api/elemental-expath-pkg-mgmt-api/src/main/java/xyz/elemental/api/expath/pkg/mgmt/ExpathPkgMgmtServlet.java b/elemental-api/elemental-expath-pkg-mgmt-api/src/main/java/xyz/elemental/api/expath/pkg/mgmt/ExpathPkgMgmtServlet.java
new file mode 100644
index 0000000000..eaa8995fb9
--- /dev/null
+++ b/elemental-api/elemental-expath-pkg-mgmt-api/src/main/java/xyz/elemental/api/expath/pkg/mgmt/ExpathPkgMgmtServlet.java
@@ -0,0 +1,143 @@
+package xyz.elemental.api.expath.pkg.mgmt;
+
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.exist.EXistException;
+import org.exist.http.servlets.AbstractExistHttpServlet;
+import org.exist.repo.ExistRepository;
+import org.exist.security.Subject;
+import org.exist.storage.DBBroker;
+import org.exist.storage.txn.Txn;
+import org.exist.util.serializer.SAXSerializer;
+import org.exist.util.serializer.SerializerPool;
+import org.expath.pkg.repo.Packages;
+import org.expath.pkg.repo.Package;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
+import xyz.elemental.mediatype.MediaType;
+
+import javax.xml.transform.OutputKeys;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.util.Optional;
+import java.util.Properties;
+
+
+public class ExpathPkgMgmtServlet extends AbstractExistHttpServlet {
+
+ private final static Logger LOG = LogManager.getLogger(ExpathPkgMgmtServlet.class);
+
+ protected final static Properties defaultProperties = new Properties();
+
+ static {
+ defaultProperties.setProperty(OutputKeys.INDENT, "yes");
+ defaultProperties.setProperty(OutputKeys.MEDIA_TYPE, MediaType.APPLICATION_XML);
+ }
+
+ private static final String PKG_API_NS = "http://expath.org/ns/pkg-api";
+ private static final String PKG_NS = "http://expath.org/ns/pkg";
+ private static final String PKG_PREFIX = "pkg";
+
+ @Override
+ public Logger getLog() {
+ return LOG;
+ }
+
+ @Override
+ protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
+
+ // authenticate the user
+ final Subject user = authenticate(request, response);
+ if (user == null) {
+ // You now get a HTTP Authentication challenge if there is no user
+ return;
+ }
+ // process the request and a connection for this user
+ try (final DBBroker broker = getPool().get(Optional.of(user));
+ final Txn transaction = getPool().getTransactionManager().beginTransaction()) {
+
+ try {
+ final Optional repo = broker.getBrokerPool().getExpathRepo();
+
+ if (repo.isPresent()) {
+ writePackageList(response, getContainerEncoding(), repo.get());
+ } else {
+ throw new ServletException("expath repository not available");
+ }
+
+ transaction.commit();
+
+ } catch (final Throwable t) {
+ transaction.abort();
+ throw t;
+ }
+
+ } catch (final EXistException e) {
+ if (response.isCommitted()) {
+ throw new ServletException(e.getMessage(), e);
+ }
+ response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
+ } catch (final Throwable e) {
+ getLog().error(e.getMessage(), e);
+ throw new ServletException("An error occurred: " + e.getMessage(), e);
+ }
+ }
+
+ protected void writePackageList(final HttpServletResponse response, final String encoding,
+ final ExistRepository repo) throws IOException {
+
+ response.setContentType(MediaType.APPLICATION_XML + "; charset=" + encoding);
+
+ SAXSerializer serializer = null;
+
+ Writer writerToClose = null;
+ try {
+ final Writer writer = new OutputStreamWriter(response.getOutputStream(), encoding);
+ serializer = (SAXSerializer) SerializerPool.getInstance().borrowObject(SAXSerializer.class);
+
+ serializer.setOutput(writer, defaultProperties);
+
+ serializer.startDocument();
+ serializer.startPrefixMapping("", PKG_API_NS);
+ serializer.startPrefixMapping(PKG_PREFIX, PKG_NS);
+
+ final AttributesImpl attrs = new AttributesImpl();
+ attrs.addAttribute("", "spec", "spec", "CDATA", "1.0.0");
+
+ serializer.startElement(PKG_API_NS, "package-list", "package-list", attrs);
+
+ for (final Packages pkgs : repo.getParentRepo().listPackages()) {
+ final Package pkg = pkgs.latest();
+ attrs.clear();
+ attrs.addAttribute("", "name", "name", "CDATA", pkgs.name());
+ attrs.addAttribute("", "abbrev", "abbrev", "CDATA", pkg.getAbbrev());
+ attrs.addAttribute("", "version", "version", "CDATA", pkg.getVersion());
+ serializer.startElement(PKG_NS, "package", PKG_PREFIX + ":package", attrs);
+ serializer.endElement(PKG_NS, "package", PKG_PREFIX + ":package");
+ }
+
+ serializer.endElement(PKG_API_NS, "package-list", "package-list");
+
+ serializer.endDocument();
+
+ writer.flush();
+ writerToClose = writer;
+
+ } catch (final SAXException e) {
+ // should never happen
+ LOG.warn("Error while serializing package list: {}", e.getMessage(), e);
+ } finally {
+ if (serializer != null) {
+ SerializerPool.getInstance().returnObject(serializer);
+ }
+ if (writerToClose != null) {
+ writerToClose.close();
+ }
+ }
+ }
+
+}
diff --git a/elemental-api/elemental-expath-pkg-mgmt-api/src/test/java/xyz/elemental/api/expath/pkg/mgmt/ExpathPkgMgmtServletTest.java b/elemental-api/elemental-expath-pkg-mgmt-api/src/test/java/xyz/elemental/api/expath/pkg/mgmt/ExpathPkgMgmtServletTest.java
new file mode 100644
index 0000000000..650b7ae03d
--- /dev/null
+++ b/elemental-api/elemental-expath-pkg-mgmt-api/src/test/java/xyz/elemental/api/expath/pkg/mgmt/ExpathPkgMgmtServletTest.java
@@ -0,0 +1,64 @@
+package xyz.elemental.api.expath.pkg.mgmt;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
+import org.apache.http.client.fluent.Request;
+import org.exist.test.ExistWebServer;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.xmlunit.builder.DiffBuilder;
+import org.xmlunit.builder.Input;
+import org.xmlunit.diff.Diff;
+
+import javax.xml.transform.Source;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+public class ExpathPkgMgmtServletTest {
+
+ @ClassRule
+ public static final ExistWebServer existWebServer = new ExistWebServer(true, false, true, true);
+
+ private static String getPackageUri() {
+ return "http://localhost:" + existWebServer.getPort() + "/expath/package/";
+ }
+
+ @Test
+ public void packageQuery() throws IOException {
+ final HttpResponse response = Request.Get(getPackageUri())
+ .execute()
+ .returnResponse();
+ final int resultStatusCode = response.getStatusLine().getStatusCode();
+ assertEquals("Server returned response code: " + resultStatusCode, HttpStatus.SC_OK, resultStatusCode);
+ final String responseBody = readResponse(response.getEntity());
+
+ final Source expectedSource = Input.from("").build();
+ final Source actualSource = Input.from(responseBody).build();
+ final Diff diff = DiffBuilder.compare(expectedSource)
+ .withTest(actualSource)
+ .checkForSimilar()
+ .build();
+
+ assertFalse(diff.toString(), diff.hasDifferences());
+ }
+
+ private String readResponse(final HttpEntity response) throws IOException {
+ try (final InputStream is = response.getContent();
+ final BufferedReader reader = new BufferedReader(new InputStreamReader(is, UTF_8))) {
+ String line;
+ final StringBuilder out = new StringBuilder();
+ while ((line = reader.readLine()) != null) {
+ out.append(line);
+ out.append("\r\n");
+ }
+ return out.toString();
+ }
+ }
+}
\ No newline at end of file
diff --git a/elemental-api/elemental-expath-pkg-mgmt-api/src/test/resources-filtered/conf.xml b/elemental-api/elemental-expath-pkg-mgmt-api/src/test/resources-filtered/conf.xml
new file mode 100644
index 0000000000..8d57f08dfe
--- /dev/null
+++ b/elemental-api/elemental-expath-pkg-mgmt-api/src/test/resources-filtered/conf.xml
@@ -0,0 +1,160 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/elemental-api/elemental-expath-pkg-mgmt-api/src/test/resources/log4j2.xml b/elemental-api/elemental-expath-pkg-mgmt-api/src/test/resources/log4j2.xml
new file mode 100644
index 0000000000..f061d56ce8
--- /dev/null
+++ b/elemental-api/elemental-expath-pkg-mgmt-api/src/test/resources/log4j2.xml
@@ -0,0 +1,259 @@
+
+
+
+
+ ${log4j:configParentLocation}/../../target/test-logs-${date:yyyyMMddHHmmssSSS}
+ 10MB
+ 0 0 0 * * ?
+ 14
+ %d{yyyyMMddHHmmss}
+ %d{yyyy-MM-dd}
+ %d [%t] %-5p (%F [%M]:%L) - %m%n
+ %m%n
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/elemental-api/elemental-expath-pkg-mgmt-api/src/test/resources/standalone-webapp/WEB-INF/controller-config.xml b/elemental-api/elemental-expath-pkg-mgmt-api/src/test/resources/standalone-webapp/WEB-INF/controller-config.xml
new file mode 100644
index 0000000000..3c477d2246
--- /dev/null
+++ b/elemental-api/elemental-expath-pkg-mgmt-api/src/test/resources/standalone-webapp/WEB-INF/controller-config.xml
@@ -0,0 +1,34 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/elemental-api/elemental-expath-pkg-mgmt-api/src/test/resources/standalone-webapp/WEB-INF/web.xml b/elemental-api/elemental-expath-pkg-mgmt-api/src/test/resources/standalone-webapp/WEB-INF/web.xml
new file mode 100644
index 0000000000..eb0aa0e602
--- /dev/null
+++ b/elemental-api/elemental-expath-pkg-mgmt-api/src/test/resources/standalone-webapp/WEB-INF/web.xml
@@ -0,0 +1,109 @@
+
+
+
+
+ Elemental – NoSQL Database
+ Elemental
+
+
+ org.exist.xmlrpc.RpcServlet
+ org.exist.xmlrpc.RpcServlet
+
+ enabledForExtensions
+ true
+
+
+
+
+ EXistServlet
+ org.exist.http.servlets.EXistServlet
+
+ configuration
+ conf.xml
+
+
+ basedir
+ WEB-INF/
+
+
+ start
+ true
+
+ 2
+
+
+
+ XQueryURLRewrite
+ org.exist.http.urlrewrite.XQueryURLRewrite
+
+ config
+ WEB-INF/controller-config.xml
+
+
+
+
+ XSLTServlet
+ org.exist.http.servlets.XSLTServlet
+
+
+
+ ExpathPkgMgmtServlet
+ xyz.elemental.api.expath.pkg.mgmt.ExpathPkgMgmtServlet
+
+
+
+ XQueryURLRewrite
+ /*
+
+
diff --git a/elemental-api/pom.xml b/elemental-api/pom.xml
new file mode 100644
index 0000000000..5c6ca077f9
--- /dev/null
+++ b/elemental-api/pom.xml
@@ -0,0 +1,84 @@
+
+
+
+ 4.0.0
+
+
+ xyz.elemental
+ elemental-parent
+ 7.7.1-SNAPSHOT
+ ../elemental-parent
+
+
+
+ elemental-api
+ pom
+
+ Elemental APIs
+ APIs for Elemental
+
+
+ scm:git:https://github.com/evolvedbinary/elemental.git
+ scm:git:https://github.com/evolvedbinary/elemental.git
+ scm:git:https://github.com/evolvedbinary/elemental.git
+ HEAD
+
+
+
+ elemental-expath-pkg-mgmt-api
+
+
+
+
+
+ com.mycila
+ license-maven-plugin
+
+
+
+ ${project.parent.relativePath}/FDB-backport-to-EDB-LGPL-21-ONLY-license.template.txt
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/elemental-parent/pom.xml b/elemental-parent/pom.xml
index 0c3d3e2598..46f4b00a3a 100644
--- a/elemental-parent/pom.xml
+++ b/elemental-parent/pom.xml
@@ -106,6 +106,12 @@
4.0.6
2.0.17
9.9.1-8
+ 4.13.2
+ 4.5.14
+ 4.4.16
+ 11.0.26
+ 2.11.0
+ 2.26.1
1C
@@ -161,6 +167,74 @@
${slf4j.version}
+
+ jakarta.servlet
+ jakarta.servlet-api
+ 5.0.0
+
+
+
+ org.apache.httpcomponents
+ httpcore
+ ${apache.httpcomponents.core.version}
+
+
+
+ org.apache.httpcomponents
+ fluent-hc
+ ${apache.httpcomponents.version}
+
+
+
+ junit
+ junit
+ ${junit.version}
+
+
+
+
+ org.hamcrest
+ hamcrest-core
+
+
+
+
+
+ org.eclipse.jetty
+ jetty-deploy
+ ${jetty.version}
+
+
+
+ org.eclipse.jetty
+ jetty-jmx
+ ${jetty.version}
+
+
+
+ org.xmlunit
+ xmlunit-core
+ ${xmlunit.version}
+
+
+
+ org.expath.packaging
+ pkg-java
+ 2.0.1
+
+
+
+ org.apache.logging.log4j
+ log4j-api
+ ${log4j.version}
+
+
+
+ com.evolvedbinary.thirdparty.xml-apis
+ xml-apis
+ 1.4.02
+
+
jakarta.activation
jakarta.activation-api
diff --git a/exist-distribution/pom.xml b/exist-distribution/pom.xml
index 13dff82df5..78375fe749 100644
--- a/exist-distribution/pom.xml
+++ b/exist-distribution/pom.xml
@@ -81,6 +81,12 @@
+
+ xyz.elemental
+ elemental-expath-pkg-mgmt-api
+ ${project.version}
+ runtime
+
${project.groupId}
exist-core
diff --git a/exist-jetty-config/src/main/resources/standalone-webapp/WEB-INF/controller-config.xml b/exist-jetty-config/src/main/resources/standalone-webapp/WEB-INF/controller-config.xml
index 622b986ea5..7603883acf 100644
--- a/exist-jetty-config/src/main/resources/standalone-webapp/WEB-INF/controller-config.xml
+++ b/exist-jetty-config/src/main/resources/standalone-webapp/WEB-INF/controller-config.xml
@@ -19,6 +19,9 @@
+
+
+
+
+ ExpathPkgMgmtServlet
+ xyz.elemental.api.expath.pkg.mgmt.ExpathPkgMgmtServlet
+
+
+
+
+
diff --git a/exist-jetty-config/src/main/resources/webapp/WEB-INF/web.xml b/exist-jetty-config/src/main/resources/webapp/WEB-INF/web.xml
index 83d7303cba..13165d425f 100644
--- a/exist-jetty-config/src/main/resources/webapp/WEB-INF/web.xml
+++ b/exist-jetty-config/src/main/resources/webapp/WEB-INF/web.xml
@@ -270,6 +270,14 @@
org.exist.webstart.JnlpServlet
+
+
+ ExpathPkgMgmtServlet
+ xyz.elemental.api.expath.pkg.mgmt.ExpathPkgMgmtServlet
+
+
-
-
-
- org.hamcrest
- hamcrest-core
-
-
-
+
org.hamcrest
hamcrest
diff --git a/pom.xml b/pom.xml
index 6b7d1bb789..3fed2b11fe 100644
--- a/pom.xml
+++ b/pom.xml
@@ -46,6 +46,7 @@
elemental-parent
+ elemental-api
elemental-media-type
exist-parent
exist-ant