This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push: new 3945fe7 CAMEL-14499: SendDynamicAware to share code in camel-support. 3945fe7 is described below commit 3945fe741c4e8ad9914fb8c4c3617e516e60f4ad Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Sat Sep 26 18:14:11 2020 +0200 CAMEL-14499: SendDynamicAware to share code in camel-support. --- .../file/GenericFileSendDynamicAware.java | 14 +++---- .../camel/http/base/HttpSendDynamicAware.java | 22 +++++----- .../support/component/SendDynamicAwareSupport.java | 47 ++++++++++++++++++++++ 3 files changed, 61 insertions(+), 22 deletions(-) diff --git a/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileSendDynamicAware.java b/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileSendDynamicAware.java index 2203a32..04059d5 100644 --- a/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileSendDynamicAware.java +++ b/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileSendDynamicAware.java @@ -20,13 +20,11 @@ import java.util.LinkedHashMap; import java.util.Map; import org.apache.camel.Exchange; -import org.apache.camel.ExtendedCamelContext; import org.apache.camel.Processor; -import org.apache.camel.catalog.RuntimeCamelCatalog; -import org.apache.camel.spi.SendDynamicAware; +import org.apache.camel.support.component.SendDynamicAwareSupport; import org.apache.camel.util.URISupport; -public abstract class GenericFileSendDynamicAware implements SendDynamicAware { +public abstract class GenericFileSendDynamicAware extends SendDynamicAwareSupport { private String scheme; @@ -42,9 +40,8 @@ public abstract class GenericFileSendDynamicAware implements SendDynamicAware { @Override public DynamicAwareEntry prepare(Exchange exchange, String uri, String originalUri) throws Exception { - RuntimeCamelCatalog catalog = exchange.getContext().adapt(ExtendedCamelContext.class).getRuntimeCamelCatalog(); - Map<String, String> properties = catalog.endpointProperties(uri); - Map<String, String> lenient = catalog.endpointLenientProperties(uri); + Map<String, String> properties = endpointProperties(exchange, uri); + Map<String, String> lenient = endpointLenientProperties(exchange, uri); return new DynamicAwareEntry(uri, originalUri, properties, lenient); } @@ -106,8 +103,7 @@ public abstract class GenericFileSendDynamicAware implements SendDynamicAware { } } - RuntimeCamelCatalog catalog = exchange.getContext().adapt(ExtendedCamelContext.class).getRuntimeCamelCatalog(); - return catalog.asEndpointUri(scheme, params, false); + return asEndpointUri(exchange, scheme, params); } else { return entry.getUri(); } diff --git a/components/camel-http-base/src/main/java/org/apache/camel/http/base/HttpSendDynamicAware.java b/components/camel-http-base/src/main/java/org/apache/camel/http/base/HttpSendDynamicAware.java index d7efd6c..9892acb 100644 --- a/components/camel-http-base/src/main/java/org/apache/camel/http/base/HttpSendDynamicAware.java +++ b/components/camel-http-base/src/main/java/org/apache/camel/http/base/HttpSendDynamicAware.java @@ -22,21 +22,19 @@ import java.util.LinkedHashMap; import java.util.Map; import org.apache.camel.Exchange; -import org.apache.camel.ExtendedCamelContext; import org.apache.camel.Processor; -import org.apache.camel.catalog.RuntimeCamelCatalog; -import org.apache.camel.spi.SendDynamicAware; +import org.apache.camel.support.component.SendDynamicAwareSupport; import org.apache.camel.util.ObjectHelper; import org.apache.camel.util.StringHelper; import org.apache.camel.util.URISupport; /** - * HTTP based {@link SendDynamicAware} which allows to optimise HTTP components with the toD (dynamic to) DSL in Camel. - * This implementation optimises by allowing to provide dynamic parameters via {@link Exchange#HTTP_PATH} and - * {@link Exchange#HTTP_QUERY} headers instead of the endpoint uri. That allows to use a static endpoint and its - * producer to service dynamic requests. + * HTTP based {@link org.apache.camel.spi.SendDynamicAware} which allows to optimise HTTP components with the toD + * (dynamic to) DSL in Camel. This implementation optimises by allowing to provide dynamic parameters via + * {@link Exchange#HTTP_PATH} and {@link Exchange#HTTP_QUERY} headers instead of the endpoint uri. That allows to use a + * static endpoint and its producer to service dynamic requests. */ -public class HttpSendDynamicAware implements SendDynamicAware { +public class HttpSendDynamicAware extends SendDynamicAwareSupport { private final Processor postProcessor = new HttpSendDynamicPostProcessor(); @@ -54,9 +52,8 @@ public class HttpSendDynamicAware implements SendDynamicAware { @Override public DynamicAwareEntry prepare(Exchange exchange, String uri, String originalUri) throws Exception { - RuntimeCamelCatalog catalog = exchange.getContext().adapt(ExtendedCamelContext.class).getRuntimeCamelCatalog(); - Map<String, String> properties = catalog.endpointProperties(uri); - Map<String, String> lenient = catalog.endpointLenientProperties(uri); + Map<String, String> properties = endpointProperties(exchange, uri); + Map<String, String> lenient = endpointLenientProperties(exchange, uri); return new DynamicAwareEntry(uri, originalUri, properties, lenient); } @@ -83,8 +80,7 @@ public class HttpSendDynamicAware implements SendDynamicAware { params.remove("path"); } } - RuntimeCamelCatalog catalog = exchange.getContext().adapt(ExtendedCamelContext.class).getRuntimeCamelCatalog(); - return catalog.asEndpointUri(scheme, params, false); + return asEndpointUri(exchange, scheme, params); } else { // no need for optimisation return null; diff --git a/core/camel-support/src/main/java/org/apache/camel/support/component/SendDynamicAwareSupport.java b/core/camel-support/src/main/java/org/apache/camel/support/component/SendDynamicAwareSupport.java new file mode 100644 index 0000000..12262db --- /dev/null +++ b/core/camel-support/src/main/java/org/apache/camel/support/component/SendDynamicAwareSupport.java @@ -0,0 +1,47 @@ +/* + * 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.support.component; + +import java.util.Map; + +import org.apache.camel.Exchange; +import org.apache.camel.ExtendedCamelContext; +import org.apache.camel.catalog.RuntimeCamelCatalog; +import org.apache.camel.spi.SendDynamicAware; + +/** + * Support class for {@link SendDynamicAware} implementations. + */ +public abstract class SendDynamicAwareSupport implements SendDynamicAware { + + public Map<String, String> endpointProperties(Exchange exchange, String uri) throws Exception { + RuntimeCamelCatalog catalog = exchange.getContext().adapt(ExtendedCamelContext.class).getRuntimeCamelCatalog(); + Map<String, String> properties = catalog.endpointProperties(uri); + return properties; + } + + public Map<String, String> endpointLenientProperties(Exchange exchange, String uri) throws Exception { + RuntimeCamelCatalog catalog = exchange.getContext().adapt(ExtendedCamelContext.class).getRuntimeCamelCatalog(); + Map<String, String> properties = catalog.endpointLenientProperties(uri); + return properties; + } + + public String asEndpointUri(Exchange exchange, String scheme, Map<String, String> properties) throws Exception { + RuntimeCamelCatalog catalog = exchange.getContext().adapt(ExtendedCamelContext.class).getRuntimeCamelCatalog(); + return catalog.asEndpointUri(scheme, properties, false); + } +}