This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new e114fee0fc1 CAMEL-19344: camel-jbang - Upload/delete files in
--source-dir via http
e114fee0fc1 is described below
commit e114fee0fc182915715e09bdb1e22b0ed8efe9ee
Author: Claus Ibsen <[email protected]>
AuthorDate: Sun May 14 09:55:38 2023 +0200
CAMEL-19344: camel-jbang - Upload/delete files in --source-dir via http
---
.../modules/ROOT/pages/camel-jbang.adoc | 21 ++++++++++++++++
.../apache/camel/main/http/VertxHttpServer.java | 28 ++++++++++++++++++----
2 files changed, 45 insertions(+), 4 deletions(-)
diff --git a/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
b/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
index 3b85ad1c21e..a02eb08156e 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
@@ -322,6 +322,27 @@ For example from a CURL `--ascii-trace`:
== Info: Connection #0 to host 0.0.0.0 left intact
----
+To delete one or more files you use the DELETE verb, such as:
+
+[source,bash]
+----
+curl -X DELETE http://0.0.0.0:8080/q/upload/bar.java
+----
+
+You can also use wildcards ('*') to delete all .java files:
+
+[source,bash]
+----
+curl -X DELETE http://0.0.0.0:8080/q/upload/*.java
+----
+
+Or to delete everything
+
+[source,bash]
+----
+curl -X DELETE http://0.0.0.0:8080/q/upload/*
+----
+
=== Developer Console
You can enable the developer console, which presents a variety of information
to the developer.
diff --git
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/http/VertxHttpServer.java
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/http/VertxHttpServer.java
index 0439cf6b12f..e53e7520f60 100644
---
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/http/VertxHttpServer.java
+++
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/http/VertxHttpServer.java
@@ -55,6 +55,7 @@ import org.apache.camel.health.HealthCheckRegistry;
import org.apache.camel.main.util.CamelJBangSettingsHelper;
import org.apache.camel.spi.CamelEvent;
import org.apache.camel.support.SimpleEventNotifierSupport;
+import org.apache.camel.util.AntPathMatcher;
import org.apache.camel.util.FileUtil;
import org.apache.camel.util.IOHelper;
import org.apache.camel.util.ObjectHelper;
@@ -495,10 +496,29 @@ public final class VertxHttpServer {
int status = 200;
boolean delete = HttpMethod.DELETE == ctx.request().method();
if (delete) {
- LOG.info("Deleting file: {}/{}", dir, name);
- File f = new File(dir, name);
- if (f.exists() && f.isFile()) {
- FileUtil.deleteFile(f);
+ if (name.contains("*")) {
+ if (name.equals("*")) {
+ name = "**";
+ }
+ AntPathMatcher match = AntPathMatcher.INSTANCE;
+ File[] files = new File(dir).listFiles();
+ if (files != null) {
+ for (File f : files) {
+ if (f.getName().startsWith(".") ||
f.isHidden()) {
+ continue;
+ }
+ if (match.match(name, f.getName())) {
+ LOG.info("Deleting file: {}/{}", dir,
name);
+ FileUtil.deleteFile(f);
+ }
+ }
+ }
+ } else {
+ File f = new File(dir, name);
+ if (f.exists() && f.isFile()) {
+ LOG.info("Deleting file: {}/{}", dir, name);
+ FileUtil.deleteFile(f);
+ }
}
} else {
File f = new File(dir, name);