camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1309735 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/ main/java/org/apache/camel/builder/ main/java/org/apache/camel/impl/ main/java/org/apache/camel/model/ main/java/org/apache/camel/util/ test/java/org/apache/camel/proces...
Date Thu, 05 Apr 2012 10:17:43 GMT
Author: davsclaus
Date: Thu Apr  5 10:17:42 2012
New Revision: 1309735

URL: http://svn.apache.org/viewvc?rev=1309735&view=rev
Log:
CAMEL-5129: Fixed interceptFrom to support property placeholders.

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptFromPropertyPlaceholderTest.java
    camel/trunk/camel-core/src/test/resources/org/apache/camel/processor/intercept/
    camel/trunk/camel-core/src/test/resources/org/apache/camel/processor/intercept/myproperties.properties
      - copied, changed from r1309668, camel/trunk/camel-core/src/test/resources/org/apache/camel/component/properties/myproperties.properties
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/builder/AdviceWithRouteBuilder.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/InterceptSendToMockEndpointStrategy.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptSendToEndpointDefinition.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java?rev=1309735&r1=1309734&r2=1309735&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java Thu Apr  5 10:17:42
2012
@@ -308,7 +308,7 @@ public interface CamelContext extends Su
      * @param pattern an uri or pattern to match
      * @return a collection of endpoints removed which could be empty if there are no endpoints
found for the given <tt>pattern</tt>
      * @throws Exception if at least one endpoint could not be stopped
-     * @see org.apache.camel.util.EndpointHelper#matchEndpoint(String, String) for pattern
+     * @see org.apache.camel.util.EndpointHelper#matchEndpoint(CamelContext, String, String)
 for pattern
      */
     Collection<Endpoint> removeEndpoints(String pattern) throws Exception;
 

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/AdviceWithRouteBuilder.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/AdviceWithRouteBuilder.java?rev=1309735&r1=1309734&r2=1309735&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/builder/AdviceWithRouteBuilder.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/builder/AdviceWithRouteBuilder.java
Thu Apr  5 10:17:42 2012
@@ -82,7 +82,7 @@ public abstract class AdviceWithRouteBui
      *
      * @param pattern the pattern(s).
      * @throws Exception can be thrown if error occurred
-     * @see org.apache.camel.util.EndpointHelper#matchEndpoint(String, String)
+     * @see org.apache.camel.util.EndpointHelper#matchEndpoint(org.apache.camel.CamelContext,
String, String)
      */
     public void mockEndpoints(String... pattern) throws Exception {
         for (String s : pattern) {
@@ -95,7 +95,7 @@ public abstract class AdviceWithRouteBui
      *
      * @param pattern the pattern(s).
      * @throws Exception can be thrown if error occurred
-     * @see org.apache.camel.util.EndpointHelper#matchEndpoint(String, String)
+     * @see org.apache.camel.util.EndpointHelper#matchEndpoint(org.apache.camel.CamelContext,
String, String)
      */
     public void mockEndpointsAndSkip(String... pattern) throws Exception {
         for (String s : pattern) {

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java?rev=1309735&r1=1309734&r2=1309735&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java Thu Apr
 5 10:17:42 2012
@@ -101,7 +101,7 @@ public class NotifyBuilder {
      *
      * @param endpointUri uri of endpoint or pattern (see the EndpointHelper javadoc)
      * @return the builder
-     * @see org.apache.camel.util.EndpointHelper#matchEndpoint(String, String)
+     * @see org.apache.camel.util.EndpointHelper#matchEndpoint(org.apache.camel.CamelContext,
String, String)
      */
     public NotifyBuilder from(final String endpointUri) {
         stack.add(new EventPredicateSupport() {
@@ -115,7 +115,7 @@ public class NotifyBuilder {
             @Override
             public boolean onExchange(Exchange exchange) {
                 // filter non matching exchanges
-                return EndpointHelper.matchEndpoint(exchange.getFromEndpoint().getEndpointUri(),
endpointUri);
+                return EndpointHelper.matchEndpoint(context, exchange.getFromEndpoint().getEndpointUri(),
endpointUri);
             }
 
             public boolean matches() {
@@ -137,7 +137,7 @@ public class NotifyBuilder {
      *
      * @param routeId id of route or pattern (see the EndpointHelper javadoc)
      * @return the builder
-     * @see org.apache.camel.util.EndpointHelper#matchEndpoint(String, String)
+     * @see org.apache.camel.util.EndpointHelper#matchEndpoint(org.apache.camel.CamelContext,
String, String)
      */
     public NotifyBuilder fromRoute(final String routeId) {
         stack.add(new EventPredicateSupport() {
@@ -282,7 +282,7 @@ public class NotifyBuilder {
      *
      * @param endpointUri uri of endpoint or pattern (see the EndpointHelper javadoc)
      * @return the builder
-     * @see org.apache.camel.util.EndpointHelper#matchEndpoint(String, String)
+     * @see org.apache.camel.util.EndpointHelper#matchEndpoint(org.apache.camel.CamelContext,
String, String)
      */
     public NotifyBuilder wereSentTo(final String endpointUri) {
         // insert in start of stack but after the previous wereSentTo
@@ -304,7 +304,7 @@ public class NotifyBuilder {
 
             @Override
             public boolean onExchangeSent(Exchange exchange, Endpoint endpoint, long timeTaken)
{
-                if (EndpointHelper.matchEndpoint(endpoint.getEndpointUri(), endpointUri))
{
+                if (EndpointHelper.matchEndpoint(context, endpoint.getEndpointUri(), endpointUri))
{
                     sentTo = true;
                 }
                 return onExchange(exchange);

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?rev=1309735&r1=1309734&r2=1309735&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java Thu
Apr  5 10:17:42 2012
@@ -393,7 +393,7 @@ public class DefaultCamelContext extends
         } else {
             for (Map.Entry<EndpointKey, Endpoint> entry : endpoints.entrySet()) {
                 oldEndpoint = entry.getValue();
-                if (EndpointHelper.matchEndpoint(oldEndpoint.getEndpointUri(), uri)) {
+                if (EndpointHelper.matchEndpoint(this, oldEndpoint.getEndpointUri(), uri))
{
                     try {
                         stopServices(oldEndpoint);
                         answer.add(oldEndpoint);

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/InterceptSendToMockEndpointStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/InterceptSendToMockEndpointStrategy.java?rev=1309735&r1=1309734&r2=1309735&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/InterceptSendToMockEndpointStrategy.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/InterceptSendToMockEndpointStrategy.java
Thu Apr  5 10:17:42 2012
@@ -52,7 +52,7 @@ public class InterceptSendToMockEndpoint
      * Mock endpoints based on the given pattern.
      *
      * @param pattern the pattern.
-     * @see EndpointHelper#matchEndpoint(String, String)
+     * @see EndpointHelper#matchEndpoint(org.apache.camel.CamelContext, String, String)
      */
     public InterceptSendToMockEndpointStrategy(String pattern) {
         this(pattern, false);
@@ -63,7 +63,7 @@ public class InterceptSendToMockEndpoint
      *
      * @param pattern the pattern.
      * @param skip <tt>true</tt> to skip sending after the detour to the original
endpoint
-     * @see EndpointHelper#matchEndpoint(String, String)
+     * @see EndpointHelper#matchEndpoint(org.apache.camel.CamelContext, String, String)
      */
     public InterceptSendToMockEndpointStrategy(String pattern, boolean skip) {
         this.pattern = pattern;
@@ -77,7 +77,7 @@ public class InterceptSendToMockEndpoint
         } else if (endpoint instanceof MockEndpoint) {
             // we should not intercept mock endpoints
             return endpoint;
-        } else if (uri == null || pattern == null || EndpointHelper.matchEndpoint(uri, pattern))
{
+        } else if (uri == null || pattern == null || EndpointHelper.matchEndpoint(endpoint.getCamelContext(),
uri, pattern)) {
             // if pattern is null then it mean to match all
 
             // only proxy if the uri is matched decorate endpoint with our proxy

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptSendToEndpointDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptSendToEndpointDefinition.java?rev=1309735&r1=1309734&r2=1309735&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptSendToEndpointDefinition.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptSendToEndpointDefinition.java
Thu Apr  5 10:17:42 2012
@@ -80,7 +80,7 @@ public class InterceptSendToEndpointDefi
     }
 
     @Override
-    public Processor createProcessor(RouteContext routeContext) throws Exception {
+    public Processor createProcessor(final RouteContext routeContext) throws Exception {
         // create the detour
         final Processor detour = this.createChildProcessor(routeContext, true);
 
@@ -90,7 +90,7 @@ public class InterceptSendToEndpointDefi
                 if (endpoint instanceof InterceptSendToEndpoint) {
                     // endpoint already decorated
                     return endpoint;
-                } else if (getUri() == null || EndpointHelper.matchEndpoint(uri, getUri()))
{
+                } else if (getUri() == null || EndpointHelper.matchEndpoint(routeContext.getCamelContext(),
uri, getUri())) {
                     // only proxy if the uri is matched decorate endpoint with our proxy
                     // should be false by default
                     boolean skip = isSkipSendToOriginalEndpoint();

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java?rev=1309735&r1=1309734&r2=1309735&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java
Thu Apr  5 10:17:42 2012
@@ -270,7 +270,7 @@ public final class RouteDefinitionHelper
                             // lookup the endpoint to get its url
                             uri = CamelContextHelper.getMandatoryEndpoint(context, "ref:"
+ input.getRef()).getEndpointUri();
                         }
-                        if (EndpointHelper.matchEndpoint(uri, intercept.getUri())) {
+                        if (EndpointHelper.matchEndpoint(context, uri, intercept.getUri()))
{
                             match = true;
                             break;
                         }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java?rev=1309735&r1=1309734&r2=1309735&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java Thu Apr
 5 10:17:42 2012
@@ -91,6 +91,8 @@ public final class EndpointHelper {
     /**
      * Matches the endpoint with the given pattern.
      * <p/>
+     * The endpoint will first resolve property placeholders using {@link CamelContext#resolvePropertyPlaceholders(String)}.
+     * <p/>
      * The match rules are applied in this order:
      * <ul>
      *   <li>exact match, returns true</li>
@@ -99,11 +101,20 @@ public final class EndpointHelper {
      *   <li>otherwise returns false</li>
      * </ul>
      *
+     * @param context the Camel context, if <tt>null</tt> then property placeholder
resolution is skipped.
      * @param uri     the endpoint uri
      * @param pattern a pattern to match
      * @return <tt>true</tt> if match, <tt>false</tt> otherwise.
      */
-    public static boolean matchEndpoint(String uri, String pattern) {
+    public static boolean matchEndpoint(CamelContext context, String uri, String pattern)
{
+        if (context != null) {
+            try {
+                uri = context.resolvePropertyPlaceholders(uri);
+            } catch (Exception e) {
+                throw new ResolveEndpointFailedException(uri, e);
+            }
+        }
+
         // normalize uri so we can do endpoint hits with minor mistakes and parameters is
not in the same order
         try {
             uri = URISupport.normalizeUri(uri);
@@ -133,6 +144,17 @@ public final class EndpointHelper {
     }
 
     /**
+     * Matches the endpoint with the given pattern.
+     * @see #matchEndpoint(org.apache.camel.CamelContext, String, String)
+     *
+     * @deprecated use {@link #matchEndpoint(org.apache.camel.CamelContext, String, String)}
instead.
+     */
+    @Deprecated
+    public static boolean matchEndpoint(String uri, String pattern) {
+        return matchEndpoint(null, uri, pattern);
+    }
+
+    /**
      * Matches the name with the given pattern.
      * <p/>
      * The match rules are applied in this order:

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptFromPropertyPlaceholderTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptFromPropertyPlaceholderTest.java?rev=1309735&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptFromPropertyPlaceholderTest.java
(added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptFromPropertyPlaceholderTest.java
Thu Apr  5 10:17:42 2012
@@ -0,0 +1,61 @@
+/**
+ * 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.intercept;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.properties.PropertiesComponent;
+
+/**
+ *
+ */
+public class InterceptFromPropertyPlaceholderTest extends ContextTestSupport {
+
+    public void testInterceptFrom() throws Exception {
+        getMockEndpoint("mock:foo").expectedMessageCount(1);
+        getMockEndpoint("mock:result").expectedMessageCount(1);
+
+        template.sendBody("seda:foo", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                interceptFrom("seda:foo").to("mock:foo");
+
+                from("seda:{{queue}}").to("mock:result");
+            }
+        };
+    }
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+
+        PropertiesComponent pc = new PropertiesComponent();
+        pc.setLocation("classpath:org/apache/camel/processor/intercept/myproperties.properties");
+        context.addComponent("properties", pc);
+
+        return context;
+    }
+
+}

Copied: camel/trunk/camel-core/src/test/resources/org/apache/camel/processor/intercept/myproperties.properties
(from r1309668, camel/trunk/camel-core/src/test/resources/org/apache/camel/component/properties/myproperties.properties)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/resources/org/apache/camel/processor/intercept/myproperties.properties?p2=camel/trunk/camel-core/src/test/resources/org/apache/camel/processor/intercept/myproperties.properties&p1=camel/trunk/camel-core/src/test/resources/org/apache/camel/component/properties/myproperties.properties&r1=1309668&r2=1309735&rev=1309735&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/resources/org/apache/camel/component/properties/myproperties.properties
(original)
+++ camel/trunk/camel-core/src/test/resources/org/apache/camel/processor/intercept/myproperties.properties
Thu Apr  5 10:17:42 2012
@@ -15,20 +15,4 @@
 ## limitations under the License.
 ## ---------------------------------------------------------------------------
 
-cool.end=mock:result
-cool.result=result
-cool.concat=mock:{{cool.result}}
-cool.start=direct:cool
-cool.showid=true
-
-# circular reference test
-cool.a={{cool.b}}
-cool.b={{cool.c}}
-cool.c={{cool.a}}
-
-cool.mock=mock
-
-myCoolCharset=iso-8859-1
-slipDelimiter=##
-
-stop=true
\ No newline at end of file
+queue=foo
\ No newline at end of file



Mime
View raw message