Repository: camel Updated Branches: refs/heads/master 5be6f68fe -> c912cd8ae
CAMEL-11126: add petstore connector for example Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b04d6a83 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b04d6a83 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b04d6a83 Branch: refs/heads/master Commit: b04d6a83f7feb3ffbfcc35ce841f110d131e16c7 Parents: 5be6f68 Author: Claus Ibsen <[email protected]> Authored: Mon Apr 10 13:14:53 2017 +0200 Committer: Claus Ibsen <[email protected]> Committed: Tue Apr 11 10:39:57 2017 +0200 ---------------------------------------------------------------------- .../examples/petstore-connector/Readme.md | 6 + connectors/examples/petstore-connector/pom.xml | 192 +++++++++++++++++++ .../org/foo/connector/PetStoreComponent.java | 27 +++ .../PetStoreConnectorAutoConfiguration.java | 59 ++++++ .../PetStoreConnectorConfiguration.java | 28 +++ .../org/apache/camel/component/petstore | 18 ++ .../main/resources/META-INF/spring.factories | 19 ++ .../main/resources/camel-connector-schema.json | 25 +++ .../src/main/resources/camel-connector.json | 22 +++ connectors/examples/pom.xml | 4 +- 10 files changed, 399 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/b04d6a83/connectors/examples/petstore-connector/Readme.md ---------------------------------------------------------------------- diff --git a/connectors/examples/petstore-connector/Readme.md b/connectors/examples/petstore-connector/Readme.md new file mode 100644 index 0000000..68891d0 --- /dev/null +++ b/connectors/examples/petstore-connector/Readme.md @@ -0,0 +1,6 @@ +## PetStore Connector + +This is a basic Camel connector that is based on the Rest Swagger component from Apache Camel. + +The connector is configured to call the Swagger PetStore API online service every 5th second +and return a list of pets in json format. http://git-wip-us.apache.org/repos/asf/camel/blob/b04d6a83/connectors/examples/petstore-connector/pom.xml ---------------------------------------------------------------------- diff --git a/connectors/examples/petstore-connector/pom.xml b/connectors/examples/petstore-connector/pom.xml new file mode 100644 index 0000000..f129d55 --- /dev/null +++ b/connectors/examples/petstore-connector/pom.xml @@ -0,0 +1,192 @@ +<?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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.camel</groupId> + <artifactId>connectors-examples</artifactId> + <version>2.19.0-SNAPSHOT</version> + <relativePath>..</relativePath> + </parent> + + <groupId>org.foo</groupId> + <artifactId>petstore-connector</artifactId> + <name>Camel :: Connectors :: Examples :: PetStore Connector</name> + <description>PetStore Connector</description> + <packaging>jar</packaging> + + <dependencyManagement> + <dependencies> + <!-- Camel BOM --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-parent</artifactId> + <version>${project.version}</version> + <scope>import</scope> + <type>pom</type> + </dependency> + </dependencies> + </dependencyManagement> + + <dependencies> + + <!-- base component to use for this connector --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-core</artifactId> + <version>${project.version}</version> + </dependency> + + <!-- camel-connector --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-connector</artifactId> + <version>${project.version}</version> + </dependency> + + <!-- component --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-rest-swagger</artifactId> + <version>${project.version}</version> + </dependency> + + <!-- camel and spring boot compiler plugins --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>apt</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-configuration-processor</artifactId> + <version>${spring-boot-version}</version> + </dependency> + + <!-- logging --> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-api</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-slf4j-impl</artifactId> + <scope>test</scope> + </dependency> + + <!-- testing --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + + <build> + <defaultGoal>install</defaultGoal> + + <plugins> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>${maven-compiler-plugin-version}</version> + <configuration> + <source>1.8</source> + <target>1.8</target> + </configuration> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-resources-plugin</artifactId> + <version>${maven-resources-plugin-version}</version> + <configuration> + <encoding>UTF-8</encoding> + </configuration> + </plugin> + + <!-- generate components meta-data and validate component includes documentation etc --> + <plugin> + <groupId>org.apache.camel</groupId> + <artifactId>camel-package-maven-plugin</artifactId> + <version>${project.version}</version> + <executions> + <execution> + <id>prepare</id> + <goals> + <goal>prepare-components</goal> + </goals> + <phase>generate-resources</phase> + </execution> + <execution> + <id>validate</id> + <goals> + <goal>validate-components</goal> + </goals> + <phase>prepare-package</phase> + </execution> + </executions> + </plugin> + + <!-- turn off jar plugin as we use connector plugin to jar instead --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <version>${maven-jar-plugin-version}</version> + <executions> + <execution> + <id>default-jar</id> + <phase/> + </execution> + </executions> + </plugin> + + <!-- connector plugin will build the jar --> + <plugin> + <groupId>org.apache.camel</groupId> + <artifactId>camel-connector-maven-plugin</artifactId> + <version>${project.version}</version> + <executions> + <execution> + <id>boot</id> + <goals> + <goal>prepare-spring-boot-auto-configuration</goal> + </goals> + </execution> + <execution> + <id>connector</id> + <goals> + <goal>jar</goal> + </goals> + </execution> + </executions> + </plugin> + + </plugins> + </build> + +</project> http://git-wip-us.apache.org/repos/asf/camel/blob/b04d6a83/connectors/examples/petstore-connector/src/main/java/org/foo/connector/PetStoreComponent.java ---------------------------------------------------------------------- diff --git a/connectors/examples/petstore-connector/src/main/java/org/foo/connector/PetStoreComponent.java b/connectors/examples/petstore-connector/src/main/java/org/foo/connector/PetStoreComponent.java new file mode 100644 index 0000000..11c2bb9 --- /dev/null +++ b/connectors/examples/petstore-connector/src/main/java/org/foo/connector/PetStoreComponent.java @@ -0,0 +1,27 @@ +/** + * 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.foo.connector; + +import org.apache.camel.component.connector.DefaultConnectorComponent; + +public class PetStoreComponent extends DefaultConnectorComponent { + + public PetStoreComponent() { + super("petstore", "org.foo.connector.PetStoreComponent"); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/b04d6a83/connectors/examples/petstore-connector/src/main/java/org/foo/connector/springboot/PetStoreConnectorAutoConfiguration.java ---------------------------------------------------------------------- diff --git a/connectors/examples/petstore-connector/src/main/java/org/foo/connector/springboot/PetStoreConnectorAutoConfiguration.java b/connectors/examples/petstore-connector/src/main/java/org/foo/connector/springboot/PetStoreConnectorAutoConfiguration.java new file mode 100644 index 0000000..b2739c5 --- /dev/null +++ b/connectors/examples/petstore-connector/src/main/java/org/foo/connector/springboot/PetStoreConnectorAutoConfiguration.java @@ -0,0 +1,59 @@ +/** + * 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.foo.connector.springboot; + +import java.util.HashMap; +import java.util.Map; +import org.apache.camel.CamelContext; +import org.apache.camel.util.IntrospectionSupport; +import org.foo.connector.PetStoreComponent; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Lazy; + +/** + * Generated by camel-connector-maven-plugin - do not edit this file! + */ +@Configuration +@ConditionalOnBean(type = "org.apache.camel.spring.boot.CamelAutoConfiguration") +@AutoConfigureAfter(name = "org.apache.camel.spring.boot.CamelAutoConfiguration") +@EnableConfigurationProperties(PetStoreConnectorConfiguration.class) +public class PetStoreConnectorAutoConfiguration { + + @Lazy + @Bean(name = "petstore-component") + @ConditionalOnClass(CamelContext.class) + @ConditionalOnMissingBean(org.foo.connector.PetStoreComponent.class) + public PetStoreComponent configurePetStoreComponent( + CamelContext camelContext, + PetStoreConnectorConfiguration configuration) throws Exception { + PetStoreComponent connector = new PetStoreComponent(); + connector.setCamelContext(camelContext); + Map<String, Object> parameters = new HashMap<>(); + IntrospectionSupport.getProperties(configuration, parameters, null, + false); + IntrospectionSupport.setProperties(camelContext, + camelContext.getTypeConverter(), connector, parameters); + connector.setComponentOptions(parameters); + return connector; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/b04d6a83/connectors/examples/petstore-connector/src/main/java/org/foo/connector/springboot/PetStoreConnectorConfiguration.java ---------------------------------------------------------------------- diff --git a/connectors/examples/petstore-connector/src/main/java/org/foo/connector/springboot/PetStoreConnectorConfiguration.java b/connectors/examples/petstore-connector/src/main/java/org/foo/connector/springboot/PetStoreConnectorConfiguration.java new file mode 100644 index 0000000..88409ab --- /dev/null +++ b/connectors/examples/petstore-connector/src/main/java/org/foo/connector/springboot/PetStoreConnectorConfiguration.java @@ -0,0 +1,28 @@ +/** + * 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.foo.connector.springboot; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * An awesome REST endpoint backed by Swagger specifications. + * + * Generated by camel-connector-maven-plugin - do not edit this file! + */ +@ConfigurationProperties(prefix = "camel.connector.petstore") +public class PetStoreConnectorConfiguration { +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/b04d6a83/connectors/examples/petstore-connector/src/main/resources/META-INF/services/org/apache/camel/component/petstore ---------------------------------------------------------------------- diff --git a/connectors/examples/petstore-connector/src/main/resources/META-INF/services/org/apache/camel/component/petstore b/connectors/examples/petstore-connector/src/main/resources/META-INF/services/org/apache/camel/component/petstore new file mode 100644 index 0000000..3344d63 --- /dev/null +++ b/connectors/examples/petstore-connector/src/main/resources/META-INF/services/org/apache/camel/component/petstore @@ -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.foo.connector.PetStoreComponent \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/b04d6a83/connectors/examples/petstore-connector/src/main/resources/META-INF/spring.factories ---------------------------------------------------------------------- diff --git a/connectors/examples/petstore-connector/src/main/resources/META-INF/spring.factories b/connectors/examples/petstore-connector/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..1a5d3bd --- /dev/null +++ b/connectors/examples/petstore-connector/src/main/resources/META-INF/spring.factories @@ -0,0 +1,19 @@ +# +# 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. +# + +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ +org.foo.connector.springboot.PetStoreConnectorAutoConfiguration http://git-wip-us.apache.org/repos/asf/camel/blob/b04d6a83/connectors/examples/petstore-connector/src/main/resources/camel-connector-schema.json ---------------------------------------------------------------------- diff --git a/connectors/examples/petstore-connector/src/main/resources/camel-connector-schema.json b/connectors/examples/petstore-connector/src/main/resources/camel-connector-schema.json new file mode 100644 index 0000000..d2e33ed --- /dev/null +++ b/connectors/examples/petstore-connector/src/main/resources/camel-connector-schema.json @@ -0,0 +1,25 @@ +{ + "component": { + "kind": "component", + "baseScheme": "rest-swagger", + "scheme": "petstore", + "syntax": "petstore:specificationUri#operationId", + "title": "PetStore", + "description": "Pets in the store", + "label": "api,rest", + "deprecated": false, + "async": false, + "producerOnly": true, + "lenientProperties": false, + "javaType": "org.foo.connector.PetStoreComponent", + "groupId": "org.foo", + "artifactId": "petstore-connector", + "version": "2.19.0-SNAPSHOT" + }, + "componentProperties": { + }, + "properties": { + "specificationUri": { "kind": "path", "displayName": "Specification Uri", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.net.URI", "deprecated": false, "secret": false, "defaultValue": "http://petstore.swagger.io/v2/swagger.json", "description": "Path to the Swagger specification file. The scheme host base path are taken from this specification but these can be overriden with properties on the component or endpoint level. If not given the component tries to load swagger.json resource. Note that the host defined on the component and endpoint of this Component should contain the scheme hostname and optionally the port in the URI syntax (i.e. https://api.example.com:8080). Overrides component configuration." }, + "operationId": { "kind": "path", "displayName": "Operation Id", "group": "producer", "label": "producer", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "description": "ID of the operation from the Swagger specification." } + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/b04d6a83/connectors/examples/petstore-connector/src/main/resources/camel-connector.json ---------------------------------------------------------------------- diff --git a/connectors/examples/petstore-connector/src/main/resources/camel-connector.json b/connectors/examples/petstore-connector/src/main/resources/camel-connector.json new file mode 100644 index 0000000..fdc9d26 --- /dev/null +++ b/connectors/examples/petstore-connector/src/main/resources/camel-connector.json @@ -0,0 +1,22 @@ +{ + "baseScheme": "rest-swagger", + "baseGroupId": "org.apache.camel", + "baseArtifactId": "camel-rest-swagger", + "baseVersion": "2.19.0-SNAPSHOT", + "baseJavaType": "org.apache.camel.component.rest.swagger.RestSwaggerComponent", + "name": "PetStore", + "scheme": "petstore", + "javaType": "org.foo.connector.PetStoreComponent", + "groupId": "org.foo", + "artifactId": "petstore-connector", + "version": "2.19.0-SNAPSHOT", + "description": "Pets in the store", + "labels": [ "api", "rest" ], + "pattern": "To", + "inputDataType": "none", + "outputDataType": "json", + "endpointOptions": [ "specificationUri", "operationId" ], + "endpointValues": { + "specificationUri": "http://petstore.swagger.io/v2/swagger.json" + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/b04d6a83/connectors/examples/pom.xml ---------------------------------------------------------------------- diff --git a/connectors/examples/pom.xml b/connectors/examples/pom.xml index 2148263..15eeb81 100644 --- a/connectors/examples/pom.xml +++ b/connectors/examples/pom.xml @@ -14,7 +14,8 @@ 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. ---><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> @@ -39,6 +40,7 @@ <module>twitter-mention-connector</module> <module>twitter-salesforce-example</module> <module>salesforce-upsert-contact-connector</module> + <module>petstore-connector</module> </modules> </project> \ No newline at end of file
