Author: davsclaus
Date: Sun Sep 14 05:04:55 2008
New Revision: 695204
URL: http://svn.apache.org/viewvc?rev=695204&view=rev
Log:
CAMEL-585: Fault message is now supported by camel-jms. Will return FAULT
message if the exchange contains it.
Added:
activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/BruceHandlingBeanExceptionTest.java
(with props)
Modified:
activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/EndpointMessageListener.java
activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsExchange.java
Modified:
activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/EndpointMessageListener.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/EndpointMessageListener.java?rev=695204&r1=695203&r2=695204&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/EndpointMessageListener.java
(original)
+++
activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/EndpointMessageListener.java
Sun Sep 14 05:04:55 2008
@@ -65,16 +65,32 @@
if (eagerLoadingOfProperties) {
exchange.getIn().getHeaders();
}
+
+ // process the exchange
processor.process(exchange);
- final JmsMessage out = exchange.getOut(false);
- if (exchange.getException() != null) {
- rce = new RuntimeCamelException(exchange.getException());
+
+ // get the correct jms message to send as reply
+ JmsMessage body = null;
+ if (exchange.isFailed()) {
+ if (exchange.getException() != null) {
+ // an exception occured while processing
+ // TODO: Camel-585 somekind of flag to determine if we
should send the exchange back to the client
+ // or do as new wrap as runtime exception to be thrown
back to spring so it can do rollback
+ rce = wrapRuntimeCamelException(exchange.getException());
+ } else if (exchange.getFault().getBody() != null) {
+ // a fault occured while processing
+ body = exchange.getFault();
+ }
+ } else {
+ // process OK so get the reply
+ body = exchange.getOut(false);
}
- if (rce == null && out != null && !disableReplyTo) {
- sendReply(replyDestination, message, exchange, out);
+ // send the reply
+ if (rce == null && body != null && !disableReplyTo) {
+ sendReply(replyDestination, message, exchange, body);
}
} catch (Exception e) {
- rce = new RuntimeCamelException(e);
+ rce = wrapRuntimeCamelException(e);
}
if (rce != null) {
LOG.warn(endpoint + " consumer caught an exception while
processing "
@@ -159,6 +175,19 @@
// Implementation methods
//-------------------------------------------------------------------------
+ /**
+ * Wraps the caused exception in a RuntimeCamelException if its not
already such an exception
+ */
+ private static RuntimeCamelException wrapRuntimeCamelException(Throwable
e) {
+ // TODO: Move to camel-core
+ if (e instanceof RuntimeCamelException) {
+ // dont double wrap if already a RuntimeCamelException
+ return (RuntimeCamelException) e;
+ } else {
+ return new RuntimeCamelException(e);
+ }
+ }
+
protected void sendReply(Destination replyDestination, final Message
message, final JmsExchange exchange, final JmsMessage out) {
if (replyDestination == null) {
if (LOG.isDebugEnabled()) {
Modified:
activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsExchange.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsExchange.java?rev=695204&r1=695203&r2=695204&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsExchange.java
(original)
+++
activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsExchange.java
Sun Sep 14 05:04:55 2008
@@ -103,7 +103,7 @@
* @return the JMS fault message
*/
public Message getFaultMessage() {
- return getOut().getJmsMessage();
+ return getFault().getJmsMessage();
}
// Implementation methods
Added:
activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/BruceHandlingBeanExceptionTest.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/BruceHandlingBeanExceptionTest.java?rev=695204&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/BruceHandlingBeanExceptionTest.java
(added)
+++
activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/BruceHandlingBeanExceptionTest.java
Sun Sep 14 05:04:55 2008
@@ -0,0 +1,76 @@
+/**
+ * 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 org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import static
org.apache.camel.component.jms.JmsComponent.jmsComponentClientAcknowledge;
+
+/**
+ * Unit test for request-reply with jms where processing the input could
cause: OK, FAULT or Exception
+ */
+public class BruceHandlingBeanExceptionTest extends ContextTestSupport {
+
+ public void testSendOK() throws Exception {
+ Object out = template.requestBody("activemq:queue:ok", "Hello World");
+ assertEquals("Bye World", out);
+ }
+
+ public void testSendFailure() throws Exception {
+ Object out = template.requestBody("activemq:queue:fault", "Hello
World");
+ assertEquals("This is a fault message", out);
+ }
+
+ public void xxxtestSendError() throws Exception {
+ // TODO: See CAMEL-585
+ Object out = template.requestBody("activemq:queue:error", "Hello
World");
+ assertEquals("Damm", out);
+ }
+
+ 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() {
+ public void configure() throws Exception {
+ from("activemq:queue:ok").transform(constant("Bye World"));
+
+ from("activemq:queue:fault").setFaultBody(constant("This is a
fault message"));
+
+ from("activemq:queue:error").bean(MyExceptionBean.class);
+ }
+ };
+ }
+
+ public static class MyExceptionBean {
+ public String doSomething(String input) throws Exception {
+ throw new IllegalArgumentException("Forced exception by unit
test");
+ }
+ }
+}
Propchange:
activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/BruceHandlingBeanExceptionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/BruceHandlingBeanExceptionTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date