You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2022/04/05 16:14:59 UTC

[camel] 12/20: CAMEL-17792: Add doc about the message headers of camel-spring-integration

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 b2d70ceed0ea576e14ccd241b43ca9fdbdaa7c4a
Author: Nicolas Filotto <nf...@talend.com>
AuthorDate: Tue Apr 5 15:06:12 2022 +0200

    CAMEL-17792: Add doc about the message headers of camel-spring-integration
---
 .../spring/integration/spring-integration.json     |  5 ++++
 .../main/docs/spring-integration-component.adoc    |  4 ++-
 .../integration/SpringIntegrationConstants.java    | 34 ++++++++++++++++++++++
 .../integration/SpringIntegrationEndpoint.java     |  2 +-
 .../integration/SpringIntegrationProducer.java     |  3 +-
 .../integration/adapter/CamelSourceAdapter.java    |  4 +--
 .../integration/adapter/CamelTargetAdapter.java    |  5 ++--
 7 files changed, 49 insertions(+), 8 deletions(-)

diff --git a/components/camel-spring-integration/src/generated/resources/org/apache/camel/component/spring/integration/spring-integration.json b/components/camel-spring-integration/src/generated/resources/org/apache/camel/component/spring/integration/spring-integration.json
index 5b29229bd27..771171b594c 100644
--- a/components/camel-spring-integration/src/generated/resources/org/apache/camel/component/spring/integration/spring-integration.json
+++ b/components/camel-spring-integration/src/generated/resources/org/apache/camel/component/spring/integration/spring-integration.json
@@ -26,6 +26,11 @@
     "lazyStartProducer": { "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during star [...]
     "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": {
+    "id": { "kind": "header", "displayName": "", "group": "common", "label": "", "required": false, "javaType": "java.util.UUID", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The message id." },
+    "replyChannel": { "kind": "header", "displayName": "", "group": "common", "label": "", "required": false, "javaType": "org.springframework.integration.channel.DirectChannel", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The reply channel." },
+    "timestamp": { "kind": "header", "displayName": "", "group": "common", "label": "", "required": false, "javaType": "Long", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The timestamp of the message." }
+  },
   "properties": {
     "defaultChannel": { "kind": "path", "displayName": "Default Channel", "group": "common", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The default channel name which is used by the Spring Integration Spring context. It will equal to the inputChannel name for the Spring Integration consumer and the outputChannel name for the Spring Integration provider." },
     "inOut": { "kind": "parameter", "displayName": "In Out", "group": "common", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "The exchange pattern that the Spring integration endpoint should use. If inOut=true then a reply channel is expected, either from the Spring Integration Message header or configured on the endpoint." },
diff --git a/components/camel-spring-integration/src/main/docs/spring-integration-component.adoc b/components/camel-spring-integration/src/main/docs/spring-integration-component.adoc
index 77f2adb2084..892624ac9b5 100644
--- a/components/camel-spring-integration/src/main/docs/spring-integration-component.adoc
+++ b/components/camel-spring-integration/src/main/docs/spring-integration-component.adoc
@@ -60,7 +60,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
 
 == Usage
 
diff --git a/components/camel-spring-integration/src/main/java/org/apache/camel/component/spring/integration/SpringIntegrationConstants.java b/components/camel-spring-integration/src/main/java/org/apache/camel/component/spring/integration/SpringIntegrationConstants.java
new file mode 100644
index 00000000000..5abf880bb19
--- /dev/null
+++ b/components/camel-spring-integration/src/main/java/org/apache/camel/component/spring/integration/SpringIntegrationConstants.java
@@ -0,0 +1,34 @@
+/*
+ * 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.spring.integration;
+
+import org.apache.camel.spi.Metadata;
+import org.springframework.messaging.MessageHeaders;
+
+public final class SpringIntegrationConstants {
+
+    @Metadata(description = "The message id.", javaType = "java.util.UUID")
+    public static final String ID = MessageHeaders.ID;
+    @Metadata(description = "The reply channel.", javaType = "org.springframework.integration.channel.DirectChannel")
+    public static final String REPLY_CHANNEL = MessageHeaders.REPLY_CHANNEL;
+    @Metadata(description = "The timestamp of the message.", javaType = "Long")
+    public static final String TIMESTAMP = MessageHeaders.TIMESTAMP;
+
+    private SpringIntegrationConstants() {
+
+    }
+}
diff --git a/components/camel-spring-integration/src/main/java/org/apache/camel/component/spring/integration/SpringIntegrationEndpoint.java b/components/camel-spring-integration/src/main/java/org/apache/camel/component/spring/integration/SpringIntegrationEndpoint.java
index fc6297685bd..490835d4716 100644
--- a/components/camel-spring-integration/src/main/java/org/apache/camel/component/spring/integration/SpringIntegrationEndpoint.java
+++ b/components/camel-spring-integration/src/main/java/org/apache/camel/component/spring/integration/SpringIntegrationEndpoint.java
@@ -33,7 +33,7 @@ import org.springframework.messaging.MessageChannel;
  */
 @UriEndpoint(firstVersion = "1.4.0", scheme = "spring-integration", title = "Spring Integration",
              syntax = "spring-integration:defaultChannel",
-             category = { Category.SPRING, Category.EVENTBUS })
+             category = { Category.SPRING, Category.EVENTBUS }, headersClass = SpringIntegrationConstants.class)
 public class SpringIntegrationEndpoint extends DefaultEndpoint {
     private MessageChannel messageChannel; // TODO is this field never assigned
     @UriPath
diff --git a/components/camel-spring-integration/src/main/java/org/apache/camel/component/spring/integration/SpringIntegrationProducer.java b/components/camel-spring-integration/src/main/java/org/apache/camel/component/spring/integration/SpringIntegrationProducer.java
index d8d6cbb5c10..5f91616a26f 100644
--- a/components/camel-spring-integration/src/main/java/org/apache/camel/component/spring/integration/SpringIntegrationProducer.java
+++ b/components/camel-spring-integration/src/main/java/org/apache/camel/component/spring/integration/SpringIntegrationProducer.java
@@ -29,7 +29,6 @@ import org.springframework.integration.support.channel.BeanFactoryChannelResolve
 import org.springframework.messaging.Message;
 import org.springframework.messaging.MessageChannel;
 import org.springframework.messaging.MessageHandler;
-import org.springframework.messaging.MessageHeaders;
 import org.springframework.messaging.core.DestinationResolver;
 
 /**
@@ -95,7 +94,7 @@ public class SpringIntegrationProducer extends DefaultProducer implements Proces
             if (inputChannel == null) {
                 throw new IllegalArgumentException("InputChannel has not been configured on " + getEndpoint());
             }
-            exchange.getIn().getHeaders().put(MessageHeaders.REPLY_CHANNEL, inputChannel);
+            exchange.getIn().getHeaders().put(SpringIntegrationConstants.REPLY_CHANNEL, inputChannel);
 
             // subscribe so we can receive the reply from spring integration
             inputChannel.subscribe(new MessageHandler() {
diff --git a/components/camel-spring-integration/src/main/java/org/apache/camel/component/spring/integration/adapter/CamelSourceAdapter.java b/components/camel-spring-integration/src/main/java/org/apache/camel/component/spring/integration/adapter/CamelSourceAdapter.java
index dca15150378..c94053b701c 100644
--- a/components/camel-spring-integration/src/main/java/org/apache/camel/component/spring/integration/adapter/CamelSourceAdapter.java
+++ b/components/camel-spring-integration/src/main/java/org/apache/camel/component/spring/integration/adapter/CamelSourceAdapter.java
@@ -23,6 +23,7 @@ import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.component.spring.integration.SpringIntegrationBinding;
+import org.apache.camel.component.spring.integration.SpringIntegrationConstants;
 import org.apache.camel.support.service.ServiceHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -32,7 +33,6 @@ import org.springframework.integration.channel.DirectChannel;
 import org.springframework.messaging.Message;
 import org.springframework.messaging.MessageChannel;
 import org.springframework.messaging.MessageHandler;
-import org.springframework.messaging.MessageHeaders;
 
 /**
  * A CamelContext will be injected into CameSourceAdapter which will let Spring Integration channel talk to the
@@ -66,7 +66,7 @@ public class CamelSourceAdapter extends AbstractCamelAdapter implements Initiali
                     = SpringIntegrationBinding.createSpringIntegrationMessage(exchange);
 
             if (exchange.getPattern().isOutCapable()) {
-                exchange.getIn().getHeaders().put(MessageHeaders.REPLY_CHANNEL, replyChannel);
+                exchange.getIn().getHeaders().put(SpringIntegrationConstants.REPLY_CHANNEL, replyChannel);
 
                 // we want to do in-out so the inputChannel is mandatory (used to receive reply from spring integration)
                 if (replyChannel == null) {
diff --git a/components/camel-spring-integration/src/main/java/org/apache/camel/component/spring/integration/adapter/CamelTargetAdapter.java b/components/camel-spring-integration/src/main/java/org/apache/camel/component/spring/integration/adapter/CamelTargetAdapter.java
index f076735eeeb..9f8b59eba6e 100644
--- a/components/camel-spring-integration/src/main/java/org/apache/camel/component/spring/integration/adapter/CamelTargetAdapter.java
+++ b/components/camel-spring-integration/src/main/java/org/apache/camel/component/spring/integration/adapter/CamelTargetAdapter.java
@@ -21,13 +21,13 @@ import org.apache.camel.Exchange;
 import org.apache.camel.ExchangePattern;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.component.spring.integration.SpringIntegrationBinding;
+import org.apache.camel.component.spring.integration.SpringIntegrationConstants;
 import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.support.DefaultExchange;
 import org.springframework.messaging.Message;
 import org.springframework.messaging.MessageChannel;
 import org.springframework.messaging.MessageDeliveryException;
 import org.springframework.messaging.MessageHandler;
-import org.springframework.messaging.MessageHeaders;
 
 /**
  * CamelTargetAdapter will redirect the Spring Integration message to the Camel context. When we inject the camel
@@ -77,7 +77,8 @@ public class CamelTargetAdapter extends AbstractCamelAdapter implements MessageH
             //Check the message header for the return address
             response = SpringIntegrationBinding.storeToSpringIntegrationMessage(outExchange.getOut());
             if (replyChannel == null) {
-                MessageChannel messageReplyChannel = (MessageChannel) message.getHeaders().get(MessageHeaders.REPLY_CHANNEL);
+                MessageChannel messageReplyChannel
+                        = (MessageChannel) message.getHeaders().get(SpringIntegrationConstants.REPLY_CHANNEL);
                 if (messageReplyChannel != null) {
                     result = messageReplyChannel.send(response);
                 } else {