This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-3.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-3.x by this push:
new 8bc150af413 camel-jbang - Fix tracer for 3.x with latest changes from
main
8bc150af413 is described below
commit 8bc150af41344832f29c226d5fe3b817eb1de887
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Mar 22 09:41:15 2023 +0100
camel-jbang - Fix tracer for 3.x with latest changes from main
---
.../main/java/org/apache/camel/util/IOHelper.java | 13 +++++++++++
.../camel/cli/connector/LocalCliConnector.java | 26 +++++++++++++---------
2 files changed, 29 insertions(+), 10 deletions(-)
diff --git a/core/camel-util/src/main/java/org/apache/camel/util/IOHelper.java
b/core/camel-util/src/main/java/org/apache/camel/util/IOHelper.java
index b6d9b8f9e6d..ba1cfffcb9a 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/IOHelper.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/IOHelper.java
@@ -472,6 +472,19 @@ public final class IOHelper {
}
}
+ /**
+ * Appends the text to the file.
+ */
+ public static void appendText(String text, File file) throws IOException {
+ if (!file.exists()) {
+ String path = FileUtil.onlyPath(file.getPath());
+ if (path != null) {
+ new File(path).mkdirs();
+ }
+ }
+ writeText(text, new FileOutputStream(file, true));
+ }
+
/**
* Writes the text to the file.
*/
diff --git
a/dsl/camel-cli-connector/src/main/java/org/apache/camel/cli/connector/LocalCliConnector.java
b/dsl/camel-cli-connector/src/main/java/org/apache/camel/cli/connector/LocalCliConnector.java
index 75c19f72ad0..6d7dab139fc 100644
---
a/dsl/camel-cli-connector/src/main/java/org/apache/camel/cli/connector/LocalCliConnector.java
+++
b/dsl/camel-cli-connector/src/main/java/org/apache/camel/cli/connector/LocalCliConnector.java
@@ -53,6 +53,7 @@ import org.apache.camel.support.service.ServiceSupport;
import org.apache.camel.util.FileUtil;
import org.apache.camel.util.IOHelper;
import org.apache.camel.util.concurrent.ThreadHelper;
+import org.apache.camel.util.json.JsonArray;
import org.apache.camel.util.json.JsonObject;
import org.apache.camel.util.json.Jsoner;
import org.slf4j.Logger;
@@ -79,6 +80,7 @@ public class LocalCliConnector extends ServiceSupport
implements CliConnector, C
private File actionFile;
private File outputFile;
private File traceFile;
+ private long traceFilePos; // keep track of trace offset
public LocalCliConnector(CliConnectorFactory cliConnectorFactory) {
this.cliConnectorFactory = cliConnectorFactory;
@@ -288,13 +290,6 @@ public class LocalCliConnector extends ServiceSupport
implements CliConnector, C
LOG.trace("Updating output file: {}", outputFile);
IOHelper.writeText(json.toJson(), outputFile);
}
- } else if ("trace".equals(action)) {
- DevConsole dc =
camelContext.getExtension(DevConsoleRegistry.class).resolveById("trace");
- if (dc != null) {
- JsonObject json = (JsonObject)
dc.call(DevConsole.MediaType.JSON);
- LOG.trace("Updating trace file: {}", traceFile);
- IOHelper.writeText(json.toJson(), traceFile);
- }
}
// action done so delete file
@@ -430,10 +425,21 @@ public class LocalCliConnector extends ServiceSupport
implements CliConnector, C
DevConsole dc12 = dcr.resolveById("trace");
if (dc12 != null) {
JsonObject json = (JsonObject)
dc12.call(DevConsole.MediaType.JSON);
- if (json != null && !json.isEmpty()) {
- // special for trace messages which is stored in its
own file
+ JsonArray arr = json.getCollection("traces");
+ // filter based on last uid
+ if (traceFilePos > 0) {
+ arr.removeIf(r -> {
+ JsonObject jo = (JsonObject) r;
+ return jo.getLong("uid") <= traceFilePos;
+ });
+ }
+ if (arr != null && !arr.isEmpty()) {
+ // store traces in a special file
LOG.trace("Updating trace file: {}", traceFile);
- IOHelper.writeText(json.toJson(), traceFile);
+ String data = json.toJson() + System.lineSeparator();
+ IOHelper.appendText(data, traceFile);
+ json = arr.getMap(arr.size() - 1);
+ traceFilePos = json.getLong("uid");
}
}
}