You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2009/03/13 09:20:06 UTC
svn commit: r753155 - in /camel/trunk/camel-core/src:
main/java/org/apache/camel/builder/ main/java/org/apache/camel/model/
test/java/org/apache/camel/processor/
Author: davsclaus
Date: Fri Mar 13 08:20:05 2009
New Revision: 753155
URL: http://svn.apache.org/viewvc?rev=753155&view=rev
Log:
CAMEL-1226: Added toF and fromF for building String uris using String.format
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RouteFormattedUriTest.java (with props)
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/builder/Builder.java
camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/Builder.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/Builder.java?rev=753155&r1=753154&r2=753155&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/builder/Builder.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/builder/Builder.java Fri Mar 13 08:20:05 2009
@@ -16,7 +16,6 @@
*/
package org.apache.camel.builder;
-import org.apache.camel.Exchange;
import org.apache.camel.Expression;
/**
@@ -96,7 +95,7 @@
* Returns a predicate and value builder for the inbound message body as a
* specific type
*/
- public static <E extends Exchange, T> ValueBuilder bodyAs(Class<T> type) {
+ public static <T> ValueBuilder bodyAs(Class<T> type) {
Expression expression = ExpressionBuilder.bodyExpression(type);
return new ValueBuilder(expression);
}
@@ -114,7 +113,7 @@
* Returns a predicate and value builder for the outbound message body as a
* specific type
*/
- public static <E extends Exchange, T> ValueBuilder outBodyAs(Class<T> type) {
+ public static <T> ValueBuilder outBodyAs(Class<T> type) {
Expression expression = ExpressionBuilder.outBodyExpression(type);
return new ValueBuilder(expression);
}
@@ -132,7 +131,7 @@
* Returns a predicate and value builder for the fault message body as a
* specific type
*/
- public static <E extends Exchange, T> ValueBuilder faultBodyAs(Class<T> type) {
+ public static <T> ValueBuilder faultBodyAs(Class<T> type) {
Expression expression = ExpressionBuilder.faultBodyExpression(type);
return new ValueBuilder(expression);
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java?rev=753155&r1=753154&r2=753155&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java Fri Mar 13 08:20:05 2009
@@ -81,6 +81,19 @@
}
/**
+ * Creates a new route from the given URI input
+ *
+ * @param uri the String formatted from uri
+ * @param args arguments for the string formatting of the uri
+ * @return the builder
+ */
+ public RouteDefinition fromF(String uri, Object... args) {
+ RouteDefinition answer = routeCollection.from(String.format(uri, args));
+ configureRoute(answer);
+ return answer;
+ }
+
+ /**
* Creates a new route from the given endpoint
*
* @param endpoint the from endpoint
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java?rev=753155&r1=753154&r2=753155&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java Fri Mar 13 08:20:05 2009
@@ -126,6 +126,19 @@
return (Type) this;
}
+ /**
+ * Sends the exchange to the given endpoint
+ *
+ * @param uri the String formatted endpoint uri to send to
+ * @param args arguments for the string formatting of the uri
+ * @return the builder
+ */
+ @SuppressWarnings("unchecked")
+ public Type toF(String uri, Object... args) {
+ addOutput(new ToDefinition(String.format(uri, args)));
+ return (Type) this;
+ }
+
/**
* Sends the exchange to the given endpoint
Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RouteFormattedUriTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RouteFormattedUriTest.java?rev=753155&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RouteFormattedUriTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RouteFormattedUriTest.java Fri Mar 13 08:20:05 2009
@@ -0,0 +1,55 @@
+/**
+ * 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;
+
+/**
+ * @version $Revision$
+ */
+public class RouteFormattedUriTest extends ContextTestSupport {
+
+ private String path = "target/toformat";
+ private String name = "hello.txt";
+ private String pattern = ".*txt$";
+ private String result = "result";
+
+ public void testFormattedUri() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:" + result);
+ mock.expectedBodiesReceived("Hello World");
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ // START SNIPPET: e1
+ from("direct:start").toF("file://%s?fileName=%s", path, name);
+
+ fromF("file://%s?include=%s", path, pattern).toF("mock:%s", result);
+ // END SNIPPET: e1
+ }
+ };
+ }
+}
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RouteFormattedUriTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RouteFormattedUriTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date