Author: ningjiang
Date: Wed Dec 10 01:41:55 2008
New Revision: 725040
URL: http://svn.apache.org/viewvc?rev=725040&view=rev
Log:
CAMEL-1171 supports to specify the ExchangePatterns explicitly in the routing
DSL
Added:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ExchangePatternType.java
(with props)
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/ExchangePatternProcessor.java
(with props)
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ExchangePatternTest.java
(with props)
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringExchangePatternTest.java
(with props)
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/exchangePattern.xml
(with props)
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/ExchangePattern.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/AggregatorType.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/CatchType.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java
activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/ExchangePattern.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/ExchangePattern.java?rev=725040&r1=725039&r2=725040&view=diff
==============================================================================
---
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/ExchangePattern.java
(original)
+++
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/ExchangePattern.java
Wed Dec 10 01:41:55 2008
@@ -100,6 +100,14 @@
public static ExchangePattern fromWsdlUri(String wsdlUri) {
return MAP.get(wsdlUri);
}
+
+ public static ExchangePattern asEnum(String value) {
+ try {
+ return valueOf(value);
+ } catch (Exception e) {
+ throw new IllegalArgumentException("Unknown message exchange
pattern: " + value);
+ }
+ }
static {
for (ExchangePattern mep : values()) {
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/AggregatorType.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/AggregatorType.java?rev=725040&r1=725039&r2=725040&view=diff
==============================================================================
---
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/AggregatorType.java
(original)
+++
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/AggregatorType.java
Wed Dec 10 01:41:55 2008
@@ -45,7 +45,7 @@
*/
@XmlRootElement(name = "aggregate")
@XmlAccessorType(XmlAccessType.FIELD)
-public class AggregatorType extends ProcessorType<ProcessorType> {
+public class AggregatorType extends ProcessorType<AggregatorType> {
@XmlElement(name = "correlationExpression", required = false)
private ExpressionSubElementType correlationExpression;
@XmlTransient
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/CatchType.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/CatchType.java?rev=725040&r1=725039&r2=725040&view=diff
==============================================================================
---
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/CatchType.java
(original)
+++
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/CatchType.java
Wed Dec 10 01:41:55 2008
@@ -38,7 +38,7 @@
*/
@XmlRootElement(name = "catch")
@XmlAccessorType(XmlAccessType.FIELD)
-public class CatchType extends ProcessorType<ProcessorType> {
+public class CatchType extends ProcessorType<CatchType> {
@XmlElement(name = "exception")
private List<String> exceptions = new ArrayList<String>();
@XmlElementRef
Added:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ExchangePatternType.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ExchangePatternType.java?rev=725040&view=auto
==============================================================================
---
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ExchangePatternType.java
(added)
+++
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ExchangePatternType.java
Wed Dec 10 01:41:55 2008
@@ -0,0 +1,102 @@
+/**
+ * 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.model;
+
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlTransient;
+
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.Processor;
+import org.apache.camel.processor.ExchangePatternProcessor;
+import org.apache.camel.spi.RouteContext;
+import org.apache.camel.util.ObjectHelper;
+
+/**
+ * Represents an XML <SetExchangePattern/> element
+ *
+ * @version $Revision$
+ */
[EMAIL PROTECTED](name = "setExchangePattern")
[EMAIL PROTECTED](XmlAccessType.FIELD)
+public class ExchangePatternType extends OutputType {
+ @XmlAttribute(name = "pattern", required = true)
+ private String pattern;
+ @XmlTransient
+ private ExchangePattern exchangePattern;
+ @XmlTransient
+ private ExchangePatternProcessor processor;
+
+ public ExchangePatternType() {
+ }
+
+ public ExchangePatternType(ExchangePattern ep) {
+ exchangePattern = ep;
+ pattern = exchangePattern.toString();
+ }
+
+ public void setPattern(String pattern) {
+ this.pattern = pattern;
+ exchangePattern = ExchangePattern.asEnum(pattern);
+ }
+
+ public String getPattern() {
+ return pattern;
+ }
+
+ public ExchangePattern getExchangePattern() {
+ if (exchangePattern == null) {
+ if (pattern != null) {
+ exchangePattern = ExchangePattern.asEnum(pattern);
+ } else {
+ exchangePattern = ExchangePattern.InOnly;
+ }
+ }
+ return exchangePattern;
+ }
+
+ @Override
+ public String getShortName() {
+ return "setExchangePattern";
+ }
+
+ @Override
+ public String toString() {
+ return "setExchangePattern["
+ + "exchangePattern: " + exchangePattern
+ + "]";
+ }
+
+ @Override
+ public String getLabel() {
+ return "exchangePattern: " + exchangePattern;
+ }
+
+ @Override
+ public Processor createProcessor(RouteContext routeContext) {
+ if (processor == null) {
+ processor = new ExchangePatternProcessor(getExchangePattern());
+ }
+ return processor;
+ }
+
+}
Propchange:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ExchangePatternType.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ExchangePatternType.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
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=725040&r1=725039&r2=725040&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 Dec 10 01:41:55 2008
@@ -34,6 +34,7 @@
import org.apache.camel.CamelContext;
import org.apache.camel.CamelException;
import org.apache.camel.Endpoint;
+import org.apache.camel.ExchangePattern;
import org.apache.camel.Expression;
import org.apache.camel.Predicate;
import org.apache.camel.Processor;
@@ -1653,6 +1654,40 @@
addOutput(new MarshalType(dataTypeRef));
return (Type) this;
}
+
+ /**
+ * <a
href="http://activemq.apache.org/camel/exchange-pattern.html">ExchangePattern:</a>
+ * set the ExchangePattern [EMAIL PROTECTED] ExchangePattern} into the
exchange
+ *
+ * @param exchangePattern instance of [EMAIL PROTECTED] ExchangePattern}
+ * @return the builder
+ */
+ public Type setExchangePattern(ExchangePattern exchangePattern) {
+ addOutput(new ExchangePatternType(exchangePattern));
+ return (Type) this;
+ }
+
+ /**
+ * <a
href="http://activemq.apache.org/camel/exchange-pattern.html">ExchangePattern:</a>
+ * set the exchange's ExchangePattern [EMAIL PROTECTED] ExchangePattern}
to be InOnly
+ *
+ *
+ * @return the builder
+ */
+ public Type inOnly() {
+ return setExchangePattern(ExchangePattern.InOnly);
+ }
+
+ /**
+ * <a
href="http://activemq.apache.org/camel/exchange-pattern.html">ExchangePattern:</a>
+ * set the exchange's ExchangePattern [EMAIL PROTECTED] ExchangePattern}
to be InOut
+ *
+ *
+ * @return the builder
+ */
+ public Type inOut() {
+ return setExchangePattern(ExchangePattern.InOut);
+ }
// Properties
//
-------------------------------------------------------------------------
Added:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/ExchangePatternProcessor.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/ExchangePatternProcessor.java?rev=725040&view=auto
==============================================================================
---
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/ExchangePatternProcessor.java
(added)
+++
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/ExchangePatternProcessor.java
Wed Dec 10 01:41:55 2008
@@ -0,0 +1,50 @@
+/**
+ * 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 org.apache.camel.AsyncCallback;
+import org.apache.camel.AsyncProcessor;
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.Processor;
+
+public class ExchangePatternProcessor implements AsyncProcessor {
+ private ExchangePattern exchangePattern = ExchangePattern.InOnly;
+
+ public ExchangePatternProcessor() {
+
+ }
+
+ public ExchangePatternProcessor(ExchangePattern ep) {
+ setExchangePattern(ep);
+ }
+
+ public void setExchangePattern(ExchangePattern ep) {
+ exchangePattern = ep;
+ }
+
+ public void process(Exchange exchange) throws Exception {
+ exchange.setPattern(exchangePattern);
+ }
+
+ public boolean process(Exchange exchange, AsyncCallback callback) {
+ exchange.setPattern(exchangePattern);
+ callback.done(true);
+ return true;
+ }
+
+}
Propchange:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/ExchangePatternProcessor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/ExchangePatternProcessor.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/jaxb.index?rev=725040&r1=725039&r2=725040&view=diff
==============================================================================
---
activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
(original)
+++
activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
Wed Dec 10 01:41:55 2008
@@ -22,6 +22,7 @@
DelayerType
Description
ExceptionType
+ExchangePatternType
ExpressionSubElementType
FilterType
FinallyType
Added:
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ExchangePatternTest.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ExchangePatternTest.java?rev=725040&view=auto
==============================================================================
---
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ExchangePatternTest.java
(added)
+++
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ExchangePatternTest.java
Wed Dec 10 01:41:55 2008
@@ -0,0 +1,66 @@
+/**
+ * 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 org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+public class ExchangePatternTest extends ContextTestSupport {
+
+ private void sendMessage(String uri, final ExchangePattern ep, final
String message) {
+ template.send(uri, new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ exchange.setPattern(ep);
+ exchange.getIn().setBody(message);
+ }
+
+ });
+ }
+
+ public void testInOut() throws Exception {
+ MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result",
MockEndpoint.class);
+ resultEndpoint.expectedBodiesReceived("InOnlyMessage");
+ sendMessage("direct:inOnly", ExchangePattern.InOnly, "InOnlyMessage");
+ resultEndpoint.assertIsSatisfied();
+ assertEquals("The exchange pattern should be InOut",
resultEndpoint.getExchanges().get(0).getPattern(), ExchangePattern.InOut);
+ }
+
+ public void testInOnly() throws Exception {
+ MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result",
MockEndpoint.class);
+ resultEndpoint.expectedBodiesReceived("InOutMessage");
+ sendMessage("direct:inOut", ExchangePattern.InOut, "InOutMessage");
+ resultEndpoint.assertIsSatisfied();
+ assertEquals("The exchange pattern should be InOnly",
resultEndpoint.getExchanges().get(0).getPattern(), ExchangePattern.InOnly);
+ }
+
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+
+ from("direct:inOnly").inOut().to("mock:result");
+
+
from("direct:inOut").setExchangePattern(ExchangePattern.InOnly).to("mock:result");
+
+ }
+ };
+ }
+
+}
Propchange:
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ExchangePatternTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ExchangePatternTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringExchangePatternTest.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringExchangePatternTest.java?rev=725040&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringExchangePatternTest.java
(added)
+++
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringExchangePatternTest.java
Wed Dec 10 01:41:55 2008
@@ -0,0 +1,32 @@
+/**
+ * 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.processor.ExchangePatternTest;
+import static
org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
+
+
+public class SpringExchangePatternTest extends ExchangePatternTest {
+
+ protected CamelContext createCamelContext() throws Exception {
+ return createSpringCamelContext(this,
"org/apache/camel/spring/processor/exchangePattern.xml");
+ }
+
+}
Propchange:
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringExchangePatternTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringExchangePatternTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/exchangePattern.xml
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/exchangePattern.xml?rev=725040&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/exchangePattern.xml
(added)
+++
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/exchangePattern.xml
Wed Dec 10 01:41:55 2008
@@ -0,0 +1,41 @@
+<?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
+ ">
+
+
+ <camelContext id="camel"
xmlns="http://activemq.apache.org/camel/schema/spring">
+ <route>
+ <from uri="direct:inOnly"/>
+ <setExchangePattern pattern="InOut"/>
+ <to uri="mock:result"/>
+ </route>
+
+ <route>
+ <from uri="direct:inOut"/>
+ <setExchangePattern pattern="InOnly"/>
+ <to uri="mock:result"/>
+ </route>
+ </camelContext>
+
+
+</beans>
Propchange:
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/exchangePattern.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/exchangePattern.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange:
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/exchangePattern.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml