http://git-wip-us.apache.org/repos/asf/camel/blob/b23fbb46/platforms/camel-catalog-rest/src/main/java/org/apache/camel/catalog/rest/CamelCatalogRest.java ---------------------------------------------------------------------- diff --git a/platforms/camel-catalog-rest/src/main/java/org/apache/camel/catalog/rest/CamelCatalogRest.java b/platforms/camel-catalog-rest/src/main/java/org/apache/camel/catalog/rest/CamelCatalogRest.java new file mode 100644 index 0000000..d47ce27 --- /dev/null +++ b/platforms/camel-catalog-rest/src/main/java/org/apache/camel/catalog/rest/CamelCatalogRest.java @@ -0,0 +1,287 @@ +/** + * 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.catalog.rest; + +import java.util.List; +import java.util.Set; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import org.apache.camel.catalog.CamelCatalog; +import org.apache.camel.catalog.DefaultCamelCatalog; + +/** + * A REST based {@link CamelCatalog} service as a JAX-RS resource class. + */ +@Api(value = "/camel-catalog", description = "Camel Catalog REST API") +@Path("/camel-catalog") +public class CamelCatalogRest { + + private CamelCatalog catalog = new DefaultCamelCatalog(true); + + public CamelCatalog getCatalog() { + return catalog; + } + + /** + * To inject an existing {@link CamelCatalog} + */ + public void setCatalog(CamelCatalog catalog) { + this.catalog = catalog; + } + + @GET + @Path("/catalogVersion") + @Produces("text/plain") + @ApiOperation(value = "The version of this Camel Catalog") + public String getCatalogVersion() { + return catalog.getCatalogVersion(); + } + + @GET + @Path("/findComponentNames") + @Produces("application/json") + @ApiOperation(value = "Find all the component names from the Camel catalog") + public List<String> findComponentNames() { + return catalog.findComponentNames(); + } + + @GET + @Path("/findDataFormatNames") + @Produces("application/json") + @ApiOperation(value = "Find all the data format names from the Camel catalog") + public List<String> findDataFormatNames() { + return catalog.findDataFormatNames(); + } + + @GET + @Path("/findLanguageNames") + @Produces("application/json") + @ApiOperation(value = "Find all the language names from the Camel catalog") + public List<String> findLanguageNames() { + return catalog.findLanguageNames(); + } + + @GET + @Path("/findModelNames") + @Produces("application/json") + @ApiOperation(value = "Find all the model (EIP) names from the Camel catalog") + public List<String> findModelNames() { + return catalog.findModelNames(); + } + + @GET + @Path("/findComponentNames/{filter}") + @Produces("application/json") + @ApiOperation(value = "Find all the component names from the Camel catalog that matches the label") + public List<String> findComponentNames(@ApiParam("Filter used to only return component names that matches by their labels") + @PathParam("filter") String filter) { + return catalog.findComponentNames(filter); + } + + @GET + @Path("/findDataFormatNames/{filter}") + @Produces("application/json") + @ApiOperation(value = "Find all the data format names from the Camel catalog that matches the label") + public List<String> findDataFormatNames(@ApiParam("Filter used to only return data format names that matches by their labels") + @PathParam("filter") String filter) { + return catalog.findDataFormatNames(filter); + } + + @GET + @Path("/findLanguageNames/{filter}") + @Produces("application/json") + @ApiOperation(value = "Find all the language names from the Camel catalog that matches the label") + public List<String> findLanguageNames(@ApiParam("Filter used to only return language names that matches by their labels") + @PathParam("filter") String filter) { + return catalog.findLanguageNames(filter); + } + + @GET + @Path("/findModelNames/{filter}") + @Produces("application/json") + @ApiOperation(value = "Find all the model (EIP) names from the Camel catalog that matches the label") + public List<String> findModelNames(@ApiParam("Filter used to only return model (EIP) names that matches by their labels") + @PathParam("filter") String filter) { + return catalog.findModelNames(filter); + } + + @GET + @Path("/componentJSonSchema/{name}") + @Produces("application/json") + @ApiOperation(value = "Returns the component information as JSon format") + public String componentJSonSchema(@ApiParam("The name of the component") + @PathParam("name") String name) { + return catalog.componentJSonSchema(name); + } + + @GET + @Path("/dataFormatJSonSchema/{name}") + @Produces("application/json") + @ApiOperation(value = "Returns the data format information as JSon format") + public String dataFormatJSonSchema(@ApiParam("The name of the data format") + @PathParam("name") String name) { + return catalog.dataFormatJSonSchema(name); + } + + @GET + @Path("/languageJSonSchema/{name}") + @Produces("application/json") + @ApiOperation(value = "Returns the language information as JSon format") + public String languageJSonSchema(@ApiParam("The name of the language") + @PathParam("name") String name) { + return catalog.languageJSonSchema(name); + } + + @GET + @Path("/modelJSonSchema/{name}") + @Produces("application/json") + @ApiOperation(value = "Returns the model (EIP) information as JSon format") + public String modelJSonSchema(@ApiParam("The name of the model (EIP)") + @PathParam("name") String name) { + return catalog.modelJSonSchema(name); + } + + @GET + @Path("/componentAsciiDoc/{name}") + @Produces("text/plain") + @ApiOperation(value = "Returns the component documentation as Ascii doc format") + public String componentAsciiDoc(@ApiParam("The name of the component") + @PathParam("name") String name) { + return catalog.componentAsciiDoc(name); + } + + @GET + @Path("/dataFormatAsciiDoc/{name}") + @Produces("text/plain") + @ApiOperation(value = "Returns the data format documentation as Ascii doc format") + public String dataFormatAsciiDoc(@ApiParam("The name of the data format") + @PathParam("name") String name) { + return catalog.dataFormatAsciiDoc(name); + } + + @GET + @Path("/languageAsciiDoc/{name}") + @Produces("text/plain") + @ApiOperation(value = "Returns the language documentation as Ascii doc format") + public String languageAsciiDoc(@ApiParam("The name of the language") + @PathParam("name") String name) { + return catalog.languageAsciiDoc(name); + } + + @GET + @Path("/findComponentLabels") + @Produces("application/json") + @ApiOperation(value = "Find all the unique label names all the components are using") + public Set<String> findComponentLabels() { + return catalog.findComponentLabels(); + } + + @GET + @Path("/findDataFormatLabels") + @Produces("application/json") + @ApiOperation(value = "Find all the unique label names all the data formats are using") + public Set<String> findDataFormatLabels() { + return catalog.findDataFormatLabels(); + } + + @GET + @Path("/findLanguageLabels") + @Produces("application/json") + @ApiOperation(value = "Find all the unique label names all the languages are using") + public Set<String> findLanguageLabels() { + return catalog.findLanguageLabels(); + } + + @GET + @Path("/findModelLabels") + @Produces("application/json") + @ApiOperation(value = "Find all the unique label names all the models (EIP) are using.") + public Set<String> findModelLabels() { + return catalog.findModelLabels(); + } + + @GET + @Path("/archetypeCatalogAsXml") + @Produces("application/xml") + @ApiOperation(value = "Returns the Apache Camel Maven Archetype catalog in XML format") + public String archetypeCatalogAsXml() { + return catalog.archetypeCatalogAsXml(); + } + + @GET + @Path("/springSchemaAsXml") + @Produces("application/xml") + @ApiOperation(value = "Returns the Camel Spring XML schema") + public String springSchemaAsXml() { + return catalog.springSchemaAsXml(); + } + + @GET + @Path("/blueprintSchemaAsXml") + @Produces("application/xml") + @ApiOperation(value = "Returns the Camel Blueprint XML schema") + public String blueprintSchemaAsXml() { + return catalog.blueprintSchemaAsXml(); + } + + @GET + @Path("/listComponentsAsJson") + @Produces("application/json") + @ApiOperation(value = "Lists all the components summary details in JSon") + public String listComponentsAsJson() { + return catalog.listComponentsAsJson(); + } + + @GET + @Path("/listDataFormatsAsJson") + @Produces("application/json") + @ApiOperation(value = "Lists all the data formats summary details in JSon") + public String listDataFormatsAsJson() { + return catalog.listDataFormatsAsJson(); + } + + @GET + @Path("/listLanguagesAsJson") + @Produces("application/json") + @ApiOperation(value = "Lists all the languages summary details in JSon") + public String listLanguagesAsJson() { + return catalog.listLanguagesAsJson(); + } + + @GET + @Path("/listModelsAsJson") + @Produces("application/json") + @ApiOperation(value = "Lists all the models (EIP) summary details in JSon") + public String listModelsAsJson() { + return catalog.listModelsAsJson(); + } + + @GET + @Path("/summaryAsJson") + @Produces("application/json") + @ApiOperation(value = "Reports a summary what the catalog contains in JSon") + public String summaryAsJson() { + return catalog.summaryAsJson(); + } + +}
http://git-wip-us.apache.org/repos/asf/camel/blob/b23fbb46/platforms/camel-catalog-rest/src/main/java/org/apache/camel/catalog/rest/CamelConnectorCatalogRest.java ---------------------------------------------------------------------- diff --git a/platforms/camel-catalog-rest/src/main/java/org/apache/camel/catalog/rest/CamelConnectorCatalogRest.java b/platforms/camel-catalog-rest/src/main/java/org/apache/camel/catalog/rest/CamelConnectorCatalogRest.java new file mode 100644 index 0000000..afe2445 --- /dev/null +++ b/platforms/camel-catalog-rest/src/main/java/org/apache/camel/catalog/rest/CamelConnectorCatalogRest.java @@ -0,0 +1,99 @@ +/** + * 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.catalog.rest; + +import java.util.List; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import org.apache.camel.catalog.connector.CamelConnectorCatalog; +import org.apache.camel.catalog.connector.ConnectorDto; +import org.apache.camel.catalog.connector.DefaultCamelConnectorCatalog; + +/** + * A REST based {@link CamelConnectorCatalog} service as a JAX-RS resource class. + */ +@Api(value = "/camel-connector-catalog", description = "Camel Connector Catalog REST API") +@Path("/camel-connector-catalog") +public class CamelConnectorCatalogRest { + + private CamelConnectorCatalog catalog = new DefaultCamelConnectorCatalog(); + + public CamelConnectorCatalog getCatalog() { + return catalog; + } + + /** + * To inject an existing {@link CamelConnectorCatalog} + */ + public void setCatalog(CamelConnectorCatalog catalog) { + this.catalog = catalog; + } + + @GET + @Path("/findConnector") + @Produces("application/json") + @ApiOperation(value = "Find all the connectors from the catalog") + public List<ConnectorDto> findConnector(@ApiParam("Whether to include latest version only") + @QueryParam("latestVersionOnly") boolean latestVersionOnly) { + return catalog.findConnector(latestVersionOnly); + } + + @GET + @Path("/findConnector/{filter}") + @Produces("application/json") + @ApiOperation(value = "Find all the connectors from the catalog") + public List<ConnectorDto> findConnector(@ApiParam("Filter the connector matching by name, description or labels") + @PathParam("filter") String filter, + @ApiParam("Whether to include latest version only") + @QueryParam("latestVersionOnly") boolean latestVersionOnly) { + return catalog.findConnector(latestVersionOnly); + } + + @GET + @Path("/connectorJSon/{groupId}/{artifactId}/{version}") + @Produces("application/json") + @ApiOperation(value = "Returns the camel-connector json file for the given connector with the Maven coordinate") + public String connectorJSon(@ApiParam("Maven groupdId of the connector") + @PathParam("groupId") String groupId, + @ApiParam("Maven artifactId of the connector") + @PathParam("artifactId") String artifactId, + @ApiParam("Maven version of the connector") + @PathParam("version") String version) { + return catalog.connectorJSon(groupId, artifactId, version); + } + + @GET + @Path("/connectorSchemaJSon/{groupId}/{artifactId}/{version}") + @Produces("application/json") + @ApiOperation(value = "Returns the camel-connector-schema json file for the given connector with the Maven coordinate") + public String connectorSchemaJSon(@ApiParam("Maven groupdId of the connector") + @PathParam("groupId") String groupId, + @ApiParam("Maven artifactId of the connector") + @PathParam("artifactId") String artifactId, + @ApiParam("Maven version of the connector") + @PathParam("version") String version) { + return catalog.connectorSchemaJSon(groupId, artifactId, version); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/b23fbb46/platforms/camel-catalog-rest/src/main/resources/META-INF/LICENSE.txt ---------------------------------------------------------------------- diff --git a/platforms/camel-catalog-rest/src/main/resources/META-INF/LICENSE.txt b/platforms/camel-catalog-rest/src/main/resources/META-INF/LICENSE.txt new file mode 100755 index 0000000..6b0b127 --- /dev/null +++ b/platforms/camel-catalog-rest/src/main/resources/META-INF/LICENSE.txt @@ -0,0 +1,203 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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. + http://git-wip-us.apache.org/repos/asf/camel/blob/b23fbb46/platforms/camel-catalog-rest/src/main/resources/META-INF/NOTICE.txt ---------------------------------------------------------------------- diff --git a/platforms/camel-catalog-rest/src/main/resources/META-INF/NOTICE.txt b/platforms/camel-catalog-rest/src/main/resources/META-INF/NOTICE.txt new file mode 100644 index 0000000..2e215bf --- /dev/null +++ b/platforms/camel-catalog-rest/src/main/resources/META-INF/NOTICE.txt @@ -0,0 +1,11 @@ + ========================================================================= + == NOTICE file corresponding to the section 4 d of == + == the Apache License, Version 2.0, == + == in this case for the Apache Camel distribution. == + ========================================================================= + + This product includes software developed by + The Apache Software Foundation (http://www.apache.org/). + + Please read the different LICENSE files present in the licenses directory of + this distribution. http://git-wip-us.apache.org/repos/asf/camel/blob/b23fbb46/platforms/camel-catalog-rest/src/test/java/org/apache/camel/catalog/rest/CamelCatalogRestTest.java ---------------------------------------------------------------------- diff --git a/platforms/camel-catalog-rest/src/test/java/org/apache/camel/catalog/rest/CamelCatalogRestTest.java b/platforms/camel-catalog-rest/src/test/java/org/apache/camel/catalog/rest/CamelCatalogRestTest.java new file mode 100644 index 0000000..46f233b --- /dev/null +++ b/platforms/camel-catalog-rest/src/test/java/org/apache/camel/catalog/rest/CamelCatalogRestTest.java @@ -0,0 +1,85 @@ +/** + * 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.catalog.rest; + +import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider; +import org.apache.camel.test.AvailablePortFinder; +import org.apache.cxf.endpoint.Server; +import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; +import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider; +import org.hamcrest.Matchers; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.CoreMatchers.hasItems; + +public class CamelCatalogRestTest { + + private Server server; + private CamelCatalogRest catalog; + private int port; + + @Before + public void setup() { + catalog = new CamelCatalogRest(); + + port = AvailablePortFinder.getNextAvailable(9000); + + // setup Apache CXF REST server + JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean(); + sf.setResourceClasses(CamelCatalogRest.class); + sf.setResourceProvider(CamelCatalogRest.class, new SingletonResourceProvider(catalog)); + // to use jackson for json + sf.setProvider(JacksonJsonProvider.class); + sf.setAddress("http://localhost:" + port); + + // create and start the CXF server (non blocking) + server = sf.create(); + server.start(); + } + + @After + public void stop() { + if (server != null) { + server.stop(); + } + } + + @Test + public void testFindComponentLabels() throws Exception { + given(). + baseUri("http://localhost:" + port). + accept("application/json"). + when(). + get("/camel-catalog/findComponentLabels"). + then(). + body("$", hasItems("bigdata", "messaging")); + } + + @Test + public void testComponentJSonSchema() throws Exception { + given(). + baseUri("http://localhost:" + port). + accept("application/json"). + when(). + get("/camel-catalog/componentJSonSchema/quartz2"). + then(). + body("component.description", Matchers.is("Provides a scheduled delivery of messages using the Quartz 2.x scheduler.")); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/b23fbb46/platforms/camel-catalog-rest/src/test/java/org/apache/camel/catalog/rest/CamelCatalogSwaggerTest.java ---------------------------------------------------------------------- diff --git a/platforms/camel-catalog-rest/src/test/java/org/apache/camel/catalog/rest/CamelCatalogSwaggerTest.java b/platforms/camel-catalog-rest/src/test/java/org/apache/camel/catalog/rest/CamelCatalogSwaggerTest.java new file mode 100644 index 0000000..91ca90e --- /dev/null +++ b/platforms/camel-catalog-rest/src/test/java/org/apache/camel/catalog/rest/CamelCatalogSwaggerTest.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.catalog.rest; + +import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider; +import org.apache.camel.test.AvailablePortFinder; +import org.apache.cxf.endpoint.Server; +import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; +import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider; +import org.apache.cxf.jaxrs.swagger.Swagger2Feature; +import org.hamcrest.Matchers; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import static io.restassured.RestAssured.given; + +public class CamelCatalogSwaggerTest { + + private Server server; + private CamelCatalogRest catalog; + private int port; + + @Before + public void setup() { + catalog = new CamelCatalogRest(); + + port = AvailablePortFinder.getNextAvailable(9000); + + // setup Apache CXF REST server + JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean(); + sf.setResourceClasses(CamelCatalogRest.class); + sf.setResourceProvider(CamelCatalogRest.class, new SingletonResourceProvider(catalog)); + + Swagger2Feature swagger = new Swagger2Feature(); + swagger.setBasePath("/"); + swagger.setScanAllResources(false); + swagger.setPrettyPrint(true); + swagger.setSupportSwaggerUi(true); + swagger.setTitle("Camel Catalog REST Api"); + swagger.setDescription("REST Api for the Camel Catalog"); + swagger.setVersion(catalog.getCatalogVersion()); + swagger.setContact("Apache Camel"); + sf.getFeatures().add(swagger); + + // to use jackson for json + sf.setProvider(JacksonJsonProvider.class); + sf.setAddress("http://localhost:" + port); + + // create and start the CXF server (non blocking) + server = sf.create(); + server.start(); + } + + @After + public void stop() { + if (server != null) { + server.stop(); + } + } + + @Test + public void testSwagger() throws Exception { + given(). + baseUri("http://localhost:" + port). + when(). + get("/swagger.json"). + then(). + body("paths./camel-catalog/catalogVersion.get.summary", Matchers.is("The version of this Camel Catalog")); + + // System.out.println("Swagger UI: http://localhost:9000/api-docs?url=/swagger.json"); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/b23fbb46/platforms/camel-catalog-rest/src/test/java/org/apache/camel/catalog/rest/CamelConnectorCatalogRestTest.java ---------------------------------------------------------------------- diff --git a/platforms/camel-catalog-rest/src/test/java/org/apache/camel/catalog/rest/CamelConnectorCatalogRestTest.java b/platforms/camel-catalog-rest/src/test/java/org/apache/camel/catalog/rest/CamelConnectorCatalogRestTest.java new file mode 100644 index 0000000..04dfc22 --- /dev/null +++ b/platforms/camel-catalog-rest/src/test/java/org/apache/camel/catalog/rest/CamelConnectorCatalogRestTest.java @@ -0,0 +1,88 @@ +/** + * 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.catalog.rest; + +import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider; +import org.apache.camel.test.AvailablePortFinder; +import org.apache.cxf.endpoint.Server; +import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; +import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider; +import org.hamcrest.Matchers; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import static io.restassured.RestAssured.given; + +public class CamelConnectorCatalogRestTest { + + private Server server; + private CamelConnectorCatalogRest catalog; + private int port; + + @Before + public void setup() { + catalog = new CamelConnectorCatalogRest(); + + port = AvailablePortFinder.getNextAvailable(9000); + + // setup Apache CXF REST server + JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean(); + sf.setResourceClasses(CamelConnectorCatalogRest.class); + sf.setResourceProvider(CamelConnectorCatalogRest.class, new SingletonResourceProvider(catalog)); + // to use jackson for json + sf.setProvider(JacksonJsonProvider.class); + sf.setAddress("http://localhost:" + port); + + // create and start the CXF server (non blocking) + server = sf.create(); + server.start(); + } + + @After + public void stop() { + if (server != null) { + server.stop(); + } + } + + @Test + public void testEmptyFindConnectors() throws Exception { + given(). + baseUri("http://localhost:" + port). + accept("application/json"). + when(). + get("/camel-connector-catalog/findConnector?latestVersionOnly=false"). + then(). + body(Matchers.hasToString("[]")); + } + + @Test + public void testFindConnectors() throws Exception { + catalog.getCatalog().addConnector("org.apache.camel", "myfoo-connector", "2.19.0", "MyFoo", "Something cool", "foo,timer", null, null); + + given(). + baseUri("http://localhost:" + port). + accept("application/json"). + when(). + get("/camel-connector-catalog/findConnector?latestVersionOnly=false"). + then(). + body(Matchers.containsString("MyFoo")); + + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/b23fbb46/platforms/camel-catalog-rest/src/test/resources/log4j2.properties ---------------------------------------------------------------------- diff --git a/platforms/camel-catalog-rest/src/test/resources/log4j2.properties b/platforms/camel-catalog-rest/src/test/resources/log4j2.properties new file mode 100644 index 0000000..2b5b5d6 --- /dev/null +++ b/platforms/camel-catalog-rest/src/test/resources/log4j2.properties @@ -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. +## --------------------------------------------------------------------------- + +appender.file.type = File +appender.file.name = file +appender.file.fileName = target/camel-catalog-rest-test.log +appender.file.layout.type = PatternLayout +appender.file.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n +appender.out.type = Console +appender.out.name = out +appender.out.layout.type = PatternLayout +appender.out.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n +rootLogger.level = INFO +rootLogger.appenderRef.file.ref = file http://git-wip-us.apache.org/repos/asf/camel/blob/b23fbb46/platforms/camel-catalog/pom.xml ---------------------------------------------------------------------- diff --git a/platforms/camel-catalog/pom.xml b/platforms/camel-catalog/pom.xml new file mode 100644 index 0000000..f092073 --- /dev/null +++ b/platforms/camel-catalog/pom.xml @@ -0,0 +1,119 @@ +<?xml version="1.0" encoding="UTF-8"?> +<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"> + <!-- + 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. + --> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.camel</groupId> + <artifactId>platforms</artifactId> + <version>2.19.0-SNAPSHOT</version> + </parent> + + <artifactId>camel-catalog</artifactId> + <packaging>jar</packaging> + <name>Camel :: Platforms :: Catalog</name> + <description>Camel Catalog</description> + + <dependencies> + + <!-- no dependency --> + + <!-- testing --> + <dependency> + <groupId>com.fasterxml.jackson.core</groupId> + <artifactId>jackson-databind</artifactId> + <scope>test</scope> + </dependency> + + <!-- for testing simple language parser --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-core</artifactId> + <scope>test</scope> + </dependency> + + <!-- for testing activemq component --> + <dependency> + <groupId>org.apache.activemq</groupId> + <artifactId>activemq-camel</artifactId> + <version>${activemq-version}</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </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> + + </dependencies> + + <build> + <plugins> + + <!-- generate and include all components in the catalog --> + <plugin> + <groupId>org.apache.camel</groupId> + <artifactId>camel-package-maven-plugin</artifactId> + <version>${project.version}</version> + <executions> + <execution> + <!-- prepare the catalog before the user guide / readme --> + <goals> + <goal>prepare-catalog</goal> + <goal>prepare-user-guide</goal> + <goal>prepare-readme</goal> + </goals> + <phase>process-resources</phase> + </execution> + </executions> + </plugin> + + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <extensions>true</extensions> + <configuration> + <instructions> + <Export-Package>org.apache.camel.catalog*</Export-Package> + <Import-Package>org.apache.camel.language.simple;resolution:=optional,*</Import-Package> + </instructions> + </configuration> + </plugin> + </plugins> + + </build> + +</project> http://git-wip-us.apache.org/repos/asf/camel/blob/b23fbb46/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java ---------------------------------------------------------------------- diff --git a/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java b/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java new file mode 100644 index 0000000..bc4d9fa --- /dev/null +++ b/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java @@ -0,0 +1,577 @@ +/** + * 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.catalog; + +import java.net.URISyntaxException; +import java.util.List; +import java.util.Map; +import java.util.Set; +import javax.management.MXBean; + +/** + * Catalog of components, data formats, models (EIPs), languages, and more from this Apache Camel release. + */ +@MXBean +public interface CamelCatalog { + + /** + * To plugin a custom {@link RuntimeProvider} that amends the catalog to only include information that is supported on the runtime. + */ + void setRuntimeProvider(RuntimeProvider provider); + + /** + * Gets the {@link RuntimeProvider} in use. + * @return + */ + RuntimeProvider getRuntimeProvider(); + + /** + * Enables caching of the resources which makes the catalog faster, but keeps data in memory during caching. + * <p/> + * The catalog does not cache by default. + */ + void enableCache(); + + /** + * Whether caching has been enabled. + */ + boolean isCaching(); + + /** + * To plugin a custom {@link SuggestionStrategy} to provide suggestion for unknown options + */ + void setSuggestionStrategy(SuggestionStrategy suggestionStrategy); + + /** + * Gets the {@link SuggestionStrategy} in use + */ + SuggestionStrategy getSuggestionStrategy(); + + /** + * To plugin a custom {@link VersionManager} to load other versions of Camel the catalog should use. + */ + void setVersionManager(VersionManager versionManager); + + /** + * Gets the {@link VersionManager} in use + */ + VersionManager getVersionManager(); + + /** + * Adds a 3rd party component to this catalog. + * + * @param name the component name + * @param className the fully qualified class name for the component class + */ + void addComponent(String name, String className); + + /** + * Adds a 3rd party component to this catalog. + * + * @param name the component name + * @param className the fully qualified class name for the component class + * @param jsonSchema the component JSon schema + */ + void addComponent(String name, String className, String jsonSchema); + + /** + * Adds a 3rd party data format to this catalog. + * + * @param name the data format name + * @param className the fully qualified class name for the data format class + */ + void addDataFormat(String name, String className); + + /** + * Adds a 3rd party data format to this catalog. + * + * @param name the data format name + * @param className the fully qualified class name for the data format class + * @param jsonSchema the data format JSon schema + */ + void addDataFormat(String name, String className, String jsonSchema); + + /** + * The version of this Camel Catalog + */ + String getCatalogVersion(); + + /** + * Attempt to load the Camel version to be used by the catalog. + * <p/> + * Loading the camel-catalog JAR of the given version of choice may require internet access + * to download the JAR from Maven central. You can pre download the JAR and install in a local + * Maven repository to avoid internet access for offline environments. + * <p/> + * When loading a new version the cache will be invalidated. + * + * @param version the Camel version such as <tt>2.17.1</tt> + * @return <tt>true</tt> if the version was loaded, <tt>false</tt> if not. + */ + boolean loadVersion(String version); + + /** + * Gets the current loaded Camel version used by the catalog. + */ + String getLoadedVersion(); + + /** + * Gets the current loaded runtime provider version used by the catalog. + */ + String getRuntimeProviderLoadedVersion(); + + /** + * Attempt to load the runtime provider version to be used by the catalog. + * <p/> + * Loading the runtime provider JAR of the given version of choice may require internet access + * to download the JAR from Maven central. You can pre download the JAR and install in a local + * Maven repository to avoid internet access for offline environments. + * + * @param groupId the runtime provider Maven groupId + * @param artifactId the runtime provider Maven artifactId + * @param version the runtime provider Maven version + * @return <tt>true</tt> if the version was loaded, <tt>false</tt> if not. + */ + boolean loadRuntimeProviderVersion(String groupId, String artifactId, String version); + + /** + * Find all the component names from the Camel catalog + */ + List<String> findComponentNames(); + + /** + * Find all the data format names from the Camel catalog + */ + List<String> findDataFormatNames(); + + /** + * Find all the language names from the Camel catalog + */ + List<String> findLanguageNames(); + + /** + * Find all the model names from the Camel catalog + */ + List<String> findModelNames(); + + /** + * Find all the other (miscellaneous) names from the Camel catalog + */ + List<String> findOtherNames(); + + /** + * Find all the component names from the Camel catalog that matches the label + */ + List<String> findComponentNames(String filter); + + /** + * Find all the data format names from the Camel catalog that matches the label + */ + List<String> findDataFormatNames(String filter); + + /** + * Find all the language names from the Camel catalog that matches the label + */ + List<String> findLanguageNames(String filter); + + /** + * Find all the model names from the Camel catalog that matches the label + */ + List<String> findModelNames(String filter); + + /** + * Find all the other (miscellaneous) names from the Camel catalog that matches the label + */ + List<String> findOtherNames(String filter); + + /** + * Returns the component information as JSon format. + * + * @param name the component name + * @return component details in JSon + */ + String componentJSonSchema(String name); + + /** + * Returns the data format information as JSon format. + * + * @param name the data format name + * @return data format details in JSon + */ + String dataFormatJSonSchema(String name); + + /** + * Returns the language information as JSon format. + * + * @param name the language name + * @return language details in JSon + */ + String languageJSonSchema(String name); + + /** + * Returns the other (miscellaneous) information as JSon format. + * + * @param name the other (miscellaneous) name + * @return other (miscellaneous) details in JSon + */ + String otherJSonSchema(String name); + + /** + * Returns the model information as JSon format. + * + * @param name the model name + * @return model details in JSon + */ + String modelJSonSchema(String name); + + /** + * Returns the component documentation as Ascii doc format. + * + * @param name the component name + * @return component documentation in ascii doc format. + */ + String componentAsciiDoc(String name); + + /** + * Returns the component documentation as HTML format. + * + * @param name the component name + * @return component documentation in html format. + */ + String componentHtmlDoc(String name); + + /** + * Returns the data format documentation as Ascii doc format. + * + * @param name the data format name + * @return data format documentation in ascii doc format. + */ + String dataFormatAsciiDoc(String name); + + /** + * Returns the data format documentation as HTML format. + * + * @param name the data format name + * @return data format documentation in HTML format. + */ + String dataFormatHtmlDoc(String name); + + /** + * Returns the language documentation as Ascii doc format. + * + * @param name the language name + * @return language documentation in ascii doc format. + */ + String languageAsciiDoc(String name); + + /** + * Returns the language documentation as HTML format. + * + * @param name the language name + * @return language documentation in HTML format. + */ + String languageHtmlDoc(String name); + + /** + * Returns the other (miscellaneous) documentation as Ascii doc format. + * + * @param name the other (miscellaneous) name + * @return other (miscellaneous) documentation in ascii doc format. + */ + String otherAsciiDoc(String name); + + /** + * Returns the other (miscellaneous) documentation as HTML format. + * + * @param name the other (miscellaneous) name + * @return other (miscellaneous) documentation in HTML format. + */ + String otherHtmlDoc(String name); + + /** + * Find all the unique label names all the components are using. + * + * @return a set of all the labels. + */ + Set<String> findComponentLabels(); + + /** + * Find all the unique label names all the data formats are using. + * + * @return a set of all the labels. + */ + Set<String> findDataFormatLabels(); + + /** + * Find all the unique label names all the languages are using. + * + * @return a set of all the labels. + */ + Set<String> findLanguageLabels(); + + /** + * Find all the unique label names all the models are using. + * + * @return a set of all the labels. + */ + Set<String> findModelLabels(); + + /** + * Find all the unique label names all the other (miscellaneous) are using. + * + * @return a set of all the labels. + */ + Set<String> findOtherLabels(); + + /** + * Returns the Apache Camel Maven Archetype catalog in XML format. + * + * @return the catalog in XML + */ + String archetypeCatalogAsXml(); + + /** + * Returns the Camel Spring XML schema + * + * @return the spring XML schema + */ + String springSchemaAsXml(); + + /** + * Returns the Camel Blueprint XML schema + * + * @return the blueprint XML schema + */ + String blueprintSchemaAsXml(); + + /** + * Parses the endpoint uri and constructs a key/value properties of each option + * + * @param uri the endpoint uri + * @return properties as key value pairs of each endpoint option + */ + Map<String, String> endpointProperties(String uri) throws URISyntaxException; + + /** + * Parses the endpoint uri and constructs a key/value properties of only the lenient properties (eg custom options) + * <p/> + * For example using the HTTP components to provide query parameters in the endpoint uri. + * + * @param uri the endpoint uri + * @return properties as key value pairs of each lenient properties + */ + Map<String, String> endpointLenientProperties(String uri) throws URISyntaxException; + + /** + * Validates the pattern whether its a valid time pattern. + * + * @param pattern the pattern such as 5000, 5s, 5sec, 4min, 4m30s, 1h, etc. + * @return <tt>true</tt> if valid, <tt>false</tt> if invalid + */ + boolean validateTimePattern(String pattern); + + /** + * Parses and validates the endpoint uri and constructs a key/value properties of each option. + * + * @param uri the endpoint uri + * @return validation result + */ + EndpointValidationResult validateEndpointProperties(String uri); + + /** + * Parses and validates the endpoint uri and constructs a key/value properties of each option. + * <p/> + * The option ignoreLenientProperties can be used to ignore components that uses lenient properties. + * When this is true, then the uri validation is stricter but would fail on properties that are not part of the component + * but in the uri because of using lenient properties. + * For example using the HTTP components to provide query parameters in the endpoint uri. + * + * @param uri the endpoint uri + * @param ignoreLenientProperties whether to ignore components that uses lenient properties. + * @return validation result + */ + EndpointValidationResult validateEndpointProperties(String uri, boolean ignoreLenientProperties); + + /** + * Parses and validates the endpoint uri and constructs a key/value properties of each option. + * <p/> + * The option ignoreLenientProperties can be used to ignore components that uses lenient properties. + * When this is true, then the uri validation is stricter but would fail on properties that are not part of the component + * but in the uri because of using lenient properties. + * For example using the HTTP components to provide query parameters in the endpoint uri. + * + * @param uri the endpoint uri + * @param ignoreLenientProperties whether to ignore components that uses lenient properties. + * @param consumerOnly whether the endpoint is only used as a consumer + * @param producerOnly whether the endpoint is only used as a producer + * @return validation result + */ + EndpointValidationResult validateEndpointProperties(String uri, boolean ignoreLenientProperties, boolean consumerOnly, boolean producerOnly); + + /** + * Parses and validates the simple expression. + * <p/> + * <b>Important:</b> This requires having <tt>camel-core</tt> on the classpath + * + * @param simple the simple expression + * @return validation result + * @deprecated use {@link #validateSimpleExpression(ClassLoader, String)} + */ + @Deprecated + SimpleValidationResult validateSimpleExpression(String simple); + + /** + * Parses and validates the simple expression. + * <p/> + * <b>Important:</b> This requires having <tt>camel-core</tt> on the classpath + * + * @param classLoader a custom classloader to use for loading the language from the classpath, or <tt>null</tt> for using default classloader + * @param simple the simple expression + * @return validation result + */ + SimpleValidationResult validateSimpleExpression(ClassLoader classLoader, String simple); + + /** + * Parses and validates the simple predicate + * <p/> + * <b>Important:</b> This requires having <tt>camel-core</tt> on the classpath + * + * @param simple the simple predicate + * @return validation result + * @deprecated use {@link #validateSimplePredicate(ClassLoader, String)} + */ + @Deprecated + SimpleValidationResult validateSimplePredicate(String simple); + + /** + * Parses and validates the simple predicate + * <p/> + * <b>Important:</b> This requires having <tt>camel-core</tt> on the classpath + * + * @param classLoader a custom classloader to use for loading the language from the classpath, or <tt>null</tt> for using default classloader + * @param simple the simple predicate + * @return validation result + */ + SimpleValidationResult validateSimplePredicate(ClassLoader classLoader, String simple); + + /** + * Parses and validates the language as a predicate + * <p/> + * <b>Important:</b> This requires having <tt>camel-core</tt> and the language dependencies on the classpath + * + * @param classLoader a custom classloader to use for loading the language from the classpath, or <tt>null</tt> for using default classloader + * @param language the name of the language + * @param text the predicate text + * @return validation result + */ + LanguageValidationResult validateLanguagePredicate(ClassLoader classLoader, String language, String text); + + /** + * Parses and validates the language as an expression + * <p/> + * <b>Important:</b> This requires having <tt>camel-core</tt> and the language dependencies on the classpath + * + * @param classLoader a custom classloader to use for loading the language from the classpath, or <tt>null</tt> for using default classloader + * @param language the name of the language + * @param text the expression text + * @return validation result + */ + LanguageValidationResult validateLanguageExpression(ClassLoader classLoader, String language, String text); + + /** + * Returns the component name from the given endpoint uri + * + * @param uri the endpoint uri + * @return the component name (aka scheme), or <tt>null</tt> if not possible to determine + */ + String endpointComponentName(String uri); + + /** + * Creates an endpoint uri in Java style from the information in the json schema + * + * @param scheme the endpoint schema + * @param json the json schema with the endpoint properties + * @param encode whether to URL encode the returned uri or not + * @return the constructed endpoint uri + * @throws java.net.URISyntaxException is thrown if there is encoding error + */ + String asEndpointUri(String scheme, String json, boolean encode) throws URISyntaxException; + + /** + * Creates an endpoint uri in XML style (eg escape & as &l;) from the information in the json schema + * + * @param scheme the endpoint schema + * @param json the json schema with the endpoint properties + * @param encode whether to URL encode the returned uri or not + * @return the constructed endpoint uri + * @throws java.net.URISyntaxException is thrown if there is encoding error + */ + String asEndpointUriXml(String scheme, String json, boolean encode) throws URISyntaxException; + + /** + * Creates an endpoint uri in Java style from the information from the properties + * + * @param scheme the endpoint schema + * @param properties the properties as key value pairs + * @param encode whether to URL encode the returned uri or not + * @return the constructed endpoint uri + * @throws java.net.URISyntaxException is thrown if there is encoding error + */ + String asEndpointUri(String scheme, Map<String, String> properties, boolean encode) throws URISyntaxException; + + /** + * Creates an endpoint uri in XML style (eg escape & as &l;) from the information from the properties + * + * @param scheme the endpoint schema + * @param properties the properties as key value pairs + * @param encode whether to URL encode the returned uri or not + * @return the constructed endpoint uri + * @throws java.net.URISyntaxException is thrown if there is encoding error + */ + String asEndpointUriXml(String scheme, Map<String, String> properties, boolean encode) throws URISyntaxException; + + /** + * Lists all the components summary details in JSon + */ + String listComponentsAsJson(); + + /** + * Lists all the data formats summary details in JSon + */ + String listDataFormatsAsJson(); + + /** + * Lists all the languages summary details in JSon + */ + String listLanguagesAsJson(); + + /** + * Lists all the models (EIPs) summary details in JSon + */ + String listModelsAsJson(); + + /** + * Lists all the others (miscellaneous) summary details in JSon + */ + String listOthersAsJson(); + + /** + * Reports a summary what the catalog contains in JSon + */ + String summaryAsJson(); + +} http://git-wip-us.apache.org/repos/asf/camel/blob/b23fbb46/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/CamelCatalogMBeanExporter.java ---------------------------------------------------------------------- diff --git a/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/CamelCatalogMBeanExporter.java b/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/CamelCatalogMBeanExporter.java new file mode 100644 index 0000000..fd95a16 --- /dev/null +++ b/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/CamelCatalogMBeanExporter.java @@ -0,0 +1,85 @@ +/** + * 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.catalog; + +import java.lang.management.ManagementFactory; +import javax.management.InstanceAlreadyExistsException; +import javax.management.MBeanServer; +import javax.management.ObjectInstance; +import javax.management.ObjectName; + +/** + * MBean exporter to register the {@link CamelCatalog} in JMX. + */ +public class CamelCatalogMBeanExporter { + + public static final String MBEAN_NAME = "org.apache.camel.catalog:type=catalog,name=catalog"; + + private CamelCatalog catalog; + private ObjectName objectName; + private MBeanServer mBeanServer; + + /** + * Initializes and exports the {@link CamelCatalog} in JMX using the domain name, + * which can be obtained using {@link #getObjectName()}. + * + * @throws Exception is thrown if error during registration + */ + public void init() throws Exception { + catalog = new DefaultCamelCatalog(); + + if (objectName == null) { + objectName = getObjectName(); + } + + if (mBeanServer == null) { + mBeanServer = ManagementFactory.getPlatformMBeanServer(); + } + + if (mBeanServer != null) { + try { + // notice some mbean servers may register using a changed object name + ObjectInstance oi = mBeanServer.registerMBean(catalog, objectName); + if (oi != null && oi.getObjectName() != null) { + objectName = oi.getObjectName(); + } + } catch (InstanceAlreadyExistsException iaee) { + // Try to remove and re-register + mBeanServer.unregisterMBean(objectName); + mBeanServer.registerMBean(catalog, objectName); + } + } + } + + /** + * Destroys and un-registers the {@link CamelCatalog} from JMX. + * + * @throws Exception is thrown if error during un-registration + */ + public void destroy() throws Exception { + if (mBeanServer != null) { + if (objectName != null) { + mBeanServer.unregisterMBean(objectName); + } + } + } + + protected ObjectName getObjectName() throws Exception { + return new ObjectName(MBEAN_NAME); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/b23fbb46/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/CatalogHelper.java ---------------------------------------------------------------------- diff --git a/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/CatalogHelper.java b/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/CatalogHelper.java new file mode 100644 index 0000000..f7c0072 --- /dev/null +++ b/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/CatalogHelper.java @@ -0,0 +1,195 @@ +/** + * 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.catalog; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.LineNumberReader; +import java.util.List; + +public final class CatalogHelper { + + private CatalogHelper() { + } + + /** + * Loads the entire stream into memory as a String and returns it. + * <p/> + * <b>Notice:</b> This implementation appends a <tt>\n</tt> as line + * terminator at the of the text. + * <p/> + * Warning, don't use for crazy big streams :) + */ + public static void loadLines(InputStream in, List<String> lines) throws IOException { + InputStreamReader isr = new InputStreamReader(in); + try { + BufferedReader reader = new LineNumberReader(isr); + while (true) { + String line = reader.readLine(); + if (line != null) { + lines.add(line); + } else { + break; + } + } + } finally { + isr.close(); + in.close(); + } + } + + /** + * Loads the entire stream into memory as a String and returns it. + * <p/> + * <b>Notice:</b> This implementation appends a <tt>\n</tt> as line + * terminator at the of the text. + * <p/> + * Warning, don't use for crazy big streams :) + */ + public static String loadText(InputStream in) throws IOException { + StringBuilder builder = new StringBuilder(); + InputStreamReader isr = new InputStreamReader(in); + try { + BufferedReader reader = new LineNumberReader(isr); + while (true) { + String line = reader.readLine(); + if (line != null) { + builder.append(line); + builder.append("\n"); + } else { + break; + } + } + return builder.toString(); + } finally { + isr.close(); + in.close(); + } + } + + /** + * Matches the name with the pattern. + * + * @param name the name + * @param pattern the pattern + * @return <tt>true</tt> if matched, or <tt>false</tt> if not + */ + public static boolean matchWildcard(String name, String pattern) { + // we have wildcard support in that hence you can match with: file* to match any file endpoints + if (pattern.endsWith("*") && name.startsWith(pattern.substring(0, pattern.length() - 1))) { + return true; + } + return false; + } + + /** + * Returns the string after the given token + * + * @param text the text + * @param after the token + * @return the text after the token, or <tt>null</tt> if text does not contain the token + */ + public static String after(String text, String after) { + if (!text.contains(after)) { + return null; + } + return text.substring(text.indexOf(after) + after.length()); + } + + /** + * Returns the string before the given token + * + * @param text the text + * @param before the token + * @return the text before the token, or <tt>null</tt> if text does not contain the token + */ + public static String before(String text, String before) { + if (!text.contains(before)) { + return null; + } + return text.substring(0, text.indexOf(before)); + } + + /** + * Returns the string between the given tokens + * + * @param text the text + * @param after the before token + * @param before the after token + * @return the text between the tokens, or <tt>null</tt> if text does not contain the tokens + */ + public static String between(String text, String after, String before) { + text = after(text, after); + if (text == null) { + return null; + } + return before(text, before); + } + + /** + * Tests whether the value is <tt>null</tt> or an empty string. + * + * @param value the value, if its a String it will be tested for text length as well + * @return true if empty + */ + public static boolean isEmpty(Object value) { + return !isNotEmpty(value); + } + + /** + * Tests whether the value is <b>not</b> <tt>null</tt> or an empty string. + * + * @param value the value, if its a String it will be tested for text length as well + * @return true if <b>not</b> empty + */ + public static boolean isNotEmpty(Object value) { + if (value == null) { + return false; + } else if (value instanceof String) { + String text = (String) value; + return text.trim().length() > 0; + } else { + return true; + } + } + + /** + * Removes all leading and ending quotes (single and double) from the string + * + * @param s the string + * @return the string without leading and ending quotes (single and double) + */ + public static String removeLeadingAndEndingQuotes(String s) { + if (isEmpty(s)) { + return s; + } + + String copy = s.trim(); + if (copy.startsWith("'") && copy.endsWith("'")) { + return copy.substring(1, copy.length() - 1); + } + if (copy.startsWith("\"") && copy.endsWith("\"")) { + return copy.substring(1, copy.length() - 1); + } + + // no quotes, so return as-is + return s; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/b23fbb46/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/CollectionStringBuffer.java ---------------------------------------------------------------------- diff --git a/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/CollectionStringBuffer.java b/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/CollectionStringBuffer.java new file mode 100644 index 0000000..2844ca9 --- /dev/null +++ b/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/CollectionStringBuffer.java @@ -0,0 +1,57 @@ +/** + * 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.catalog; + +public class CollectionStringBuffer { + private final StringBuilder buffer = new StringBuilder(); + private String separator; + private boolean first = true; + + public CollectionStringBuffer() { + this(", "); + } + + public CollectionStringBuffer(String separator) { + this.separator = separator; + } + + @Override + public String toString() { + return buffer.toString(); + } + + public void append(Object value) { + if (first) { + first = false; + } else { + buffer.append(separator); + } + buffer.append(value); + } + + public String getSeparator() { + return separator; + } + + public void setSeparator(String separator) { + this.separator = separator; + } + + public boolean isEmpty() { + return first; + } +}