You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ha...@apache.org on 2008/04/30 04:36:03 UTC
svn commit: r652234 - in /activemq/camel/trunk:
camel-core/src/main/java/org/apache/camel/language/simple/
camel-core/src/main/java/org/apache/camel/model/
camel-core/src/main/java/org/apache/camel/processor/
camel-core/src/main/resources/org/apache/ca...
Author: hadrian
Date: Tue Apr 29 19:36:03 2008
New Revision: 652234
URL: http://svn.apache.org/viewvc?rev=652234&view=rev
Log:
CAMEL-201. Patch applied with thanks!
Added:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/TransformType.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/TransformProcessor.java
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SetOutBodyTest.java
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TransformProcessorTest.java
activemq/camel/trunk/camel-core/src/test/resources/org/apache/camel/model/transform.xml
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/TransformWithExpressionTest.java
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/transformWithExpressionContext.xml
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/SimpleLanguage.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
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/model/XmlParseTest.java
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/SimpleLanguage.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/SimpleLanguage.java?rev=652234&r1=652233&r2=652234&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/SimpleLanguage.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/SimpleLanguage.java Tue Apr 29 19:36:03 2008
@@ -30,7 +30,7 @@
/**
* A <a href="http://activemq.apache.org/camel/simple.html>simple language</a>
- * which maps simple property style notations to acces headers and bodies.
+ * which maps simple property style notations to access headers and bodies.
* Examples of supported expressions are <p/>
* <ul>
* <li>in.header.foo or header.foo to access an inbound header called 'foo'</li>
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=652234&r1=652233&r2=652234&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 Tue Apr 29 19:36:03 2008
@@ -1084,26 +1084,48 @@
public Type setBody(Expression expression) {
return process(ProcessorBuilder.setBody(expression));
}
-
+
/**
* Adds a processor which sets the body on the OUT message
+ *
+ * @deprecated Please use {@link #transform(Expression)} instead
*/
public Type setOutBody(Expression expression) {
- return process(ProcessorBuilder.setOutBody(expression));
+ return transform(expression);
}
/**
* Adds a processor which sets the body on the OUT message
+ *
+ * @deprecated Please use {@link #transform()} instead
*/
public ExpressionClause<ProcessorType<Type>> setOutBody() {
- ExpressionClause<ProcessorType<Type>> clause = new ExpressionClause<ProcessorType<Type>>((Type) this);
- process(ProcessorBuilder.setOutBody(clause));
- return clause;
+ return transform();
+ }
+
+ /**
+ * Adds a processor which sets the body on the OUT message
+ */
+ public Type transform(Expression expression) {
+ TransformType answer = new TransformType(expression);
+ addOutput(answer);
+ return (Type) this;
}
/**
- * Adds a processor which sets the body on the FAULT message
+ * Adds a processor which sets the body on the OUT message
*/
+ public ExpressionClause<ProcessorType<Type>> transform() {
+ ExpressionClause<ProcessorType<Type>> clause = new ExpressionClause<ProcessorType<Type>>(
+ (Type) this);
+ TransformType answer = new TransformType(clause);
+ addOutput(answer);
+ return clause;
+ }
+
+ /**
+ * Adds a processor which sets the body on the FAULT message
+ */
public Type setFaultBody(Expression expression) {
return process(ProcessorBuilder.setFaultBody(expression));
}
Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/TransformType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/TransformType.java?rev=652234&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/TransformType.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/TransformType.java Tue Apr 29 19:36:03 2008
@@ -0,0 +1,51 @@
+/**
+ * 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 javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.Expression;
+import org.apache.camel.Processor;
+import org.apache.camel.impl.RouteContext;
+import org.apache.camel.processor.TransformProcessor;
+
+@XmlRootElement(name = "transform")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class TransformType extends ExpressionNode {
+
+ public TransformType() {
+ }
+
+ public TransformType(Expression expression) {
+ super(expression);
+ }
+
+ @Override
+ public String toString() {
+ return "Transform[ " + getExpression() + "]";
+ }
+
+ @Override
+ public Processor createProcessor(RouteContext routeContext) throws Exception {
+ Expression expr = getExpression().createExpression(routeContext);
+ Processor childProcessor = routeContext.createProcessor(this);
+
+ return new TransformProcessor(expr, childProcessor);
+ }
+}
Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/TransformProcessor.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/TransformProcessor.java?rev=652234&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/TransformProcessor.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/TransformProcessor.java Tue Apr 29 19:36:03 2008
@@ -0,0 +1,53 @@
+/**
+ *
+ * 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.Exchange;
+import org.apache.camel.Expression;
+import org.apache.camel.Processor;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * A processor which sets the body on the OUT message with an expression
+ */
+public class TransformProcessor extends DelegateProcessor implements Processor {
+ private static final transient Log LOG = LogFactory.getLog(TransformProcessor.class);
+ private Expression expression;
+
+ public TransformProcessor(Expression expression) {
+ this.expression = expression;
+ }
+
+ public TransformProcessor(Expression expression, Processor childProcessor) {
+ super(childProcessor);
+ this.expression = expression;
+ }
+
+ public void process(Exchange exchange) throws Exception {
+ Object newBody = expression.evaluate(exchange);
+ exchange.getOut().setBody(newBody);
+
+ super.process(exchange);
+ }
+
+ @Override
+ public String toString() {
+ return "transform(" + expression + ")";
+ }
+}
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=652234&r1=652233&r2=652234&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 Tue Apr 29 19:36:03 2008
@@ -49,6 +49,7 @@
ThreadType
ThrowFaultType
ToType
+TransformType
TryType
UnmarshalType
WhenType
Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/model/XmlParseTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/model/XmlParseTest.java?rev=652234&r1=652233&r2=652234&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/model/XmlParseTest.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/model/XmlParseTest.java Tue Apr 29 19:36:03 2008
@@ -81,6 +81,14 @@
assertChildTo(route, "seda:b", "seda:c", "seda:d");
}
+ public void testParseTransformXml() throws Exception {
+ RouteType route = assertOneRoute("transform.xml");
+ assertFrom(route, "direct:start");
+ TransformType node = assertTransform(route);
+ assertExpression(node.getExpression(), "simple", "${in.body} extra data!");
+ assertChildTo(route, "mock:end", 1);
+ }
+
public void testParseSetHeaderXml() throws Exception {
RouteType route = assertOneRoute("setHeader.xml");
assertFrom(route, "seda:a");
@@ -280,6 +288,11 @@
ProcessorType<?> processor = route.getOutputs().get(0);
return assertIsInstanceOf(SetHeaderType.class, processor);
}
+
+ protected TransformType assertTransform(ProcessorType<?> route) {
+ ProcessorType<?> processor = route.getOutputs().get(0);
+ return assertIsInstanceOf(TransformType.class, processor);
+ }
protected ChoiceType assertChoice(ProcessorType<?> route) {
ProcessorType<?> processor = assertOneElement(route.getOutputs());
Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SetOutBodyTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SetOutBodyTest.java?rev=652234&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SetOutBodyTest.java (added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SetOutBodyTest.java Tue Apr 29 19:36:03 2008
@@ -0,0 +1,36 @@
+/**
+ * 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.builder.RouteBuilder;
+
+/*
+ * This tests whether the deprecated setOutBody method in ProcessorType behaves the
+ * same as the new transform method.
+ */
+public class SetOutBodyTest extends TransformProcessorTest {
+
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ // START SNIPPET: example
+ from("direct:start").setOutBody(body().append(" World!")).to("mock:result");
+ // END SNIPPET: example
+ }
+ };
+ }
+}
Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TransformProcessorTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TransformProcessorTest.java?rev=652234&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TransformProcessorTest.java (added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TransformProcessorTest.java Tue Apr 29 19:36:03 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.processor;
+
+import org.apache.camel.builder.RouteBuilder;
+
+public class TransformProcessorTest extends TransformViaDSLTest {
+
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ // START SNIPPET: example
+ from("direct:start").transform(body().append(" World!")).to("mock:result");
+ // END SNIPPET: example
+ }
+ };
+ }
+}
Added: activemq/camel/trunk/camel-core/src/test/resources/org/apache/camel/model/transform.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/resources/org/apache/camel/model/transform.xml?rev=652234&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/resources/org/apache/camel/model/transform.xml (added)
+++ activemq/camel/trunk/camel-core/src/test/resources/org/apache/camel/model/transform.xml Tue Apr 29 19:36:03 2008
@@ -0,0 +1,26 @@
+<?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.
+-->
+<routes id="camel" xmlns="http://activemq.apache.org/camel/schema/spring">
+ <route>
+ <from uri="direct:start"/>
+ <transform>
+ <simple>${in.body} extra data!</simple>
+ </transform>
+ <to uri="mock:end"/>
+ </route>
+</routes>
Added: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/TransformWithExpressionTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/TransformWithExpressionTest.java?rev=652234&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/TransformWithExpressionTest.java (added)
+++ activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/TransformWithExpressionTest.java Tue Apr 29 19:36:03 2008
@@ -0,0 +1,45 @@
+/**
+ * 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.component.mock.MockEndpoint;
+import org.apache.camel.spring.SpringTestSupport;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class TransformWithExpressionTest extends SpringTestSupport {
+ protected MockEndpoint endEndpoint;
+
+ public void testTransforms() throws Exception {
+ endEndpoint.expectedBodiesReceived("Some data plus ... extra data!");
+
+ template.sendBody("direct:start", "Some data plus ...");
+
+ assertMockEndpointsSatisifed();
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ endEndpoint = getMockEndpoint("mock:end");
+ }
+
+
+ protected ClassPathXmlApplicationContext createApplicationContext() {
+ return new ClassPathXmlApplicationContext("org/apache/camel/spring/processor/transformWithExpressionContext.xml");
+ }
+}
\ No newline at end of file
Added: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/transformWithExpressionContext.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/transformWithExpressionContext.xml?rev=652234&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/transformWithExpressionContext.xml (added)
+++ activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/transformWithExpressionContext.xml Tue Apr 29 19:36:03 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.0.xsd
+ http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
+ ">
+
+ <!-- START SNIPPET: example -->
+ <camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
+ <route>
+ <from uri="direct:start"/>
+ <transform>
+ <simple>${in.body} extra data!</simple>
+ </transform>
+ <to uri="mock:end"/>
+ </route>
+ </camelContext>
+ <!-- END SNIPPET: example -->
+
+</beans>