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 e9420aa07e9 CAMEL-22008: camel-sjms - Add option to set jmsMessageType to force a given type e9420aa07e9 is described below commit e9420aa07e90075188a8e16a98a5e538f0a50649 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Wed Apr 23 11:07:27 2025 +0200 CAMEL-22008: camel-sjms - Add option to set jmsMessageType to force a given type --- .../org/apache/camel/catalog/components/sjms.json | 13 +-- .../component/sjms/SjmsEndpointConfigurer.java | 6 ++ .../component/sjms/SjmsEndpointUriFactory.java | 3 +- .../org/apache/camel/component/sjms/sjms.json | 13 +-- .../apache/camel/component/sjms/SjmsEndpoint.java | 33 +++++- .../camel/component/sjms/jms/JmsBinding.java | 10 +- .../sjms/producer/JmsMessageTypeTest.java | 75 ++++++++++++++ .../endpoint/dsl/SjmsEndpointBuilderFactory.java | 114 +++++++++++++++++++++ 8 files changed, 251 insertions(+), 16 deletions(-) diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/sjms.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/sjms.json index a8bd943fe5a..0c68fa72ac1 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/sjms.json +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/sjms.json @@ -84,11 +84,12 @@ "headerFilterStrategy": { "index": 37, "kind": "parameter", "displayName": "Header Filter Strategy", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.apache.camel.spi.HeaderFilterStrategy", "deprecated": false, "autowired": false, "secret": false, "description": "To use a custom HeaderFilterStrategy to filter header to and from Camel message." }, "includeAllJMSXProperties": { "index": 38, "kind": "parameter", "displayName": "Include All JMSXProperties", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to include all JMSXxxx properties when mapping from JMS to Camel Message. Setting this to true will include properties such as JMSXAppID, and JMSXUserID etc. Note: If you [...] "jmsKeyFormatStrategy": { "index": 39, "kind": "parameter", "displayName": "Jms Key Format Strategy", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.apache.camel.component.sjms.jms.JmsKeyFormatStrategy", "deprecated": false, "autowired": false, "secret": false, "description": "Pluggable strategy for encoding and decoding JMS keys so they can be compliant with the JMS specification. Camel provides two implementations out of the box: def [...] - "mapJmsMessage": { "index": 40, "kind": "parameter", "displayName": "Map Jms Message", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Specifies whether Camel should auto map the received JMS message to a suited payload type, such as jakarta.jms.TextMessage to a String etc. See section about how mapping works below for more details." }, - "messageCreatedStrategy": { "index": 41, "kind": "parameter", "displayName": "Message Created Strategy", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.apache.camel.component.sjms.jms.MessageCreatedStrategy", "deprecated": false, "autowired": false, "secret": false, "description": "To use the given MessageCreatedStrategy which are invoked when Camel creates new instances of jakarta.jms.Message objects when Camel is sending a JMS message." }, - "recoveryInterval": { "index": 42, "kind": "parameter", "displayName": "Recovery Interval", "group": "advanced", "label": "advanced", "required": false, "type": "duration", "javaType": "long", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "5000", "description": "Specifies the interval between recovery attempts, i.e. when a connection is being refreshed, in milliseconds. The default is 5000 ms, that is, 5 seconds." }, - "synchronous": { "index": 43, "kind": "parameter", "displayName": "Synchronous", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Sets whether synchronous processing should be strictly used" }, - "transferException": { "index": 44, "kind": "parameter", "displayName": "Transfer Exception", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "If enabled and you are using Request Reply messaging (InOut) and an Exchange failed on the consumer side, then the caused Exception will be send back in response as a jakarta.jms.ObjectMessage. [...] - "transacted": { "index": 45, "kind": "parameter", "displayName": "Transacted", "group": "transaction", "label": "transaction", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Specifies whether to use transacted mode" } + "jmsMessageType": { "index": 40, "kind": "parameter", "displayName": "Jms Message Type", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.apache.camel.component.sjms.jms.JmsMessageType", "enum": [ "Bytes", "Map", "Object", "Stream", "Text" ], "deprecated": false, "autowired": false, "secret": false, "description": "Allows you to force the use of a specific jakarta.jms.Message implementation for sending JMS messages. Possible values are: [...] + "mapJmsMessage": { "index": 41, "kind": "parameter", "displayName": "Map Jms Message", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Specifies whether Camel should auto map the received JMS message to a suited payload type, such as jakarta.jms.TextMessage to a String etc. See section about how mapping works below for more details." }, + "messageCreatedStrategy": { "index": 42, "kind": "parameter", "displayName": "Message Created Strategy", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.apache.camel.component.sjms.jms.MessageCreatedStrategy", "deprecated": false, "autowired": false, "secret": false, "description": "To use the given MessageCreatedStrategy which are invoked when Camel creates new instances of jakarta.jms.Message objects when Camel is sending a JMS message." }, + "recoveryInterval": { "index": 43, "kind": "parameter", "displayName": "Recovery Interval", "group": "advanced", "label": "advanced", "required": false, "type": "duration", "javaType": "long", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "5000", "description": "Specifies the interval between recovery attempts, i.e. when a connection is being refreshed, in milliseconds. The default is 5000 ms, that is, 5 seconds." }, + "synchronous": { "index": 44, "kind": "parameter", "displayName": "Synchronous", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Sets whether synchronous processing should be strictly used" }, + "transferException": { "index": 45, "kind": "parameter", "displayName": "Transfer Exception", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "If enabled and you are using Request Reply messaging (InOut) and an Exchange failed on the consumer side, then the caused Exception will be send back in response as a jakarta.jms.ObjectMessage. [...] + "transacted": { "index": 46, "kind": "parameter", "displayName": "Transacted", "group": "transaction", "label": "transaction", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Specifies whether to use transacted mode" } } } diff --git a/components/camel-sjms/src/generated/java/org/apache/camel/component/sjms/SjmsEndpointConfigurer.java b/components/camel-sjms/src/generated/java/org/apache/camel/component/sjms/SjmsEndpointConfigurer.java index 8c3bee1e021..66c4efa9b3e 100644 --- a/components/camel-sjms/src/generated/java/org/apache/camel/component/sjms/SjmsEndpointConfigurer.java +++ b/components/camel-sjms/src/generated/java/org/apache/camel/component/sjms/SjmsEndpointConfigurer.java @@ -73,6 +73,8 @@ public class SjmsEndpointConfigurer extends PropertyConfigurerSupport implements case "includeAllJMSXProperties": target.setIncludeAllJMSXProperties(property(camelContext, boolean.class, value)); return true; case "jmskeyformatstrategy": case "jmsKeyFormatStrategy": target.setJmsKeyFormatStrategy(property(camelContext, org.apache.camel.component.sjms.jms.JmsKeyFormatStrategy.class, value)); return true; + case "jmsmessagetype": + case "jmsMessageType": target.setJmsMessageType(property(camelContext, org.apache.camel.component.sjms.jms.JmsMessageType.class, value)); return true; case "lazystartproducer": case "lazyStartProducer": target.setLazyStartProducer(property(camelContext, boolean.class, value)); return true; case "mapjmsmessage": @@ -165,6 +167,8 @@ public class SjmsEndpointConfigurer extends PropertyConfigurerSupport implements case "includeAllJMSXProperties": return boolean.class; case "jmskeyformatstrategy": case "jmsKeyFormatStrategy": return org.apache.camel.component.sjms.jms.JmsKeyFormatStrategy.class; + case "jmsmessagetype": + case "jmsMessageType": return org.apache.camel.component.sjms.jms.JmsMessageType.class; case "lazystartproducer": case "lazyStartProducer": return boolean.class; case "mapjmsmessage": @@ -258,6 +262,8 @@ public class SjmsEndpointConfigurer extends PropertyConfigurerSupport implements case "includeAllJMSXProperties": return target.isIncludeAllJMSXProperties(); case "jmskeyformatstrategy": case "jmsKeyFormatStrategy": return target.getJmsKeyFormatStrategy(); + case "jmsmessagetype": + case "jmsMessageType": return target.getJmsMessageType(); case "lazystartproducer": case "lazyStartProducer": return target.isLazyStartProducer(); case "mapjmsmessage": diff --git a/components/camel-sjms/src/generated/java/org/apache/camel/component/sjms/SjmsEndpointUriFactory.java b/components/camel-sjms/src/generated/java/org/apache/camel/component/sjms/SjmsEndpointUriFactory.java index b2c746465af..01d0ea38692 100644 --- a/components/camel-sjms/src/generated/java/org/apache/camel/component/sjms/SjmsEndpointUriFactory.java +++ b/components/camel-sjms/src/generated/java/org/apache/camel/component/sjms/SjmsEndpointUriFactory.java @@ -23,7 +23,7 @@ public class SjmsEndpointUriFactory extends org.apache.camel.support.component.E private static final Set<String> SECRET_PROPERTY_NAMES; private static final Set<String> MULTI_VALUE_PREFIXES; static { - Set<String> props = new HashSet<>(46); + Set<String> props = new HashSet<>(47); props.add("acknowledgementMode"); props.add("allowNullBody"); props.add("asyncConsumer"); @@ -51,6 +51,7 @@ public class SjmsEndpointUriFactory extends org.apache.camel.support.component.E props.add("headerFilterStrategy"); props.add("includeAllJMSXProperties"); props.add("jmsKeyFormatStrategy"); + props.add("jmsMessageType"); props.add("lazyStartProducer"); props.add("mapJmsMessage"); props.add("messageCreatedStrategy"); diff --git a/components/camel-sjms/src/generated/resources/META-INF/org/apache/camel/component/sjms/sjms.json b/components/camel-sjms/src/generated/resources/META-INF/org/apache/camel/component/sjms/sjms.json index a8bd943fe5a..0c68fa72ac1 100644 --- a/components/camel-sjms/src/generated/resources/META-INF/org/apache/camel/component/sjms/sjms.json +++ b/components/camel-sjms/src/generated/resources/META-INF/org/apache/camel/component/sjms/sjms.json @@ -84,11 +84,12 @@ "headerFilterStrategy": { "index": 37, "kind": "parameter", "displayName": "Header Filter Strategy", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.apache.camel.spi.HeaderFilterStrategy", "deprecated": false, "autowired": false, "secret": false, "description": "To use a custom HeaderFilterStrategy to filter header to and from Camel message." }, "includeAllJMSXProperties": { "index": 38, "kind": "parameter", "displayName": "Include All JMSXProperties", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to include all JMSXxxx properties when mapping from JMS to Camel Message. Setting this to true will include properties such as JMSXAppID, and JMSXUserID etc. Note: If you [...] "jmsKeyFormatStrategy": { "index": 39, "kind": "parameter", "displayName": "Jms Key Format Strategy", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.apache.camel.component.sjms.jms.JmsKeyFormatStrategy", "deprecated": false, "autowired": false, "secret": false, "description": "Pluggable strategy for encoding and decoding JMS keys so they can be compliant with the JMS specification. Camel provides two implementations out of the box: def [...] - "mapJmsMessage": { "index": 40, "kind": "parameter", "displayName": "Map Jms Message", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Specifies whether Camel should auto map the received JMS message to a suited payload type, such as jakarta.jms.TextMessage to a String etc. See section about how mapping works below for more details." }, - "messageCreatedStrategy": { "index": 41, "kind": "parameter", "displayName": "Message Created Strategy", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.apache.camel.component.sjms.jms.MessageCreatedStrategy", "deprecated": false, "autowired": false, "secret": false, "description": "To use the given MessageCreatedStrategy which are invoked when Camel creates new instances of jakarta.jms.Message objects when Camel is sending a JMS message." }, - "recoveryInterval": { "index": 42, "kind": "parameter", "displayName": "Recovery Interval", "group": "advanced", "label": "advanced", "required": false, "type": "duration", "javaType": "long", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "5000", "description": "Specifies the interval between recovery attempts, i.e. when a connection is being refreshed, in milliseconds. The default is 5000 ms, that is, 5 seconds." }, - "synchronous": { "index": 43, "kind": "parameter", "displayName": "Synchronous", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Sets whether synchronous processing should be strictly used" }, - "transferException": { "index": 44, "kind": "parameter", "displayName": "Transfer Exception", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "If enabled and you are using Request Reply messaging (InOut) and an Exchange failed on the consumer side, then the caused Exception will be send back in response as a jakarta.jms.ObjectMessage. [...] - "transacted": { "index": 45, "kind": "parameter", "displayName": "Transacted", "group": "transaction", "label": "transaction", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Specifies whether to use transacted mode" } + "jmsMessageType": { "index": 40, "kind": "parameter", "displayName": "Jms Message Type", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.apache.camel.component.sjms.jms.JmsMessageType", "enum": [ "Bytes", "Map", "Object", "Stream", "Text" ], "deprecated": false, "autowired": false, "secret": false, "description": "Allows you to force the use of a specific jakarta.jms.Message implementation for sending JMS messages. Possible values are: [...] + "mapJmsMessage": { "index": 41, "kind": "parameter", "displayName": "Map Jms Message", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Specifies whether Camel should auto map the received JMS message to a suited payload type, such as jakarta.jms.TextMessage to a String etc. See section about how mapping works below for more details." }, + "messageCreatedStrategy": { "index": 42, "kind": "parameter", "displayName": "Message Created Strategy", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.apache.camel.component.sjms.jms.MessageCreatedStrategy", "deprecated": false, "autowired": false, "secret": false, "description": "To use the given MessageCreatedStrategy which are invoked when Camel creates new instances of jakarta.jms.Message objects when Camel is sending a JMS message." }, + "recoveryInterval": { "index": 43, "kind": "parameter", "displayName": "Recovery Interval", "group": "advanced", "label": "advanced", "required": false, "type": "duration", "javaType": "long", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "5000", "description": "Specifies the interval between recovery attempts, i.e. when a connection is being refreshed, in milliseconds. The default is 5000 ms, that is, 5 seconds." }, + "synchronous": { "index": 44, "kind": "parameter", "displayName": "Synchronous", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Sets whether synchronous processing should be strictly used" }, + "transferException": { "index": 45, "kind": "parameter", "displayName": "Transfer Exception", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "If enabled and you are using Request Reply messaging (InOut) and an Exchange failed on the consumer side, then the caused Exception will be send back in response as a jakarta.jms.ObjectMessage. [...] + "transacted": { "index": 46, "kind": "parameter", "displayName": "Transacted", "group": "transaction", "label": "transaction", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Specifies whether to use transacted mode" } } } diff --git a/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/SjmsEndpoint.java b/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/SjmsEndpoint.java index b2d12ad9ce1..8e4801e73e1 100644 --- a/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/SjmsEndpoint.java +++ b/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/SjmsEndpoint.java @@ -44,6 +44,7 @@ import org.apache.camel.component.sjms.jms.Jms11ObjectFactory; import org.apache.camel.component.sjms.jms.JmsBinding; import org.apache.camel.component.sjms.jms.JmsKeyFormatStrategy; import org.apache.camel.component.sjms.jms.JmsMessageHelper; +import org.apache.camel.component.sjms.jms.JmsMessageType; import org.apache.camel.component.sjms.jms.JmsObjectFactory; import org.apache.camel.component.sjms.jms.MessageCreatedStrategy; import org.apache.camel.component.sjms.jms.SessionAcknowledgementType; @@ -208,6 +209,11 @@ public class SjmsEndpoint extends DefaultEndpoint description = "Specifies whether Camel should auto map the received JMS message to a suited payload type, such as jakarta.jms.TextMessage to a String etc." + " See section about how mapping works below for more details.") private boolean mapJmsMessage = true; + @UriParam(label = "advanced", enums = "Bytes,Map,Object,Stream,Text", + description = "Allows you to force the use of a specific jakarta.jms.Message implementation for sending JMS messages." + + " Possible values are: Bytes, Map, Object, Stream, Text." + + " By default, Camel would determine which JMS message type to use from the In body type. This option allows you to specify it.") + private JmsMessageType jmsMessageType; @UriParam(label = "advanced", description = "To use a custom DestinationCreationStrategy.") private DestinationCreationStrategy destinationCreationStrategy = new DefaultDestinationCreationStrategy(); @@ -288,6 +294,15 @@ public class SjmsEndpoint extends DefaultEndpoint } } + /** + * Should get overridden by implementations which support BlobMessages + * + * @return false + */ + protected boolean supportBlobMessage() { + return false; + } + /** * Gets the destination name which was configured from the endpoint uri. * @@ -449,7 +464,7 @@ public class SjmsEndpoint extends DefaultEndpoint protected JmsBinding createBinding() { return new JmsBinding( isMapJmsMessage(), isAllowNullBody(), getHeaderFilterStrategy(), getJmsKeyFormatStrategy(), - getMessageCreatedStrategy()); + getMessageCreatedStrategy(), getJmsMessageType()); } public void setBinding(JmsBinding binding) { @@ -813,4 +828,20 @@ public class SjmsEndpoint extends DefaultEndpoint public void setSynchronous(boolean synchronous) { this.synchronous = synchronous; } + + public JmsMessageType getJmsMessageType() { + return jmsMessageType; + } + + /** + * Allows you to force the use of a specific jakarta.jms.Message implementation for sending JMS messages. Possible + * values are: Bytes, Map, Object, Stream, Text. By default, Camel would determine which JMS message type to use + * from the In body type. This option allows you to specify it. + */ + public void setJmsMessageType(JmsMessageType jmsMessageType) { + if (jmsMessageType == JmsMessageType.Blob && !supportBlobMessage()) { + throw new IllegalArgumentException("BlobMessage is not supported by this implementation"); + } + this.jmsMessageType = jmsMessageType; + } } diff --git a/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/jms/JmsBinding.java b/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/jms/JmsBinding.java index 332282beac6..25ffd1f9503 100644 --- a/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/jms/JmsBinding.java +++ b/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/jms/JmsBinding.java @@ -70,15 +70,17 @@ public class JmsBinding { private final HeaderFilterStrategy headerFilterStrategy; private final JmsKeyFormatStrategy jmsJmsKeyFormatStrategy; private final MessageCreatedStrategy messageCreatedStrategy; + private final JmsMessageType jmsMessageType; public JmsBinding(boolean mapJmsMessage, boolean allowNullBody, HeaderFilterStrategy headerFilterStrategy, JmsKeyFormatStrategy jmsJmsKeyFormatStrategy, - MessageCreatedStrategy messageCreatedStrategy) { + MessageCreatedStrategy messageCreatedStrategy, JmsMessageType jmsMessageType) { this.mapJmsMessage = mapJmsMessage; this.allowNullBody = allowNullBody; this.headerFilterStrategy = headerFilterStrategy; this.jmsJmsKeyFormatStrategy = jmsJmsKeyFormatStrategy; this.messageCreatedStrategy = messageCreatedStrategy; + this.jmsMessageType = jmsMessageType; } /** @@ -373,7 +375,11 @@ public class JmsBinding { Exchange exchange, Object body, Map<String, Object> headers, Session session, CamelContext context) throws JMSException { - JmsMessageType type = getJMSMessageTypeForBody(exchange, body, headers, session, context); + JmsMessageType type = jmsMessageType; + if (type == null) { + // no explicit type so determine via body + type = getJMSMessageTypeForBody(exchange, body, headers, session, context); + } // create the JmsMessage based on the type if (type != null) { diff --git a/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/producer/JmsMessageTypeTest.java b/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/producer/JmsMessageTypeTest.java new file mode 100644 index 00000000000..2df3bf604e7 --- /dev/null +++ b/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/producer/JmsMessageTypeTest.java @@ -0,0 +1,75 @@ +/* + * 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.sjms.producer; + +import jakarta.jms.BytesMessage; +import jakarta.jms.Message; +import jakarta.jms.MessageConsumer; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.sjms.support.JmsTestSupport; +import org.apache.camel.util.ObjectHelper; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class JmsMessageTypeTest extends JmsTestSupport { + + private static final String TEST_DESTINATION_NAME = "test.foo.JmsMessageTypeTest"; + + public JmsMessageTypeTest() { + } + + @Override + protected boolean useJmx() { + return false; + } + + @Test + public void testJmsMessageType() throws Exception { + MessageConsumer mc = createQueueConsumer(TEST_DESTINATION_NAME); + assertNotNull(mc); + final String expectedBody = "Hello World!"; + + template.sendBody("direct:start", expectedBody); + Message message = mc.receive(5000); + assertNotNull(message); + assertTrue(message instanceof BytesMessage); + + BytesMessage tm = (BytesMessage) message; + long len = tm.getBodyLength(); + assertEquals(12, len); + + byte[] arr = new byte[12]; + tm.readBytes(arr); + assertTrue(ObjectHelper.equalByteArray(expectedBody.getBytes(), arr)); + + mc.close(); + } + + @Override + protected RouteBuilder createRouteBuilder() { + return new RouteBuilder() { + public void configure() { + from("direct:start") + .to("sjms:queue:" + TEST_DESTINATION_NAME + "?jmsMessageType=Bytes"); + } + }; + } +} diff --git a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/SjmsEndpointBuilderFactory.java b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/SjmsEndpointBuilderFactory.java index f943b806288..dd069d19203 100644 --- a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/SjmsEndpointBuilderFactory.java +++ b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/SjmsEndpointBuilderFactory.java @@ -910,6 +910,44 @@ public interface SjmsEndpointBuilderFactory { doSetProperty("jmsKeyFormatStrategy", jmsKeyFormatStrategy); return this; } + /** + * Allows you to force the use of a specific jakarta.jms.Message + * implementation for sending JMS messages. Possible values are: Bytes, + * Map, Object, Stream, Text. By default, Camel would determine which + * JMS message type to use from the In body type. This option allows you + * to specify it. + * + * The option is a: + * <code>org.apache.camel.component.sjms.jms.JmsMessageType</code> type. + * + * Group: advanced + * + * @param jmsMessageType the value to set + * @return the dsl builder + */ + default AdvancedSjmsEndpointConsumerBuilder jmsMessageType(org.apache.camel.component.sjms.jms.JmsMessageType jmsMessageType) { + doSetProperty("jmsMessageType", jmsMessageType); + return this; + } + /** + * Allows you to force the use of a specific jakarta.jms.Message + * implementation for sending JMS messages. Possible values are: Bytes, + * Map, Object, Stream, Text. By default, Camel would determine which + * JMS message type to use from the In body type. This option allows you + * to specify it. + * + * The option will be converted to a + * <code>org.apache.camel.component.sjms.jms.JmsMessageType</code> type. + * + * Group: advanced + * + * @param jmsMessageType the value to set + * @return the dsl builder + */ + default AdvancedSjmsEndpointConsumerBuilder jmsMessageType(String jmsMessageType) { + doSetProperty("jmsMessageType", jmsMessageType); + return this; + } /** * Specifies whether Camel should auto map the received JMS message to a * suited payload type, such as jakarta.jms.TextMessage to a String etc. @@ -2038,6 +2076,44 @@ public interface SjmsEndpointBuilderFactory { doSetProperty("jmsKeyFormatStrategy", jmsKeyFormatStrategy); return this; } + /** + * Allows you to force the use of a specific jakarta.jms.Message + * implementation for sending JMS messages. Possible values are: Bytes, + * Map, Object, Stream, Text. By default, Camel would determine which + * JMS message type to use from the In body type. This option allows you + * to specify it. + * + * The option is a: + * <code>org.apache.camel.component.sjms.jms.JmsMessageType</code> type. + * + * Group: advanced + * + * @param jmsMessageType the value to set + * @return the dsl builder + */ + default AdvancedSjmsEndpointProducerBuilder jmsMessageType(org.apache.camel.component.sjms.jms.JmsMessageType jmsMessageType) { + doSetProperty("jmsMessageType", jmsMessageType); + return this; + } + /** + * Allows you to force the use of a specific jakarta.jms.Message + * implementation for sending JMS messages. Possible values are: Bytes, + * Map, Object, Stream, Text. By default, Camel would determine which + * JMS message type to use from the In body type. This option allows you + * to specify it. + * + * The option will be converted to a + * <code>org.apache.camel.component.sjms.jms.JmsMessageType</code> type. + * + * Group: advanced + * + * @param jmsMessageType the value to set + * @return the dsl builder + */ + default AdvancedSjmsEndpointProducerBuilder jmsMessageType(String jmsMessageType) { + doSetProperty("jmsMessageType", jmsMessageType); + return this; + } /** * Specifies whether Camel should auto map the received JMS message to a * suited payload type, such as jakarta.jms.TextMessage to a String etc. @@ -2701,6 +2777,44 @@ public interface SjmsEndpointBuilderFactory { doSetProperty("jmsKeyFormatStrategy", jmsKeyFormatStrategy); return this; } + /** + * Allows you to force the use of a specific jakarta.jms.Message + * implementation for sending JMS messages. Possible values are: Bytes, + * Map, Object, Stream, Text. By default, Camel would determine which + * JMS message type to use from the In body type. This option allows you + * to specify it. + * + * The option is a: + * <code>org.apache.camel.component.sjms.jms.JmsMessageType</code> type. + * + * Group: advanced + * + * @param jmsMessageType the value to set + * @return the dsl builder + */ + default AdvancedSjmsEndpointBuilder jmsMessageType(org.apache.camel.component.sjms.jms.JmsMessageType jmsMessageType) { + doSetProperty("jmsMessageType", jmsMessageType); + return this; + } + /** + * Allows you to force the use of a specific jakarta.jms.Message + * implementation for sending JMS messages. Possible values are: Bytes, + * Map, Object, Stream, Text. By default, Camel would determine which + * JMS message type to use from the In body type. This option allows you + * to specify it. + * + * The option will be converted to a + * <code>org.apache.camel.component.sjms.jms.JmsMessageType</code> type. + * + * Group: advanced + * + * @param jmsMessageType the value to set + * @return the dsl builder + */ + default AdvancedSjmsEndpointBuilder jmsMessageType(String jmsMessageType) { + doSetProperty("jmsMessageType", jmsMessageType); + return this; + } /** * Specifies whether Camel should auto map the received JMS message to a * suited payload type, such as jakarta.jms.TextMessage to a String etc.