Author: gertv
Date: Mon Nov  3 05:18:57 2008
New Revision: 710053

URL: http://svn.apache.org/viewvc?rev=710053&view=rev
Log:
SM-1673: Improve error handling in servicemix-camel

Added:
    
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiCamelErrorHandlingTestSupport.java
   (with props)
    
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOnlyCamelErrorHandlingTest.java
   (with props)
    
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOnlyWithErrorHandledTrueSpringDSLTest.java
   (with props)
    
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/SpringJbiTestSupport.java
   (with props)
    
servicemix/components/engines/servicemix-camel/trunk/src/test/resources/org/apache/servicemix/camel/su8-src/
    
servicemix/components/engines/servicemix-camel/trunk/src/test/resources/org/apache/servicemix/camel/su8-src/camel-context.xml
   (with props)
Modified:
    
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOutCamelErrorHandlingTest.java
    
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiTestSupport.java
    
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/NonJbiCamelEndpointsIntegrationTest.java

Added: 
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiCamelErrorHandlingTestSupport.java
URL: 
http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiCamelErrorHandlingTestSupport.java?rev=710053&view=auto
==============================================================================
--- 
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiCamelErrorHandlingTestSupport.java
 (added)
+++ 
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiCamelErrorHandlingTestSupport.java
 Mon Nov  3 05:18:57 2008
@@ -0,0 +1,100 @@
+/*
+ * 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.servicemix.camel;
+
+import java.util.List;
+
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.Fault;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.xml.namespace.QName;
+
+import org.apache.camel.converter.jaxp.StringSource;
+import org.apache.servicemix.MessageExchangeListener;
+import org.apache.servicemix.components.util.ComponentSupport;
+import org.apache.servicemix.jbi.container.ActivationSpec;
+import org.apache.servicemix.tck.ReceiverComponent;
+
+/**
+ * Tests on handling fault messages with the Camel Exception handler
+ */
+public abstract class JbiCamelErrorHandlingTestSupport extends JbiTestSupport {
+
+    protected ReceiverComponent receiverComponent = new ReceiverComponent();
+
+    protected static final String MESSAGE = "<just><a>test</a></just>";
+
+    @Override
+    protected void appendJbiActivationSpecs(List<ActivationSpec> 
activationSpecList) {
+        ActivationSpec spec;
+
+        spec = new ActivationSpec(new ReturnFaultComponent());
+        spec.setService(new QName("urn:test", "faulty-service"));
+        spec.setEndpoint("endpoint");
+        activationSpecList.add(spec);
+
+        spec = new ActivationSpec(new ReturnErrorComponent(new 
IllegalArgumentException("iae error")));
+        spec.setService(new QName("urn:test", "iae-error-service"));
+        spec.setEndpoint("endpoint");
+        activationSpecList.add(spec);
+
+        spec = new ActivationSpec(new ReturnErrorComponent(new 
IllegalStateException("ise error")));
+        spec.setService(new QName("urn:test", "ise-error-service"));
+        spec.setEndpoint("endpoint");
+        activationSpecList.add(spec);
+
+        spec = new ActivationSpec(new ReturnErrorComponent(new 
NullPointerException("npe error")));
+        spec.setService(new QName("urn:test", "npe-error-service"));
+        spec.setEndpoint("endpoint");
+        activationSpecList.add(spec);
+
+        spec = new ActivationSpec(receiverComponent);
+        spec.setService(new QName("urn:test", "receiver-service"));
+        spec.setEndpoint("endpoint");
+        activationSpecList.add(spec);
+
+        spec = new ActivationSpec(new MyEchoComponent());
+        spec.setService(new QName("urn:test", "echo-service"));
+        spec.setEndpoint("endpoint");
+        activationSpecList.add(spec);
+    }
+
+    protected static class ReturnErrorComponent extends ComponentSupport 
implements MessageExchangeListener {
+        private Exception exception;
+
+        public ReturnErrorComponent(Exception exception) {
+            this.exception = exception;
+        }
+
+        public void onMessageExchange(MessageExchange exchange) throws 
MessagingException {
+            if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
+                fail(exchange, exception);
+            }
+        }
+    }
+
+    protected static class ReturnFaultComponent extends ComponentSupport 
implements MessageExchangeListener {
+        public void onMessageExchange(MessageExchange exchange) throws 
MessagingException {
+            if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
+                Fault fault = exchange.createFault();
+                fault.setContent(new StringSource("<fault/>"));
+                fail(exchange, fault);
+            }
+        }
+    }
+}

Propchange: 
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiCamelErrorHandlingTestSupport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOnlyCamelErrorHandlingTest.java
URL: 
http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOnlyCamelErrorHandlingTest.java?rev=710053&view=auto
==============================================================================
--- 
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOnlyCamelErrorHandlingTest.java
 (added)
+++ 
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOnlyCamelErrorHandlingTest.java
 Mon Nov  3 05:18:57 2008
@@ -0,0 +1,131 @@
+/*
+ * 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.servicemix.camel;
+
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOnly;
+import javax.xml.namespace.QName;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.converter.jaxp.StringSource;
+import org.apache.servicemix.client.DefaultServiceMixClient;
+import org.apache.servicemix.client.ServiceMixClient;
+import org.apache.servicemix.jbi.FaultException;
+
+/**
+ * Tests on handling fault messages with the Camel Exception handler  
+ */
+public class JbiInOnlyCamelErrorHandlingTest extends 
JbiCamelErrorHandlingTestSupport {
+    
+    private static final String MESSAGE = "<just><a>test</a></just>";
+
+    public void testInOnlyWithNoHandleFault() throws Exception {
+        MockEndpoint errors = getMockEndpoint("mock:errors");
+        errors.expectedMessageCount(1);
+        
+        ServiceMixClient client = new DefaultServiceMixClient(jbiContainer);
+        InOnly exchange = client.createInOnlyExchange();
+        exchange.setService(new QName("urn:test", "no-handle-fault"));
+        exchange.getInMessage().setContent(new StringSource(MESSAGE));
+        client.sendSync(exchange);
+        assertEquals(ExchangeStatus.ERROR, exchange.getStatus());
+        assertTrue("A FaultException was expected", exchange.getError() 
instanceof FaultException);
+        
+        errors.assertIsSatisfied();
+    }
+
+    public void testInOnlyWithHandleFault() throws Exception {
+        MockEndpoint errors = getMockEndpoint("mock:errors");
+        errors.expectedMessageCount(1);
+        
+        ServiceMixClient client = new DefaultServiceMixClient(jbiContainer);
+        InOnly exchange = client.createInOnlyExchange();
+        exchange.setService(new QName("urn:test", "handle-fault"));
+        exchange.getInMessage().setContent(new StringSource(MESSAGE));
+        client.sendSync(exchange);
+        assertEquals(ExchangeStatus.ERROR, exchange.getStatus());
+        assertTrue("A FaultException was expected", exchange.getError() 
instanceof FaultException);
+
+        errors.assertIsSatisfied();
+    }
+
+    public void testInOnlyWithErrorNotHandled() throws Exception {
+        MockEndpoint errors = getMockEndpoint("mock:errors");
+        errors.expectedMessageCount(1);
+        
+        ServiceMixClient client = new DefaultServiceMixClient(jbiContainer);
+        InOnly exchange = client.createInOnlyExchange();
+        exchange.setService(new QName("urn:test", "error-not-handled"));
+        exchange.getInMessage().setContent(new StringSource(MESSAGE));
+        client.sendSync(exchange);
+        assertEquals(ExchangeStatus.ERROR, exchange.getStatus());
+        assertTrue("A IllegalArgumentException was expected", 
exchange.getError() instanceof IllegalArgumentException);
+
+        errors.assertIsSatisfied();
+    }
+
+    public void testInOnlyWithErrorHandledFalse() throws Exception {
+        MockEndpoint errors = getMockEndpoint("mock:errors");
+        errors.expectedMessageCount(0);
+        
+        ServiceMixClient client = new DefaultServiceMixClient(jbiContainer);
+        InOnly exchange = client.createInOnlyExchange();
+        exchange.setService(new QName("urn:test", "error-handled-false"));
+        exchange.getInMessage().setContent(new StringSource(MESSAGE));
+        client.sendSync(exchange);
+        assertEquals(ExchangeStatus.ERROR, exchange.getStatus());
+        assertTrue("A IllegalStateException was expected", exchange.getError() 
instanceof IllegalStateException);
+
+        receiverComponent.getMessageList().assertMessagesReceived(1);
+        
+        errors.assertIsSatisfied();
+    }
+    
+    public void testInOnlyWithErrorHandledTrue() throws Exception {
+        MockEndpoint errors = getMockEndpoint("mock:errors");
+        errors.expectedMessageCount(0);
+        
+        ServiceMixClient client = new DefaultServiceMixClient(jbiContainer);
+        InOnly exchange = client.createInOnlyExchange();
+        exchange.setService(new QName("urn:test", "error-handled-true"));
+        exchange.getInMessage().setContent(new StringSource(MESSAGE));
+        client.sendSync(exchange);
+        assertEquals(ExchangeStatus.DONE, exchange.getStatus());
+
+        receiverComponent.getMessageList().assertMessagesReceived(1);
+        
+        errors.assertIsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRoutes() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+               
onException(IllegalStateException.class).handled(false).to("jbi:service:urn:test:receiver-service?mep=in-only");
+               
onException(NullPointerException.class).handled(true).to("jbi:service:urn:test:receiver-service?mep=in-only");
+                
errorHandler(deadLetterChannel("mock:errors").maximumRedeliveries(1).initialRedeliveryDelay(300));
+                
from("jbi:service:urn:test:no-handle-fault").to("jbi:service:urn:test:faulty-service?mep=in-only");
+                
from("jbi:service:urn:test:handle-fault").handleFault().to("jbi:service:urn:test:faulty-service?mep=in-only");
+                
from("jbi:service:urn:test:error-not-handled").to("jbi:service:urn:test:iae-error-service?mep=in-only");
+                
from("jbi:service:urn:test:error-handled-false").to("jbi:service:urn:test:ise-error-service?mep=in-only");
+                
from("jbi:service:urn:test:error-handled-true").to("jbi:service:urn:test:npe-error-service?mep=in-only");
+            }
+        };
+    }
+}

Propchange: 
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOnlyCamelErrorHandlingTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOnlyWithErrorHandledTrueSpringDSLTest.java
URL: 
http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOnlyWithErrorHandledTrueSpringDSLTest.java?rev=710053&view=auto
==============================================================================
--- 
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOnlyWithErrorHandledTrueSpringDSLTest.java
 (added)
+++ 
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOnlyWithErrorHandledTrueSpringDSLTest.java
 Mon Nov  3 05:18:57 2008
@@ -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.servicemix.camel;
+
+import java.util.List;
+
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.xml.namespace.QName;
+
+import org.apache.servicemix.MessageExchangeListener;
+import org.apache.servicemix.client.ServiceMixClient;
+import org.apache.servicemix.components.util.ComponentSupport;
+import org.apache.servicemix.jbi.container.ActivationSpec;
+import org.apache.servicemix.tck.ReceiverComponent;
+
+/**
+ * Tests on handling fault messages with the Camel Exception handler
+ */
+public class JbiInOnlyWithErrorHandledTrueSpringDSLTest extends 
SpringJbiTestSupport {
+
+    private static final QName TEST_SERVICE = new QName("urn:test", 
"error-handled-true");
+
+    private ReceiverComponent receiver;
+    private ReceiverComponent deadLetter;
+
+    @Override
+    protected void setUp() throws Exception {
+        receiver = new ReceiverComponent();
+        deadLetter = new ReceiverComponent();
+
+        super.setUp();
+    }
+
+    public void testErrorHandledByExceptionClause() throws Exception {
+        ServiceMixClient smxClient = getServicemixClient();
+        InOnly exchange = smxClient.createInOnlyExchange();
+        
exchange.setEndpoint(jbiContainer.getRegistry().getEndpointsForService(TEST_SERVICE)[0]);
+
+        smxClient.sendSync(exchange);
+
+        assertEquals(ExchangeStatus.DONE, exchange.getStatus());
+        receiver.getMessageList().assertMessagesReceived(1);
+        deadLetter.getMessageList().assertMessagesReceived(0);
+    }
+
+    @Override
+    protected String getServiceUnitName() {
+        return "su8";
+    }
+
+    @Override
+    protected void appendJbiActivationSpecs(List<ActivationSpec> 
activationSpecList) {
+        activationSpecList.add(createActivationSpec(new 
ReturnNullPointerExceptionErrorComponent(), 
+                                                    new QName("urn:test", 
"npe-error-service")));
+
+        activationSpecList.add(createActivationSpec(receiver, new 
QName("urn:test", "receiver-service")));
+        activationSpecList.add(createActivationSpec(deadLetter, new 
QName("urn:test", "deadLetter-service")));
+    }
+
+    protected static class ReturnNullPointerExceptionErrorComponent extends 
ComponentSupport implements MessageExchangeListener {
+        public void onMessageExchange(MessageExchange exchange) throws 
MessagingException {
+            if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
+                fail(exchange, new NullPointerException());
+            }
+        }
+    }
+}

Propchange: 
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOnlyWithErrorHandledTrueSpringDSLTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOutCamelErrorHandlingTest.java
URL: 
http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOutCamelErrorHandlingTest.java?rev=710053&r1=710052&r2=710053&view=diff
==============================================================================
--- 
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOutCamelErrorHandlingTest.java
 (original)
+++ 
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOutCamelErrorHandlingTest.java
 Mon Nov  3 05:18:57 2008
@@ -18,11 +18,8 @@
 
 import java.util.List;
 
-import javax.jbi.messaging.Fault;
+import javax.jbi.messaging.ExchangeStatus;
 import javax.jbi.messaging.InOut;
-import javax.jbi.messaging.MessageExchange;
-import javax.jbi.messaging.MessagingException;
-import javax.jbi.messaging.NormalizedMessage;
 import javax.xml.namespace.QName;
 
 import org.apache.camel.builder.RouteBuilder;
@@ -30,42 +27,94 @@
 import org.apache.camel.converter.jaxp.StringSource;
 import org.apache.servicemix.client.DefaultServiceMixClient;
 import org.apache.servicemix.client.ServiceMixClient;
-import org.apache.servicemix.jbi.FaultException;
 import org.apache.servicemix.jbi.container.ActivationSpec;
 
 /**
- * Tests on handling fault messages with the Camel Exception handler  
+ * Tests on handling fault messages with the Camel Exception handler
  */
-public class JbiInOutCamelErrorHandlingTest extends JbiTestSupport {
-    
+public class JbiInOutCamelErrorHandlingTest extends 
JbiCamelErrorHandlingTestSupport {
+
     private static final String MESSAGE = "<just><a>test</a></just>";
 
-    public void testInOnlyExchangeConvertBody() throws Exception {
+    public void testInOutWithNoHandleFault() throws Exception {
+        MockEndpoint errors = getMockEndpoint("mock:errors");
+        errors.expectedMessageCount(0);
+
+        ServiceMixClient client = new DefaultServiceMixClient(jbiContainer);
+        InOut exchange = client.createInOutExchange();
+        exchange.setService(new QName("urn:test", "no-handle-fault"));
+        exchange.getInMessage().setContent(new StringSource(MESSAGE));
+        client.sendSync(exchange);
+        assertEquals(ExchangeStatus.ACTIVE, exchange.getStatus());
+        assertNotNull(exchange.getFault());
+        client.done(exchange);
+
+        errors.assertIsSatisfied();
+    }
+
+    public void testInOutWithHandleFault() throws Exception {
         MockEndpoint errors = getMockEndpoint("mock:errors");
         errors.expectedMessageCount(1);
-        
+
         ServiceMixClient client = new DefaultServiceMixClient(jbiContainer);
         InOut exchange = client.createInOutExchange();
-        exchange.setService(new QName("urn:test", "service"));
+        exchange.setService(new QName("urn:test", "handle-fault"));
         exchange.getInMessage().setContent(new StringSource(MESSAGE));
         client.sendSync(exchange);
-        
+        assertEquals(ExchangeStatus.ACTIVE, exchange.getStatus());
+        assertNotNull(exchange.getFault());
+        client.done(exchange);
+
         errors.assertIsSatisfied();
     }
 
-    @Override
-    protected void appendJbiActivationSpecs(List<ActivationSpec> 
activationSpecList) {
-        // no additional activation specs required
-        ActivationSpec spec = new ActivationSpec(new MyEchoComponent() {
-            protected boolean transform(MessageExchange exchange, 
NormalizedMessage in, NormalizedMessage out) throws MessagingException {
-                Fault f = exchange.createFault();
-                f.setContent(new StringSource("<fault/>"));
-                throw new FaultException("Error", exchange, f);
-            }
-        });
-        spec.setService(new QName("urn:test", "faulty-service"));
-        spec.setEndpoint("endpoint");
-        activationSpecList.add(spec);
+    public void testInOutWithErrorNotHandled() throws Exception {
+        MockEndpoint errors = getMockEndpoint("mock:errors");
+        errors.expectedMessageCount(1);
+
+        ServiceMixClient client = new DefaultServiceMixClient(jbiContainer);
+        InOut exchange = client.createInOutExchange();
+        exchange.setService(new QName("urn:test", "error-not-handled"));
+        exchange.getInMessage().setContent(new StringSource(MESSAGE));
+        client.sendSync(exchange);
+        assertEquals(ExchangeStatus.ERROR, exchange.getStatus());
+        assertTrue("A IllegalArgumentException was expected", 
exchange.getError() instanceof IllegalArgumentException);
+
+        errors.assertIsSatisfied();
+    }
+
+    public void testInOutWithErrorHandledFalse() throws Exception {
+        MockEndpoint errors = getMockEndpoint("mock:errors");
+        errors.expectedMessageCount(0);
+
+        ServiceMixClient client = new DefaultServiceMixClient(jbiContainer);
+        InOut exchange = client.createInOutExchange();
+        exchange.setService(new QName("urn:test", "error-handled-false"));
+        exchange.getInMessage().setContent(new StringSource(MESSAGE));
+        client.sendSync(exchange);
+        assertEquals(ExchangeStatus.ERROR, exchange.getStatus());
+        assertTrue("A IllegalStateException was expected", exchange.getError() 
instanceof IllegalStateException);
+
+        receiverComponent.getMessageList().assertMessagesReceived(1);
+
+        errors.assertIsSatisfied();
+    }
+
+    public void testInOutWithErrorHandledTrue() throws Exception {
+        MockEndpoint errors = getMockEndpoint("mock:errors");
+        errors.expectedMessageCount(0);
+
+        ServiceMixClient client = new DefaultServiceMixClient(jbiContainer);
+        InOut exchange = client.createInOutExchange();
+        exchange.setService(new QName("urn:test", "error-handled-true"));
+        exchange.getInMessage().setContent(new StringSource(MESSAGE));
+        client.sendSync(exchange);
+        assertEquals(ExchangeStatus.ACTIVE, exchange.getStatus());
+        client.done(exchange);
+
+        receiverComponent.getMessageList().assertMessagesReceived(1);
+
+        errors.assertIsSatisfied();
     }
 
     @Override
@@ -73,9 +122,21 @@
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                errorHandler(deadLetterChannel("mock:errors"));
-                
from("jbi:service:urn:test:service").handleFault().to("jbi:service:urn:test:faulty-service");
+                
onException(IllegalStateException.class).handled(false).to("jbi:service:urn:test:receiver-service?mep=in-only");
+                
onException(NullPointerException.class).handled(true).to("jbi:service:urn:test:receiver-service?mep=in-only");
+                
errorHandler(deadLetterChannel("mock:errors").maximumRedeliveries(1).initialRedeliveryDelay(300));
+                
from("jbi:service:urn:test:no-handle-fault").to("jbi:service:urn:test:faulty-service");
+                
from("jbi:service:urn:test:handle-fault").handleFault().to("jbi:service:urn:test:faulty-service");
+                
from("jbi:service:urn:test:error-not-handled").to("jbi:service:urn:test:iae-error-service");
+                
from("jbi:service:urn:test:error-handled-false").to("jbi:service:urn:test:ise-error-service");
+                
from("jbi:service:urn:test:error-handled-true").to("jbi:service:urn:test:npe-error-service");
             }
         };
     }
+
+    @Override
+    protected void appendJbiActivationSpecs(List<ActivationSpec> 
activationSpecList) {
+        super.appendJbiActivationSpecs(activationSpecList);
+    }
+
 }

Modified: 
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiTestSupport.java
URL: 
http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiTestSupport.java?rev=710053&r1=710052&r2=710053&view=diff
==============================================================================
--- 
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiTestSupport.java
 (original)
+++ 
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiTestSupport.java
 Mon Nov  3 05:18:57 2008
@@ -22,6 +22,7 @@
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 
+import javax.jbi.JBIException;
 import javax.xml.namespace.QName;
 
 import org.apache.camel.CamelContext;
@@ -35,7 +36,10 @@
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.servicemix.client.DefaultServiceMixClient;
+import org.apache.servicemix.client.ServiceMixClient;
 import org.apache.servicemix.jbi.container.ActivationSpec;
+import org.apache.servicemix.jbi.container.JBIContainer;
 import org.apache.servicemix.jbi.container.SpringJBIContainer;
 import org.apache.servicemix.tck.ExchangeCompletedListener;
 
@@ -43,6 +47,7 @@
  * @version $Revision: 563665 $
  */
 public abstract class JbiTestSupport extends TestSupport {
+    
     protected Exchange receivedExchange;
 
     protected CamelContext camelContext = new DefaultCamelContext();
@@ -58,6 +63,8 @@
     protected String startEndpointUri = 
"jbi:endpoint:serviceNamespace:serviceA:endpointA";
 
     protected ProducerTemplate<Exchange> client = 
camelContext.createProducerTemplate();
+    
+    protected ServiceMixClient servicemixClient;
 
     /**
      * Sends an exchange to the endpoint
@@ -108,42 +115,65 @@
 
     @Override
     protected void setUp() throws Exception {
-        jbiContainer.setEmbedded(true);
-        exchangeCompletedListener = new ExchangeCompletedListener();
-
-        CamelJbiComponent component = new CamelJbiComponent();
-
+        configureContainer(jbiContainer);
         List<ActivationSpec> activationSpecList = new 
ArrayList<ActivationSpec>();
-
+        
         // lets add the Camel endpoint
-        ActivationSpec activationSpec = new ActivationSpec();
-        activationSpec.setId("camel");
-        activationSpec.setService(new QName("camel", "camel"));
-        activationSpec.setEndpoint("camelEndpoint");
-        activationSpec.setComponent(component);
-        activationSpecList.add(activationSpec);
+        CamelJbiComponent component = new CamelJbiComponent();
+        activationSpecList.add(createActivationSpec(component, new 
QName("camel", "camel"), "camelEndpoint"));
 
+        // and provide a callback method for adding more services
         appendJbiActivationSpecs(activationSpecList);
-
-        ActivationSpec[] activationSpecs = activationSpecList
-                .toArray(new ActivationSpec[activationSpecList.size()]);
-        jbiContainer.setActivationSpecs(activationSpecs);
+        jbiContainer.setActivationSpecs(activationSpecList.toArray(new 
ActivationSpec[activationSpecList.size()]));
+        
         jbiContainer.afterPropertiesSet();
+        
+        exchangeCompletedListener = new ExchangeCompletedListener();
         jbiContainer.addListener(exchangeCompletedListener);
 
-        // lets configure some componnets
-        camelContext.addComponent("jbi", component);
-
+        // allow for additional configuration of the compenent (e.g. deploying 
SU)
+        configureComponent(component);
+        
         // lets add some routes
-        camelContext.addRoutes(createRoutes());
+        RouteBuilder builder = createRoutes();
+        if (builder != null) {
+            camelContext.addRoutes(builder);
+        }
         endpoint = camelContext.getEndpoint(startEndpointUri);
-        assertNotNull("No endpoint found!", endpoint);
 
         camelContext.start();
     }
 
+    protected void configureComponent(CamelJbiComponent component) throws 
Exception {
+        // add the ServiceMix Camel component to the CamelContext
+        camelContext.addComponent("jbi", component);
+    }
+
+    protected void configureContainer(final JBIContainer container) throws 
Exception {
+        container.setEmbedded(true);
+    }
+    
+    public ServiceMixClient getServicemixClient() throws JBIException {
+        if (servicemixClient == null) {
+            servicemixClient = new DefaultServiceMixClient(jbiContainer);
+        }
+        return servicemixClient;
+    }
+    
+    protected ActivationSpec createActivationSpec(Object component, QName 
service) {
+        return createActivationSpec(component, service, "endpoint");
+    }
+    
+    protected ActivationSpec createActivationSpec(Object component, QName 
service, String endpoint) {
+        ActivationSpec spec = new ActivationSpec(component);
+        spec.setService(service);
+        spec.setEndpoint(endpoint);
+        return spec;
+    }
+
     @Override
     protected void tearDown() throws Exception {
+        getServicemixClient().close();
         client.stop();
         camelContext.stop();
         super.tearDown();

Modified: 
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/NonJbiCamelEndpointsIntegrationTest.java
URL: 
http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/NonJbiCamelEndpointsIntegrationTest.java?rev=710053&r1=710052&r2=710053&view=diff
==============================================================================
--- 
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/NonJbiCamelEndpointsIntegrationTest.java
 (original)
+++ 
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/NonJbiCamelEndpointsIntegrationTest.java
 Mon Nov  3 05:18:57 2008
@@ -20,7 +20,7 @@
 import java.net.URI;
 import java.net.URL;
 
-import javax.jbi.messaging.InOut;
+import javax.jbi.messaging.ExchangeStatus;
 import javax.jbi.messaging.MessageExchange;
 import javax.jbi.messaging.MessagingException;
 import javax.jbi.messaging.NormalizedMessage;
@@ -39,8 +39,8 @@
  * @version $Revision: 1.1 $
  */
 public class NonJbiCamelEndpointsIntegrationTest extends TestCase {
-    private static final transient Log LOG = LogFactory
-            .getLog(NonJbiCamelEndpointsIntegrationTest.class);
+    
+    private static final transient Log LOG = 
LogFactory.getLog(NonJbiCamelEndpointsIntegrationTest.class);
 
     protected String suName = "su1";
 
@@ -77,7 +77,9 @@
                 checkResult(exchange);
                 //assertNotNull(exchange.getMessage("out").getContent());
                 // TODO: check out the exchange
-                client.done(exchange);
+                if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
+                    client.done(exchange);
+                }
 
                 // Stop and undeploy
                 component.getServiceUnitManager().stop(suName);
@@ -142,7 +144,7 @@
         deleteDir(tempRootDir);
     }
 
-    protected InOut createExchange(ServiceMixClient client)
+    protected MessageExchange createExchange(ServiceMixClient client)
         throws MessagingException {
 
         return client.createInOutExchange();

Added: 
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/SpringJbiTestSupport.java
URL: 
http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/SpringJbiTestSupport.java?rev=710053&view=auto
==============================================================================
--- 
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/SpringJbiTestSupport.java
 (added)
+++ 
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/SpringJbiTestSupport.java
 Mon Nov  3 05:18:57 2008
@@ -0,0 +1,85 @@
+/*
+ * 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.servicemix.camel;
+
+import java.io.File;
+import java.net.URI;
+import java.net.URL;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.jbi.container.JBIContainer;
+import org.apache.servicemix.util.FileUtil;
+
+/**
+ * Enhances [EMAIL PROTECTED] JbiTestSupport} to enable SU deployment as well
+ */
+public abstract class SpringJbiTestSupport extends JbiTestSupport {
+    
+    private static final Log LOG = 
LogFactory.getLog(SpringJbiTestSupport.class);
+    
+    private File tempRootDir;
+    
+    @Override
+    protected void configureComponent(CamelJbiComponent component) throws 
Exception {
+        super.configureComponent(component);
+
+        // let's add a Camel SU from the camel-context.xml
+        URL url = getClass().getResource(getServiceUnitName() + 
"-src/camel-context.xml");
+        File path = new File(new URI(url.toString())).getParentFile();
+
+        component.getServiceUnitManager().deploy(getServiceUnitName(), 
path.getAbsolutePath());
+        component.getServiceUnitManager().init(getServiceUnitName(), 
path.getAbsolutePath());
+        component.getServiceUnitManager().start(getServiceUnitName());
+
+    }
+    
+    @Override
+    protected void configureContainer(JBIContainer container) throws Exception 
{
+        super.configureContainer(container);
+        jbiContainer.setCreateMBeanServer(false);
+        jbiContainer.setMonitorInstallationDirectory(false);
+        tempRootDir = File.createTempFile("servicemix", "rootDir");
+        tempRootDir.delete();
+        File tempTemp = new File(tempRootDir.getAbsolutePath() + "/temp");
+        if (!tempTemp.mkdirs()) {
+            fail("Unable to create temporary working root directory [" + 
tempTemp.getAbsolutePath() + "]");
+        }
+        LOG.info("Using temporary root directory [" + 
tempRootDir.getAbsolutePath() + "]");
+        jbiContainer.setRootDir(tempRootDir.getAbsolutePath());
+
+        jbiContainer.setEmbedded(true);
+        jbiContainer.setCreateJmxConnector(false);
+        jbiContainer.setFlowName("st");
+    }
+    
+    @Override
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        jbiContainer.stop();
+        jbiContainer.shutDown();
+        FileUtil.deleteFile(tempRootDir);
+    }
+    
+    protected abstract String getServiceUnitName();
+    
+    @Override
+    protected RouteBuilder createRoutes() {
+        return null;
+    }
+}

Propchange: 
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/SpringJbiTestSupport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
servicemix/components/engines/servicemix-camel/trunk/src/test/resources/org/apache/servicemix/camel/su8-src/camel-context.xml
URL: 
http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/resources/org/apache/servicemix/camel/su8-src/camel-context.xml?rev=710053&view=auto
==============================================================================
--- 
servicemix/components/engines/servicemix-camel/trunk/src/test/resources/org/apache/servicemix/camel/su8-src/camel-context.xml
 (added)
+++ 
servicemix/components/engines/servicemix-camel/trunk/src/test/resources/org/apache/servicemix/camel/su8-src/camel-context.xml
 Mon Nov  3 05:18:57 2008
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<!-- START SNIPPET: camel -->
+<beans xmlns="http://www.springframework.org/schema/beans";
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
+       http://activemq.apache.org/camel/schema/spring 
http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
+    ">
+    
+    <bean id="camelTracer" 
class="org.apache.camel.processor.interceptor.Tracer">
+    <property name="traceExceptions" value="false"/>
+    <property name="traceInterceptors" value="true"/>
+    <property name="logLevel" value="FATAL"/>
+    <property name="logName" value="com.mycompany.messages"/>
+</bean>
+    
+
+  <camelContext trace="true"  
xmlns="http://activemq.apache.org/camel/schema/spring";>
+    <route errorHandlerRef="deadLetterErrorHandler">
+      <from uri="jbi:service:urn:test:error-handled-true"/>
+      <onException>
+        <exception>java.lang.NullPointerException</exception>
+            <redeliveryPolicy maximumRedeliveries="0"/>
+            <handled>
+              <constant>true</constant>
+            </handled>
+            <to uri="jbi:service:urn:test:receiver-service?mep=in-only"/>
+      </onException>
+      <to uri="jbi:service:urn:test:npe-error-service?mep=in-only"/>
+    </route>
+  </camelContext>
+
+  <bean id="deadLetterErrorHandler" 
class="org.apache.camel.builder.DeadLetterChannelBuilder">
+    <property name="defaultDeadLetterEndpointUri" 
value="jbi:service:urn:test:deadLetter-service?mep=in-only"/>
+  </bean>
+
+</beans>

Propchange: 
servicemix/components/engines/servicemix-camel/trunk/src/test/resources/org/apache/servicemix/camel/su8-src/camel-context.xml
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to