svn commit: r691588 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/model/ components/camel-spring/src/main/java/org/apache/camel/spring/ components/camel-spring/src/main/java/org/apache/camel/spring/handler/ components/camel-spri...

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r691588 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/model/ components/camel-spring/src/main/java/org/apache/camel/spring/ components/camel-spring/src/main/java/org/apache/camel/spring/handler/ components/camel-spri...

ningjiang
Author: ningjiang
Date: Wed Sep  3 05:30:04 2008
New Revision: 691588

URL: http://svn.apache.org/viewvc?rev=691588&view=rev
Log:
CAMEL-460 added the <intercept> tag under the <camelContext>

Added:
    activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringInterceptorTest.java   (with props)
    activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptorTest.xml   (with props)
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java
    activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
    activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java?rev=691588&r1=691587&r2=691588&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java Wed Sep  3 05:30:04 2008
@@ -901,11 +901,11 @@
         addInterceptor(new InterceptorRef(interceptor));
     }
 
-    protected void pushBlock(Block block) {
+    public void pushBlock(Block block) {
         blocks.add(block);
     }
 
-    protected Block popBlock() {
+    public Block popBlock() {
         return blocks.isEmpty() ? null : blocks.removeLast();
     }
 
@@ -1636,6 +1636,10 @@
         List<Processor> list = new ArrayList<Processor>();
         for (ProcessorType output : outputs) {
             Processor processor = output.createProcessor(routeContext);
+            // if the ProceedType create processor is null we keep on going
+            if (output instanceof ProceedType && processor == null) {
+                continue;
+            }
             processor = output.wrapProcessorInInterceptors(routeContext, processor);
 
             ProcessorType currentProcessor = this;

Modified: activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java?rev=691588&r1=691587&r2=691588&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java (original)
+++ activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java Wed Sep  3 05:30:04 2008
@@ -35,7 +35,11 @@
 import org.apache.camel.impl.DefaultLifecycleStrategy;
 import org.apache.camel.management.DefaultInstrumentationAgent;
 import org.apache.camel.management.InstrumentationLifecycleStrategy;
+import org.apache.camel.management.InstrumentationProcessor;
+import org.apache.camel.model.ExceptionType;
 import org.apache.camel.model.IdentifiedType;
+import org.apache.camel.model.InterceptType;
+import org.apache.camel.model.ProcessorType;
 import org.apache.camel.model.RouteBuilderRef;
 import org.apache.camel.model.RouteContainer;
 import org.apache.camel.model.RouteType;
@@ -93,6 +97,8 @@
     private List<EndpointFactoryBean> endpoints;
     @XmlElementRef
     private List<DataFormatType> dataFormats;
+    @XmlElement(name = "intercept", required = false)
+    private List<InterceptType> intercepts = new ArrayList<InterceptType>();
     @XmlElement(name = "route", required = false)
     private List<RouteType> routes = new ArrayList<RouteType>();
     @XmlTransient
@@ -159,6 +165,35 @@
             }
         }
 
+        // setup the intercepts
+        for (RouteType route : routes) {
+
+            for (InterceptType intercept : intercepts) {
+                List<ProcessorType<?>> outputs = new ArrayList<ProcessorType<?>>();
+                List<ProcessorType<?>> exceptionHandlers = new ArrayList<ProcessorType<?>>();
+                for (ProcessorType output : route.getOutputs()) {
+                    if (output instanceof ExceptionType) {
+                        exceptionHandlers.add(output);
+                    } else {
+                        outputs.add(output);
+                    }
+                }
+
+                // clearing the outputs
+                route.clearOutput();
+
+                // add exception handlers as top children
+                route.getOutputs().addAll(exceptionHandlers);
+
+                // add the interceptor
+                InterceptType proxy = intercept.createProxy();
+                route.addOutput(proxy);
+                route.pushBlock(proxy.getProceed());
+
+                route.getOutputs().addAll(outputs);
+            }
+
+        }
         // lets force any lazy creation
         getContext().addRouteDefinitions(routes);
 
@@ -256,6 +291,14 @@
         this.routes = routes;
     }
 
+    public List<InterceptType> getIntercepts() {
+        return intercepts;
+    }
+
+    public void setIntercepts(List<InterceptType> intercepts) {
+        this.intercepts = intercepts;
+    }
+
     public RouteBuilder getRouteBuilder() {
         return routeBuilder;
     }

Modified: activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java?rev=691588&r1=691587&r2=691588&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java (original)
+++ activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java Wed Sep  3 05:30:04 2008
@@ -196,6 +196,7 @@
                 CamelContextFactoryBean factoryBean = (CamelContextFactoryBean)value;
                 builder.addPropertyValue("id", contextId);
                 builder.addPropertyValue("routes", factoryBean.getRoutes());
+                builder.addPropertyValue("intercepts", factoryBean.getIntercepts());
                 builder.addPropertyValue("builderRefs", factoryBean.getBuilderRefs());
 
                 if (factoryBean.getPackages().length > 0) {

Added: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringInterceptorTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringInterceptorTest.java?rev=691588&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringInterceptorTest.java (added)
+++ activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringInterceptorTest.java Wed Sep  3 05:30:04 2008
@@ -0,0 +1,44 @@
+/**
+ * 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.spring.processor;
+
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.component.mock.MockEndpoint;
+
+import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
+
+public class SpringInterceptorTest extends ContextTestSupport {
+
+    public void testSetInterceptor() throws Exception {
+        MockEndpoint inteceptorEndpoint = getMockEndpoint("mock:middle1");
+        MockEndpoint resultEndpoint = getMockEndpoint("mock:end");
+        resultEndpoint.expectedBodiesReceived("Hello World!");
+        inteceptorEndpoint.expectedBodiesReceived("Hello World!");
+
+        sendBody("direct:start", "Hello World!");
+
+        inteceptorEndpoint.assertIsSatisfied();
+        resultEndpoint.assertIsSatisfied();
+    }
+
+    protected CamelContext createCamelContext() throws Exception {
+        return createSpringCamelContext(this, "org/apache/camel/spring/processor/SpringInterceptorTest.xml");
+    }
+
+}

Propchange: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringInterceptorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringInterceptorTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptorTest.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptorTest.xml?rev=691588&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptorTest.xml (added)
+++ activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptorTest.xml Wed Sep  3 05:30:04 2008
@@ -0,0 +1,36 @@
+<?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.
+-->
+<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.5.xsd
+       http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
+    ">
+
+  <!-- START SNIPPET: example -->
+  <camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring">
+    <intercept>
+      <to uri="mock:middle1"/>
+    </intercept>
+    <route>
+      <from uri="direct:start"/>
+      <to uri="mock:end"/>
+    </route>
+  </camelContext>
+  <!-- END SNIPPET: example -->
+</beans>

Propchange: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptorTest.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptorTest.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptorTest.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml