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/46ee93e0 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/46ee93e0 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/46ee93e0 Branch: refs/heads/master Commit: 46ee93e0219d52f4791d6a2c075afcb2c4ba4fa2 Parents: b04d6a8 Author: Claus Ibsen <[email protected]> Authored: Mon Apr 10 13:35:24 2017 +0200 Committer: Claus Ibsen <[email protected]> Committed: Tue Apr 11 10:40:05 2017 +0200 ---------------------------------------------------------------------- connectors/examples/petstore-connector/pom.xml | 5 + .../PetStoreConnectorConfiguration.java | 21 +++ .../main/resources/camel-connector-schema.json | 2 +- .../src/main/resources/camel-connector.json | 6 +- connectors/examples/petstore-example/Readme.md | 26 ++++ connectors/examples/petstore-example/pom.xml | 127 +++++++++++++++++++ .../main/java/org/foo/PetStoreApplication.java | 34 +++++ .../src/main/java/org/foo/PetStoreRoute.java | 34 +++++ .../src/main/resources/application.properties | 3 + connectors/examples/pom.xml | 1 + 10 files changed, 256 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/46ee93e0/connectors/examples/petstore-connector/pom.xml ---------------------------------------------------------------------- diff --git a/connectors/examples/petstore-connector/pom.xml b/connectors/examples/petstore-connector/pom.xml index f129d55..369e796 100644 --- a/connectors/examples/petstore-connector/pom.xml +++ b/connectors/examples/petstore-connector/pom.xml @@ -68,6 +68,11 @@ <artifactId>camel-rest-swagger</artifactId> <version>${project.version}</version> </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-undertow</artifactId> + <version>${project.version}</version> + </dependency> <!-- camel and spring boot compiler plugins --> <dependency> http://git-wip-us.apache.org/repos/asf/camel/blob/46ee93e0/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 index 88409ab..0ae5ef3 100644 --- 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 @@ -16,6 +16,7 @@ */ package org.foo.connector.springboot; +import java.net.URI; import org.springframework.boot.context.properties.ConfigurationProperties; /** @@ -25,4 +26,24 @@ import org.springframework.boot.context.properties.ConfigurationProperties; */ @ConfigurationProperties(prefix = "camel.connector.petstore") public class PetStoreConnectorConfiguration { + + /** + * 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). Can be overriden in endpoint + * configuration. + */ + private URI specificationUri; + + public URI getSpecificationUri() { + return specificationUri; + } + + public void setSpecificationUri(URI specificationUri) { + this.specificationUri = specificationUri; + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/46ee93e0/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 index d2e33ed..3018d5b 100644 --- a/connectors/examples/petstore-connector/src/main/resources/camel-connector-schema.json +++ b/connectors/examples/petstore-connector/src/main/resources/camel-connector-schema.json @@ -17,9 +17,9 @@ "version": "2.19.0-SNAPSHOT" }, "componentProperties": { + "specificationUri": { "kind": "property", "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). Can be overiden in endpoint configuration." } }, "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/46ee93e0/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 index fdc9d26..7039fbc 100644 --- a/connectors/examples/petstore-connector/src/main/resources/camel-connector.json +++ b/connectors/examples/petstore-connector/src/main/resources/camel-connector.json @@ -15,8 +15,10 @@ "pattern": "To", "inputDataType": "none", "outputDataType": "json", - "endpointOptions": [ "specificationUri", "operationId" ], - "endpointValues": { + "componentOptions": [ "specificationUri" ], + "globalOptions": [ "specificationUri" ], + "endpointOptions": [ "operationId" ], + "componentValues": { "specificationUri": "http://petstore.swagger.io/v2/swagger.json" } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/46ee93e0/connectors/examples/petstore-example/Readme.md ---------------------------------------------------------------------- diff --git a/connectors/examples/petstore-example/Readme.md b/connectors/examples/petstore-example/Readme.md new file mode 100644 index 0000000..60e717b --- /dev/null +++ b/connectors/examples/petstore-example/Readme.md @@ -0,0 +1,26 @@ +## Foo Bar and Wine Example + +This is an example that uses the `foo`, `bar` and `wine` Camel connectors. These connectors +are used as if they are regular Camel components in Camel routes. + +See the `FooBarWineRoute` class for more details. + +### How to run + +This example can be run from the command line using: + + mvn camel:run + +### Apache Camel IDEA Plugin + +You can use tooling such as the Apache Camel IDEA Plugin to offer code assistance while create the Camel route. + +The tooling offers code completions such as listing the possible options you can use with the Camel connectors. +Notice how the tool presents only the pre-selected options of these connectors. For example the `foo` connector +which is based on the Camel `Timer` component only offers two options, where as if you are using `timer` instead +you will have many more options. + +The following screenshot shows hows the `foo` connector only has two options to configure: + + + http://git-wip-us.apache.org/repos/asf/camel/blob/46ee93e0/connectors/examples/petstore-example/pom.xml ---------------------------------------------------------------------- diff --git a/connectors/examples/petstore-example/pom.xml b/connectors/examples/petstore-example/pom.xml new file mode 100644 index 0000000..851ed33 --- /dev/null +++ b/connectors/examples/petstore-example/pom.xml @@ -0,0 +1,127 @@ +<?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-example</artifactId> + <name>Camel :: Connectors :: Examples :: PetStore Example</name> + <description>PetStore Example</description> + <packaging>jar</packaging> + + <dependencyManagement> + <dependencies> + <!-- Spring Boot BOM --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-dependencies</artifactId> + <version>${spring-boot-version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + <!-- Camel BOM --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-spring-boot-dependencies</artifactId> + <version>${project.version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + </dependencies> + </dependencyManagement> + + <dependencies> + + <!-- spring-boot --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + <version>${spring-boot-version}</version> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-actuator</artifactId> + <version>${spring-boot-version}</version> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-undertow</artifactId> + <version>${spring-boot-version}</version> + </dependency> + + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-spring-boot-starter</artifactId> + <version>${project.version}</version> + </dependency> + + <!-- connectors used in this example --> + <dependency> + <groupId>org.foo</groupId> + <artifactId>petstore-connector</artifactId> + <version>${project.version}</version> + </dependency> + + </dependencies> + + <build> + + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + <version>${spring-boot-version}</version> + <executions> + <execution> + <goals> + <goal>repackage</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + + <profiles> + <profile> + <id>jdk9-build</id> + <activation> + <jdk>9</jdk> + </activation> + <build> + <plugins> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <argLine>--add-modules java.xml.bind</argLine> + </configuration> + </plugin> + </plugins> + </build> + </profile> + </profiles> +</project> http://git-wip-us.apache.org/repos/asf/camel/blob/46ee93e0/connectors/examples/petstore-example/src/main/java/org/foo/PetStoreApplication.java ---------------------------------------------------------------------- diff --git a/connectors/examples/petstore-example/src/main/java/org/foo/PetStoreApplication.java b/connectors/examples/petstore-example/src/main/java/org/foo/PetStoreApplication.java new file mode 100644 index 0000000..04ba954 --- /dev/null +++ b/connectors/examples/petstore-example/src/main/java/org/foo/PetStoreApplication.java @@ -0,0 +1,34 @@ +/** + * 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; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +//CHECKSTYLE:OFF +@SpringBootApplication +public class PetStoreApplication { + + /** + * A main method to start this application. + */ + public static void main(String[] args) { + SpringApplication.run(PetStoreApplication.class, args); + } + +} +//CHECKSTYLE:ON \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/46ee93e0/connectors/examples/petstore-example/src/main/java/org/foo/PetStoreRoute.java ---------------------------------------------------------------------- diff --git a/connectors/examples/petstore-example/src/main/java/org/foo/PetStoreRoute.java b/connectors/examples/petstore-example/src/main/java/org/foo/PetStoreRoute.java new file mode 100644 index 0000000..9287f99 --- /dev/null +++ b/connectors/examples/petstore-example/src/main/java/org/foo/PetStoreRoute.java @@ -0,0 +1,34 @@ +/** + * 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; + +import org.apache.camel.builder.RouteBuilder; +import org.springframework.stereotype.Component; + +/** + * Camel route that uses the petstore connector + */ +@Component +public class PetStoreRoute extends RouteBuilder { + + @Override + public void configure() throws Exception { + from("timer:store?period=5000") + .to("petstore?operationId=getInventory") + .log("Pets in the store ${body}"); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/46ee93e0/connectors/examples/petstore-example/src/main/resources/application.properties ---------------------------------------------------------------------- diff --git a/connectors/examples/petstore-example/src/main/resources/application.properties b/connectors/examples/petstore-example/src/main/resources/application.properties new file mode 100644 index 0000000..23023fe --- /dev/null +++ b/connectors/examples/petstore-example/src/main/resources/application.properties @@ -0,0 +1,3 @@ +camel.springboot.name=PetStore + +camel.connector.petstore.specification-uri=http://petstore.swagger.io/v2/swagger.json \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/46ee93e0/connectors/examples/pom.xml ---------------------------------------------------------------------- diff --git a/connectors/examples/pom.xml b/connectors/examples/pom.xml index 15eeb81..49eaa84 100644 --- a/connectors/examples/pom.xml +++ b/connectors/examples/pom.xml @@ -41,6 +41,7 @@ <module>twitter-salesforce-example</module> <module>salesforce-upsert-contact-connector</module> <module>petstore-connector</module> + <module>petstore-example</module> </modules> </project> \ No newline at end of file
