Repository: camel Updated Branches: refs/heads/master cc1b73c78 -> d518e543a
CAMEL-9888: Refactor endpoints Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/d518e543 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/d518e543 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/d518e543 Branch: refs/heads/master Commit: d518e543ac6ba6ac488e088a1c597cf47e7cbb64 Parents: 78d46fd Author: lburgazzoli <lburgazz...@gmail.com> Authored: Tue May 24 11:49:20 2016 +0200 Committer: lburgazzoli <lburgazz...@gmail.com> Committed: Tue May 24 11:49:43 2016 +0200 ---------------------------------------------------------------------- .../camel-consul/src/main/docs/consul.adoc | 4 +- .../consul/AbstractConsulConsumer.java | 4 +- .../consul/AbstractConsulEndpoint.java | 94 ------------ .../consul/AbstractConsulProducer.java | 4 +- .../camel/component/consul/ConsulComponent.java | 56 +++++--- .../component/consul/ConsulConfiguration.java | 6 +- .../camel/component/consul/ConsulConstants.java | 7 +- .../camel/component/consul/ConsulEndpoint.java | 144 +++++++++++++++++++ .../component/consul/ConsulEndpointFactory.java | 25 ---- .../consul/enpoint/ConsulAgentEndpoint.java | 43 ------ .../consul/enpoint/ConsulAgentProducer.java | 4 +- .../consul/enpoint/ConsulEventConsumer.java | 17 ++- .../consul/enpoint/ConsulEventEndpoint.java | 44 ------ .../consul/enpoint/ConsulEventProducer.java | 4 +- .../consul/enpoint/ConsulKeyValueConsumer.java | 9 +- .../consul/enpoint/ConsulKeyValueEndpoint.java | 43 ------ .../consul/enpoint/ConsulKeyValueProducer.java | 4 +- 17 files changed, 218 insertions(+), 294 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/d518e543/components/camel-consul/src/main/docs/consul.adoc ---------------------------------------------------------------------- diff --git a/components/camel-consul/src/main/docs/consul.adoc b/components/camel-consul/src/main/docs/consul.adoc index 776c26a..76a1683 100644 --- a/components/camel-consul/src/main/docs/consul.adoc +++ b/components/camel-consul/src/main/docs/consul.adoc @@ -46,6 +46,7 @@ The Consul component has no options. + // endpoint options: START The Consul component supports 20 endpoint options which are listed below: @@ -55,7 +56,7 @@ The Consul component supports 20 endpoint options which are listed below: | Name | Group | Default | Java Type | Description | apiEndpoint | common | | String | *Required* The API endpoint | connectTimeoutMillis | common | | Long | Connect timeout for OkHttpClient -| key | common | | String | The default action. Can be overridden by CamelConsulKey +| key | common | | String | The default key. Can be overridden by CamelConsulKey | pingInstance | common | true | boolean | Configure if the AgentClient should attempt a ping before returning the Consul instance | readTimeoutMillis | common | | Long | Read timeout for OkHttpClient | url | common | | String | The Consul agent URL @@ -77,6 +78,7 @@ The Consul component supports 20 endpoint options which are listed below: {% endraw %} // endpoint options: END + [[Consul-Headers]] Headers ^^^^^^^ http://git-wip-us.apache.org/repos/asf/camel/blob/d518e543/components/camel-consul/src/main/java/org/apache/camel/component/consul/AbstractConsulConsumer.java ---------------------------------------------------------------------- diff --git a/components/camel-consul/src/main/java/org/apache/camel/component/consul/AbstractConsulConsumer.java b/components/camel-consul/src/main/java/org/apache/camel/component/consul/AbstractConsulConsumer.java index c3b6545..536566d 100644 --- a/components/camel-consul/src/main/java/org/apache/camel/component/consul/AbstractConsulConsumer.java +++ b/components/camel-consul/src/main/java/org/apache/camel/component/consul/AbstractConsulConsumer.java @@ -29,7 +29,7 @@ import org.apache.camel.util.ObjectHelper; * @author lburgazzoli */ public abstract class AbstractConsulConsumer<C> extends DefaultConsumer { - protected final AbstractConsulEndpoint endpoint; + protected final ConsulEndpoint endpoint; protected final ConsulConfiguration configuration; protected final String key; protected final AtomicReference<BigInteger> index; @@ -37,7 +37,7 @@ public abstract class AbstractConsulConsumer<C> extends DefaultConsumer { private final Function<Consul, C> clientSupplier; private Runnable watcher; - protected AbstractConsulConsumer(AbstractConsulEndpoint endpoint, ConsulConfiguration configuration, Processor processor, Function<Consul, C> clientSupplier) { + protected AbstractConsulConsumer(ConsulEndpoint endpoint, ConsulConfiguration configuration, Processor processor, Function<Consul, C> clientSupplier) { super(endpoint, processor); this.endpoint = endpoint; http://git-wip-us.apache.org/repos/asf/camel/blob/d518e543/components/camel-consul/src/main/java/org/apache/camel/component/consul/AbstractConsulEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-consul/src/main/java/org/apache/camel/component/consul/AbstractConsulEndpoint.java b/components/camel-consul/src/main/java/org/apache/camel/component/consul/AbstractConsulEndpoint.java deleted file mode 100644 index 981c314..0000000 --- a/components/camel-consul/src/main/java/org/apache/camel/component/consul/AbstractConsulEndpoint.java +++ /dev/null @@ -1,94 +0,0 @@ -/** - * 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.component.consul; - -import com.orbitz.consul.Consul; -import org.apache.camel.impl.DefaultEndpoint; -import org.apache.camel.spi.Metadata; -import org.apache.camel.spi.UriParam; -import org.apache.camel.spi.UriPath; -import org.apache.camel.util.ObjectHelper; - -public abstract class AbstractConsulEndpoint extends DefaultEndpoint { - - @UriPath(description = "The consul configuration") - @Metadata(required = "true") - private final ConsulConfiguration configuration; - - @UriParam(description = "The API endpoint") - @Metadata(required = "true") - private final String apiEndpoint; - - private Consul consul; - - protected AbstractConsulEndpoint(String apiEndpoint, String uri, ConsulComponent component, ConsulConfiguration configuration) { - super(uri, component); - - this.configuration = configuration; - this.apiEndpoint = apiEndpoint; - } - - @Override - public boolean isSingleton() { - return true; - } - - // ************************************************************************* - // - // ************************************************************************* - - public ConsulConfiguration getConfiguration() { - return this.configuration; - } - - public String getApiEndpoint() { - return this.apiEndpoint; - } - - public synchronized Consul getConsul() throws Exception { - if (consul == null) { - Consul.Builder builder = Consul.builder(); - builder.withPing(configuration.isPingInstance()); - - if (ObjectHelper.isNotEmpty(configuration.getUrl())) { - builder.withUrl(configuration.getUrl()); - } - if (ObjectHelper.isNotEmpty(configuration.getSslContextParameters())) { - builder.withSslContext(configuration.getSslContextParameters().createSSLContext(getCamelContext())); - } - if (ObjectHelper.isNotEmpty(configuration.getAclToken())) { - builder.withAclToken(configuration.getAclToken()); - } - if (configuration.requiresBasicAuthentication()) { - builder.withBasicAuth(configuration.getUserName(), configuration.getPassword()); - } - if (ObjectHelper.isNotEmpty(configuration.getConnectTimeoutMillis())) { - builder.withConnectTimeoutMillis(configuration.getConnectTimeoutMillis()); - } - if (ObjectHelper.isNotEmpty(configuration.getReadTimeoutMillis())) { - builder.withReadTimeoutMillis(configuration.getReadTimeoutMillis()); - } - if (ObjectHelper.isNotEmpty(configuration.getWriteTimeoutMillis())) { - builder.withWriteTimeoutMillis(configuration.getWriteTimeoutMillis()); - } - - consul = builder.build(); - } - - return consul; - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/d518e543/components/camel-consul/src/main/java/org/apache/camel/component/consul/AbstractConsulProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-consul/src/main/java/org/apache/camel/component/consul/AbstractConsulProducer.java b/components/camel-consul/src/main/java/org/apache/camel/component/consul/AbstractConsulProducer.java index 2be260c..bba13f9 100644 --- a/components/camel-consul/src/main/java/org/apache/camel/component/consul/AbstractConsulProducer.java +++ b/components/camel-consul/src/main/java/org/apache/camel/component/consul/AbstractConsulProducer.java @@ -26,12 +26,12 @@ import org.apache.camel.impl.HeaderSelectorProducer; public abstract class AbstractConsulProducer<C> extends HeaderSelectorProducer { - private final AbstractConsulEndpoint endpoint; + private final ConsulEndpoint endpoint; private final ConsulConfiguration configuration; private final Function<Consul, C> clientSupplier; private C client; - protected AbstractConsulProducer(AbstractConsulEndpoint endpoint, ConsulConfiguration configuration, Function<Consul, C> clientSupplier) { + protected AbstractConsulProducer(ConsulEndpoint endpoint, ConsulConfiguration configuration, Function<Consul, C> clientSupplier) { super(endpoint, ConsulConstants.CONSUL_ACTION, configuration.getAction()); this.endpoint = endpoint; http://git-wip-us.apache.org/repos/asf/camel/blob/d518e543/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulComponent.java b/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulComponent.java index bbd6a1c..3bf94b9 100644 --- a/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulComponent.java +++ b/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulComponent.java @@ -20,46 +20,68 @@ import java.util.Map; import org.apache.camel.CamelContext; import org.apache.camel.Endpoint; -import org.apache.camel.component.consul.enpoint.ConsulAgentEndpoint; -import org.apache.camel.component.consul.enpoint.ConsulEventEndpoint; -import org.apache.camel.component.consul.enpoint.ConsulKeyValueEndpoint; +import org.apache.camel.component.consul.enpoint.ConsulAgentProducer; +import org.apache.camel.component.consul.enpoint.ConsulEventConsumer; +import org.apache.camel.component.consul.enpoint.ConsulEventProducer; +import org.apache.camel.component.consul.enpoint.ConsulKeyValueConsumer; +import org.apache.camel.component.consul.enpoint.ConsulKeyValueProducer; import org.apache.camel.impl.UriEndpointComponent; /** - * Represents the component that manages {@link AbstractConsulEndpoint}. + * Represents the component that manages {@link ConsulEndpoint}. */ public class ConsulComponent extends UriEndpointComponent { public ConsulComponent() { - super(AbstractConsulEndpoint.class); + super(ConsulEndpoint.class); } public ConsulComponent(CamelContext context) { - super(context, AbstractConsulEndpoint.class); + super(context, ConsulEndpoint.class); } @Override protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { + return ConsulApiEndpoint.valueOf(remaining).create( + remaining, + uri, + this, + createConfiguration(parameters) + ); + } + + private ConsulConfiguration createConfiguration(Map<String, Object> parameters) throws Exception { ConsulConfiguration configuration = new ConsulConfiguration(); setProperties(configuration, parameters); - return ConsulApiEndpoint.valueOf(remaining).create(uri, this, configuration); + return configuration; } - private enum ConsulApiEndpoint implements ConsulEndpointFactory { - kv(ConsulKeyValueEndpoint::new), - event(ConsulEventEndpoint::new), - agent(ConsulAgentEndpoint::new); + // ************************************************************************* + // Consul Api Enpoints (see https://www.consul.io/docs/agent/http.html) + // ************************************************************************* + + private enum ConsulApiEndpoint { + kv(ConsulKeyValueProducer::new, ConsulKeyValueConsumer::new), + event(ConsulEventProducer::new, ConsulEventConsumer::new), + agent(ConsulAgentProducer::new, null); - private final ConsulEndpointFactory factory; + private final ConsulEndpoint.ProducerFactory producerFactory; + private final ConsulEndpoint.ConsumerFactory consumerFactory; - ConsulApiEndpoint(ConsulEndpointFactory factory) { - this.factory = factory; + ConsulApiEndpoint(ConsulEndpoint.ProducerFactory producerFactory, ConsulEndpoint.ConsumerFactory consumerFactory) { + this.producerFactory = producerFactory; + this.consumerFactory = consumerFactory; } - @Override - public Endpoint create(String uri, ConsulComponent component, ConsulConfiguration configuration) throws Exception { - return factory.create(uri, component, configuration); + public Endpoint create(String apiEndpoint, String uri, ConsulComponent component, ConsulConfiguration configuration) throws Exception { + return new ConsulEndpoint( + apiEndpoint, + uri, + component, + configuration, + producerFactory, + consumerFactory); } } } http://git-wip-us.apache.org/repos/asf/camel/blob/d518e543/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulConfiguration.java ---------------------------------------------------------------------- diff --git a/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulConfiguration.java b/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulConfiguration.java index 2c0e576..f2ef537 100644 --- a/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulConfiguration.java +++ b/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulConfiguration.java @@ -157,10 +157,6 @@ public class ConsulConfiguration { /** * Write timeout for OkHttpClient */ - public void setWritTeimeoutMillis(Long writeTimeoutMillis) { - this.writeTimeoutMillis = writeTimeoutMillis; - } - public void setWriteTimeoutMillis(Long writeTimeoutMillis) { this.writeTimeoutMillis = writeTimeoutMillis; } @@ -200,7 +196,7 @@ public class ConsulConfiguration { } /** - * The default action. Can be overridden by CamelConsulKey + * The default key. Can be overridden by CamelConsulKey */ public void setKey(String key) { this.key = key; http://git-wip-us.apache.org/repos/asf/camel/blob/d518e543/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulConstants.java ---------------------------------------------------------------------- diff --git a/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulConstants.java b/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulConstants.java index 923e1d7..bb1936e 100644 --- a/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulConstants.java +++ b/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulConstants.java @@ -17,8 +17,6 @@ package org.apache.camel.component.consul; public interface ConsulConstants { - String CONSUL_ENDPOINT_KV = "kv"; - String CONSUL_ACTION = "CamelConsulAction"; String CONSUL_KEY = "CamelConsulKey"; String CONSUL_EVENT_ID = "CamelConsulEventId"; @@ -28,15 +26,12 @@ public interface ConsulConstants { String CONSUL_TAG_FILTER = "CamelConsulTagFilter"; String CONSUL_SERVICE_FILTER = "CamelConsulSessionFilter"; String CONSUL_VERSION = "CamelConsulVersion"; - String CONSUL_VALUE = "CamelConsulValue"; - String CONSUL_VALUES = "CamelConsulValues"; String CONSUL_FLAGS = "CamelConsulFlags"; String CONSUL_CREATE_INDEX = "CamelConsulCreateIndex"; - String CONSUL_LOCK_INDEX = "CamelConsulCreateIndex"; + String CONSUL_LOCK_INDEX = "CamelConsulLockIndex"; String CONSUL_MODIFY_INDEX = "CamelConsulModifyIndex"; String CONSUL_OPTIONS = "CamelConsulOptions"; String CONSUL_RESULT = "CamelConsulResult"; String CONSUL_SESSION = "CamelConsulSession"; - String CONSUL_OPERATION = "CamelConsulOperation"; String CONSUL_VALUE_AS_STRING = "CamelConsulValueAsString"; } http://git-wip-us.apache.org/repos/asf/camel/blob/d518e543/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulEndpoint.java b/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulEndpoint.java new file mode 100644 index 0000000..fd44799 --- /dev/null +++ b/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulEndpoint.java @@ -0,0 +1,144 @@ +/** + * 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.component.consul; + +import com.orbitz.consul.Consul; +import org.apache.camel.Consumer; +import org.apache.camel.Processor; +import org.apache.camel.Producer; +import org.apache.camel.impl.DefaultEndpoint; +import org.apache.camel.spi.Metadata; +import org.apache.camel.spi.UriEndpoint; +import org.apache.camel.spi.UriParam; +import org.apache.camel.spi.UriPath; +import org.apache.camel.util.ObjectHelper; + + +@UriEndpoint(scheme = "consul", title = "Consul", syntax = "consul://apiEndpoint", label = "api,cloud") +public class ConsulEndpoint extends DefaultEndpoint { + + @UriParam(description = "The consul configuration") + @Metadata(required = "true") + private final ConsulConfiguration configuration; + + @UriPath(description = "The API endpoint") + @Metadata(required = "true") + private final String apiEndpoint; + + private final ProducerFactory producerFactory; + private final ConsumerFactory consumerFactory; + + private Consul consul; + + public ConsulEndpoint( + String apiEndpoint, + String uri, + ConsulComponent component, + ConsulConfiguration configuration, + ProducerFactory producerFactory, + ConsumerFactory consumerFactory) { + + super(uri, component); + + this.configuration = ObjectHelper.notNull(configuration, "configuration"); + this.apiEndpoint = ObjectHelper.notNull(apiEndpoint, "apiEndpoint"); + this.producerFactory = producerFactory; + this.consumerFactory = consumerFactory; + } + + @Override + public boolean isSingleton() { + return true; + } + + @Override + public Producer createProducer() throws Exception { + if (producerFactory == null) { + throw new IllegalArgumentException("No producer for " + apiEndpoint); + } + + return producerFactory.create(this, configuration); + } + + @Override + public Consumer createConsumer(Processor processor) throws Exception { + if (consumerFactory == null) { + throw new IllegalArgumentException("No consumer for " + apiEndpoint); + } + + return consumerFactory.create(this, configuration, processor); + } + + // ************************************************************************* + // + // ************************************************************************* + + public ConsulConfiguration getConfiguration() { + return this.configuration; + } + + public String getApiEndpoint() { + return this.apiEndpoint; + } + + public synchronized Consul getConsul() throws Exception { + if (consul == null) { + Consul.Builder builder = Consul.builder(); + builder.withPing(configuration.isPingInstance()); + + if (ObjectHelper.isNotEmpty(configuration.getUrl())) { + builder.withUrl(configuration.getUrl()); + } + if (ObjectHelper.isNotEmpty(configuration.getSslContextParameters())) { + builder.withSslContext(configuration.getSslContextParameters().createSSLContext(getCamelContext())); + } + if (ObjectHelper.isNotEmpty(configuration.getAclToken())) { + builder.withAclToken(configuration.getAclToken()); + } + if (configuration.requiresBasicAuthentication()) { + builder.withBasicAuth(configuration.getUserName(), configuration.getPassword()); + } + if (ObjectHelper.isNotEmpty(configuration.getConnectTimeoutMillis())) { + builder.withConnectTimeoutMillis(configuration.getConnectTimeoutMillis()); + } + if (ObjectHelper.isNotEmpty(configuration.getReadTimeoutMillis())) { + builder.withReadTimeoutMillis(configuration.getReadTimeoutMillis()); + } + if (ObjectHelper.isNotEmpty(configuration.getWriteTimeoutMillis())) { + builder.withWriteTimeoutMillis(configuration.getWriteTimeoutMillis()); + } + + consul = builder.build(); + } + + return consul; + } + + // ************************************************************************* + // + // ************************************************************************* + + @FunctionalInterface + public interface ProducerFactory { + Producer create(ConsulEndpoint endpoint, ConsulConfiguration configuration) throws Exception; + } + + @FunctionalInterface + public interface ConsumerFactory { + Consumer create(ConsulEndpoint endpoint, ConsulConfiguration configuration, Processor processor) throws Exception; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/d518e543/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulEndpointFactory.java ---------------------------------------------------------------------- diff --git a/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulEndpointFactory.java b/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulEndpointFactory.java deleted file mode 100644 index 3401ff8..0000000 --- a/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulEndpointFactory.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * 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.component.consul; - - -import org.apache.camel.Endpoint; - -@FunctionalInterface -public interface ConsulEndpointFactory { - Endpoint create(String uri, ConsulComponent component, ConsulConfiguration configuration) throws Exception; -} http://git-wip-us.apache.org/repos/asf/camel/blob/d518e543/components/camel-consul/src/main/java/org/apache/camel/component/consul/enpoint/ConsulAgentEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-consul/src/main/java/org/apache/camel/component/consul/enpoint/ConsulAgentEndpoint.java b/components/camel-consul/src/main/java/org/apache/camel/component/consul/enpoint/ConsulAgentEndpoint.java deleted file mode 100644 index 9d5742d..0000000 --- a/components/camel-consul/src/main/java/org/apache/camel/component/consul/enpoint/ConsulAgentEndpoint.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * 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.component.consul.enpoint; - -import org.apache.camel.Consumer; -import org.apache.camel.Processor; -import org.apache.camel.Producer; -import org.apache.camel.component.consul.AbstractConsulEndpoint; -import org.apache.camel.component.consul.ConsulComponent; -import org.apache.camel.component.consul.ConsulConfiguration; -import org.apache.camel.spi.UriEndpoint; - -@UriEndpoint(scheme = "consul", title = "Consul Agent", syntax = "consul://agent", producerOnly = true, label = "api,cloud") -public class ConsulAgentEndpoint extends AbstractConsulEndpoint { - public ConsulAgentEndpoint(String uri, ConsulComponent component, ConsulConfiguration configuration) { - super("agent", uri, component, configuration); - } - - @Override - public Producer createProducer() throws Exception { - return new ConsulAgentProducer(this, getConfiguration()); - } - - @Override - public Consumer createConsumer(Processor processor) throws Exception { - throw new IllegalArgumentException("Not implemented"); - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/d518e543/components/camel-consul/src/main/java/org/apache/camel/component/consul/enpoint/ConsulAgentProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-consul/src/main/java/org/apache/camel/component/consul/enpoint/ConsulAgentProducer.java b/components/camel-consul/src/main/java/org/apache/camel/component/consul/enpoint/ConsulAgentProducer.java index 940095a..079a844 100644 --- a/components/camel-consul/src/main/java/org/apache/camel/component/consul/enpoint/ConsulAgentProducer.java +++ b/components/camel-consul/src/main/java/org/apache/camel/component/consul/enpoint/ConsulAgentProducer.java @@ -17,12 +17,12 @@ package org.apache.camel.component.consul.enpoint; import com.orbitz.consul.AgentClient; -import org.apache.camel.component.consul.AbstractConsulEndpoint; import org.apache.camel.component.consul.AbstractConsulProducer; import org.apache.camel.component.consul.ConsulConfiguration; +import org.apache.camel.component.consul.ConsulEndpoint; public class ConsulAgentProducer extends AbstractConsulProducer<AgentClient> { - ConsulAgentProducer(AbstractConsulEndpoint endpoint, ConsulConfiguration configuration) { + public ConsulAgentProducer(ConsulEndpoint endpoint, ConsulConfiguration configuration) { super(endpoint, configuration, c -> c.agentClient()); bind(ConsulAgentActions.CHECKS, wrap(c -> c.getChecks())); http://git-wip-us.apache.org/repos/asf/camel/blob/d518e543/components/camel-consul/src/main/java/org/apache/camel/component/consul/enpoint/ConsulEventConsumer.java ---------------------------------------------------------------------- diff --git a/components/camel-consul/src/main/java/org/apache/camel/component/consul/enpoint/ConsulEventConsumer.java b/components/camel-consul/src/main/java/org/apache/camel/component/consul/enpoint/ConsulEventConsumer.java index f6f658c..4beeb68 100644 --- a/components/camel-consul/src/main/java/org/apache/camel/component/consul/enpoint/ConsulEventConsumer.java +++ b/components/camel-consul/src/main/java/org/apache/camel/component/consul/enpoint/ConsulEventConsumer.java @@ -30,9 +30,10 @@ import org.apache.camel.Processor; import org.apache.camel.component.consul.AbstractConsulConsumer; import org.apache.camel.component.consul.ConsulConfiguration; import org.apache.camel.component.consul.ConsulConstants; +import org.apache.camel.component.consul.ConsulEndpoint; public class ConsulEventConsumer extends AbstractConsulConsumer<EventClient> { - protected ConsulEventConsumer(ConsulEventEndpoint endpoint, ConsulConfiguration configuration, Processor processor) { + public ConsulEventConsumer(ConsulEndpoint endpoint, ConsulConfiguration configuration, Processor processor) { super(endpoint, configuration, processor, c -> c.eventClient()); } @@ -85,10 +86,18 @@ public class ConsulEventConsumer extends AbstractConsulConsumer<EventClient> { message.setHeader(ConsulConstants.CONSUL_EVENT_ID, event.getId()); message.setHeader(ConsulConstants.CONSUL_EVENT_NAME, event.getName()); message.setHeader(ConsulConstants.CONSUL_EVENT_LTIME, event.getLTime()); - message.setHeader(ConsulConstants.CONSUL_NODE_FILTER, event.getNodeFilter()); - message.setHeader(ConsulConstants.CONSUL_SERVICE_FILTER, event.getServiceFilter()); - message.setHeader(ConsulConstants.CONSUL_TAG_FILTER, event.getTagFilter()); message.setHeader(ConsulConstants.CONSUL_VERSION, event.getVersion()); + + if (event.getNodeFilter().isPresent()) { + message.setHeader(ConsulConstants.CONSUL_NODE_FILTER, event.getNodeFilter().get()); + } + if (event.getServiceFilter().isPresent()) { + message.setHeader(ConsulConstants.CONSUL_SERVICE_FILTER, event.getServiceFilter().get()); + } + if (event.getTagFilter().isPresent()) { + message.setHeader(ConsulConstants.CONSUL_TAG_FILTER, event.getTagFilter().get()); + } + message.setBody(event.getPayload().orNull()); try { http://git-wip-us.apache.org/repos/asf/camel/blob/d518e543/components/camel-consul/src/main/java/org/apache/camel/component/consul/enpoint/ConsulEventEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-consul/src/main/java/org/apache/camel/component/consul/enpoint/ConsulEventEndpoint.java b/components/camel-consul/src/main/java/org/apache/camel/component/consul/enpoint/ConsulEventEndpoint.java deleted file mode 100644 index df3254c..0000000 --- a/components/camel-consul/src/main/java/org/apache/camel/component/consul/enpoint/ConsulEventEndpoint.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * 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.component.consul.enpoint; - -import org.apache.camel.Consumer; -import org.apache.camel.Processor; -import org.apache.camel.Producer; -import org.apache.camel.component.consul.AbstractConsulEndpoint; -import org.apache.camel.component.consul.ConsulComponent; -import org.apache.camel.component.consul.ConsulConfiguration; -import org.apache.camel.spi.UriEndpoint; - - -@UriEndpoint(scheme = "consul", title = "Consul KeyValue", syntax = "consul://event", consumerClass = ConsulEventConsumer.class, label = "api,cloud") -public class ConsulEventEndpoint extends AbstractConsulEndpoint { - public ConsulEventEndpoint(String uri, ConsulComponent component, ConsulConfiguration configuration) { - super("event", uri, component, configuration); - } - - @Override - public Producer createProducer() throws Exception { - return new ConsulEventProducer(this, getConfiguration()); - } - - @Override - public Consumer createConsumer(Processor processor) throws Exception { - return new ConsulEventConsumer(this, getConfiguration(), processor); - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/d518e543/components/camel-consul/src/main/java/org/apache/camel/component/consul/enpoint/ConsulEventProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-consul/src/main/java/org/apache/camel/component/consul/enpoint/ConsulEventProducer.java b/components/camel-consul/src/main/java/org/apache/camel/component/consul/enpoint/ConsulEventProducer.java index 26b6595..b0c4af2 100644 --- a/components/camel-consul/src/main/java/org/apache/camel/component/consul/enpoint/ConsulEventProducer.java +++ b/components/camel-consul/src/main/java/org/apache/camel/component/consul/enpoint/ConsulEventProducer.java @@ -22,12 +22,12 @@ import com.orbitz.consul.option.EventOptions; import com.orbitz.consul.option.QueryOptions; import org.apache.camel.InvokeOnHeader; import org.apache.camel.Message; -import org.apache.camel.component.consul.AbstractConsulEndpoint; import org.apache.camel.component.consul.AbstractConsulProducer; import org.apache.camel.component.consul.ConsulConfiguration; +import org.apache.camel.component.consul.ConsulEndpoint; public class ConsulEventProducer extends AbstractConsulProducer<EventClient> { - ConsulEventProducer(AbstractConsulEndpoint endpoint, ConsulConfiguration configuration) { + public ConsulEventProducer(ConsulEndpoint endpoint, ConsulConfiguration configuration) { super(endpoint, configuration, c -> c.eventClient()); } http://git-wip-us.apache.org/repos/asf/camel/blob/d518e543/components/camel-consul/src/main/java/org/apache/camel/component/consul/enpoint/ConsulKeyValueConsumer.java ---------------------------------------------------------------------- diff --git a/components/camel-consul/src/main/java/org/apache/camel/component/consul/enpoint/ConsulKeyValueConsumer.java b/components/camel-consul/src/main/java/org/apache/camel/component/consul/enpoint/ConsulKeyValueConsumer.java index a90d8cb..09804af 100644 --- a/components/camel-consul/src/main/java/org/apache/camel/component/consul/enpoint/ConsulKeyValueConsumer.java +++ b/components/camel-consul/src/main/java/org/apache/camel/component/consul/enpoint/ConsulKeyValueConsumer.java @@ -30,10 +30,11 @@ import org.apache.camel.Processor; import org.apache.camel.component.consul.AbstractConsulConsumer; import org.apache.camel.component.consul.ConsulConfiguration; import org.apache.camel.component.consul.ConsulConstants; +import org.apache.camel.component.consul.ConsulEndpoint; public class ConsulKeyValueConsumer extends AbstractConsulConsumer<KeyValueClient> { - protected ConsulKeyValueConsumer(ConsulKeyValueEndpoint endpoint, ConsulConfiguration configuration, Processor processor) { + public ConsulKeyValueConsumer(ConsulEndpoint endpoint, ConsulConfiguration configuration, Processor processor) { super(endpoint, configuration, processor, c -> c.keyValueClient()); } @@ -79,7 +80,11 @@ public class ConsulKeyValueConsumer extends AbstractConsulConsumer<KeyValueClien message.setHeader(ConsulConstants.CONSUL_CREATE_INDEX, value.getCreateIndex()); message.setHeader(ConsulConstants.CONSUL_LOCK_INDEX, value.getLockIndex()); message.setHeader(ConsulConstants.CONSUL_MODIFY_INDEX, value.getModifyIndex()); - message.setHeader(ConsulConstants.CONSUL_SESSION, value.getSession().orNull()); + + if (value.getSession().isPresent()) { + message.setHeader(ConsulConstants.CONSUL_SESSION, value.getSession().get()); + } + message.setBody(configuration.isValueAsString() ? value.getValueAsString().orNull() : value.getValue().orNull()); try { http://git-wip-us.apache.org/repos/asf/camel/blob/d518e543/components/camel-consul/src/main/java/org/apache/camel/component/consul/enpoint/ConsulKeyValueEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-consul/src/main/java/org/apache/camel/component/consul/enpoint/ConsulKeyValueEndpoint.java b/components/camel-consul/src/main/java/org/apache/camel/component/consul/enpoint/ConsulKeyValueEndpoint.java deleted file mode 100644 index 2910910..0000000 --- a/components/camel-consul/src/main/java/org/apache/camel/component/consul/enpoint/ConsulKeyValueEndpoint.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * 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.component.consul.enpoint; - -import org.apache.camel.Consumer; -import org.apache.camel.Processor; -import org.apache.camel.Producer; -import org.apache.camel.component.consul.AbstractConsulEndpoint; -import org.apache.camel.component.consul.ConsulComponent; -import org.apache.camel.component.consul.ConsulConfiguration; -import org.apache.camel.spi.UriEndpoint; - -@UriEndpoint(scheme = "consul", title = "Consul KeyValue", syntax = "consul://kv", consumerClass = ConsulKeyValueConsumer.class, label = "api,cloud") -public class ConsulKeyValueEndpoint extends AbstractConsulEndpoint { - public ConsulKeyValueEndpoint(String uri, ConsulComponent component, ConsulConfiguration configuration) { - super("kv", uri, component, configuration); - } - - @Override - public Producer createProducer() throws Exception { - return new ConsulKeyValueProducer(this, getConfiguration()); - } - - @Override - public Consumer createConsumer(Processor processor) throws Exception { - return new ConsulKeyValueConsumer(this, getConfiguration(), processor); - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/d518e543/components/camel-consul/src/main/java/org/apache/camel/component/consul/enpoint/ConsulKeyValueProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-consul/src/main/java/org/apache/camel/component/consul/enpoint/ConsulKeyValueProducer.java b/components/camel-consul/src/main/java/org/apache/camel/component/consul/enpoint/ConsulKeyValueProducer.java index 9596f4c..390b103 100644 --- a/components/camel-consul/src/main/java/org/apache/camel/component/consul/enpoint/ConsulKeyValueProducer.java +++ b/components/camel-consul/src/main/java/org/apache/camel/component/consul/enpoint/ConsulKeyValueProducer.java @@ -21,14 +21,14 @@ import com.orbitz.consul.option.PutOptions; import com.orbitz.consul.option.QueryOptions; import org.apache.camel.InvokeOnHeader; import org.apache.camel.Message; -import org.apache.camel.component.consul.AbstractConsulEndpoint; import org.apache.camel.component.consul.AbstractConsulProducer; import org.apache.camel.component.consul.ConsulConfiguration; import org.apache.camel.component.consul.ConsulConstants; +import org.apache.camel.component.consul.ConsulEndpoint; public class ConsulKeyValueProducer extends AbstractConsulProducer<KeyValueClient> { - ConsulKeyValueProducer(AbstractConsulEndpoint endpoint, ConsulConfiguration configuration) { + public ConsulKeyValueProducer(ConsulEndpoint endpoint, ConsulConfiguration configuration) { super(endpoint, configuration, c -> c.keyValueClient()); }