Author: davsclaus
Date: Thu Apr 5 10:22:58 2012
New Revision: 1309738
URL: http://svn.apache.org/viewvc?rev=1309738&view=rev
Log:
CAMEL-5129: Fixed interceptFrom to support property placeholders.
Added:
camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptFromPropertyPlaceholderTest.java
- copied unchanged from r1309735,
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptFromPropertyPlaceholderTest.java
camel/branches/camel-2.9.x/camel-core/src/test/resources/org/apache/camel/processor/intercept/
- copied from r1309735,
camel/trunk/camel-core/src/test/resources/org/apache/camel/processor/intercept/
Modified:
camel/branches/camel-2.9.x/ (props changed)
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/CamelContext.java
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/builder/AdviceWithRouteBuilder.java
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/InterceptSendToMockEndpointStrategy.java
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/model/InterceptSendToEndpointDefinition.java
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java
Propchange: camel/branches/camel-2.9.x/
------------------------------------------------------------------------------
svn:mergeinfo = /camel/trunk:1309735
Propchange: camel/branches/camel-2.9.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified:
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/CamelContext.java
URL:
http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/CamelContext.java?rev=1309738&r1=1309737&r2=1309738&view=diff
==============================================================================
---
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/CamelContext.java
(original)
+++
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/CamelContext.java
Thu Apr 5 10:22:58 2012
@@ -300,7 +300,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/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/builder/AdviceWithRouteBuilder.java
URL:
http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/builder/AdviceWithRouteBuilder.java?rev=1309738&r1=1309737&r2=1309738&view=diff
==============================================================================
---
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/builder/AdviceWithRouteBuilder.java
(original)
+++
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/builder/AdviceWithRouteBuilder.java
Thu Apr 5 10:22:58 2012
@@ -82,7 +82,7 @@ public abstract class AdviceWithRouteBui
*
* @param pattern the pattern.
* @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 {
getContext().addRegisterEndpointCallback(new
InterceptSendToMockEndpointStrategy(pattern));
Modified:
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java
URL:
http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java?rev=1309738&r1=1309737&r2=1309738&view=diff
==============================================================================
---
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java
(original)
+++
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java
Thu Apr 5 10:22:58 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/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL:
http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?rev=1309738&r1=1309737&r2=1309738&view=diff
==============================================================================
---
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
(original)
+++
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
Thu Apr 5 10:22:58 2012
@@ -382,7 +382,7 @@ public class DefaultCamelContext extends
} else {
for (Map.Entry entry : endpoints.entrySet()) {
oldEndpoint = (Endpoint)entry.getValue();
- if (EndpointHelper.matchEndpoint(oldEndpoint.getEndpointUri(),
uri)) {
+ if (EndpointHelper.matchEndpoint(this,
oldEndpoint.getEndpointUri(), uri)) {
try {
stopServices(oldEndpoint);
answer.add(oldEndpoint);
Modified:
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/InterceptSendToMockEndpointStrategy.java
URL:
http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/InterceptSendToMockEndpointStrategy.java?rev=1309738&r1=1309737&r2=1309738&view=diff
==============================================================================
---
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/InterceptSendToMockEndpointStrategy.java
(original)
+++
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/InterceptSendToMockEndpointStrategy.java
Thu Apr 5 10:22:58 2012
@@ -51,7 +51,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 = pattern;
@@ -64,7 +64,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/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/model/InterceptSendToEndpointDefinition.java
URL:
http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/model/InterceptSendToEndpointDefinition.java?rev=1309738&r1=1309737&r2=1309738&view=diff
==============================================================================
---
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/model/InterceptSendToEndpointDefinition.java
(original)
+++
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/model/InterceptSendToEndpointDefinition.java
Thu Apr 5 10:22:58 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);
@@ -91,7 +91,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 = getSkipSendToOriginalEndpoint() != null ?
getSkipSendToOriginalEndpoint() : false;
Modified:
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java
URL:
http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java?rev=1309738&r1=1309737&r2=1309738&view=diff
==============================================================================
---
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java
(original)
+++
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java
Thu Apr 5 10:22:58 2012
@@ -272,7 +272,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/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java
URL:
http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java?rev=1309738&r1=1309737&r2=1309738&view=diff
==============================================================================
---
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java
(original)
+++
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java
Thu Apr 5 10:22:58 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: