You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2009/01/30 18:22:30 UTC
svn commit: r739340 - in /camel/trunk/camel-core/src:
main/java/org/apache/camel/ main/java/org/apache/camel/impl/
main/java/org/apache/camel/language/property/
main/java/org/apache/camel/model/language/
main/resources/META-INF/services/org/apache/came...
Author: janstey
Date: Fri Jan 30 17:22:29 2009
New Revision: 739340
URL: http://svn.apache.org/viewvc?rev=739340&view=rev
Log:
CAMEL-1299 - Add property language for extracting exchange properties
Added:
camel/trunk/camel-core/src/main/java/org/apache/camel/language/property/
camel/trunk/camel-core/src/main/java/org/apache/camel/language/property/PropertyLanguage.java (with props)
camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/PropertyExpression.java (with props)
camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/language/property
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RecipientListWithStringDelimitedPropertyTest.java (with props)
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/ProducerTemplate.java
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultProducerTemplate.java
camel/trunk/camel-core/src/main/resources/org/apache/camel/model/language/jaxb.index
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/ProducerTemplate.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/ProducerTemplate.java?rev=739340&r1=739339&r2=739340&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/ProducerTemplate.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/ProducerTemplate.java Fri Jan 30 17:22:29 2009
@@ -81,6 +81,17 @@
Object sendBodyAndHeader(Object body, String header, Object headerValue);
/**
+ * Sends the body to the default endpoint with a specified property and property
+ * value
+ *
+ * @param body the payload to send
+ * @param property the property name
+ * @param propertyValue the property value
+ * @return the result (see class javadoc)
+ */
+ Object sendBodyAndProperty(Object body, String property, Object propertyValue);
+
+ /**
* Sends the body to the default endpoint with the specified headers and
* header values
*
@@ -269,8 +280,60 @@
*/
Object sendBodyAndHeader(String endpoint, ExchangePattern pattern, Object body, String header,
Object headerValue);
+
+ /**
+ * Sends the body to an endpoint with a specified property and property value
+ *
+ * @param endpointUri the endpoint URI to send to
+ * @param body the payload to send
+ * @param property the property name
+ * @param propertyValue the property value
+ * @return the result (see class javadoc)
+ */
+ Object sendBodyAndProperty(String endpointUri, Object body, String property,
+ Object propertyValue);
+
+ /**
+ * Sends the body to an endpoint with a specified property and property value
+ *
+ * @param endpoint the Endpoint to send to
+ * @param body the payload to send
+ * @param property the property name
+ * @param propertyValue the property value
+ * @return the result (see class javadoc)
+ */
+ Object sendBodyAndProperty(Endpoint endpoint, Object body, String property,
+ Object propertyValue);
/**
+ * Sends the body to an endpoint with a specified property and property value
+ *
+ * @param endpoint the Endpoint to send to
+ * @param pattern the message {@link ExchangePattern} such as
+ * {@link ExchangePattern#InOnly} or {@link ExchangePattern#InOut}
+ * @param body the payload to send
+ * @param property the property name
+ * @param propertyValue the property value
+ * @return the result (see class javadoc)
+ */
+ Object sendBodyAndProperty(Endpoint endpoint, ExchangePattern pattern, Object body, String property,
+ Object propertyValue);
+
+ /**
+ * Sends the body to an endpoint with a specified property and property value
+ *
+ * @param endpoint the Endpoint URI to send to
+ * @param pattern the message {@link ExchangePattern} such as
+ * {@link ExchangePattern#InOnly} or {@link ExchangePattern#InOut}
+ * @param body the payload to send
+ * @param property the property name
+ * @param propertyValue the property value
+ * @return the result (see class javadoc)
+ */
+ Object sendBodyAndProperty(String endpoint, ExchangePattern pattern, Object body, String property,
+ Object propertyValue);
+
+ /**
* Sends the body to an endpoint with the specified headers and header
* values
*
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultProducerTemplate.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultProducerTemplate.java?rev=739340&r1=739339&r2=739340&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultProducerTemplate.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultProducerTemplate.java Fri Jan 30 17:22:29 2009
@@ -143,6 +143,29 @@
return extractResultBody(result, pattern);
}
+ public Object sendBodyAndProperty(String endpointUri, final Object body, final String property,
+ final Object propertyValue) {
+ return sendBodyAndProperty(resolveMandatoryEndpoint(endpointUri), body, property, propertyValue);
+ }
+
+ public Object sendBodyAndProperty(Endpoint endpoint, final Object body, final String property,
+ final Object propertyValue) {
+ Exchange result = send(endpoint, createBodyAndPropertyProcessor(body, property, propertyValue));
+ return extractResultBody(result);
+ }
+
+ public Object sendBodyAndProperty(Endpoint endpoint, ExchangePattern pattern, final Object body, final String property,
+ final Object propertyValue) {
+ Exchange result = send(endpoint, pattern, createBodyAndPropertyProcessor(body, property, propertyValue));
+ return extractResultBody(result, pattern);
+ }
+
+ public Object sendBodyAndProperty(String endpoint, ExchangePattern pattern, final Object body, final String property,
+ final Object propertyValue) {
+ Exchange result = send(endpoint, pattern, createBodyAndPropertyProcessor(body, property, propertyValue));
+ return extractResultBody(result, pattern);
+ }
+
public Object sendBodyAndHeaders(String endpointUri, final Object body, final Map<String, Object> headers) {
return sendBodyAndHeaders(resolveMandatoryEndpoint(endpointUri), body, headers);
}
@@ -231,6 +254,10 @@
return sendBodyAndHeader(getMandatoryDefaultEndpoint(), body, header, headerValue);
}
+ public Object sendBodyAndProperty(Object body, String property, Object propertyValue) {
+ return sendBodyAndProperty(getMandatoryDefaultEndpoint(), body, property, propertyValue);
+ }
+
public Object sendBodyAndHeaders(Object body, Map<String, Object> headers) {
return sendBodyAndHeaders(getMandatoryDefaultEndpoint(), body, headers);
}
@@ -292,6 +319,17 @@
};
}
+ protected Processor createBodyAndPropertyProcessor(final Object body, final String property, final Object propertyValue) {
+ return new Processor() {
+ public void process(Exchange exchange) {
+ exchange.setProperty(property, propertyValue);
+
+ Message in = exchange.getIn();
+ in.setBody(body);
+ }
+ };
+ }
+
protected Processor createSetBodyProcessor(final Object body) {
return new Processor() {
public void process(Exchange exchange) {
Added: camel/trunk/camel-core/src/main/java/org/apache/camel/language/property/PropertyLanguage.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/language/property/PropertyLanguage.java?rev=739340&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/language/property/PropertyLanguage.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/language/property/PropertyLanguage.java Fri Jan 30 17:22:29 2009
@@ -0,0 +1,41 @@
+/**
+ * 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.language.property;
+
+import org.apache.camel.Expression;
+import org.apache.camel.Predicate;
+import org.apache.camel.builder.ExpressionBuilder;
+import org.apache.camel.builder.PredicateBuilder;
+import org.apache.camel.spi.Language;
+
+/**
+ * A language for property expressions.
+ */
+public class PropertyLanguage implements Language {
+
+ public static Expression property(String propertyName) {
+ return ExpressionBuilder.propertyExpression(propertyName);
+ }
+
+ public Predicate createPredicate(String expression) {
+ return PredicateBuilder.toPredicate(createExpression(expression));
+ }
+
+ public Expression createExpression(String expression) {
+ return PropertyLanguage.property(expression);
+ }
+}
Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/language/property/PropertyLanguage.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/PropertyExpression.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/PropertyExpression.java?rev=739340&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/PropertyExpression.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/PropertyExpression.java Fri Jan 30 17:22:29 2009
@@ -0,0 +1,38 @@
+/**
+ * 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.language;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * An expression which extracts the named exchange property
+ *
+ * @version $Revision: 630591 $
+ */
+@XmlRootElement(name = "property")
+public class PropertyExpression extends ExpressionType {
+ public PropertyExpression() {
+ }
+
+ public PropertyExpression(String expression) {
+ super(expression);
+ }
+
+ public String getLanguage() {
+ return "property";
+ }
+}
\ No newline at end of file
Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/PropertyExpression.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/language/property
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/language/property?rev=739340&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/language/property (added)
+++ camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/language/property Fri Jan 30 17:22:29 2009
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+class=org.apache.camel.language.property.PropertyLanguage
Modified: camel/trunk/camel-core/src/main/resources/org/apache/camel/model/language/jaxb.index
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/language/jaxb.index?rev=739340&r1=739339&r2=739340&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/resources/org/apache/camel/model/language/jaxb.index (original)
+++ camel/trunk/camel-core/src/main/resources/org/apache/camel/model/language/jaxb.index Fri Jan 30 17:22:29 2009
@@ -26,6 +26,7 @@
MvelExpression
OgnlExpression
PhpExpression
+PropertyExpression
PythonExpression
RubyExpression
SimpleExpression
Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RecipientListWithStringDelimitedPropertyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RecipientListWithStringDelimitedPropertyTest.java?rev=739340&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RecipientListWithStringDelimitedPropertyTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RecipientListWithStringDelimitedPropertyTest.java Fri Jan 30 17:22:29 2009
@@ -0,0 +1,58 @@
+/**
+ * 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.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import static org.apache.camel.language.property.PropertyLanguage.property;
+
+/**
+ * @version $Revision: 736555 $
+ */
+public class RecipientListWithStringDelimitedPropertyTest extends ContextTestSupport {
+
+ public void testSendingAMessageUsingMulticastReceivesItsOwnExchange() throws Exception {
+ MockEndpoint x = getMockEndpoint("mock:x");
+ MockEndpoint y = getMockEndpoint("mock:y");
+ MockEndpoint z = getMockEndpoint("mock:z");
+
+ x.expectedBodiesReceived("answer");
+ y.expectedBodiesReceived("answer");
+ z.expectedBodiesReceived("answer");
+
+ sendBody();
+
+ assertMockEndpointsSatisfied();
+ }
+
+ protected void sendBody() {
+ template.sendBodyAndProperty("direct:a", "answer", "myProperty", "mock:x, mock:y, mock:z");
+ }
+
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ // START SNIPPET: example
+ from("direct:a").recipientList(property("myProperty"));
+ // END SNIPPET: example
+ }
+ };
+
+ }
+
+}
\ No newline at end of file
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RecipientListWithStringDelimitedPropertyTest.java
------------------------------------------------------------------------------
svn:eol-style = native