You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2008/09/06 04:06:07 UTC
svn commit: r692605 - 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/test/java/org/apache/camel/spring/processor/
components/camel-sp...
Author: ningjiang
Date: Fri Sep 5 19:06:07 2008
New Revision: 692605
URL: http://svn.apache.org/viewvc?rev=692605&view=rev
Log:
CAMEL-878 applied patch with thanks to Jonathan
Added:
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringInterceptorWithStopTest.java (with props)
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptorWithStopTest.xml (with props)
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptType.java
activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptType.java?rev=692605&r1=692604&r2=692605&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptType.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptType.java Fri Sep 5 19:06:07 2008
@@ -22,6 +22,7 @@
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
@@ -32,6 +33,7 @@
import org.apache.camel.processor.Interceptor;
import org.apache.camel.spi.RouteContext;
+
/**
* Represents an XML <intercept/> element
*
@@ -40,11 +42,11 @@
@XmlRootElement(name = "intercept")
@XmlAccessorType(XmlAccessType.FIELD)
public class InterceptType extends OutputType<ProcessorType> {
-
+
@XmlTransient
private ProceedType proceed = new ProceedType();
@XmlTransient
- private Boolean stop = Boolean.FALSE;
+ private Boolean stopIntercept = Boolean.FALSE;
@XmlTransient
private Boolean usePredicate = Boolean.FALSE;
@@ -84,12 +86,19 @@
}
public void stopIntercept() {
- stop = Boolean.TRUE;
+ setStopIntercept(Boolean.TRUE);
}
+ @XmlElement(name = "stop", required = false)
+ public void setStop(String elementValue /* not used */) {
+ stopIntercept();
+ }
+
public InterceptType createProxy() {
InterceptType answer = new InterceptType();
answer.getOutputs().addAll(this.getOutputs());
+
+ answer.setStopIntercept(getStopIntercept());
// hack: now we need to replace the proceed of the proxy with its own
// a bit ugly, operating based on the assumption that the proceed is
@@ -105,19 +114,19 @@
// for the predicated version we add the proceed() to otherwise()
// before knowing if stop() will follow, so let's make a small adjustment
- if (usePredicate.booleanValue() && stop.booleanValue()) {
+ if (usePredicate.booleanValue() && getStopIntercept().booleanValue()) {
WhenType when = choice.getWhenClauses().get(0);
when.getOutputs().remove(this.getProceed());
}
// add proceed to the when clause
addProceedProxy(this.getProceed(), answer.getProceed(),
- choice.getWhenClauses().get(choice.getWhenClauses().size() - 1), usePredicate.booleanValue() && !stop.booleanValue());
+ choice.getWhenClauses().get(choice.getWhenClauses().size() - 1), usePredicate.booleanValue() && !getStopIntercept().booleanValue());
// force adding a proceed at the end (otherwise) if its not a stop type
- addProceedProxy(this.getProceed(), answer.getProceed(), choice.getOtherwise(), !stop.booleanValue());
+ addProceedProxy(this.getProceed(), answer.getProceed(), choice.getOtherwise(), !getStopIntercept().booleanValue());
- if (stop.booleanValue()) {
+ if (getStopIntercept().booleanValue()) {
// must add proceed to when clause if stop is explictiy declared, otherwise when the
// predicate test fails then there is no proceed
// See example: InterceptorSimpleRouteTest (City Paris is never proceeded)
@@ -130,7 +139,7 @@
}
if (choice == null) {
// force adding a proceed at the end if its not a stop type
- addProceedProxy(this.getProceed(), answer.getProceed(), answer, !stop.booleanValue());
+ addProceedProxy(this.getProceed(), answer.getProceed(), answer, !getStopIntercept().booleanValue());
}
}
@@ -150,4 +159,12 @@
}
}
+ public void setStopIntercept(Boolean stop) {
+ this.stopIntercept = stop;
+ }
+
+ public Boolean getStopIntercept() {
+ return stopIntercept;
+ }
+
}
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=692605&r1=692604&r2=692605&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 Fri Sep 5 19:06:07 2008
@@ -39,6 +39,7 @@
import org.apache.camel.model.ExceptionType;
import org.apache.camel.model.IdentifiedType;
import org.apache.camel.model.InterceptType;
+import org.apache.camel.model.ProceedType;
import org.apache.camel.model.ProcessorType;
import org.apache.camel.model.RouteBuilderRef;
import org.apache.camel.model.RouteContainer;
@@ -190,7 +191,13 @@
route.addOutput(proxy);
route.pushBlock(proxy.getProceed());
- route.getOutputs().addAll(outputs);
+ int outputsSize = proxy.getOutputs().size();
+ if (outputsSize > 0) {
+ ProcessorType<?> processorType = proxy.getOutputs().get(outputsSize - 1);
+ if (processorType instanceof ProceedType) {
+ route.getOutputs().addAll(outputs);
+ }
+ }
}
}
Added: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringInterceptorWithStopTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringInterceptorWithStopTest.java?rev=692605&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringInterceptorWithStopTest.java (added)
+++ activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringInterceptorWithStopTest.java Fri Sep 5 19:06:07 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 SpringInterceptorWithStopTest extends ContextTestSupport {
+
+ public void testSetInterceptorWithStop() throws Exception {
+ MockEndpoint inteceptorEndpoint = getMockEndpoint("mock:middle1");
+ MockEndpoint resultEndpoint = getMockEndpoint("mock:end");
+ resultEndpoint.expectedMessageCount(0);
+ 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/SpringInterceptorWithStopTest.xml");
+ }
+
+}
Propchange: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringInterceptorWithStopTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringInterceptorWithStopTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptorWithStopTest.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptorWithStopTest.xml?rev=692605&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptorWithStopTest.xml (added)
+++ activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptorWithStopTest.xml Fri Sep 5 19:06:07 2008
@@ -0,0 +1,37 @@
+<?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"/>
+ <stop/>
+ </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/SpringInterceptorWithStopTest.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptorWithStopTest.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptorWithStopTest.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml