This is an automated email from the ASF dual-hosted git repository.
jamesnetherton pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/main by this push:
new 0708d893f2c Remove zstd-jni dependency from camel-quarkus-zipfile
0708d893f2c is described below
commit 0708d893f2c606fd6cc4fd0f5a089dbf6fa1b577
Author: James Netherton <[email protected]>
AuthorDate: Wed Nov 11 18:59:02 2026 +0000
Remove zstd-jni dependency from camel-quarkus-zipfile
zstd-jni is an optional dependency of commons-compress. It was only added
so that native compilation would succeed, since ZipArchiveInputStream
unconditionally references the zstd classes for ZSTD compressed entries.
Replace it with a GraalVM substitution that is active only when zstd-jni
is absent, making reads of ZSTD compressed entries fail with a clear
ZipException in native mode. Users who need ZSTD support in JVM mode can
add zstd-jni to their application.
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
.../ROOT/pages/reference/extensions/zipfile.adoc | 17 ++++++++
extensions/zipfile/runtime/pom.xml | 5 ++-
extensions/zipfile/runtime/src/main/doc/usage.adoc | 12 ++++++
.../graal/ZipArchiveInputStreamSubstitutions.java | 50 ++++++++++++++++++++++
.../component/zipfile/it/ZipFileResource.java | 40 +++++++++++++++++
.../component/compression/it/ZipFileTest.java | 11 +++++
6 files changed, 133 insertions(+), 2 deletions(-)
diff --git a/docs/modules/ROOT/pages/reference/extensions/zipfile.adoc
b/docs/modules/ROOT/pages/reference/extensions/zipfile.adoc
index ad8ddcc2af6..4736a739340 100644
--- a/docs/modules/ROOT/pages/reference/extensions/zipfile.adoc
+++ b/docs/modules/ROOT/pages/reference/extensions/zipfile.adoc
@@ -44,3 +44,20 @@ Or add the coordinates to your existing project:
ifeval::[{doc-show-user-guide-link} == true]
Check the xref:user-guide/index.adoc[User guide] for more information about
writing Camel Quarkus applications.
endif::[]
+
+[id="extensions-zipfile-usage"]
+== Usage
+[id="extensions-zipfile-usage-reading-zstd-compressed-zip-entries"]
+=== Reading ZSTD compressed ZIP entries
+
+Reading ZIP entries compressed with the ZSTD method requires the optional
`com.github.luben:zstd-jni` library.
+It is not added to the classpath by this extension, so you must add it to your
application yourself.
+
+[source,xml]
+----
+<dependency>
+ <groupId>com.github.luben</groupId>
+ <artifactId>zstd-jni</artifactId>
+</dependency>
+----
+
diff --git a/extensions/zipfile/runtime/pom.xml
b/extensions/zipfile/runtime/pom.xml
index 0559d185920..3b9b3e81556 100644
--- a/extensions/zipfile/runtime/pom.xml
+++ b/extensions/zipfile/runtime/pom.xml
@@ -45,8 +45,9 @@
<artifactId>camel-zipfile</artifactId>
</dependency>
<dependency>
- <groupId>com.github.luben</groupId>
- <artifactId>zstd-jni</artifactId>
+ <groupId>org.graalvm.sdk</groupId>
+ <artifactId>nativeimage</artifactId>
+ <scope>provided</scope>
</dependency>
</dependencies>
diff --git a/extensions/zipfile/runtime/src/main/doc/usage.adoc
b/extensions/zipfile/runtime/src/main/doc/usage.adoc
new file mode 100644
index 00000000000..c48f7c7e1c7
--- /dev/null
+++ b/extensions/zipfile/runtime/src/main/doc/usage.adoc
@@ -0,0 +1,12 @@
+=== Reading ZSTD compressed ZIP entries
+
+Reading ZIP entries compressed with the ZSTD method requires the optional
`com.github.luben:zstd-jni` library.
+It is not added to the classpath by this extension, so you must add it to your
application yourself.
+
+[source,xml]
+----
+<dependency>
+ <groupId>com.github.luben</groupId>
+ <artifactId>zstd-jni</artifactId>
+</dependency>
+----
diff --git
a/extensions/zipfile/runtime/src/main/java/org/apache/camel/quarkus/component/zipfile/graal/ZipArchiveInputStreamSubstitutions.java
b/extensions/zipfile/runtime/src/main/java/org/apache/camel/quarkus/component/zipfile/graal/ZipArchiveInputStreamSubstitutions.java
new file mode 100644
index 00000000000..a93bfa07c15
--- /dev/null
+++
b/extensions/zipfile/runtime/src/main/java/org/apache/camel/quarkus/component/zipfile/graal/ZipArchiveInputStreamSubstitutions.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.quarkus.component.zipfile.graal;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.function.BooleanSupplier;
+import java.util.zip.ZipException;
+
+import com.oracle.svm.core.annotate.Substitute;
+import com.oracle.svm.core.annotate.TargetClass;
+
+/**
+ * commons-compress unconditionally references the optional zstd-jni library
when reading ZSTD compressed ZIP entries.
+ * When zstd-jni is not on the classpath, fail reading such entries rather
than the native image build.
+ */
+@TargetClass(className =
"org.apache.commons.compress.archivers.zip.ZipArchiveInputStream", onlyWith =
ZstdJniIsAbsent.class)
+final class ZipArchiveInputStreamSubstitutions {
+ @Substitute
+ protected InputStream createZstdInputStream(InputStream in) throws
IOException {
+ throw new ZipException(
+ "Reading ZSTD compressed ZIP entries requires
com.github.luben:zstd-jni, which is not on the classpath");
+ }
+}
+
+final class ZstdJniIsAbsent implements BooleanSupplier {
+ @Override
+ public boolean getAsBoolean() {
+ try {
+
Thread.currentThread().getContextClassLoader().loadClass("com.github.luben.zstd.ZstdInputStream");
+ return false;
+ } catch (ClassNotFoundException e) {
+ return true;
+ }
+ }
+}
diff --git
a/integration-test-groups/compression/zipfile/src/main/java/org/apache/camel/quarkus/component/zipfile/it/ZipFileResource.java
b/integration-test-groups/compression/zipfile/src/main/java/org/apache/camel/quarkus/component/zipfile/it/ZipFileResource.java
index dfee3071f5b..9981529c98d 100644
---
a/integration-test-groups/compression/zipfile/src/main/java/org/apache/camel/quarkus/component/zipfile/it/ZipFileResource.java
+++
b/integration-test-groups/compression/zipfile/src/main/java/org/apache/camel/quarkus/component/zipfile/it/ZipFileResource.java
@@ -20,9 +20,12 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.net.URI;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.Arrays;
+import java.util.zip.CRC32;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
@@ -40,6 +43,7 @@ import org.apache.camel.CamelContext;
import org.apache.camel.Message;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.commons.compress.archivers.zip.ZipMethod;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -84,6 +88,42 @@ public class ZipFileResource {
.build();
}
+ @Path("/uncompress/zstd")
+ @GET
+ @Produces(MediaType.TEXT_PLAIN)
+ public String uncompressZstd() throws Exception {
+ byte[] content = "Hello ZSTD".getBytes(StandardCharsets.UTF_8);
+ CRC32 crc = new CRC32();
+ crc.update(content);
+
+ ZipEntry entry = new ZipEntry("zstd.txt");
+ entry.setMethod(ZipEntry.STORED);
+ entry.setSize(content.length);
+ entry.setCrc(crc.getValue());
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ try (ZipOutputStream zipOutputStream = new ZipOutputStream(baos)) {
+ zipOutputStream.putNextEntry(entry);
+ zipOutputStream.write(content);
+ zipOutputStream.closeEntry();
+ }
+
+ // Rewrite the local file header compression method to ZSTD
+ ByteBuffer zip =
ByteBuffer.wrap(baos.toByteArray()).order(ByteOrder.LITTLE_ENDIAN);
+ zip.putShort(8, (short) ZipMethod.ZSTD.getCode());
+
+ try {
+ producerTemplate.requestBody("direct:zipfile-uncompress",
zip.array(), byte[].class);
+ return "No exception thrown";
+ } catch (Throwable t) {
+ Throwable rootCause = t;
+ while (rootCause.getCause() != null) {
+ rootCause = rootCause.getCause();
+ }
+ return rootCause.getMessage();
+ }
+ }
+
@Path("/splitIteratorShouldSucceed")
@GET
public void splitIteratorShouldSucceed() throws Exception {
diff --git
a/integration-test-groups/compression/zipfile/src/test/java/org/apache/camel/quarkus/component/compression/it/ZipFileTest.java
b/integration-test-groups/compression/zipfile/src/test/java/org/apache/camel/quarkus/component/compression/it/ZipFileTest.java
index a4fca8078b4..518d1d7bf93 100644
---
a/integration-test-groups/compression/zipfile/src/test/java/org/apache/camel/quarkus/component/compression/it/ZipFileTest.java
+++
b/integration-test-groups/compression/zipfile/src/test/java/org/apache/camel/quarkus/component/compression/it/ZipFileTest.java
@@ -24,6 +24,8 @@ import io.restassured.http.ContentType;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
+import static org.hamcrest.Matchers.containsStringIgnoringCase;
+
@QuarkusTest
class ZipFileTest {
final byte[] UNCOMPRESSED = "Hello World Zip
File!".getBytes(StandardCharsets.UTF_8);
@@ -48,6 +50,15 @@ class ZipFileTest {
Assertions.assertArrayEquals(UNCOMPRESSED, uncompressed);
}
+ @Test
+ public void uncompressZstdEntryWithoutZstdJniShouldFail() {
+ RestAssured.given()
+ .get("/zipfile/uncompress/zstd")
+ .then()
+ .statusCode(200)
+ .body(containsStringIgnoringCase("zstd"));
+ }
+
@Test
public void splitIteratorShouldSucceed() {
RestAssured.given()