Author: davsclaus
Date: Tue Aug 4 07:54:31 2009
New Revision: 800694
URL: http://svn.apache.org/viewvc?rev=800694&view=rev
Log:
CAMEL-1867: Fixed camel-jms to be consistent with how headers works when
getting and mutating them.
Added:
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsGetHeaderKeyFormatIssueTest.java
(with props)
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsGetHeaderKeyFormatIssueWithContentTypeHeaderTest.java
(with props)
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsMutateMessageTest.java
(with props)
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsMutateRemoveHeaderMessageTest.java
(with props)
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsPassThroughtJmsKeyFormatStrategyEndUserIssueTest.java
(with props)
Modified:
camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsBinding.java
camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessage.java
camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java
Modified:
camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsBinding.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsBinding.java?rev=800694&r1=800693&r2=800694&view=diff
==============================================================================
---
camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsBinding.java
(original)
+++
camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsBinding.java
Tue Aug 4 07:54:31 2009
@@ -206,6 +206,17 @@
return map;
}
+
+ public Object getObjectProperty(Message jmsMessage, String name) throws
JMSException {
+ // try a direct lookup first
+ Object answer = jmsMessage.getObjectProperty(name);
+ if (answer == null) {
+ // then encode the key and do another lookup
+ String key = jmsKeyFormatStrategy.encodeKey(name);
+ answer = jmsMessage.getObjectProperty(key);
+ }
+ return answer;
+ }
protected byte[] createByteArrayFromBytesMessage(BytesMessage message)
throws JMSException {
if (message.getBodyLength() > Integer.MAX_VALUE) {
Modified:
camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessage.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessage.java?rev=800694&r1=800693&r2=800694&view=diff
==============================================================================
---
camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessage.java
(original)
+++
camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessage.java
Tue Aug 4 07:54:31 2009
@@ -18,7 +18,6 @@
import java.io.File;
import java.util.Map;
-
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
@@ -57,6 +56,10 @@
@Override
public void copyFrom(org.apache.camel.Message that) {
+ // must initialize headers before we set the JmsMessage to avoid Camel
+ // populateing it before we do the copy
+ getHeaders().clear();
+
boolean copyMessageId = true;
if (that instanceof JmsMessage) {
JmsMessage thatMessage = (JmsMessage) that;
@@ -66,6 +69,7 @@
copyMessageId = false;
}
}
+
if (copyMessageId) {
setMessageId(that.getMessageId());
}
@@ -108,35 +112,45 @@
// we will exclude using JMS-prefixed headers here to avoid
strangeness with some JMS providers
// e.g. ActiveMQ returns the String not the Destination type for
"JMSReplyTo"!
- if (jmsMessage != null && !name.startsWith("JMS")) {
+ // only look in jms message directly if we have not populated headers
+ if (jmsMessage != null && !hasPopulatedHeaders() &&
!name.startsWith("JMS")) {
try {
- answer = jmsMessage.getObjectProperty(name);
+ // use binding to do the lookup as it has to consider using
encoded keys
+ answer = getBinding().getObjectProperty(jmsMessage, name);
} catch (JMSException e) {
throw new RuntimeExchangeException("Unable to retrieve header
from JMS Message: " + name, getExchange(), e);
}
}
- if (answer == null) {
+ // only look if we have populated headers otherwise there are no
headers at all
+ // if we do lookup a header starting with JMS then force a lookup
+ if (answer == null && (hasPopulatedHeaders() ||
name.startsWith("JMS"))) {
answer = super.getHeader(name);
}
return answer;
}
@Override
+ public Map<String, Object> getHeaders() {
+ ensureInitialHeaders();
+ return super.getHeaders();
+ }
+
+ @Override
public Object removeHeader(String name) {
- Object answer = super.removeHeader(name);
+ ensureInitialHeaders();
+ return super.removeHeader(name);
+ }
- if (jmsMessage != null && !name.startsWith("JMS")) {
- try {
- // also remove header from the JMS message
- if (jmsMessage.propertyExists(name)) {
- answer = JmsMessageHelper.removeJmsProperty(jmsMessage,
name);
- }
- } catch (JMSException e) {
- throw new RuntimeExchangeException("Unable to remove header
from JMS Message: " + name, getExchange(), e);
- }
- }
+ @Override
+ public void setHeaders(Map<String, Object> headers) {
+ ensureInitialHeaders();
+ super.setHeaders(headers);
+ }
- return answer;
+ @Override
+ public void setHeader(String name, Object value) {
+ ensureInitialHeaders();
+ super.setHeader(name, value);
}
@Override
@@ -151,6 +165,18 @@
return super.hasPopulatedHeaders();
}
+ /**
+ * Ensure that the headers have been populated from the underlying JMS
message
+ * before we start mutating the headers
+ */
+ protected void ensureInitialHeaders() {
+ if (jmsMessage != null && !hasPopulatedHeaders()) {
+ // we have not populated headers so force this by creating
+ // new headers and set it on super
+ super.setHeaders(createHeaders());
+ }
+ }
+
@Override
protected Object createBody() {
if (jmsMessage != null) {
Modified:
camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java?rev=800694&r1=800693&r2=800694&view=diff
==============================================================================
---
camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java
(original)
+++
camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java
Tue Aug 4 07:54:31 2009
@@ -274,15 +274,19 @@
final org.apache.camel.Message in = exchange.getIn();
String destinationName =
in.getHeader(JmsConstants.JMS_DESTINATION_NAME, String.class);
- // remove the header so it wont be propagated
- in.removeHeader(JmsConstants.JMS_DESTINATION_NAME);
+ if (destinationName != null) {
+ // remove the header so it wont be propagated
+ in.removeHeader(JmsConstants.JMS_DESTINATION_NAME);
+ }
if (destinationName == null) {
destinationName = endpoint.getDestinationName();
}
Destination destination = in.getHeader(JmsConstants.JMS_DESTINATION,
Destination.class);
- // remove the header so it wont be propagated
- in.removeHeader(JmsConstants.JMS_DESTINATION);
+ if (destination != null) {
+ // remove the header so it wont be propagated
+ in.removeHeader(JmsConstants.JMS_DESTINATION);
+ }
if (destination == null) {
destination = endpoint.getDestination();
}
Added:
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsGetHeaderKeyFormatIssueTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsGetHeaderKeyFormatIssueTest.java?rev=800694&view=auto
==============================================================================
---
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsGetHeaderKeyFormatIssueTest.java
(added)
+++
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsGetHeaderKeyFormatIssueTest.java
Tue Aug 4 07:54:31 2009
@@ -0,0 +1,79 @@
+/**
+ * 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.jms.issues;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.CamelTestSupport;
+
+import static
org.apache.activemq.camel.component.ActiveMQComponent.activeMQComponent;
+
+/**
+ * @version $Revision$
+ */
+public class JmsGetHeaderKeyFormatIssueTest extends CamelTestSupport {
+
+ private String uri = "activemq:queue:hello?jmsKeyFormatStrategy=default";
+
+ public void testSendWithHeaders() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(1);
+ mock.message(0).body().isEqualTo("Hello World");
+ mock.message(0).header("HEADER_1").isEqualTo("VALUE_2");
+
+ template.sendBodyAndHeader(uri, "Hello World", "HEADER_1", "VALUE_1");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext camelContext = super.createCamelContext();
+ camelContext.addComponent("activemq",
activeMQComponent("vm://localhost?broker.persistent=false&broker.useJmx=false"));
+ return camelContext;
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from(uri)
+ .process(new Processor() {
+ public void process(Exchange exchange) throws
Exception {
+ Map headers = exchange.getIn().getHeaders();
+ assertEquals("VALUE_1", headers.get("HEADER_1"));
+ assertEquals("VALUE_1",
exchange.getIn().getHeader("HEADER_1"));
+ }
+ })
+ .setHeader("HEADER_1", constant("VALUE_2"))
+ .process(new Processor() {
+ public void process(Exchange exchange) throws
Exception {
+ Map headers = exchange.getIn().getHeaders();
+ assertEquals("VALUE_2", headers.get("HEADER_1"));
+ assertEquals("VALUE_2",
exchange.getIn().getHeader("HEADER_1"));
+ }
+ })
+ .to("mock:result");
+ }
+ };
+ }
+}
Propchange:
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsGetHeaderKeyFormatIssueTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsGetHeaderKeyFormatIssueTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsGetHeaderKeyFormatIssueWithContentTypeHeaderTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsGetHeaderKeyFormatIssueWithContentTypeHeaderTest.java?rev=800694&view=auto
==============================================================================
---
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsGetHeaderKeyFormatIssueWithContentTypeHeaderTest.java
(added)
+++
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsGetHeaderKeyFormatIssueWithContentTypeHeaderTest.java
Tue Aug 4 07:54:31 2009
@@ -0,0 +1,84 @@
+/**
+ * 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.jms.issues;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.jms.JmsMessage;
+import org.apache.camel.test.CamelTestSupport;
+
+import static
org.apache.activemq.camel.component.ActiveMQComponent.activeMQComponent;
+
+/**
+ * Unit test to verify that we can route a JMS message and do header lookup by
name
+ * without mutating it and that it can handle the default keyFormatStrategy
with _HYPHEN_
+ * in the key name
+ *
+ * @version $Revision$
+ */
+public class JmsGetHeaderKeyFormatIssueWithContentTypeHeaderTest extends
CamelTestSupport {
+
+ private String uri = "activemq:queue:hello?jmsKeyFormatStrategy=default";
+
+ public void testSendWithHeaders() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(1);
+ mock.message(0).body().isEqualTo("Hello World");
+ mock.message(0).header("Content-Type").isEqualTo("text/plain");
+
+ MockEndpoint copy = getMockEndpoint("mock:copy");
+ copy.expectedMessageCount(1);
+ copy.message(0).body().isEqualTo("Hello World");
+ copy.message(0).header("Content-Type").isEqualTo("text/plain");
+
+ template.sendBodyAndHeader(uri, "Hello World", "Content-Type",
"text/plain");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext camelContext = super.createCamelContext();
+ camelContext.addComponent("activemq",
activeMQComponent("vm://localhost?broker.persistent=false&broker.useJmx=false"));
+ return camelContext;
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from(uri)
+ .process(new Processor() {
+ public void process(Exchange exchange) throws
Exception {
+ assertEquals("text/plain",
exchange.getIn().getHeader("Content-Type"));
+
+ // do not mutate it
+ JmsMessage msg =
assertIsInstanceOf(JmsMessage.class, exchange.getIn());
+ assertNotNull("javax.jms.Message should not be
null", msg.getJmsMessage());
+ assertEquals("Should NOT have been muated", false,
msg.shouldCreateNewMessage());
+ }
+ })
+ .to("activemq:queue:copy", "mock:result");
+
+ from("activemq:queue:copy").to("mock:copy");
+ }
+ };
+ }
+}
\ No newline at end of file
Propchange:
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsGetHeaderKeyFormatIssueWithContentTypeHeaderTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsGetHeaderKeyFormatIssueWithContentTypeHeaderTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsMutateMessageTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsMutateMessageTest.java?rev=800694&view=auto
==============================================================================
---
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsMutateMessageTest.java
(added)
+++
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsMutateMessageTest.java
Tue Aug 4 07:54:31 2009
@@ -0,0 +1,86 @@
+/**
+ * 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.jms.issues;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.jms.JmsMessage;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.CamelTestSupport;
+
+import static
org.apache.activemq.camel.component.ActiveMQComponent.activeMQComponent;
+
+/**
+ * @version $Revision$
+ */
+public class JmsMutateMessageTest extends CamelTestSupport {
+
+ private String uri = "activemq:queue:hello";
+
+ public void testMuateMessage() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(1);
+ mock.message(0).body().isEqualTo("Hello World");
+ mock.message(0).header("HEADER_1").isEqualTo("VALUE_2");
+
+ template.sendBodyAndHeader(uri, "Hello World", "HEADER_1", "VALUE_1");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext camelContext = super.createCamelContext();
+ camelContext.addComponent("activemq",
activeMQComponent("vm://localhost?broker.persistent=false&broker.useJmx=false"));
+ return camelContext;
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from(uri)
+ .process(new Processor() {
+ public void process(Exchange exchange) throws
Exception {
+ // do not mutate it
+ JmsMessage msg =
assertIsInstanceOf(JmsMessage.class, exchange.getIn());
+ assertNotNull("javax.jms.Message should not be
null", msg.getJmsMessage());
+
+ // get header should not mutate it
+ assertEquals("VALUE_1",
exchange.getIn().getHeader("HEADER_1"));
+ }
+ })
+ // setting a new header should mutate it
+ .setHeader("HEADER_1", constant("VALUE_2"))
+ .process(new Processor() {
+ public void process(Exchange exchange) throws
Exception {
+ // it should have been mutated
+ JmsMessage msg =
assertIsInstanceOf(JmsMessage.class, exchange.getIn());
+ assertNotNull("javax.jms.Message should not be
null", msg.getJmsMessage());
+
+ // get header should not mutate it
+ assertEquals("VALUE_2",
exchange.getIn().getHeader("HEADER_1"));
+ }
+ })
+ .to("mock:result");
+ }
+ };
+ }
+
+}
Propchange:
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsMutateMessageTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsMutateMessageTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsMutateRemoveHeaderMessageTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsMutateRemoveHeaderMessageTest.java?rev=800694&view=auto
==============================================================================
---
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsMutateRemoveHeaderMessageTest.java
(added)
+++
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsMutateRemoveHeaderMessageTest.java
Tue Aug 4 07:54:31 2009
@@ -0,0 +1,86 @@
+/**
+ * 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.jms.issues;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.jms.JmsMessage;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.CamelTestSupport;
+
+import static
org.apache.activemq.camel.component.ActiveMQComponent.activeMQComponent;
+
+/**
+ * @version $Revision$
+ */
+public class JmsMutateRemoveHeaderMessageTest extends CamelTestSupport {
+
+ private String uri = "activemq:queue:hello";
+
+ public void testMuateMessage() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(1);
+ mock.message(0).body().isEqualTo("Hello World");
+ mock.message(0).header("HEADER_1").isNull();
+
+ template.sendBodyAndHeader(uri, "Hello World", "HEADER_1", "VALUE_1");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext camelContext = super.createCamelContext();
+ camelContext.addComponent("activemq",
activeMQComponent("vm://localhost?broker.persistent=false&broker.useJmx=false"));
+ return camelContext;
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from(uri)
+ .process(new Processor() {
+ public void process(Exchange exchange) throws
Exception {
+ // do not mutate it
+ JmsMessage msg =
assertIsInstanceOf(JmsMessage.class, exchange.getIn());
+ assertNotNull("javax.jms.Message should not be
null", msg.getJmsMessage());
+
+ // get header should not mutate it
+ assertEquals("VALUE_1",
exchange.getIn().getHeader("HEADER_1"));
+ }
+ })
+ // removing a header should mutate it
+ .removeHeader("HEADER_1")
+ .process(new Processor() {
+ public void process(Exchange exchange) throws
Exception {
+ // it should have been mutated
+ JmsMessage msg =
assertIsInstanceOf(JmsMessage.class, exchange.getIn());
+ assertNotNull("javax.jms.Message should not be
null", msg.getJmsMessage());
+
+ // get header should not mutate it
+ assertNull("Header should have been removed",
exchange.getIn().getHeader("HEADER_1"));
+ }
+ })
+ .to("mock:result");
+ }
+ };
+ }
+
+}
\ No newline at end of file
Propchange:
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsMutateRemoveHeaderMessageTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsMutateRemoveHeaderMessageTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsPassThroughtJmsKeyFormatStrategyEndUserIssueTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsPassThroughtJmsKeyFormatStrategyEndUserIssueTest.java?rev=800694&view=auto
==============================================================================
---
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsPassThroughtJmsKeyFormatStrategyEndUserIssueTest.java
(added)
+++
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsPassThroughtJmsKeyFormatStrategyEndUserIssueTest.java
Tue Aug 4 07:54:31 2009
@@ -0,0 +1,80 @@
+/**
+ * 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.jms.issues;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.CamelTestSupport;
+
+import static
org.apache.activemq.camel.component.ActiveMQComponent.activeMQComponent;
+
+/**
+ * @version $Revision$
+ */
+public class JmsPassThroughtJmsKeyFormatStrategyEndUserIssueTest extends
CamelTestSupport {
+
+ private String uri =
"activemq:queue:hello?jmsKeyFormatStrategy=passthrough";
+
+ public void testSendWithHeaders() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(1);
+ mock.message(0).body().isEqualTo("Hello World");
+ mock.message(0).header("HEADER_1").isEqualTo("VALUE_2");
+
+ template.sendBodyAndHeader(uri, "Hello World", "HEADER_1", "VALUE_1");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext camelContext = super.createCamelContext();
+ camelContext.addComponent("activemq",
activeMQComponent("vm://localhost?broker.persistent=false&broker.useJmx=false"));
+ return camelContext;
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from(uri)
+ .process(new Processor() {
+ public void process(Exchange exchange) throws
Exception {
+ Map headers = exchange.getIn().getHeaders();
+ assertEquals("VALUE_1", headers.get("HEADER_1"));
+ assertEquals("VALUE_1",
exchange.getIn().getHeader("HEADER_1"));
+ }
+ })
+ .setHeader("HEADER_1", constant("VALUE_2"))
+ .process(new Processor() {
+ public void process(Exchange exchange) throws
Exception {
+ Map headers = exchange.getIn().getHeaders();
+ assertEquals("VALUE_2", headers.get("HEADER_1"));
+ assertEquals("VALUE_2",
exchange.getIn().getHeader("HEADER_1"));
+ }
+ })
+ .to("mock:result");
+ }
+ };
+ }
+
+}
Propchange:
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsPassThroughtJmsKeyFormatStrategyEndUserIssueTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsPassThroughtJmsKeyFormatStrategyEndUserIssueTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date