You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2010/05/28 09:05:13 UTC
svn commit: r949117 - in /camel/trunk/components/camel-jms/src:
main/java/org/apache/camel/component/jms/
test/java/org/apache/camel/component/jms/issues/
Author: davsclaus
Date: Fri May 28 07:05:12 2010
New Revision: 949117
URL: http://svn.apache.org/viewvc?rev=949117&view=rev
Log:
CAMEL-2470: Adding test for sending back a reply to JMSReplyTo based on a temporary queue.
Added:
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/TempReplyToIssueTest.java (with props)
Modified:
camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java
camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsTemporaryQueueEndpoint.java
Modified: camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java?rev=949117&r1=949116&r2=949117&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java (original)
+++ camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java Fri May 28 07:05:12 2010
@@ -120,11 +120,9 @@ public class JmsEndpoint extends Default
public static JmsEndpoint newInstance(Destination destination) throws JMSException {
if (destination instanceof TemporaryQueue) {
return new JmsTemporaryQueueEndpoint((TemporaryQueue) destination);
- }
- if (destination instanceof TemporaryTopic) {
+ } else if (destination instanceof TemporaryTopic) {
return new JmsTemporaryTopicEndpoint((TemporaryTopic) destination);
- }
- if (destination instanceof Queue) {
+ } else if (destination instanceof Queue) {
return new JmsQueueEndpoint((Queue) destination);
} else {
return new JmsEndpoint((Topic) destination);
Modified: camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsTemporaryQueueEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsTemporaryQueueEndpoint.java?rev=949117&r1=949116&r2=949117&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsTemporaryQueueEndpoint.java (original)
+++ camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsTemporaryQueueEndpoint.java Fri May 28 07:05:12 2010
@@ -24,10 +24,11 @@ import javax.jms.TemporaryQueue;
/**
* A <a href="http://activemq.apache.org/jms.html">JMS Endpoint</a>
* for working with a {@link TemporaryQueue}
+ * <p/>
+ * <b>Important:</b> Need to be really careful to always use the same Connection otherwise the destination goes stale
*
* @version $Revision$
*/
-// TODO need to be really careful to always use the same Connection otherwise the destination goes stale
public class JmsTemporaryQueueEndpoint extends JmsQueueEndpoint implements DestinationEndpoint {
private Destination jmsDestination;
@@ -61,11 +62,10 @@ public class JmsTemporaryQueueEndpoint e
}
@Override
- // We don't want to manage this temporary object
public Object getManagedObject(JmsEndpoint object) {
+ // We don't want to manage this temporary object, so return null
return null;
}
-
public synchronized Destination getJmsDestination(Session session) throws JMSException {
if (jmsDestination == null) {
Added: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/TempReplyToIssueTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/TempReplyToIssueTest.java?rev=949117&view=auto
==============================================================================
--- camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/TempReplyToIssueTest.java (added)
+++ camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/TempReplyToIssueTest.java Fri May 28 07:05:12 2010
@@ -0,0 +1,91 @@
+/**
+ * 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 javax.jms.ConnectionFactory;
+import javax.jms.Destination;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.camel.Body;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.Header;
+import org.apache.camel.Processor;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.jms.JmsConstants;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+import static org.apache.camel.component.jms.JmsComponent.jmsComponentClientAcknowledge;
+
+/**
+ * @version $Revision$
+ */
+public class TempReplyToIssueTest extends CamelTestSupport {
+
+ @Test
+ public void testReplyToIssue() throws Exception {
+ String out = template.requestBody("activemq:queue:test.queue", "World", String.class);
+ // we should receive that fixed reply
+ assertEquals("Hello Moon", out);
+ }
+
+ public String handleMessage(final @Header("JMSReplyTo") Destination jmsReplyTo, final @Header("JMSCorrelationID") String id,
+ @Body String body, Exchange exchange) throws Exception {
+ assertNotNull(jmsReplyTo);
+ assertTrue("Should be a temp queue", jmsReplyTo.toString().startsWith("temp-queue"));
+
+ // we send the reply manually (notice we just use a bogus endpoint uri)
+ ProducerTemplate producer = exchange.getContext().createProducerTemplate();
+ producer.send("activemq:queue:xxx", new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setBody("Hello Moon");
+ // remember to set correlation id
+ exchange.getIn().setHeader("JMSCorrelationID", id);
+ // this is the real destination we send the reply to
+ exchange.getIn().setHeader(JmsConstants.JMS_DESTINATION, jmsReplyTo);
+ }
+ });
+ // stop it after use
+ producer.stop();
+
+ // sleep a bit so Camel will send the reply a bit later
+ Thread.sleep(1000);
+
+ // this will later cause a problem as the temp queue has been deleted
+ // and exceptions will be logged etc
+ return "Hello " + body;
+ }
+
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext camelContext = super.createCamelContext();
+ ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
+ camelContext.addComponent("activemq", jmsComponentClientAcknowledge(connectionFactory));
+ return camelContext;
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("activemq:queue:test.queue").bean(TempReplyToIssueTest.class, "handleMessage");
+ }
+ };
+ }
+}
Propchange: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/TempReplyToIssueTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/TempReplyToIssueTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date