This is an automated email from the ASF dual-hosted git repository.

nfilotto pushed a commit to branch CAMEL-17792/doc-message-headers
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 630251fea4dece1426b7628ef377b998e1ba0d28
Author: Nicolas Filotto <[email protected]>
AuthorDate: Mon Mar 21 14:43:52 2022 +0100

    CAMEL-17792: Add doc about the message headers of camel-file-watch
---
 .../camel/component/file/watch/file-watch.json     | 12 +++++
 .../src/main/docs/file-watch-component.adoc        | 42 ++-------------
 .../component/file/watch/FileWatchComponent.java   |  1 -
 .../component/file/watch/FileWatchConstants.java   | 60 ++++++++++++++++++++++
 .../component/file/watch/FileWatchConsumer.java    | 21 ++++----
 .../component/file/watch/FileWatchEndpoint.java    |  2 +-
 .../file/watch/FileWatchComponentTest.java         |  2 +-
 .../file/watch/FileWatchComponentTestBase.java     |  2 +-
 8 files changed, 89 insertions(+), 53 deletions(-)

diff --git 
a/components/camel-file-watch/src/generated/resources/org/apache/camel/component/file/watch/file-watch.json
 
b/components/camel-file-watch/src/generated/resources/org/apache/camel/component/file/watch/file-watch.json
index 321974f..8577608 100644
--- 
a/components/camel-file-watch/src/generated/resources/org/apache/camel/component/file/watch/file-watch.json
+++ 
b/components/camel-file-watch/src/generated/resources/org/apache/camel/component/file/watch/file-watch.json
@@ -30,6 +30,18 @@
     "useFileHashing": { "kind": "property", "displayName": "Use File Hashing", 
"group": "consumer", "label": "consumer", "required": false, "type": "boolean", 
"javaType": "boolean", "deprecated": false, "autowired": false, "secret": 
false, "defaultValue": true, "description": "Enables or disables file hashing 
to detect duplicate events. If you disable this, you can get some events 
multiple times on some platforms and JDKs. Check java.nio.file.WatchService 
limitations for your target plat [...]
     "autowiredEnabled": { "kind": "property", "displayName": "Autowired 
Enabled", "group": "advanced", "label": "advanced", "required": false, "type": 
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false, 
"secret": false, "defaultValue": true, "description": "Whether autowiring is 
enabled. This is used for automatic autowiring options (the option must be 
marked as autowired) by looking up in the registry to find if there is a single 
instance of matching type, which t [...]
   },
+  "headers": {
+    "CamelFileEventType": { "kind": "header", "displayName": "", "group": 
"consumer", "label": "", "required": false, "javaType": "String", "deprecated": 
false, "deprecationNote": "", "autowired": false, "secret": false, 
"description": "Type of event. Possible values: CREATE, DELETE, MODIFY." },
+    "CamelFileNameOnly": { "kind": "header", "displayName": "", "group": 
"consumer", "label": "", "required": false, "javaType": "String", "deprecated": 
false, "deprecationNote": "", "autowired": false, "secret": false, 
"description": "Only the file name (the name with no leading paths)." },
+    "CamelFileAbsolute": { "kind": "header", "displayName": "", "group": 
"consumer", "label": "", "required": false, "javaType": "Boolean", 
"deprecated": false, "deprecationNote": "", "autowired": false, "secret": 
false, "description": "A `boolean` option specifying whether the consumed file 
denotes an\nabsolute path or not. Should normally be `false` for relative 
paths.\nAbsolute paths should normally not be used but we added to the 
move\noption to allow moving files to absolute paths.  [...]
+    "CamelFileAbsolutePath": { "kind": "header", "displayName": "", "group": 
"consumer", "label": "", "required": false, "javaType": "String", "deprecated": 
false, "deprecationNote": "", "autowired": false, "secret": false, 
"description": "The absolute path to the file. For relative files this path 
holds the\nrelative path instead." },
+    "CamelFilePath": { "kind": "header", "displayName": "", "group": 
"consumer", "label": "", "required": false, "javaType": "String", "deprecated": 
false, "deprecationNote": "", "autowired": false, "secret": false, 
"description": "The file path. For relative files this is the starting 
directory + the\nrelative filename. For absolute files this is the absolute 
path." },
+    "CamelFileName": { "kind": "header", "displayName": "", "group": 
"consumer", "label": "", "required": false, "javaType": "String", "deprecated": 
false, "deprecationNote": "", "autowired": false, "secret": false, 
"description": "Name of the consumed file as a relative file path with offset 
from the\nstarting directory configured on the endpoint." },
+    "CamelFileRelativePath": { "kind": "header", "displayName": "", "group": 
"consumer", "label": "", "required": false, "javaType": "String", "deprecated": 
false, "deprecationNote": "", "autowired": false, "secret": false, 
"description": "The relative path." },
+    "CamelFileNameConsumed": { "kind": "header", "displayName": "", "group": 
"consumer", "label": "", "required": false, "javaType": "String", "deprecated": 
false, "deprecationNote": "", "autowired": false, "secret": false, 
"description": "The name of the file that has been consumed" },
+    "CamelFileParent": { "kind": "header", "displayName": "", "group": 
"consumer", "label": "", "required": false, "javaType": "String", "deprecated": 
false, "deprecationNote": "", "autowired": false, "secret": false, 
"description": "The parent path." },
+    "CamelFileLastModified": { "kind": "header", "displayName": "", "group": 
"consumer", "label": "", "required": false, "javaType": "long", "deprecated": 
false, "deprecationNote": "", "autowired": false, "secret": false, 
"description": "A `Long` value containing the last modified timestamp of the 
file." }
+  },
   "properties": {
     "path": { "kind": "path", "displayName": "Path", "group": "consumer", 
"label": "consumer", "required": true, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": 
false, "secret": false, "description": "Path of directory to consume events 
from." },
     "antInclude": { "kind": "parameter", "displayName": "Ant Include", 
"group": "consumer", "label": "consumer", "required": false, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "defaultValue": "**", "description": "ANT style pattern to 
match files. The file is matched against path relative to endpoint path. 
Pattern must be also relative (not starting with slash)" },
diff --git 
a/components/camel-file-watch/src/main/docs/file-watch-component.adoc 
b/components/camel-file-watch/src/main/docs/file-watch-component.adoc
index 2f9b72d..30d6001c 100644
--- a/components/camel-file-watch/src/main/docs/file-watch-component.adoc
+++ b/components/camel-file-watch/src/main/docs/file-watch-component.adoc
@@ -30,7 +30,9 @@ include::partial$component-endpoint-options.adoc[]
 // endpoint options: START
 
 // endpoint options: END
-
+// component headers: START
+include::partial$component-endpoint-headers.adoc[]
+// component headers: END
 
 == Examples:
 
@@ -59,42 +61,4 @@ 
from("file-watch://some-directory?events=MODIFY&recursive=false")
     .to("file:some-directory/snapshots");
 ----
 
-== Message Headers
-
-The following headers are supported by this component:
-
-=== File Watch consumer only
-
-[width="100%",cols="10%,90%",options="header",]
-|===
-|Header |Description
-
-|`CamelFileEventType` |Type of event. Possible values: CREATE, DELETE, MODIFY.
-The java type of this header is String
-
-|`CamelFileName` |Name of the consumed file as a relative file path with 
offset from the
-starting directory configured on the endpoint.
-
-|`CamelFileNameOnly` |Only the file name (the name with no leading paths).
-
-|`CamelFileAbsolute` |A `boolean` option specifying whether the consumed file 
denotes an
-absolute path or not. Should normally be `false` for relative paths.
-Absolute paths should normally not be used but we added to the move
-option to allow moving files to absolute paths. But can be used
-elsewhere as well.
-
-|`CamelFileAbsolutePath` |The absolute path to the file. For relative files 
this path holds the
-relative path instead.
-
-|`CamelFilePath` |The file path. For relative files this is the starting 
directory + the
-relative filename. For absolute files this is the absolute path.
-
-|`CamelFileRelativePath` |The relative path.
-
-|`CamelFileParent` |The parent path.
-
-|`CamelFileLastModified` |A `Long` value containing the last modified 
timestamp of the file.
-|===
-
-
 include::spring-boot:partial$starter.adoc[]
diff --git 
a/components/camel-file-watch/src/main/java/org/apache/camel/component/file/watch/FileWatchComponent.java
 
b/components/camel-file-watch/src/main/java/org/apache/camel/component/file/watch/FileWatchComponent.java
index 5805f9e..45f53f2 100644
--- 
a/components/camel-file-watch/src/main/java/org/apache/camel/component/file/watch/FileWatchComponent.java
+++ 
b/components/camel-file-watch/src/main/java/org/apache/camel/component/file/watch/FileWatchComponent.java
@@ -30,7 +30,6 @@ import org.apache.camel.support.DefaultComponent;
  */
 @Component("file-watch")
 public class FileWatchComponent extends DefaultComponent {
-    public static final String EVENT_TYPE_HEADER = "CamelFileEventType";
 
     @Metadata(label = "consumer",
               description = "The number of concurrent consumers. Increase this 
value, if your route is slow to prevent buffering in queue.",
diff --git 
a/components/camel-file-watch/src/main/java/org/apache/camel/component/file/watch/FileWatchConstants.java
 
b/components/camel-file-watch/src/main/java/org/apache/camel/component/file/watch/FileWatchConstants.java
new file mode 100644
index 0000000..17242c3
--- /dev/null
+++ 
b/components/camel-file-watch/src/main/java/org/apache/camel/component/file/watch/FileWatchConstants.java
@@ -0,0 +1,60 @@
+/*
+ * 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.component.file.watch;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.spi.Metadata;
+
+public final class FileWatchConstants {
+
+    @Metadata(description = "Type of event. Possible values: CREATE, DELETE, 
MODIFY.", javaType = "String")
+    public static final String EVENT_TYPE_HEADER = "CamelFileEventType";
+    @Metadata(description = "Only the file name (the name with no leading 
paths).", javaType = "String")
+    public static final String FILE_NAME_ONLY = Exchange.FILE_NAME_ONLY;
+    @Metadata(description = "A `boolean` option specifying whether the 
consumed file denotes an\n" +
+                            "absolute path or not. Should normally be `false` 
for relative paths.\n" +
+                            "Absolute paths should normally not be used but we 
added to the move\n" +
+                            "option to allow moving files to absolute paths. 
But can be used\n" +
+                            "elsewhere as well.",
+              javaType = "Boolean")
+    public static final String FILE_ABSOLUTE = "CamelFileAbsolute";
+    @Metadata(description = "The absolute path to the file. For relative files 
this path holds the\n" +
+                            "relative path instead.",
+              javaType = "String")
+    public static final String FILE_ABSOLUTE_PATH = "CamelFileAbsolutePath";
+    @Metadata(description = "The file path. For relative files this is the 
starting directory + the\n" +
+                            "relative filename. For absolute files this is the 
absolute path.",
+              javaType = "String")
+    public static final String FILE_PATH = Exchange.FILE_PATH;
+    @Metadata(description = "Name of the consumed file as a relative file path 
with offset from the\n" +
+                            "starting directory configured on the endpoint.",
+              javaType = "String")
+    public static final String FILE_NAME = Exchange.FILE_NAME;
+    @Metadata(description = "The relative path.", javaType = "String")
+    public static final String FILE_RELATIVE_PATH = "CamelFileRelativePath";
+    @Metadata(description = "The name of the file that has been consumed", 
javaType = "String")
+    public static final String FILE_NAME_CONSUMED = 
Exchange.FILE_NAME_CONSUMED;
+    @Metadata(description = "The parent path.", javaType = "String")
+    public static final String FILE_PARENT = Exchange.FILE_PARENT;
+    @Metadata(description = "A `Long` value containing the last modified 
timestamp of the file.",
+              javaType = "long")
+    public static final String FILE_LAST_MODIFIED = 
Exchange.FILE_LAST_MODIFIED;
+
+    private FileWatchConstants() {
+        // Utility class
+    }
+}
diff --git 
a/components/camel-file-watch/src/main/java/org/apache/camel/component/file/watch/FileWatchConsumer.java
 
b/components/camel-file-watch/src/main/java/org/apache/camel/component/file/watch/FileWatchConsumer.java
index 59141ec..5967597 100644
--- 
a/components/camel-file-watch/src/main/java/org/apache/camel/component/file/watch/FileWatchConsumer.java
+++ 
b/components/camel-file-watch/src/main/java/org/apache/camel/component/file/watch/FileWatchConsumer.java
@@ -143,21 +143,22 @@ public class FileWatchConsumer extends DefaultConsumer {
         File file = event.getEventPath().toFile();
         Message message = exchange.getIn();
         message.setBody(file);
-        message.setHeader(FileWatchComponent.EVENT_TYPE_HEADER, 
event.getEventType().name());
-        message.setHeader(Exchange.FILE_NAME_ONLY, 
event.getEventPath().getFileName().toString());
-        message.setHeader("CamelFileAbsolute", true);
+        message.setHeader(FileWatchConstants.EVENT_TYPE_HEADER, 
event.getEventType().name());
+        message.setHeader(FileWatchConstants.FILE_NAME_ONLY, 
event.getEventPath().getFileName().toString());
+        message.setHeader(FileWatchConstants.FILE_ABSOLUTE, true);
 
         final String absolutePath = 
PathUtils.normalizeToString(event.getEventPath().toAbsolutePath());
-        message.setHeader("CamelFileAbsolutePath", absolutePath);
-        message.setHeader(Exchange.FILE_PATH, absolutePath);
+        message.setHeader(FileWatchConstants.FILE_ABSOLUTE_PATH, absolutePath);
+        message.setHeader(FileWatchConstants.FILE_PATH, absolutePath);
 
         final String relativePath = 
PathUtils.normalizeToString(baseDirectory.relativize(event.getEventPath()));
-        message.setHeader(Exchange.FILE_NAME, relativePath);
-        message.setHeader("CamelFileRelativePath", relativePath);
-        message.setHeader(Exchange.FILE_NAME_CONSUMED, relativePath);
+        message.setHeader(FileWatchConstants.FILE_NAME, relativePath);
+        message.setHeader(FileWatchConstants.FILE_RELATIVE_PATH, relativePath);
+        message.setHeader(FileWatchConstants.FILE_NAME_CONSUMED, relativePath);
 
-        message.setHeader(Exchange.FILE_PARENT, 
PathUtils.normalizeToString(event.getEventPath().getParent().toAbsolutePath()));
-        message.setHeader(Exchange.FILE_LAST_MODIFIED, event.getEventDate());
+        message.setHeader(FileWatchConstants.FILE_PARENT,
+                
PathUtils.normalizeToString(event.getEventPath().getParent().toAbsolutePath()));
+        message.setHeader(FileWatchConstants.FILE_LAST_MODIFIED, 
event.getEventDate());
         message.setHeader(Exchange.MESSAGE_TIMESTAMP, event.getEventDate());
 
         return exchange;
diff --git 
a/components/camel-file-watch/src/main/java/org/apache/camel/component/file/watch/FileWatchEndpoint.java
 
b/components/camel-file-watch/src/main/java/org/apache/camel/component/file/watch/FileWatchEndpoint.java
index f38ed75..6fe3ded 100644
--- 
a/components/camel-file-watch/src/main/java/org/apache/camel/component/file/watch/FileWatchEndpoint.java
+++ 
b/components/camel-file-watch/src/main/java/org/apache/camel/component/file/watch/FileWatchEndpoint.java
@@ -37,7 +37,7 @@ import org.apache.camel.support.DefaultEndpoint;
  * Get notified about file events in a directory using {@link 
java.nio.file.WatchService}.
  */
 @UriEndpoint(firstVersion = "3.0.0", scheme = "file-watch", title = "File 
Watch", syntax = "file-watch:path",
-             category = { Category.FILE }, consumerOnly = true)
+             category = { Category.FILE }, consumerOnly = true, headersClass = 
FileWatchConstants.class)
 public class FileWatchEndpoint extends DefaultEndpoint implements 
MultipleConsumersSupport {
     @UriPath(label = "consumer", description = "Path of directory to consume 
events from.")
     @Metadata(required = true)
diff --git 
a/components/camel-file-watch/src/test/java/org/apache/camel/component/file/watch/FileWatchComponentTest.java
 
b/components/camel-file-watch/src/test/java/org/apache/camel/component/file/watch/FileWatchComponentTest.java
index 6b25275..05e2132 100644
--- 
a/components/camel-file-watch/src/test/java/org/apache/camel/component/file/watch/FileWatchComponentTest.java
+++ 
b/components/camel-file-watch/src/test/java/org/apache/camel/component/file/watch/FileWatchComponentTest.java
@@ -122,7 +122,7 @@ public class FileWatchComponentTest extends 
FileWatchComponentTestBase {
         MockEndpoint mock = getMockEndpoint("mock:watchAll");
         mock.expectedMessageCount(10);
         mock.expectedMessagesMatches(exchange -> exchange.getIn()
-                .getHeader(FileWatchComponent.EVENT_TYPE_HEADER, 
FileEventEnum.class) == FileEventEnum.CREATE);
+                .getHeader(FileWatchConstants.EVENT_TYPE_HEADER, 
FileEventEnum.class) == FileEventEnum.CREATE);
 
         for (int i = 0; i < 10; i++) {
             createFile(testPath(), i + "");
diff --git 
a/components/camel-file-watch/src/test/java/org/apache/camel/component/file/watch/FileWatchComponentTestBase.java
 
b/components/camel-file-watch/src/test/java/org/apache/camel/component/file/watch/FileWatchComponentTestBase.java
index ac9fd29..1a9d9f2 100644
--- 
a/components/camel-file-watch/src/test/java/org/apache/camel/component/file/watch/FileWatchComponentTestBase.java
+++ 
b/components/camel-file-watch/src/test/java/org/apache/camel/component/file/watch/FileWatchComponentTestBase.java
@@ -47,7 +47,7 @@ public class FileWatchComponentTestBase extends 
CamelTestSupport {
 
     static void assertFileEvent(String expectedFileName, FileEventEnum 
expectedEventType, Exchange exchange) {
         assertEquals(expectedFileName, 
exchange.getIn().getBody(File.class).getName());
-        assertEquals(expectedEventType, 
exchange.getIn().getHeader(FileWatchComponent.EVENT_TYPE_HEADER, 
FileEventEnum.class));
+        assertEquals(expectedEventType, 
exchange.getIn().getHeader(FileWatchConstants.EVENT_TYPE_HEADER, 
FileEventEnum.class));
     }
 
     public void beforeEach(ExtensionContext context) throws Exception {

Reply via email to