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 2009/03/18 08:05:15 UTC

svn commit: r755493 - in /camel/branches/camel-1.x: ./ camel-core/src/main/java/org/apache/camel/builder/xml/ camel-core/src/main/java/org/apache/camel/impl/ camel-core/src/main/java/org/apache/camel/management/ camel-core/src/main/java/org/apache/came...

Author: davsclaus
Date: Wed Mar 18 07:05:14 2009
New Revision: 755493

URL: http://svn.apache.org/viewvc?rev=755493&view=rev
Log:
Merged revisions 755487 via svnmerge from 
https://svn.apache.org/repos/asf/camel/trunk

........
  r755487 | davsclaus | 2009-03-18 07:19:24 +0100 (Wed, 18 Mar 2009) | 1 line
  
  CAMEL-1463: Fixed rare bug when disabled JMX and using no error handler, the DeadLetterHandler could still be added to the route in some routes.
........

Added:
    camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/impl/DefaultErrorHandlerWrappingStrategy.java
      - copied, changed from r755487, camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultErrorHandlerWrappingStrategy.java
    camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/processor/ChoiceNoErrorHandlerTest.java   (with props)
    camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/processor/NoErrorHandlerTest.java
      - copied unchanged from r755487, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/NoErrorHandlerTest.java
Modified:
    camel/branches/camel-1.x/   (props changed)
    camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/builder/xml/XPathBuilder.java
    camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/impl/DefaultLifecycleStrategy.java
    camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/management/InstrumentationLifecycleStrategy.java
    camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/util/ProcessorTypeHelper.java
    camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/issues/BelasThreadErrorHandlerIssue901Test.java

Propchange: camel/branches/camel-1.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Mar 18 07:05:14 2009
@@ -1 +1 @@
-/camel/trunk:736980,739733,739904,740251,740295,740306,740596,740663,741848,742231,742705,742739,742854,742856,742898,742906,743613,743762,743773,743920,743959-743960,744123,745105,745367,745541,745751,745826,745978,746269,746872,746895,746962,747258,747678-747704,748392,748436,748821,749563-749564,749574,749628-749629,749936,749956,750017,750334,750396,750761,750796,752068,752117,752418,752751-752755,752764-752773,752956,753087,753101,753175,755136
+/camel/trunk:736980,739733,739904,740251,740295,740306,740596,740663,741848,742231,742705,742739,742854,742856,742898,742906,743613,743762,743773,743920,743959-743960,744123,745105,745367,745541,745751,745826,745978,746269,746872,746895,746962,747258,747678-747704,748392,748436,748821,749563-749564,749574,749628-749629,749936,749956,750017,750334,750396,750761,750796,752068,752117,752418,752751-752755,752764-752773,752956,753087,753101,753175,755136,755487

Propchange: camel/branches/camel-1.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/builder/xml/XPathBuilder.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/builder/xml/XPathBuilder.java?rev=755493&r1=755492&r2=755493&view=diff
==============================================================================
--- camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/builder/xml/XPathBuilder.java (original)
+++ camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/builder/xml/XPathBuilder.java Wed Mar 18 07:05:14 2009
@@ -91,6 +91,12 @@
         return new XPathBuilder(text);
     }
 
+    public static XPathBuilder xpath(String text, Class resultType) {
+        XPathBuilder builder = new XPathBuilder(text);
+        builder.setResultType(resultType);
+        return builder;
+    }
+
     @Override
     public String toString() {
         return "XPath: " + text;

Copied: camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/impl/DefaultErrorHandlerWrappingStrategy.java (from r755487, camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultErrorHandlerWrappingStrategy.java)
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/impl/DefaultErrorHandlerWrappingStrategy.java?p2=camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/impl/DefaultErrorHandlerWrappingStrategy.java&p1=camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultErrorHandlerWrappingStrategy.java&r1=755487&r2=755493&rev=755493&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultErrorHandlerWrappingStrategy.java (original)
+++ camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/impl/DefaultErrorHandlerWrappingStrategy.java Wed Mar 18 07:05:14 2009
@@ -19,7 +19,7 @@
 import java.util.List;
 
 import org.apache.camel.Processor;
-import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.model.ProcessorType;
 import org.apache.camel.spi.ErrorHandlerWrappingStrategy;
 import org.apache.camel.spi.RouteContext;
 
@@ -30,19 +30,18 @@
  */
 public class DefaultErrorHandlerWrappingStrategy implements ErrorHandlerWrappingStrategy {
 
-    private final RouteContext routeContext;
-    private final List<ProcessorDefinition> counterList;
+    private final List<ProcessorType> counterList;
 
-    public DefaultErrorHandlerWrappingStrategy(RouteContext routeContext, List<ProcessorDefinition> counterList) {
-        this.routeContext = routeContext;
+    public DefaultErrorHandlerWrappingStrategy(List<ProcessorType> counterList) {
         this.counterList = counterList;
     }
 
-    public Processor wrapProcessorInErrorHandler(ProcessorDefinition processorDefinition, Processor target) throws Exception {
+    public Processor wrapProcessorInErrorHandler(RouteContext routeContext, ProcessorType processorType, Processor target)
+        throws Exception {
 
         // don't wrap our instrumentation interceptors
-        if (counterList.contains(processorDefinition)) {
-            return processorDefinition.getErrorHandlerBuilder().createErrorHandler(routeContext, target);
+        if (counterList.contains(processorType)) {
+            return processorType.getErrorHandlerBuilder().createErrorHandler(routeContext, target);
         }
 
         return target;

Modified: camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/impl/DefaultLifecycleStrategy.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/impl/DefaultLifecycleStrategy.java?rev=755493&r1=755492&r2=755493&view=diff
==============================================================================
--- camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/impl/DefaultLifecycleStrategy.java (original)
+++ camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/impl/DefaultLifecycleStrategy.java Wed Mar 18 07:05:14 2009
@@ -53,6 +53,7 @@
 
     public void onRouteContextCreate(RouteContext routeContext) {
         RouteType routeType = routeContext.getRoute();
+
         if (routeType.getInputs() != null && !routeType.getInputs().isEmpty()) {
             // configure the outputs
             List<ProcessorType<?>> outputs = new ArrayList<ProcessorType<?>>(routeType.getOutputs());
@@ -60,10 +61,18 @@
             // clearing the outputs
             routeType.clearOutput();
 
+            // a list of processors in the route
+            List<ProcessorType> counterList = new ArrayList<ProcessorType>();
+
             // add the output configure the outputs with the routeType
             for (ProcessorType<?> processorType : outputs) {
                 routeType.addOutput(processorType);
+                counterList.add(processorType);
             }
+
+            // set the error handler strategy containing the list of outputs added
+            // TODO: align this code with InstrumentationLifecycleStrategy
+            routeContext.setErrorHandlerWrappingStrategy(new DefaultErrorHandlerWrappingStrategy(counterList));
         }
     }
 

Modified: camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/management/InstrumentationLifecycleStrategy.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/management/InstrumentationLifecycleStrategy.java?rev=755493&r1=755492&r2=755493&view=diff
==============================================================================
--- camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/management/InstrumentationLifecycleStrategy.java (original)
+++ camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/management/InstrumentationLifecycleStrategy.java Wed Mar 18 07:05:14 2009
@@ -187,7 +187,8 @@
                 LOG.warn("Could not register PerformanceCounter MBean: " + name, e);
             }
         }
-        
+
+        // TODO: align this code with InstrumentationLifecycleStrategy
         routeContext.addInterceptStrategy(new InstrumentationInterceptStrategy(counterMap));
 
         routeContext.setErrorHandlerWrappingStrategy(
@@ -200,7 +201,7 @@
         RouteType routeType = routeContext.getRoute();
         if (routeType.getInputs() != null && !routeType.getInputs().isEmpty()) {
             if (routeType.getInputs().size() > 1) {
-                LOG.warn("Add InstrumentationProcessor to first input only.");
+                LOG.warn("Addding InstrumentationProcessor to first input only.");
             }
 
             Endpoint endpoint  = routeType.getInputs().get(0).getEndpoint();

Modified: camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/util/ProcessorTypeHelper.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/util/ProcessorTypeHelper.java?rev=755493&r1=755492&r2=755493&view=diff
==============================================================================
--- camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/util/ProcessorTypeHelper.java (original)
+++ camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/util/ProcessorTypeHelper.java Wed Mar 18 07:05:14 2009
@@ -61,9 +61,11 @@
                 }
 
                 List<ProcessorType<?>> children = choice.getOtherwise().getOutputs();
-                T child = findFirstTypeInOutputs(children, type);
-                if (child != null) {
-                    return child;
+                if (children != null) {
+                    T child = findFirstTypeInOutputs(children, type);
+                    if (child != null) {
+                        return child;
+                    }
                 }
             }
 

Modified: camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/issues/BelasThreadErrorHandlerIssue901Test.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/issues/BelasThreadErrorHandlerIssue901Test.java?rev=755493&r1=755492&r2=755493&view=diff
==============================================================================
--- camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/issues/BelasThreadErrorHandlerIssue901Test.java (original)
+++ camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/issues/BelasThreadErrorHandlerIssue901Test.java Wed Mar 18 07:05:14 2009
@@ -39,14 +39,11 @@
     private int callCounter3;
     private int redelivery = 1;
 
-    protected void setUp() throws Exception {
-        disableJMX();
-        super.setUp();
-    }
-
     public void testThreadErrorHandlerLogging() throws Exception {
         MockEndpoint handled = getMockEndpoint("mock:handled");
-        handled.expectedBodiesReceived(msg3);
+        // in case of an exception we should receive the original input,
+        // so this is message 1
+        handled.expectedBodiesReceived(msg1);
 
         try {
             template.sendBody("direct:errorTest", msg1);
@@ -57,9 +54,9 @@
 
         assertMockEndpointsSatisfied();
 
-        assertEquals(1, callCounter1);
-        assertEquals(1, callCounter2);
-        assertEquals(1 + redelivery, callCounter3);  // Only this should be more then 1
+        assertEquals(1 + redelivery, callCounter1);
+        assertEquals(1 + redelivery, callCounter2);
+        assertEquals(1 + redelivery, callCounter3);
     }
 
     protected RouteBuilder createRouteBuilder() throws Exception {

Added: camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/processor/ChoiceNoErrorHandlerTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/processor/ChoiceNoErrorHandlerTest.java?rev=755493&view=auto
==============================================================================
--- camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/processor/ChoiceNoErrorHandlerTest.java (added)
+++ camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/processor/ChoiceNoErrorHandlerTest.java Wed Mar 18 07:05:14 2009
@@ -0,0 +1,177 @@
+/**
+ * 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.processor;
+
+import java.lang.reflect.Method;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.Route;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.EventDrivenConsumerRoute;
+import org.apache.camel.model.RouteType;
+import org.apache.camel.processor.interceptor.StreamCachingInterceptor;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.ProcessorTypeHelper;
+
+/**
+ * Unit test based on user forum problem - CAMEL-1463.
+ *
+ * @version $Revision$
+ */
+public class ChoiceNoErrorHandlerTest extends ContextTestSupport {
+
+    private static boolean jmx = true;
+
+    @Override
+    protected void setUp() throws Exception {
+        // we must enable/disable JMX in this setUp
+        if (jmx) {
+            enableJMX();
+            jmx = false;
+        } else {
+            disableJMX();
+        }
+        super.setUp();
+    }
+
+    public void testChoiceNoErrorHandler() throws Exception {
+        doTest();
+    }
+
+    public void testChoiceNoErrorHandlerJMXDisabled() throws Exception {
+        doTest();
+    }
+
+    private void doTest() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceived("Hello World");
+
+        template.sendBodyAndHeader("direct:start", "Hello World", "foo", "bar");
+
+        assertMockEndpointsSatisfied();
+
+        // there should be no error handlers and no stream cache
+        for (RouteType route : context.getRouteDefinitions()) {
+            assertNull("StreamCache should be disabled", route.getStreamCaching());
+
+            ErrorHandler error = ProcessorTypeHelper.findFirstTypeInOutputs(route.getOutputs(), DeadLetterChannel.class);
+            assertNull("There should be no error handler", error);
+        }
+
+        // there should be no error handlers and no stream cache
+        for (Route route : context.getRoutes()) {
+            if (route instanceof EventDrivenConsumerRoute) {
+                EventDrivenConsumerRoute consumer = (EventDrivenConsumerRoute) route;
+
+                StreamCachingInterceptor cache = findProceesorInRoute(consumer.getProcessor(), StreamCachingInterceptor.class);
+                assertNull("There should be no stream cache found: " + cache, cache);
+
+                ErrorHandler error = findProceesorInRoute(consumer.getProcessor(), ErrorHandler.class);
+                assertNull("There should be no error handler found: " + error, error);
+            }
+        }
+    }
+
+    private <T> T findProceesorInRoute(Processor route, Class<T> type) {
+        if (route == null) {
+            return null;
+        }
+
+        if (type.isInstance(route)) {
+            return type.cast(route);
+        }
+
+        try {
+            Method m = route.getClass().getMethod("getProcessor");
+
+            Processor child = (Processor) ObjectHelper.invokeMethod(m, route);
+            // look its children
+            return findProceesorInRoute(child, type);
+        } catch (NoSuchMethodException e) {
+            // ignore
+        }
+
+        try {
+            Method m = route.getClass().getMethod("getProcessors");
+
+            // look its children
+            Collection<Processor> children = (Collection<Processor>) ObjectHelper.invokeMethod(m, route);
+            for (Processor child : children) {
+                T out = findProceesorInRoute(child, type);
+                if (out != null) {
+                    return out;
+                }
+            }
+        } catch (NoSuchMethodException e) {
+            // ignore
+        }
+
+        try {
+            Method m = route.getClass().getMethod("getFilters");
+
+            // look its children
+            List<FilterProcessor> children = (List<FilterProcessor>) ObjectHelper.invokeMethod(m, route);
+            for (Processor child : children) {
+                T out = findProceesorInRoute(child, type);
+                if (out != null) {
+                    return out;
+                }
+            }
+        } catch (NoSuchMethodException e) {
+            // ignore
+        }
+
+        try {
+            Method m = route.getClass().getMethod("getOtherwise");
+
+            Processor child = (Processor) ObjectHelper.invokeMethod(m, route);
+            // look its children
+            return findProceesorInRoute(child, type);
+        } catch (NoSuchMethodException e) {
+            // ignore
+        }
+
+        return null;
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                errorHandler(noErrorHandler());
+
+                from("direct:start")
+                        .choice()
+                        .when(header("foo").isEqualTo("bar")).to("direct:end")
+                        .otherwise().end();
+
+                from("direct:end")
+                        .process(new Processor() {
+                            public void process(Exchange exchange) {
+                                assertEquals("Hello World", exchange.getIn().getBody(String.class));
+                            }
+                        }).to("mock:result");
+            }
+        };
+    }
+}

Propchange: camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/processor/ChoiceNoErrorHandlerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/processor/ChoiceNoErrorHandlerTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date