From eb2e18299fabd81c9e60dc45ab5f7df5305d3154 Mon Sep 17 00:00:00 2001 From: Rainer Prosi Date: Wed, 1 Oct 2025 14:56:31 +0200 Subject: [PATCH 1/3] gradle + test updates --- build.gradle | 5 +++-- gradle/wrapper/gradle-wrapper.properties | 2 +- .../org/cip4/jdfutility/server/JettyServerTest.java | 1 + .../jdfutility/server/MyResourceHandlerTest.java | 12 ++++++++---- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index af83ba4..4fea1f3 100644 --- a/build.gradle +++ b/build.gradle @@ -138,8 +138,9 @@ implementation 'org.apache.commons:commons-fileupload2-jakarta-servlet6:2.+' implementation 'org.apache.logging.log4j:log4j-core:2.24.1' implementation 'org.apache.logging.log4j:log4j-jcl:2.24.3' - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.11.4' - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.11.4' + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.13.4' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.13.4' +testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.13.4' testImplementation 'org.springframework:spring-test:6.2.+' testImplementation 'org.springframework:spring-web:6.2.+' testImplementation 'org.mockito:mockito-core:5.17.0' diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index f42e62f..8357d84 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/test/java/org/cip4/jdfutility/server/JettyServerTest.java b/src/test/java/org/cip4/jdfutility/server/JettyServerTest.java index c8b1f11..5a38bfa 100644 --- a/src/test/java/org/cip4/jdfutility/server/JettyServerTest.java +++ b/src/test/java/org/cip4/jdfutility/server/JettyServerTest.java @@ -64,6 +64,7 @@ public synchronized void testStart() ns.setPort(getPort()); // ns.setSSLPort(443); assertTrue(ns.tryStart()); + assertNotNull(ns.getJettyServer()); ns.stop(); } diff --git a/src/test/java/org/cip4/jdfutility/server/MyResourceHandlerTest.java b/src/test/java/org/cip4/jdfutility/server/MyResourceHandlerTest.java index daafad6..95d6772 100644 --- a/src/test/java/org/cip4/jdfutility/server/MyResourceHandlerTest.java +++ b/src/test/java/org/cip4/jdfutility/server/MyResourceHandlerTest.java @@ -57,17 +57,21 @@ void testConstruct() { final MyResourceHandler h = new MyResourceHandler("abc", sm_dirTestData); assertNotNull(h); + assertNotNull(h.toString()); } @Test public void testResHandler() throws Exception { - final MyResourceHandler rh = new MyResourceHandler("foo", "dummy"); + final MyResourceHandler rh = new MyResourceHandler("foo", "http://localhost/dummy"); assertEquals("http://localhost/nix", rh.update("http://localhost/nix")); + assertEquals("http://localhost/nix", rh.update("http://localhost/foo/nix")); + assertEquals("http://localhost/dummy", rh.update("http://localhost/foo")); + assertEquals("http://localhost/dummy", rh.update("http://localhost/foo/")); assertEquals("http://localhost/bar/nix", rh.update("http://localhost/bar/foo/nix")); - assertEquals("dummy", rh.update("")); - assertEquals("dummy", rh.update("/")); - assertEquals("dummy", rh.update("http://localhost")); + assertEquals("http://localhost/dummy", rh.update("")); + assertEquals("http://localhost/dummy", rh.update("/")); + assertEquals("http://localhost/dummy", rh.update("http://localhost")); } @Test From 21c3ed01f1d9b93e3c27e3821931785d1a2c0f39 Mon Sep 17 00:00:00 2001 From: Rainer Prosi Date: Wed, 1 Oct 2025 15:01:24 +0200 Subject: [PATCH 2/3] update foe commons-lang3 + gradle 8 --- .../org/cip4/jdfutility/CheckJDFServlet.java | 1 + .../org/cip4/jdfutility/FileItemList.java | 27 ++++++++++++++++--- .../org/cip4/jdfutility/GetFileServlet.java | 27 +++++++++---------- .../cip4/jdfutility/server/JettyServer.java | 10 ++++++- .../jdfutility/server/MyResourceHandler.java | 25 ++++++++++------- .../org/cip4/jdfutility/FileItemListTest.java | 16 ++++++++--- 6 files changed, 76 insertions(+), 30 deletions(-) diff --git a/src/main/java/org/cip4/jdfutility/CheckJDFServlet.java b/src/main/java/org/cip4/jdfutility/CheckJDFServlet.java index 266b95b..dee080c 100755 --- a/src/main/java/org/cip4/jdfutility/CheckJDFServlet.java +++ b/src/main/java/org/cip4/jdfutility/CheckJDFServlet.java @@ -91,6 +91,7 @@ public CheckJDFServlet() { super(); extractResources(); + FileItemList.setTracker(null); } void extractResources() diff --git a/src/main/java/org/cip4/jdfutility/FileItemList.java b/src/main/java/org/cip4/jdfutility/FileItemList.java index 816e366..6a2eff3 100644 --- a/src/main/java/org/cip4/jdfutility/FileItemList.java +++ b/src/main/java/org/cip4/jdfutility/FileItemList.java @@ -82,6 +82,7 @@ import org.apache.commons.fileupload2.core.DiskFileItemFactory.Builder; import org.apache.commons.fileupload2.core.FileUploadException; import org.apache.commons.fileupload2.jakarta.servlet6.JakartaServletFileUpload; +import org.apache.commons.io.FileCleaningTracker; import org.cip4.jdflib.datatypes.JDFAttributeMap; import org.cip4.jdflib.util.ContainerUtil; import org.cip4.jdflib.util.StreamUtil; @@ -102,6 +103,18 @@ public class FileItemList private final JDFAttributeMap mapCache; private final JDFAttributeMap reqParameters; + private static FileCleaningTracker tracker = null; + + public static FileCleaningTracker getTracker() + { + return tracker; + } + + public static void setTracker(final FileCleaningTracker tracker) + { + FileItemList.tracker = tracker; + } + /** * returns a pure in memory FileItemList * @@ -202,6 +215,7 @@ DiskFileItemFactory getFactory(final boolean inMemory, final long filesize) if (inMemory) { b.setBufferSize((int) filesize); + b.setFileCleaningTracker(tracker); } return b.get(); } @@ -219,10 +233,17 @@ public JDFAttributeMap getFieldsFromForm() final List fileList = getFileList(false, true); for (final DiskFileItem fi : fileList) { - final String itemString = StringUtil.getNonEmpty(fi.getString()); - if (itemString != null) + try + { + final String itemString = StringUtil.getNonEmpty(fi.getString()); + if (itemString != null) + { + mapCache.put(fi.getFieldName(), itemString); + } + } + catch (final Exception e) { - mapCache.put(fi.getFieldName(), itemString); + // nop } } diff --git a/src/main/java/org/cip4/jdfutility/GetFileServlet.java b/src/main/java/org/cip4/jdfutility/GetFileServlet.java index 2dd2260..f2ecacc 100755 --- a/src/main/java/org/cip4/jdfutility/GetFileServlet.java +++ b/src/main/java/org/cip4/jdfutility/GetFileServlet.java @@ -43,18 +43,18 @@ import java.nio.file.InvalidPathException; import java.nio.file.Path; +import org.apache.commons.lang3.StringEscapeUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.cip4.jdflib.util.StreamUtil; +import org.cip4.jdflib.util.UrlUtil; + import jakarta.servlet.ServletConfig; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; -import org.apache.commons.lang.StringEscapeUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.cip4.jdflib.util.StreamUtil; -import org.cip4.jdflib.util.UrlUtil; - /** * @author rainer */ @@ -128,16 +128,15 @@ void processRequest(final HttpServletRequest request, final HttpServletResponse final OutputStream os = response.getOutputStream(); final String localName = request.getPathInfo(); Path localPath = null; - try { + try + { localPath = baseDir.toPath().resolve(localName).normalize(); - } catch (InvalidPathException ignored) { + } + catch (final InvalidPathException ignored) + { } - if ( - localPath != null - && localPath.startsWith(baseDir.toPath().normalize()) - && Files.exists(localPath) - ) + if (localPath != null && localPath.startsWith(baseDir.toPath().normalize()) && Files.exists(localPath)) { response.setContentType(UrlUtil.getMimeTypeFromURL(localName)); Files.copy(localPath, os); @@ -147,7 +146,7 @@ void processRequest(final HttpServletRequest request, final HttpServletResponse response.setContentType(UrlUtil.TEXT_HTML); response.setStatus(404); os.write("

Error


Cannot find file: ".getBytes()); - os.write(StringEscapeUtils.escapeHtml(localName).getBytes()); + os.write(StringEscapeUtils.escapeHtml3(localName).getBytes()); os.write("".getBytes()); } StreamUtil.close(os); diff --git a/src/main/java/org/cip4/jdfutility/server/JettyServer.java b/src/main/java/org/cip4/jdfutility/server/JettyServer.java index e2f48ae..6c1dab1 100644 --- a/src/main/java/org/cip4/jdfutility/server/JettyServer.java +++ b/src/main/java/org/cip4/jdfutility/server/JettyServer.java @@ -44,7 +44,7 @@ import java.security.KeyStoreException; import java.util.List; -import org.apache.commons.lang.SystemUtils; +import org.apache.commons.lang3.SystemUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.cip4.jdflib.util.FileUtil; @@ -659,6 +659,14 @@ public static JettyServer getServer() return theServer; } + /** + * @return + */ + public Server getJettyServer() + { + return server; + } + /** * */ diff --git a/src/main/java/org/cip4/jdfutility/server/MyResourceHandler.java b/src/main/java/org/cip4/jdfutility/server/MyResourceHandler.java index 2ca285c..24e81d7 100644 --- a/src/main/java/org/cip4/jdfutility/server/MyResourceHandler.java +++ b/src/main/java/org/cip4/jdfutility/server/MyResourceHandler.java @@ -39,6 +39,7 @@ import java.util.HashSet; +import org.cip4.jdflib.core.JDFConstants; import org.cip4.jdflib.util.StringUtil; import org.eclipse.jetty.http.HttpURI; import org.eclipse.jetty.server.Request; @@ -61,38 +62,44 @@ public class MyResourceHandler extends ResourceHandler public MyResourceHandler(final String strip, final String home) { super(); - this.strip = strip == null ? null : StringUtil.token(StringUtil.getNonEmpty(strip.toLowerCase()), 0, "/"); + this.strip = strip == null ? null : StringUtil.token(StringUtil.getNonEmpty(strip.toLowerCase()), 0, JDFConstants.SLASH); this.home = home; whiteList = new HashSet<>(); } private final String strip; - String update(String url) + String update(final String url) { final String urlLow = url == null ? null : url.toLowerCase(); - int pos = StringUtil.posOfToken(urlLow, strip, "/", 0); + String urlOut = url; + int pos = StringUtil.posOfToken(urlLow, strip, JDFConstants.SLASH, 0); if (pos >= 0) { pos = urlLow.indexOf(strip); - url = url.substring(0, pos) + url.substring(pos + StringUtil.length(strip) + 1); + urlOut = url.substring(0, pos); + final int endPos = pos + strip.length() + 1; + if (endPos < urlLow.length()) + { + urlOut += url.substring(endPos); + } } - if (StringUtil.isEmpty(url) || "/".equals(url) || StringUtil.token(url, 2, "/") == null) + if (StringUtil.isEmpty(urlOut) || JDFConstants.SLASH.equals(urlOut) || StringUtil.token(urlOut, 2, JDFConstants.SLASH) == null) { return home; } else if (!whiteList.isEmpty()) { - final String base = StringUtil.token(url, 0, "/"); - final String base2 = StringUtil.token(url, 2, "/"); // http://host:port/root + final String base = StringUtil.token(urlOut, 0, JDFConstants.SLASH); + final String base2 = StringUtil.token(urlOut, 2, JDFConstants.SLASH); // http://host:port/root if (!whiteList.contains(base.toLowerCase()) && (base2 == null || !whiteList.contains(base2.toLowerCase()))) { return null; } } - return url; + return urlOut; } /** @@ -108,7 +115,7 @@ public void addBase(final String base) @Override public String toString() { - return "MyResourceHandler [strip=" + strip + ", getResourceBase()=" + getBaseResource(); + return "MyResourceHandler [strip=" + strip + ", base=" + getBaseResource(); } @Override diff --git a/src/test/java/org/cip4/jdfutility/FileItemListTest.java b/src/test/java/org/cip4/jdfutility/FileItemListTest.java index 39f7ebd..6bd91c9 100644 --- a/src/test/java/org/cip4/jdfutility/FileItemListTest.java +++ b/src/test/java/org/cip4/jdfutility/FileItemListTest.java @@ -85,13 +85,14 @@ import java.util.HashMap; import java.util.Map; +import org.apache.commons.io.FileCleaningTracker; +import org.cip4.jdflib.util.ContainerUtil; +import org.junit.jupiter.api.Test; + import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.Part; -import org.cip4.jdflib.util.ContainerUtil; -import org.junit.jupiter.api.Test; - class FileItemListTest extends JDFUtilityTestBase { @@ -171,4 +172,13 @@ void testGetFactory() throws Exception l.getFactory(true, 99999); } + @Test + void testGetTracker() throws Exception + { + final FileCleaningTracker tracker = new FileCleaningTracker(); + FileItemList.setTracker(tracker); + assertEquals(tracker, FileItemList.getTracker()); + assertEquals(tracker, new FileItemList(getRequestMock(), 42).getFactory(true, 42).getFileCleaningTracker()); + } + } From 44cac8c0d6a1e9614ecb15ad73f2bef92ff80935 Mon Sep 17 00:00:00 2001 From: Rainer Prosi Date: Wed, 1 Oct 2025 15:47:41 +0200 Subject: [PATCH 3/3] gradle stuff --- build.gradle | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/build.gradle b/build.gradle index 4fea1f3..3d5af2e 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { id 'java-library' id 'maven-publish' id 'signing' - id 'io.codearte.nexus-staging' version '0.30.0' + id 'io.github.gradle-nexus.publish-plugin' version '2.0.0' id 'jacoco' } @@ -70,8 +70,9 @@ publishing { } repositories { maven { - def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2" - def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots" + name = "sonatype" + def releasesRepoUrl = "https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2/" + def snapshotsRepoUrl = "https://central.sonatype.com/repository/maven-snapshots/" url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl credentials { @@ -82,13 +83,17 @@ publishing { } } -nexusStaging { - packageGroup = 'org.cip4' - stagingProfileId = '105e2b532689c6' - numberOfRetries = 400 - delayBetweenRetriesInMillis = 2500 - username ossrhUsername - password ossrhPassword +nexusPublishing { + repositories { + sonatype { + nexusUrl.set(uri("https://ossrh-staging-api.central.sonatype.com/service/local/")) + snapshotRepositoryUrl.set(uri("https://central.sonatype.com/repository/maven-snapshots/")) + username = ossrhUsername + password = ossrhPassword + stagingProfileId = '105e2b532689c6' // This can often be omitted if your packageGroup is unique + packageGroup = 'org.cip4' + } + } } repositories { @@ -123,7 +128,7 @@ processResources { } dependencies { - implementation('org.cip4.lib.jdf:JDFLibJ:2.+') { + implementation('org.cip4.lib.jdf:JDFLibJ:2.2.8.+') { exclude group: 'xml-apis' } @@ -164,6 +169,7 @@ test { jar { manifest { attributes( + "Implementation-Build-Date": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), "Implementation-Title": project.description, "Implementation-Version": project.version, "Implementation-Vendor-Id": project.group,