This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit 1d2e41d239a0cf84c3849f689305b31c58de6715 Author: Andrea Cosentino <anco...@gmail.com> AuthorDate: Sun Jan 7 17:54:42 2018 +0100 CAMEL-12053 - Camel-AWS: add a component for Amazon MQ service --- .../apache/camel/component/aws/mq/MQComponent.java | 53 ++++++ .../aws/mq/MQComponentVerifierExtension.java | 87 ++++++++++ .../camel/component/aws/mq/MQConfiguration.java | 125 ++++++++++++++ .../apache/camel/component/aws/mq/MQConstants.java | 29 ++++ .../apache/camel/component/aws/mq/MQEndpoint.java | 112 +++++++++++++ .../camel/component/aws/mq/MQOperations.java | 24 +++ .../apache/camel/component/aws/mq/MQProducer.java | 155 ++++++++++++++++++ .../services/org/apache/camel/component/aws-mq | 18 ++ .../camel/component/aws/mq/AmazonMQClientMock.java | 181 +++++++++++++++++++++ .../aws/mq/MQComponentVerifierExtensionTest.java | 73 +++++++++ .../component/aws/mq/MQProducerSpringTest.java | 111 +++++++++++++ .../camel/component/aws/mq/MQProducerTest.java | 124 ++++++++++++++ .../aws/mq/MQComponentSpringTest-context.xml | 45 +++++ .../springboot/MQComponentAutoConfiguration.java | 128 +++++++++++++++ .../mq/springboot/MQComponentConfiguration.java | 49 ++++++ .../src/main/resources/META-INF/spring.factories | 4 +- 16 files changed, 1317 insertions(+), 1 deletion(-) diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/mq/MQComponent.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/mq/MQComponent.java new file mode 100644 index 0000000..1ababf1 --- /dev/null +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/mq/MQComponent.java @@ -0,0 +1,53 @@ +/** + * 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.aws.mq; + +import java.util.Map; + +import org.apache.camel.CamelContext; +import org.apache.camel.Endpoint; +import org.apache.camel.impl.DefaultComponent; + +/** + * For working with Amazon MQ. + */ +public class MQComponent extends DefaultComponent { + + public MQComponent() { + this(null); + } + + public MQComponent(CamelContext context) { + super(context); + + registerExtension(new MQComponentVerifierExtension()); + } + + @Override + protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { + MQConfiguration configuration = new MQConfiguration(); + setProperties(configuration, parameters); + + if (configuration.getAmazonMqClient() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) { + throw new IllegalArgumentException("amazonMQClient or accessKey and secretKey must be specified"); + } + + MQEndpoint endpoint = new MQEndpoint(uri, this, configuration); + return endpoint; + } + +} diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/mq/MQComponentVerifierExtension.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/mq/MQComponentVerifierExtension.java new file mode 100644 index 0000000..003ddea --- /dev/null +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/mq/MQComponentVerifierExtension.java @@ -0,0 +1,87 @@ +/** + * 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.aws.mq; + +import java.util.Map; + +import com.amazonaws.SdkClientException; +import com.amazonaws.auth.AWSCredentials; +import com.amazonaws.auth.AWSCredentialsProvider; +import com.amazonaws.auth.AWSStaticCredentialsProvider; +import com.amazonaws.auth.BasicAWSCredentials; +import com.amazonaws.services.mq.AmazonMQ; +import com.amazonaws.services.mq.AmazonMQClientBuilder; +import com.amazonaws.services.mq.model.ListBrokersRequest; + +import org.apache.camel.component.extension.verifier.DefaultComponentVerifierExtension; +import org.apache.camel.component.extension.verifier.ResultBuilder; +import org.apache.camel.component.extension.verifier.ResultErrorBuilder; +import org.apache.camel.component.extension.verifier.ResultErrorHelper; + +public class MQComponentVerifierExtension extends DefaultComponentVerifierExtension { + + public MQComponentVerifierExtension() { + this("aws-mq"); + } + + public MQComponentVerifierExtension(String scheme) { + super(scheme); + } + + // ********************************* + // Parameters validation + // ********************************* + + @Override + protected Result verifyParameters(Map<String, Object> parameters) { + + ResultBuilder builder = ResultBuilder.withStatusAndScope(Result.Status.OK, Scope.PARAMETERS).error(ResultErrorHelper.requiresOption("accessKey", parameters)) + .error(ResultErrorHelper.requiresOption("secretKey", parameters)).error(ResultErrorHelper.requiresOption("region", parameters)); + + // Validate using the catalog + + super.verifyParametersAgainstCatalog(builder, parameters); + + return builder.build(); + } + + // ********************************* + // Connectivity validation + // ********************************* + + @Override + protected Result verifyConnectivity(Map<String, Object> parameters) { + ResultBuilder builder = ResultBuilder.withStatusAndScope(Result.Status.OK, Scope.CONNECTIVITY); + + try { + MQConfiguration configuration = setProperties(new MQConfiguration(), parameters); + AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey()); + AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials); + AmazonMQ client = AmazonMQClientBuilder.standard().withCredentials(credentialsProvider).withRegion(configuration.getRegion()).build(); + client.listBrokers(new ListBrokersRequest()); + } catch (SdkClientException e) { + ResultErrorBuilder errorBuilder = ResultErrorBuilder.withCodeAndDescription(VerificationError.StandardCode.AUTHENTICATION, e.getMessage()) + .detail("aws_mq_exception_message", e.getMessage()).detail(VerificationError.ExceptionAttribute.EXCEPTION_CLASS, e.getClass().getName()) + .detail(VerificationError.ExceptionAttribute.EXCEPTION_INSTANCE, e); + + builder.error(errorBuilder.build()); + } catch (Exception e) { + builder.error(ResultErrorBuilder.withException(e).build()); + } + return builder.build(); + } +} diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/mq/MQConfiguration.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/mq/MQConfiguration.java new file mode 100644 index 0000000..1665ca7 --- /dev/null +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/mq/MQConfiguration.java @@ -0,0 +1,125 @@ +/** + * 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.aws.mq; + +import com.amazonaws.services.mq.AmazonMQ; + +import org.apache.camel.spi.Metadata; +import org.apache.camel.spi.UriParam; +import org.apache.camel.spi.UriParams; +import org.apache.camel.spi.UriPath; + +@UriParams +public class MQConfiguration { + + @UriPath(description = "Logical name") @Metadata(required = "true") + private String label; + @UriParam(label = "producer") + private AmazonMQ amazonMqClient; + @UriParam(label = "producer", secret = true) + private String accessKey; + @UriParam(label = "producer", secret = true) + private String secretKey; + @UriParam(label = "producer") + @Metadata(required = "true") + private MQOperations operation; + @UriParam(label = "producer") + private String proxyHost; + @UriParam(label = "producer") + private Integer proxyPort; + @UriParam + private String region; + + public AmazonMQ getAmazonMqClient() { + return amazonMqClient; + } + + /** + * To use a existing configured AmazonMQClient as client + */ + public void setAmazonMqClient(AmazonMQ amazonMqClient) { + this.amazonMqClient = amazonMqClient; + } + + public String getAccessKey() { + return accessKey; + } + + /** + * Amazon AWS Access Key + */ + public void setAccessKey(String accessKey) { + this.accessKey = accessKey; + } + + public String getSecretKey() { + return secretKey; + } + + /** + * Amazon AWS Secret Key + */ + public void setSecretKey(String secretKey) { + this.secretKey = secretKey; + } + + public MQOperations getOperation() { + return operation; + } + + /** + * The operation to perform. It can be createAndRunInstances, startInstances, stopInstances, terminateInstances, + * describeInstances, describeInstancesStatus, rebootInstances, monitorInstances, unmonitorInstances, + * createTags or deleteTags + */ + public void setOperation(MQOperations operation) { + this.operation = operation; + } + + /** + * To define a proxy host when instantiating the SQS client + */ + public String getProxyHost() { + return proxyHost; + } + + public void setProxyHost(String proxyHost) { + this.proxyHost = proxyHost; + } + + /** + * To define a proxy port when instantiating the SQS client + */ + public Integer getProxyPort() { + return proxyPort; + } + + public void setProxyPort(Integer proxyPort) { + this.proxyPort = proxyPort; + } + + /** + * The region in which EC2 client needs to work + */ + public String getRegion() { + return region; + } + + public void setRegion(String region) { + this.region = region; + } +} diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/mq/MQConstants.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/mq/MQConstants.java new file mode 100644 index 0000000..48a6600 --- /dev/null +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/mq/MQConstants.java @@ -0,0 +1,29 @@ +/** + * 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.aws.mq; + +/** + * Constants used in Camel AWS MQ module + * + */ +public interface MQConstants { + String OPERATION = "CamelAwsMQOperation"; + String MAX_RESULTS = "CamelAwsMQMaxResults"; + String BROKER_NAME = "CamelAwsMQBrokerName"; + String BROKER_ID = "CamelAwsMQBrokerID"; + String BROKER_DEPLOYMENT_MODE = "CamelAwsMQBrokerDeploymentMode"; +} diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/mq/MQEndpoint.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/mq/MQEndpoint.java new file mode 100644 index 0000000..ce27c36 --- /dev/null +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/mq/MQEndpoint.java @@ -0,0 +1,112 @@ +/** + * 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.aws.mq; + +import com.amazonaws.ClientConfiguration; +import com.amazonaws.auth.AWSCredentials; +import com.amazonaws.auth.AWSCredentialsProvider; +import com.amazonaws.auth.AWSStaticCredentialsProvider; +import com.amazonaws.auth.BasicAWSCredentials; +import com.amazonaws.services.mq.AmazonMQ; +import com.amazonaws.services.mq.AmazonMQClient; +import com.amazonaws.services.mq.AmazonMQClientBuilder; + +import org.apache.camel.Component; +import org.apache.camel.Consumer; +import org.apache.camel.Processor; +import org.apache.camel.Producer; +import org.apache.camel.impl.ScheduledPollEndpoint; +import org.apache.camel.spi.UriEndpoint; +import org.apache.camel.spi.UriParam; +import org.apache.camel.util.ObjectHelper; + +/** + * The aws-mq is used for managing Amazon MQ instances. + */ +@UriEndpoint(firstVersion = "2.21.0", scheme = "aws-mq", title = "AWS MQ", syntax = "aws-mq:label", producerOnly = true, label = "cloud,management") +public class MQEndpoint extends ScheduledPollEndpoint { + + private AmazonMQ mqClient; + + @UriParam + private MQConfiguration configuration; + + public MQEndpoint(String uri, Component component, MQConfiguration configuration) { + super(uri, component); + this.configuration = configuration; + } + + public Consumer createConsumer(Processor processor) throws Exception { + throw new UnsupportedOperationException("You cannot receive messages from this endpoint"); + } + + public Producer createProducer() throws Exception { + return new MQProducer(this); + } + + public boolean isSingleton() { + return true; + } + + @Override + public void doStart() throws Exception { + super.doStart(); + + mqClient = configuration.getAmazonMqClient() != null ? configuration.getAmazonMqClient() : (AmazonMQClient) createMQClient(); + } + + public MQConfiguration getConfiguration() { + return configuration; + } + + public AmazonMQ getAmazonMqClient() { + return mqClient; + } + + AmazonMQ createMQClient() { + AmazonMQ client = null; + ClientConfiguration clientConfiguration = null; + AmazonMQClientBuilder clientBuilder = null; + boolean isClientConfigFound = false; + if (ObjectHelper.isNotEmpty(configuration.getProxyHost()) && ObjectHelper.isNotEmpty(configuration.getProxyPort())) { + clientConfiguration = new ClientConfiguration(); + clientConfiguration.setProxyHost(configuration.getProxyHost()); + clientConfiguration.setProxyPort(configuration.getProxyPort()); + isClientConfigFound = true; + } + if (configuration.getAccessKey() != null && configuration.getSecretKey() != null) { + AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey()); + AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials); + if (isClientConfigFound) { + clientBuilder = AmazonMQClientBuilder.standard().withClientConfiguration(clientConfiguration).withCredentials(credentialsProvider); + } else { + clientBuilder = AmazonMQClientBuilder.standard().withCredentials(credentialsProvider); + } + } else { + if (isClientConfigFound) { + clientBuilder = AmazonMQClientBuilder.standard(); + } else { + clientBuilder = AmazonMQClientBuilder.standard().withClientConfiguration(clientConfiguration); + } + } + if (ObjectHelper.isNotEmpty(configuration.getRegion())) { + clientBuilder = clientBuilder.withRegion(configuration.getRegion()); + } + client = clientBuilder.build(); + return client; + } +} diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/mq/MQOperations.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/mq/MQOperations.java new file mode 100644 index 0000000..0b7f4df --- /dev/null +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/mq/MQOperations.java @@ -0,0 +1,24 @@ +/** + * 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.aws.mq; + +public enum MQOperations { + + listBrokers, + createBroker, + deleteBroker +} diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/mq/MQProducer.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/mq/MQProducer.java new file mode 100644 index 0000000..f0d1d19 --- /dev/null +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/mq/MQProducer.java @@ -0,0 +1,155 @@ +/** + * 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.aws.mq; + +import com.amazonaws.AmazonServiceException; +import com.amazonaws.services.mq.AmazonMQ; +import com.amazonaws.services.mq.model.CreateBrokerRequest; +import com.amazonaws.services.mq.model.CreateBrokerResult; +import com.amazonaws.services.mq.model.DeleteBrokerRequest; +import com.amazonaws.services.mq.model.DeleteBrokerResult; +import com.amazonaws.services.mq.model.ListBrokersRequest; +import com.amazonaws.services.mq.model.ListBrokersResult; + +import org.apache.camel.Endpoint; +import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.apache.camel.impl.DefaultProducer; +import org.apache.camel.util.ObjectHelper; +import org.apache.camel.util.URISupport; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static org.apache.camel.component.aws.common.AwsExchangeUtil.getMessageForResponse; + +/** + * A Producer which sends messages to the Amazon MQ Service + * <a href="http://aws.amazon.com/mq/">AWS MQ</a> + */ +public class MQProducer extends DefaultProducer { + + private static final Logger LOG = LoggerFactory.getLogger(MQProducer.class); + + private transient String mqProducerToString; + + public MQProducer(Endpoint endpoint) { + super(endpoint); + } + + public void process(Exchange exchange) throws Exception { + switch (determineOperation(exchange)) { + case listBrokers: + listBrokers(getEndpoint().getAmazonMqClient(), exchange); + break; + case createBroker: + createBroker(getEndpoint().getAmazonMqClient(), exchange); + break; + case deleteBroker: + deleteBroker(getEndpoint().getAmazonMqClient(), exchange); + break; + default: + throw new IllegalArgumentException("Unsupported operation"); + } + } + + private MQOperations determineOperation(Exchange exchange) { + MQOperations operation = exchange.getIn().getHeader(MQConstants.OPERATION, MQOperations.class); + if (operation == null) { + operation = getConfiguration().getOperation(); + } + return operation; + } + + protected MQConfiguration getConfiguration() { + return getEndpoint().getConfiguration(); + } + + @Override + public String toString() { + if (mqProducerToString == null) { + mqProducerToString = "MQProducer[" + URISupport.sanitizeUri(getEndpoint().getEndpointUri()) + "]"; + } + return mqProducerToString; + } + + @Override + public MQEndpoint getEndpoint() { + return (MQEndpoint) super.getEndpoint(); + } + + private void listBrokers(AmazonMQ mqClient, Exchange exchange) { + ListBrokersRequest request = new ListBrokersRequest(); + if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(MQConstants.MAX_RESULTS))) { + int maxResults = exchange.getIn().getHeader(MQConstants.MAX_RESULTS, Integer.class); + request.withMaxResults(maxResults); + } + ListBrokersResult result; + try { + result = mqClient.listBrokers(request); + } catch (AmazonServiceException ase) { + LOG.trace("List Brokers command returned the error code {}", ase.getErrorCode()); + throw ase; + } + Message message = getMessageForResponse(exchange); + message.setBody(result); + } + + private void createBroker(AmazonMQ mqClient, Exchange exchange) { + String brokerName; + String deploymentMode; + CreateBrokerRequest request = new CreateBrokerRequest(); + if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(MQConstants.BROKER_NAME))) { + brokerName = exchange.getIn().getHeader(MQConstants.BROKER_NAME, String.class); + request.withBrokerName(brokerName); + } else { + throw new IllegalArgumentException("Broker Name must be specified"); + } + if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(MQConstants.BROKER_DEPLOYMENT_MODE))) { + deploymentMode = exchange.getIn().getHeader(MQConstants.BROKER_DEPLOYMENT_MODE, String.class); + request.withDeploymentMode(deploymentMode); + } + CreateBrokerResult result; + try { + result = mqClient.createBroker(request); + } catch (AmazonServiceException ase) { + LOG.trace("Create Broker command returned the error code {}", ase.getErrorCode()); + throw ase; + } + Message message = getMessageForResponse(exchange); + message.setBody(result); + } + + private void deleteBroker(AmazonMQ mqClient, Exchange exchange) { + String brokerId; + DeleteBrokerRequest request = new DeleteBrokerRequest(); + if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(MQConstants.BROKER_ID))) { + brokerId = exchange.getIn().getHeader(MQConstants.BROKER_ID, String.class); + request.withBrokerId(brokerId); + } else { + throw new IllegalArgumentException("Broker Name must be specified"); + } + DeleteBrokerResult result; + try { + result = mqClient.deleteBroker(request); + } catch (AmazonServiceException ase) { + LOG.trace("Delete Broker command returned the error code {}", ase.getErrorCode()); + throw ase; + } + Message message = getMessageForResponse(exchange); + message.setBody(result); + } +} \ No newline at end of file diff --git a/components/camel-aws/src/main/resources/META-INF/services/org/apache/camel/component/aws-mq b/components/camel-aws/src/main/resources/META-INF/services/org/apache/camel/component/aws-mq new file mode 100644 index 0000000..c1a05f1 --- /dev/null +++ b/components/camel-aws/src/main/resources/META-INF/services/org/apache/camel/component/aws-mq @@ -0,0 +1,18 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +class=org.apache.camel.component.aws.mq.MQComponent diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/mq/AmazonMQClientMock.java b/components/camel-aws/src/test/java/org/apache/camel/component/aws/mq/AmazonMQClientMock.java new file mode 100644 index 0000000..e9d3a9a --- /dev/null +++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/mq/AmazonMQClientMock.java @@ -0,0 +1,181 @@ +/** + * 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.aws.mq; + +import java.util.ArrayList; +import java.util.List; + +import com.amazonaws.AmazonWebServiceRequest; +import com.amazonaws.ResponseMetadata; +import com.amazonaws.services.mq.AmazonMQ; +import com.amazonaws.services.mq.model.BrokerState; +import com.amazonaws.services.mq.model.BrokerSummary; +import com.amazonaws.services.mq.model.CreateBrokerRequest; +import com.amazonaws.services.mq.model.CreateBrokerResult; +import com.amazonaws.services.mq.model.CreateConfigurationRequest; +import com.amazonaws.services.mq.model.CreateConfigurationResult; +import com.amazonaws.services.mq.model.CreateUserRequest; +import com.amazonaws.services.mq.model.CreateUserResult; +import com.amazonaws.services.mq.model.DeleteBrokerRequest; +import com.amazonaws.services.mq.model.DeleteBrokerResult; +import com.amazonaws.services.mq.model.DeleteUserRequest; +import com.amazonaws.services.mq.model.DeleteUserResult; +import com.amazonaws.services.mq.model.DescribeBrokerRequest; +import com.amazonaws.services.mq.model.DescribeBrokerResult; +import com.amazonaws.services.mq.model.DescribeConfigurationRequest; +import com.amazonaws.services.mq.model.DescribeConfigurationResult; +import com.amazonaws.services.mq.model.DescribeConfigurationRevisionRequest; +import com.amazonaws.services.mq.model.DescribeConfigurationRevisionResult; +import com.amazonaws.services.mq.model.DescribeUserRequest; +import com.amazonaws.services.mq.model.DescribeUserResult; +import com.amazonaws.services.mq.model.ListBrokersRequest; +import com.amazonaws.services.mq.model.ListBrokersResult; +import com.amazonaws.services.mq.model.ListConfigurationRevisionsRequest; +import com.amazonaws.services.mq.model.ListConfigurationRevisionsResult; +import com.amazonaws.services.mq.model.ListConfigurationsRequest; +import com.amazonaws.services.mq.model.ListConfigurationsResult; +import com.amazonaws.services.mq.model.ListUsersRequest; +import com.amazonaws.services.mq.model.ListUsersResult; +import com.amazonaws.services.mq.model.RebootBrokerRequest; +import com.amazonaws.services.mq.model.RebootBrokerResult; +import com.amazonaws.services.mq.model.UpdateBrokerRequest; +import com.amazonaws.services.mq.model.UpdateBrokerResult; +import com.amazonaws.services.mq.model.UpdateConfigurationRequest; +import com.amazonaws.services.mq.model.UpdateConfigurationResult; +import com.amazonaws.services.mq.model.UpdateUserRequest; +import com.amazonaws.services.mq.model.UpdateUserResult; + +public class AmazonMQClientMock implements AmazonMQ { + + public AmazonMQClientMock() { + super(); + } + + @Override + public CreateBrokerResult createBroker(CreateBrokerRequest createBrokerRequest) { + CreateBrokerResult result = new CreateBrokerResult(); + result.setBrokerArn("test"); + result.setBrokerId("1"); + return result; + } + + @Override + public CreateConfigurationResult createConfiguration(CreateConfigurationRequest createConfigurationRequest) { + throw new UnsupportedOperationException(); + } + + @Override + public CreateUserResult createUser(CreateUserRequest createUserRequest) { + throw new UnsupportedOperationException(); + } + + @Override + public DeleteBrokerResult deleteBroker(DeleteBrokerRequest deleteBrokerRequest) { + DeleteBrokerResult result = new DeleteBrokerResult(); + result.setBrokerId("1"); + return result; + } + + @Override + public DeleteUserResult deleteUser(DeleteUserRequest deleteUserRequest) { + throw new UnsupportedOperationException(); + } + + @Override + public DescribeBrokerResult describeBroker(DescribeBrokerRequest describeBrokerRequest) { + throw new UnsupportedOperationException(); + } + + @Override + public DescribeConfigurationResult describeConfiguration( + DescribeConfigurationRequest describeConfigurationRequest) { + throw new UnsupportedOperationException(); + } + + @Override + public DescribeConfigurationRevisionResult describeConfigurationRevision( + DescribeConfigurationRevisionRequest describeConfigurationRevisionRequest) { + throw new UnsupportedOperationException(); + } + + @Override + public DescribeUserResult describeUser(DescribeUserRequest describeUserRequest) { + throw new UnsupportedOperationException(); + } + + @Override + public ListBrokersResult listBrokers(ListBrokersRequest listBrokersRequest) { + ListBrokersResult result = new ListBrokersResult(); + BrokerSummary bs = new BrokerSummary(); + bs.setBrokerArn("aws:test"); + bs.setBrokerId("1"); + bs.setBrokerName("mybroker"); + bs.setBrokerState(BrokerState.RUNNING.toString()); + List<BrokerSummary> list = new ArrayList<>(); + list.add(bs); + result.setBrokerSummaries(list); + return result; + } + + @Override + public ListConfigurationRevisionsResult listConfigurationRevisions( + ListConfigurationRevisionsRequest listConfigurationRevisionsRequest) { + throw new UnsupportedOperationException(); + } + + @Override + public ListConfigurationsResult listConfigurations(ListConfigurationsRequest listConfigurationsRequest) { + throw new UnsupportedOperationException(); + } + + @Override + public ListUsersResult listUsers(ListUsersRequest listUsersRequest) { + throw new UnsupportedOperationException(); + } + + @Override + public RebootBrokerResult rebootBroker(RebootBrokerRequest rebootBrokerRequest) { + throw new UnsupportedOperationException(); + } + + @Override + public UpdateBrokerResult updateBroker(UpdateBrokerRequest updateBrokerRequest) { + throw new UnsupportedOperationException(); + } + + @Override + public UpdateConfigurationResult updateConfiguration(UpdateConfigurationRequest updateConfigurationRequest) { + throw new UnsupportedOperationException(); + } + + @Override + public UpdateUserResult updateUser(UpdateUserRequest updateUserRequest) { + throw new UnsupportedOperationException(); + } + + @Override + public void shutdown() { + throw new UnsupportedOperationException(); + } + + @Override + public ResponseMetadata getCachedResponseMetadata(AmazonWebServiceRequest request) { + throw new UnsupportedOperationException(); + } + + +} \ No newline at end of file diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/mq/MQComponentVerifierExtensionTest.java b/components/camel-aws/src/test/java/org/apache/camel/component/aws/mq/MQComponentVerifierExtensionTest.java new file mode 100644 index 0000000..1536610 --- /dev/null +++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/mq/MQComponentVerifierExtensionTest.java @@ -0,0 +1,73 @@ +/** + * 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.aws.mq; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.camel.Component; +import org.apache.camel.component.extension.ComponentVerifierExtension; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Assert; +import org.junit.Test; + +public class MQComponentVerifierExtensionTest extends CamelTestSupport { + + // ************************************************* + // Tests (parameters) + // ************************************************* + @Override + public boolean isUseRouteBuilder() { + return false; + } + + @Test + public void testParameters() throws Exception { + Component component = context().getComponent("aws-mq"); + + ComponentVerifierExtension verifier = component.getExtension(ComponentVerifierExtension.class).orElseThrow(IllegalStateException::new); + + Map<String, Object> parameters = new HashMap<>(); + parameters.put("secretKey", "l"); + parameters.put("accessKey", "k"); + parameters.put("region", "l"); + parameters.put("label", "test"); + parameters.put("operation", MQOperations.listBrokers); + + ComponentVerifierExtension.Result result = verifier.verify(ComponentVerifierExtension.Scope.PARAMETERS, parameters); + + Assert.assertEquals(ComponentVerifierExtension.Result.Status.OK, result.getStatus()); + } + + @Test + public void testConnectivity() throws Exception { + Component component = context().getComponent("aws-mq"); + ComponentVerifierExtension verifier = component.getExtension(ComponentVerifierExtension.class).orElseThrow(IllegalStateException::new); + + Map<String, Object> parameters = new HashMap<>(); + parameters.put("secretKey", "l"); + parameters.put("accessKey", "k"); + parameters.put("region", "us-east-1"); + parameters.put("label", "test"); + parameters.put("operation", MQOperations.listBrokers); + + ComponentVerifierExtension.Result result = verifier.verify(ComponentVerifierExtension.Scope.CONNECTIVITY, parameters); + + Assert.assertEquals(ComponentVerifierExtension.Result.Status.ERROR, result.getStatus()); + } + +} diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/mq/MQProducerSpringTest.java b/components/camel-aws/src/test/java/org/apache/camel/component/aws/mq/MQProducerSpringTest.java new file mode 100644 index 0000000..6e95346 --- /dev/null +++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/mq/MQProducerSpringTest.java @@ -0,0 +1,111 @@ +/** + * 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.aws.mq; + +import com.amazonaws.services.mq.model.BrokerState; +import com.amazonaws.services.mq.model.CreateBrokerResult; +import com.amazonaws.services.mq.model.DeleteBrokerResult; +import com.amazonaws.services.mq.model.DeploymentMode; +import com.amazonaws.services.mq.model.ListBrokersResult; + +import org.apache.camel.EndpointInject; +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.impl.JndiRegistry; +import org.apache.camel.test.spring.CamelSpringTestSupport; +import org.junit.Test; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +public class MQProducerSpringTest extends CamelSpringTestSupport { + + @EndpointInject(uri = "mock:result") + private MockEndpoint mock; + + @Test + public void mqListBrokersTest() throws Exception { + + mock.expectedMessageCount(1); + Exchange exchange = template.request("direct:listBrokers", new Processor() { + @Override + public void process(Exchange exchange) throws Exception { + exchange.getIn().setHeader(MQConstants.OPERATION, MQOperations.listBrokers); + } + }); + + assertMockEndpointsSatisfied(); + + ListBrokersResult resultGet = (ListBrokersResult) exchange.getIn().getBody(); + assertEquals(1, resultGet.getBrokerSummaries().size()); + assertEquals("mybroker", resultGet.getBrokerSummaries().get(0).getBrokerName()); + assertEquals(BrokerState.RUNNING.toString(), resultGet.getBrokerSummaries().get(0).getBrokerState()); + } + + @Test + public void mqCreateBrokerTest() throws Exception { + + mock.expectedMessageCount(1); + Exchange exchange = template.request("direct:createBroker", new Processor() { + @Override + public void process(Exchange exchange) throws Exception { + exchange.getIn().setHeader(MQConstants.OPERATION, MQOperations.createBroker); + exchange.getIn().setHeader(MQConstants.BROKER_NAME, "test"); + exchange.getIn().setHeader(MQConstants.BROKER_DEPLOYMENT_MODE, DeploymentMode.SINGLE_INSTANCE); + } + }); + + assertMockEndpointsSatisfied(); + + CreateBrokerResult resultGet = (CreateBrokerResult) exchange.getIn().getBody(); + assertEquals(resultGet.getBrokerId(), "1"); + assertEquals(resultGet.getBrokerArn(), "test"); + } + + @Test + public void mqDeleteBrokerTest() throws Exception { + + mock.expectedMessageCount(1); + Exchange exchange = template.request("direct:createBroker", new Processor() { + @Override + public void process(Exchange exchange) throws Exception { + exchange.getIn().setHeader(MQConstants.OPERATION, MQOperations.deleteBroker); + exchange.getIn().setHeader(MQConstants.BROKER_ID, "1"); + } + }); + + assertMockEndpointsSatisfied(); + + DeleteBrokerResult resultGet = (DeleteBrokerResult) exchange.getIn().getBody(); + assertEquals(resultGet.getBrokerId(), "1"); + } + + @Override + protected JndiRegistry createRegistry() throws Exception { + JndiRegistry registry = super.createRegistry(); + + AmazonMQClientMock clientMock = new AmazonMQClientMock(); + + registry.bind("amazonMqClient", clientMock); + + return registry; + } + + @Override + protected ClassPathXmlApplicationContext createApplicationContext() { + return new ClassPathXmlApplicationContext("org/apache/camel/component/aws/mq/MQComponentSpringTest-context.xml"); + } +} \ No newline at end of file diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/mq/MQProducerTest.java b/components/camel-aws/src/test/java/org/apache/camel/component/aws/mq/MQProducerTest.java new file mode 100644 index 0000000..9a977c4 --- /dev/null +++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/mq/MQProducerTest.java @@ -0,0 +1,124 @@ +/** + * 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.aws.mq; + +import com.amazonaws.services.mq.model.BrokerState; +import com.amazonaws.services.mq.model.CreateBrokerResult; +import com.amazonaws.services.mq.model.DeleteBrokerResult; +import com.amazonaws.services.mq.model.DeploymentMode; +import com.amazonaws.services.mq.model.ListBrokersResult; + +import org.apache.camel.EndpointInject; +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.impl.JndiRegistry; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +public class MQProducerTest extends CamelTestSupport { + + @EndpointInject(uri = "mock:result") + private MockEndpoint mock; + + @Test + public void mqListBrokersTest() throws Exception { + + mock.expectedMessageCount(1); + Exchange exchange = template.request("direct:listBrokers", new Processor() { + @Override + public void process(Exchange exchange) throws Exception { + exchange.getIn().setHeader(MQConstants.OPERATION, MQOperations.listBrokers); + } + }); + + assertMockEndpointsSatisfied(); + + ListBrokersResult resultGet = (ListBrokersResult) exchange.getIn().getBody(); + assertEquals(1, resultGet.getBrokerSummaries().size()); + assertEquals("mybroker", resultGet.getBrokerSummaries().get(0).getBrokerName()); + assertEquals(BrokerState.RUNNING.toString(), resultGet.getBrokerSummaries().get(0).getBrokerState()); + } + + @Test + public void mqCreateBrokerTest() throws Exception { + + mock.expectedMessageCount(1); + Exchange exchange = template.request("direct:createBroker", new Processor() { + @Override + public void process(Exchange exchange) throws Exception { + exchange.getIn().setHeader(MQConstants.OPERATION, MQOperations.createBroker); + exchange.getIn().setHeader(MQConstants.BROKER_NAME, "test"); + exchange.getIn().setHeader(MQConstants.BROKER_DEPLOYMENT_MODE, DeploymentMode.SINGLE_INSTANCE); + } + }); + + assertMockEndpointsSatisfied(); + + CreateBrokerResult resultGet = (CreateBrokerResult) exchange.getIn().getBody(); + assertEquals(resultGet.getBrokerId(), "1"); + assertEquals(resultGet.getBrokerArn(), "test"); + } + + @Test + public void mqDeleteBrokerTest() throws Exception { + + mock.expectedMessageCount(1); + Exchange exchange = template.request("direct:createBroker", new Processor() { + @Override + public void process(Exchange exchange) throws Exception { + exchange.getIn().setHeader(MQConstants.OPERATION, MQOperations.deleteBroker); + exchange.getIn().setHeader(MQConstants.BROKER_ID, "1"); + } + }); + + assertMockEndpointsSatisfied(); + + DeleteBrokerResult resultGet = (DeleteBrokerResult) exchange.getIn().getBody(); + assertEquals(resultGet.getBrokerId(), "1"); + } + + @Override + protected JndiRegistry createRegistry() throws Exception { + JndiRegistry registry = super.createRegistry(); + + AmazonMQClientMock clientMock = new AmazonMQClientMock(); + + registry.bind("amazonMqClient", clientMock); + + return registry; + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:listBrokers") + .to("aws-mq://test?amazonMqClient=#amazonMqClient&operation=listBrokers") + .to("mock:result"); + from("direct:createBroker") + .to("aws-mq://test?amazonMqClient=#amazonMqClient&operation=createBroker") + .to("mock:result"); + from("direct:deleteBroker") + .to("aws-mq://test?amazonMqClient=#amazonMqClient&operation=deleteBroker") + .to("mock:result"); + } + }; + } +} \ No newline at end of file diff --git a/components/camel-aws/src/test/resources/org/apache/camel/component/aws/mq/MQComponentSpringTest-context.xml b/components/camel-aws/src/test/resources/org/apache/camel/component/aws/mq/MQComponentSpringTest-context.xml new file mode 100644 index 0000000..82c3f8b --- /dev/null +++ b/components/camel-aws/src/test/resources/org/apache/camel/component/aws/mq/MQComponentSpringTest-context.xml @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> + + <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> + <route> + <from uri="direct:listBrokers"/> + <to uri="aws-mq://Test?amazonMqClient=#amazonMqClient&operation=listBrokers"/> + <to uri="mock:result"/> + </route> + <route> + <from uri="direct:createBroker"/> + <to uri="aws-mq://Test?amazonMqClient=#amazonMqClient&operation=createBroker"/> + <to uri="mock:result"/> + </route> + <route> + <from uri="direct:deleteBroker"/> + <to uri="aws-mq://Test?amazonMqClient=#amazonMqClient&operation=deleteBroker"/> + <to uri="mock:result"/> + </route> + </camelContext> + + <bean id="amazonMqClient" class="org.apache.camel.component.aws.mq.AmazonMQClientMock"/> +</beans> \ No newline at end of file diff --git a/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/mq/springboot/MQComponentAutoConfiguration.java b/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/mq/springboot/MQComponentAutoConfiguration.java new file mode 100644 index 0000000..7602bd1 --- /dev/null +++ b/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/mq/springboot/MQComponentAutoConfiguration.java @@ -0,0 +1,128 @@ +/** + * 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.aws.mq.springboot; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.annotation.Generated; +import org.apache.camel.CamelContext; +import org.apache.camel.component.aws.mq.MQComponent; +import org.apache.camel.spi.ComponentCustomizer; +import org.apache.camel.spi.HasId; +import org.apache.camel.spring.boot.CamelAutoConfiguration; +import org.apache.camel.spring.boot.ComponentConfigurationProperties; +import org.apache.camel.spring.boot.util.CamelPropertiesHelper; +import org.apache.camel.spring.boot.util.ConditionalOnCamelContextAndAutoConfigurationBeans; +import org.apache.camel.spring.boot.util.GroupCondition; +import org.apache.camel.spring.boot.util.HierarchicalPropertiesEvaluator; +import org.apache.camel.util.IntrospectionSupport; +import org.apache.camel.util.ObjectHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Conditional; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Lazy; + +/** + * Generated by camel-package-maven-plugin - do not edit this file! + */ +@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo") +@Configuration +@Conditional({ConditionalOnCamelContextAndAutoConfigurationBeans.class, + MQComponentAutoConfiguration.GroupConditions.class}) +@AutoConfigureAfter(CamelAutoConfiguration.class) +@EnableConfigurationProperties({ComponentConfigurationProperties.class, + MQComponentConfiguration.class}) +public class MQComponentAutoConfiguration { + + private static final Logger LOGGER = LoggerFactory + .getLogger(MQComponentAutoConfiguration.class); + @Autowired + private ApplicationContext applicationContext; + @Autowired + private CamelContext camelContext; + @Autowired + private MQComponentConfiguration configuration; + @Autowired(required = false) + private List<ComponentCustomizer<MQComponent>> customizers; + + static class GroupConditions extends GroupCondition { + public GroupConditions() { + super("camel.component", "camel.component.aws-mq"); + } + } + + @Lazy + @Bean(name = "aws-mq-component") + @ConditionalOnMissingBean(MQComponent.class) + public MQComponent configureMQComponent() throws Exception { + MQComponent component = new MQComponent(); + component.setCamelContext(camelContext); + Map<String, Object> parameters = new HashMap<>(); + IntrospectionSupport.getProperties(configuration, parameters, null, + false); + for (Map.Entry<String, Object> entry : parameters.entrySet()) { + Object value = entry.getValue(); + Class<?> paramClass = value.getClass(); + if (paramClass.getName().endsWith("NestedConfiguration")) { + Class nestedClass = null; + try { + nestedClass = (Class) paramClass.getDeclaredField( + "CAMEL_NESTED_CLASS").get(null); + HashMap<String, Object> nestedParameters = new HashMap<>(); + IntrospectionSupport.getProperties(value, nestedParameters, + null, false); + Object nestedProperty = nestedClass.newInstance(); + CamelPropertiesHelper.setCamelProperties(camelContext, + nestedProperty, nestedParameters, false); + entry.setValue(nestedProperty); + } catch (NoSuchFieldException e) { + } + } + } + CamelPropertiesHelper.setCamelProperties(camelContext, component, + parameters, false); + if (ObjectHelper.isNotEmpty(customizers)) { + for (ComponentCustomizer<MQComponent> customizer : customizers) { + boolean useCustomizer = (customizer instanceof HasId) + ? HierarchicalPropertiesEvaluator.evaluate( + applicationContext.getEnvironment(), + "camel.component.customizer", + "camel.component.aws-mq.customizer", + ((HasId) customizer).getId()) + : HierarchicalPropertiesEvaluator.evaluate( + applicationContext.getEnvironment(), + "camel.component.customizer", + "camel.component.aws-mq.customizer"); + if (useCustomizer) { + LOGGER.debug("Configure component {}, with customizer {}", + component, customizer); + customizer.customize(component); + } + } + } + return component; + } +} \ No newline at end of file diff --git a/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/mq/springboot/MQComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/mq/springboot/MQComponentConfiguration.java new file mode 100644 index 0000000..1bc7d42 --- /dev/null +++ b/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/mq/springboot/MQComponentConfiguration.java @@ -0,0 +1,49 @@ +/** + * 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.aws.mq.springboot; + +import javax.annotation.Generated; +import org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon; +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * The aws-mq is used for managing Amazon MQ instances. + * + * Generated by camel-package-maven-plugin - do not edit this file! + */ +@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo") +@ConfigurationProperties(prefix = "camel.component.aws-mq") +public class MQComponentConfiguration + extends + ComponentConfigurationPropertiesCommon { + + /** + * Whether the component should resolve property placeholders on itself when + * starting. Only properties which are of String type can use property + * placeholders. + */ + private Boolean resolvePropertyPlaceholders = true; + + public Boolean getResolvePropertyPlaceholders() { + return resolvePropertyPlaceholders; + } + + public void setResolvePropertyPlaceholders( + Boolean resolvePropertyPlaceholders) { + this.resolvePropertyPlaceholders = resolvePropertyPlaceholders; + } +} \ No newline at end of file diff --git a/platforms/spring-boot/components-starter/camel-aws-starter/src/main/resources/META-INF/spring.factories b/platforms/spring-boot/components-starter/camel-aws-starter/src/main/resources/META-INF/spring.factories index e126ade..c90a18a 100644 --- a/platforms/spring-boot/components-starter/camel-aws-starter/src/main/resources/META-INF/spring.factories +++ b/platforms/spring-boot/components-starter/camel-aws-starter/src/main/resources/META-INF/spring.factories @@ -27,7 +27,9 @@ org.apache.camel.component.aws.ec2.springboot.EC2ComponentAutoConfiguration,\ org.apache.camel.component.aws.cw.springboot.CwComponentAutoConfiguration,\ org.apache.camel.component.aws.ddb.springboot.DdbComponentAutoConfiguration,\ org.apache.camel.component.aws.firehose.springboot.KinesisFirehoseComponentAutoConfiguration,\ -org.apache.camel.component.aws.lambda.springboot.LambdaComponentAutoConfiguration +org.apache.camel.component.aws.lambda.springboot.LambdaComponentAutoConfiguration,\ +org.apache.camel.component.aws.mq.springboot.MQComponentAutoConfiguration + -- To stop receiving notification emails like this one, please contact "commits@camel.apache.org" <commits@camel.apache.org>.