This is an automated email from the ASF dual-hosted git repository. aldettinger pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/master by this push: new b97fc8d Added OAI-PMH support b97fc8d is described below commit b97fc8dd682cb7286277e8f01c5ebb9d3f8fc46a Author: aldettinger <aldettin...@gmail.com> AuthorDate: Thu Jan 28 10:58:59 2021 +0100 Added OAI-PMH support --- catalog/pom.xml | 13 ++ .../ROOT/pages/reference/extensions/oaipmh.adoc | 39 +++++ .../ROOT/partials/reference/components/oaipmh.adoc | 14 +- extensions/oaipmh/deployment/pom.xml | 67 ++++++++ .../oaipmh/deployment/OaipmhProcessor.java | 43 +++++ extensions/oaipmh/pom.xml | 39 +++++ extensions/oaipmh/runtime/pom.xml | 118 +++++++++++++ .../main/resources/META-INF/quarkus-extension.yaml | 31 ++++ extensions/pom.xml | 1 + integration-tests/oaipmh/pom.xml | 186 +++++++++++++++++++++ .../component/oaipmh/it/OaipmhResource.java | 94 +++++++++++ .../quarkus/component/oaipmh/it/OaipmhRoutes.java | 73 ++++++++ .../quarkus/component/oaipmh/it/OaipmhIT.java | 24 +++ .../quarkus/component/oaipmh/it/OaipmhTest.java | 70 ++++++++ .../component/oaipmh/it/OaipmhTestResource.java | 62 +++++++ .../component/oaipmh/it/OaipmhTestServer.java | 149 +++++++++++++++++ .../oaipmh/src/test/resources/data.zip | Bin 0 -> 619775 bytes .../src/test/resources/jettyKS/localhost.p12 | Bin 0 -> 2533 bytes integration-tests/pom.xml | 1 + pom.xml | 1 + poms/bom/pom.xml | 20 +++ tooling/scripts/test-categories.yaml | 1 + 22 files changed, 1045 insertions(+), 1 deletion(-) diff --git a/catalog/pom.xml b/catalog/pom.xml index 395d830..86f4439 100644 --- a/catalog/pom.xml +++ b/catalog/pom.xml @@ -2792,6 +2792,19 @@ </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-oaipmh</artifactId> + <version>${project.version}</version> + <type>pom</type> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>*</groupId> + <artifactId>*</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-ognl</artifactId> <version>${project.version}</version> <type>pom</type> diff --git a/docs/modules/ROOT/pages/reference/extensions/oaipmh.adoc b/docs/modules/ROOT/pages/reference/extensions/oaipmh.adoc new file mode 100644 index 0000000..88211b8 --- /dev/null +++ b/docs/modules/ROOT/pages/reference/extensions/oaipmh.adoc @@ -0,0 +1,39 @@ +// Do not edit directly! +// This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page += OAI-PMH +:cq-artifact-id: camel-quarkus-oaipmh +:cq-native-supported: true +:cq-status: Stable +:cq-description: Harvest metadata using OAI-PMH protocol +:cq-deprecated: false +:cq-jvm-since: 1.7.0 +:cq-native-since: 1.7.0 + +[.badges] +[.badge-key]##JVM since##[.badge-supported]##1.7.0## [.badge-key]##Native since##[.badge-supported]##1.7.0## + +Harvest metadata using OAI-PMH protocol + +== What's inside + +* xref:{cq-camel-components}::oaipmh-component.adoc[OAI-PMH component], URI syntax: `oaipmh:baseUrl` + +Please refer to the above link for usage and configuration details. + +== Maven coordinates + +[source,xml] +---- +<dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-oaipmh</artifactId> +</dependency> +---- + +Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications. + +== SSL in native mode + +This extension auto-enables SSL support in native mode. Hence you do not need to add +`quarkus.ssl.native=true` to your `application.properties` yourself. See also +https://quarkus.io/guides/native-and-ssl[Quarkus SSL guide]. diff --git a/docs/modules/ROOT/partials/reference/components/oaipmh.adoc b/docs/modules/ROOT/partials/reference/components/oaipmh.adoc index a509c1d..c06c198 100644 --- a/docs/modules/ROOT/partials/reference/components/oaipmh.adoc +++ b/docs/modules/ROOT/partials/reference/components/oaipmh.adoc @@ -1 +1,13 @@ -// Empty partial for a Camel bit unsupported by Camel Quarkus to avoid warnings when this file is included from a Camel page +// Do not edit directly! +// This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page +:cq-artifact-id: camel-quarkus-oaipmh +:cq-artifact-id-base: oaipmh +:cq-native-supported: true +:cq-status: Stable +:cq-deprecated: false +:cq-jvm-since: 1.7.0 +:cq-native-since: 1.7.0 +:cq-camel-part-name: oaipmh +:cq-camel-part-title: OAI-PMH +:cq-camel-part-description: Harvest metadata using OAI-PMH protocol +:cq-extension-page-title: OAI-PMH diff --git a/extensions/oaipmh/deployment/pom.xml b/extensions/oaipmh/deployment/pom.xml new file mode 100644 index 0000000..07079cd --- /dev/null +++ b/extensions/oaipmh/deployment/pom.xml @@ -0,0 +1,67 @@ +<?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/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-oaipmh-parent</artifactId> + <version>1.7.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <artifactId>camel-quarkus-oaipmh-deployment</artifactId> + <name>Camel Quarkus :: OAI-PMH :: Deployment</name> + + <dependencies> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-core-deployment</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-support-httpclient-deployment</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-oaipmh</artifactId> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <annotationProcessorPaths> + <path> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-extension-processor</artifactId> + <version>${quarkus.version}</version> + </path> + </annotationProcessorPaths> + </configuration> + </plugin> + </plugins> + </build> + +</project> diff --git a/extensions/oaipmh/deployment/src/main/java/org/apache/camel/quarkus/component/oaipmh/deployment/OaipmhProcessor.java b/extensions/oaipmh/deployment/src/main/java/org/apache/camel/quarkus/component/oaipmh/deployment/OaipmhProcessor.java new file mode 100644 index 0000000..238eaec --- /dev/null +++ b/extensions/oaipmh/deployment/src/main/java/org/apache/camel/quarkus/component/oaipmh/deployment/OaipmhProcessor.java @@ -0,0 +1,43 @@ +/* + * 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.quarkus.component.oaipmh.deployment; + +import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.builditem.ExtensionSslNativeSupportBuildItem; +import io.quarkus.deployment.builditem.FeatureBuildItem; +import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceDirectoryBuildItem; + +class OaipmhProcessor { + + private static final String FEATURE = "camel-oaipmh"; + + @BuildStep + FeatureBuildItem feature() { + return new FeatureBuildItem(FEATURE); + } + + @BuildStep + ExtensionSslNativeSupportBuildItem activateSslNativeSupport() { + return new ExtensionSslNativeSupportBuildItem(FEATURE); + } + + @BuildStep + NativeImageResourceDirectoryBuildItem registerNativeResources() { + return new NativeImageResourceDirectoryBuildItem("org/joda/time/tz/data"); + } + +} diff --git a/extensions/oaipmh/pom.xml b/extensions/oaipmh/pom.xml new file mode 100644 index 0000000..bcb5567 --- /dev/null +++ b/extensions/oaipmh/pom.xml @@ -0,0 +1,39 @@ +<?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/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-build-parent</artifactId> + <version>1.7.0-SNAPSHOT</version> + <relativePath>../../poms/build-parent/pom.xml</relativePath> + </parent> + + <artifactId>camel-quarkus-oaipmh-parent</artifactId> + <name>Camel Quarkus :: OAI-PMH</name> + <packaging>pom</packaging> + + <modules> + <module>deployment</module> + <module>runtime</module> + </modules> +</project> diff --git a/extensions/oaipmh/runtime/pom.xml b/extensions/oaipmh/runtime/pom.xml new file mode 100644 index 0000000..523e40c --- /dev/null +++ b/extensions/oaipmh/runtime/pom.xml @@ -0,0 +1,118 @@ +<?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/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-oaipmh-parent</artifactId> + <version>1.7.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <artifactId>camel-quarkus-oaipmh</artifactId> + <name>Camel Quarkus :: OAI-PMH :: Runtime</name> + <description>Harvest metadata using OAI-PMH protocol</description> + + <properties> + <camel.quarkus.jvmSince>1.7.0</camel.quarkus.jvmSince> + <camel.quarkus.nativeSince>1.7.0</camel.quarkus.nativeSince> + </properties> + + <dependencyManagement> + <dependencies> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-bom</artifactId> + <version>${project.version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + </dependencies> + </dependencyManagement> + + <dependencies> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-core</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-support-httpclient</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-oaipmh</artifactId> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-bootstrap-maven-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <annotationProcessorPaths> + <path> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-extension-processor</artifactId> + <version>${quarkus.version}</version> + </path> + </annotationProcessorPaths> + </configuration> + </plugin> + </plugins> + </build> + + + <profiles> + <profile> + <id>full</id> + <activation> + <property> + <name>!quickly</name> + </property> + </activation> + <build> + <plugins> + <plugin> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-maven-plugin</artifactId> + <executions> + <execution> + <id>update-extension-doc-page</id> + <goals> + <goal>update-extension-doc-page</goal> + </goals> + <phase>process-classes</phase> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + </profiles> +</project> diff --git a/extensions/oaipmh/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/extensions/oaipmh/runtime/src/main/resources/META-INF/quarkus-extension.yaml new file mode 100644 index 0000000..5f2775b --- /dev/null +++ b/extensions/oaipmh/runtime/src/main/resources/META-INF/quarkus-extension.yaml @@ -0,0 +1,31 @@ +# +# 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. +# + +# This is a generated file. Do not edit directly! +# To re-generate, run the following command from the top level directory: +# +# mvn -N cq:update-quarkus-metadata +# +--- +name: "Camel OAI-PMH" +description: "Harvest metadata using OAI-PMH protocol" +metadata: + guide: "https://camel.apache.org/camel-quarkus/latest/reference/extensions/oaipmh.html" + categories: + - "integration" + status: + - "stable" diff --git a/extensions/pom.xml b/extensions/pom.xml index 957d969..5c897be 100644 --- a/extensions/pom.xml +++ b/extensions/pom.xml @@ -174,6 +174,7 @@ <module>netty</module> <module>netty-http</module> <module>nsq</module> + <module>oaipmh</module> <module>olingo4</module> <module>openapi-java</module> <module>opentracing</module> diff --git a/integration-tests/oaipmh/pom.xml b/integration-tests/oaipmh/pom.xml new file mode 100644 index 0000000..4db0bba --- /dev/null +++ b/integration-tests/oaipmh/pom.xml @@ -0,0 +1,186 @@ +<?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/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-integration-tests</artifactId> + <version>1.7.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <artifactId>camel-quarkus-integration-test-oaipmh</artifactId> + <name>Camel Quarkus :: Integration Tests :: OAI-PMH</name> + <description>Integration tests for Camel Quarkus OAI-PMH extension</description> + + <dependencyManagement> + <dependencies> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-bom-test</artifactId> + <version>${project.version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + </dependencies> + </dependencyManagement> + + <dependencies> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-resteasy</artifactId> + </dependency> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-resteasy-jackson</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-direct</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-mock</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-oaipmh</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-xpath</artifactId> + </dependency> + + <!-- test dependencies --> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-junit5</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>io.rest-assured</groupId> + <artifactId>rest-assured</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-servlet</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-integration-test-support</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.awaitility</groupId> + <artifactId>awaitility</artifactId> + <scope>test</scope> + </dependency> + + <!-- The following dependencies guarantee that this module is built after them. You can update them by running `mvn process-resources -Pformat -N` from the source tree root directory --> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-direct-deployment</artifactId> + <version>${project.version}</version> + <type>pom</type> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>*</groupId> + <artifactId>*</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-mock-deployment</artifactId> + <version>${project.version}</version> + <type>pom</type> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>*</groupId> + <artifactId>*</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-oaipmh-deployment</artifactId> + <version>${project.version}</version> + <type>pom</type> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>*</groupId> + <artifactId>*</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-xpath-deployment</artifactId> + <version>${project.version}</version> + <type>pom</type> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>*</groupId> + <artifactId>*</artifactId> + </exclusion> + </exclusions> + </dependency> + + </dependencies> + + <profiles> + <profile> + <id>native</id> + <activation> + <property> + <name>native</name> + </property> + </activation> + <properties> + <quarkus.package.type>native</quarkus.package.type> + </properties> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>integration-test</goal> + <goal>verify</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + </profiles> + +</project> diff --git a/integration-tests/oaipmh/src/main/java/org/apache/camel/quarkus/component/oaipmh/it/OaipmhResource.java b/integration-tests/oaipmh/src/main/java/org/apache/camel/quarkus/component/oaipmh/it/OaipmhResource.java new file mode 100644 index 0000000..6fea902 --- /dev/null +++ b/integration-tests/oaipmh/src/main/java/org/apache/camel/quarkus/component/oaipmh/it/OaipmhResource.java @@ -0,0 +1,94 @@ +/* + * 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.quarkus.component.oaipmh.it; + +import java.util.List; +import java.util.stream.Collectors; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import org.apache.camel.CamelContext; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.component.mock.MockEndpoint; +import org.jboss.logging.Logger; + +@Path("/oaipmh") +@ApplicationScoped +public class OaipmhResource { + + private static final Logger LOG = Logger.getLogger(OaipmhResource.class); + + @Inject + CamelContext context; + + @Inject + ProducerTemplate producerTemplate; + + @Path("/consumerListRecords") + @GET + @Produces(MediaType.APPLICATION_JSON) + public List<String> consumerListRecords() { + LOG.debugf("Calling consumerListRecords()"); + MockEndpoint mockEndpoint = context.getEndpoint("mock:consumerListRecords", MockEndpoint.class); + return mockEndpoint.getExchanges().stream().map(e -> e.getIn().getBody(String.class)).collect(Collectors.toList()); + } + + @Path("/consumerListRecordsParticularCase") + @GET + @Produces(MediaType.APPLICATION_JSON) + public List<String> consumerListRecordsParticularCase() { + LOG.debugf("Calling consumerListRecordsParticularCase()"); + MockEndpoint mockEndpoint = context.getEndpoint("mock:consumerListRecordsParticularCase", MockEndpoint.class); + return mockEndpoint.getExchanges().stream().map(e -> e.getIn().getBody(String.class)).collect(Collectors.toList()); + } + + @Path("/consumerIdentifyHttps") + @GET + @Produces(MediaType.APPLICATION_JSON) + public List<String> consumerListRecordsHttps() { + LOG.debugf("Calling consumerIdentifyHttps()"); + MockEndpoint mockEndpoint = context.getEndpoint("mock:consumerIdentifyHttps", MockEndpoint.class); + return mockEndpoint.getExchanges().stream().map(e -> e.getIn().getBody(String.class)).collect(Collectors.toList()); + } + + @Path("/producerListRecords") + @GET + @Produces(MediaType.APPLICATION_JSON) + public List<String> producerListRecords() { + LOG.debugf("Calling producerListRecords()"); + MockEndpoint mockEndpoint = context.getEndpoint("mock:producerListRecords", MockEndpoint.class); + producerTemplate.requestBody("direct:producerListRecords", ""); + return mockEndpoint.getExchanges().stream().map(e -> e.getIn().getBody(String.class)).collect(Collectors.toList()); + } + + @Path("/producerGetRecord") + @GET + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.APPLICATION_JSON) + public List<String> producerGetRecord(String oaimphIdentifier) { + LOG.debugf("Calling producerGetRecord(%s)", oaimphIdentifier); + MockEndpoint mockEndpoint = context.getEndpoint("mock:producerGetRecord", MockEndpoint.class); + producerTemplate.requestBodyAndHeader("direct:producerGetRecord", "", "CamelOaimphIdentifier", oaimphIdentifier); + return mockEndpoint.getExchanges().stream().map(e -> e.getIn().getBody(String.class)).collect(Collectors.toList()); + } +} diff --git a/integration-tests/oaipmh/src/main/java/org/apache/camel/quarkus/component/oaipmh/it/OaipmhRoutes.java b/integration-tests/oaipmh/src/main/java/org/apache/camel/quarkus/component/oaipmh/it/OaipmhRoutes.java new file mode 100644 index 0000000..3a405a5 --- /dev/null +++ b/integration-tests/oaipmh/src/main/java/org/apache/camel/quarkus/component/oaipmh/it/OaipmhRoutes.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.quarkus.component.oaipmh.it; + +import javax.enterprise.context.ApplicationScoped; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.support.builder.Namespaces; +import org.eclipse.microprofile.config.inject.ConfigProperty; + +@ApplicationScoped +public class OaipmhRoutes extends RouteBuilder { + + @ConfigProperty(name = "cq-oaipmh-its.test1.server.authority") + String test1ServerAuthority; + @ConfigProperty(name = "cq-oaipmh-its.test2.server.authority") + String test2ServerAuthority; + @ConfigProperty(name = "cq-oaipmh-its.test3.server.authority") + String test3ServerAuthority; + @ConfigProperty(name = "cq-oaipmh-its.test4.server.authority") + String test4ServerAuthority; + + public void configure() { + + final Namespaces ns = new Namespaces(); + ns.add("default", "http://www.openarchives.org/OAI/2.0/"); + ns.add("oai_dc", "http://www.openarchives.org/OAI/2.0/oai_dc/"); + ns.add("dc", "http://purl.org/dc/elements/1.1/"); + + final String listRecordsXpath = "/default:OAI-PMH/default:ListRecords/default:record/default:metadata/oai_dc:dc/dc:title/text()"; + final String getRecordXpath = "/default:OAI-PMH/default:GetRecord/default:record/default:metadata/oai_dc:dc/dc:title/text()"; + + fromF("oaipmh://%s/oai/request?delay=1000&from=2020-06-01T00:00:00Z&initialDelay=1000", test1ServerAuthority) + .split(xpath(listRecordsXpath, ns)) + .to("mock:consumerListRecords"); + + fromF("oaipmh://%s/index.php?page=oai&delay=1000&from=2020-02-01T00:00:00Z&initialDelay=1000", test3ServerAuthority) + .split(xpath(listRecordsXpath, ns)) + .to("mock:consumerListRecordsParticularCase"); + + final String uriFormat = "oaipmh://%s/oai/request?ssl=true&ignoreSSLWarnings=true&delay=1000&verb=Identify&initialDelay=1000"; + fromF(uriFormat, test4ServerAuthority) + .to("mock:consumerIdentifyHttps"); + + from("direct:producerListRecords") + .setHeader("CamelOaimphFrom", constant("2020-06-01T00:00:00Z")) + .toF("oaipmh://%s/oai/request", test1ServerAuthority) + .split(body()) + .split(xpath(listRecordsXpath, ns)) + .to("mock:producerListRecords"); + + from("direct:producerGetRecord") + .setHeader("CamelOaimphVerb", constant("GetRecord")) + .toF("oaipmh://%s/oai/request", test2ServerAuthority) + .split(body()) + .split(xpath(getRecordXpath, ns)) + .to("mock:producerGetRecord"); + } +} diff --git a/integration-tests/oaipmh/src/test/java/org/apache/camel/quarkus/component/oaipmh/it/OaipmhIT.java b/integration-tests/oaipmh/src/test/java/org/apache/camel/quarkus/component/oaipmh/it/OaipmhIT.java new file mode 100644 index 0000000..9519f66 --- /dev/null +++ b/integration-tests/oaipmh/src/test/java/org/apache/camel/quarkus/component/oaipmh/it/OaipmhIT.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.quarkus.component.oaipmh.it; + +import io.quarkus.test.junit.NativeImageTest; + +@NativeImageTest +class OaipmhIT extends OaipmhTest { + +} diff --git a/integration-tests/oaipmh/src/test/java/org/apache/camel/quarkus/component/oaipmh/it/OaipmhTest.java b/integration-tests/oaipmh/src/test/java/org/apache/camel/quarkus/component/oaipmh/it/OaipmhTest.java new file mode 100644 index 0000000..8d67cfe --- /dev/null +++ b/integration-tests/oaipmh/src/test/java/org/apache/camel/quarkus/component/oaipmh/it/OaipmhTest.java @@ -0,0 +1,70 @@ +/* + * 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.quarkus.component.oaipmh.it; + +import java.util.concurrent.TimeUnit; + +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.junit.QuarkusTest; +import org.junit.jupiter.api.Test; + +import static io.restassured.RestAssured.get; +import static io.restassured.RestAssured.given; +import static org.awaitility.Awaitility.await; +import static org.hamcrest.Matchers.is; + +@QuarkusTest +@QuarkusTestResource(OaipmhTestResource.class) +class OaipmhTest { + + @Test + void consumerListRecordsShouldReturn532Records() { + await().atMost(10, TimeUnit.SECONDS).until(() -> { + String[] records = get("/oaipmh/consumerListRecords").then().statusCode(200).extract().as(String[].class); + return records.length == 532; + }); + } + + @Test + void consumerListRecordsParticularCaseShouldReturn45Records() { + await().atMost(5, TimeUnit.SECONDS).until(() -> { + String path = "/oaipmh/consumerListRecordsParticularCase"; + String[] records = get(path).then().statusCode(200).extract().as(String[].class); + return records.length == 45; + }); + } + + @Test + void consumerIdentifyHttpsShouldReturnSingleRecord() { + await().atMost(5, TimeUnit.SECONDS).until(() -> { + String[] records = get("/oaipmh/consumerIdentifyHttps").then().statusCode(200).extract().as(String[].class); + return records.length == 1; + }); + } + + @Test + void producerListRecordsShouldReturn532Records() { + get("/oaipmh/producerListRecords").then().statusCode(200).body("size()", is(532)); + } + + @Test + void producerGetRecordShouldReturnSingleRecord() { + String id = "oai:dspace.ucuenca.edu.ec:123456789/32374"; + given().body(id).get("/oaipmh/producerGetRecord").then().statusCode(200).body("size()", is(1)); + } + +} diff --git a/integration-tests/oaipmh/src/test/java/org/apache/camel/quarkus/component/oaipmh/it/OaipmhTestResource.java b/integration-tests/oaipmh/src/test/java/org/apache/camel/quarkus/component/oaipmh/it/OaipmhTestResource.java new file mode 100644 index 0000000..daba8e5 --- /dev/null +++ b/integration-tests/oaipmh/src/test/java/org/apache/camel/quarkus/component/oaipmh/it/OaipmhTestResource.java @@ -0,0 +1,62 @@ +/* + * 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.quarkus.component.oaipmh.it; + +import java.util.HashMap; +import java.util.Map; + +import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; +import org.apache.camel.quarkus.test.AvailablePortFinder; + +public class OaipmhTestResource implements QuarkusTestResourceLifecycleManager { + + private OaipmhTestServer test1Server, test2Server, test3Server, test4Server; + + @Override + public Map<String, String> start() { + Map<String, String> systemProperties = new HashMap<>(); + this.test1Server = initOaipmhTestServer("test1", systemProperties, false); + this.test2Server = initOaipmhTestServer("test2", systemProperties, false); + this.test3Server = initOaipmhTestServer("test3", systemProperties, false); + this.test4Server = initOaipmhTestServer("test4", systemProperties, true); + return systemProperties; + } + + private OaipmhTestServer initOaipmhTestServer(String context, Map<String, String> properties, boolean useHttps) { + int availablePort = AvailablePortFinder.getNextAvailable(); + OaipmhTestServer server = new OaipmhTestServer(context, availablePort, useHttps); + server.startServer(); + properties.put("cq-oaipmh-its." + context + ".server.authority", "localhost:" + availablePort); + return server; + } + + @Override + public void stop() { + if (test1Server != null) { + test1Server.stopServer(); + } + if (test2Server != null) { + test2Server.stopServer(); + } + if (test3Server != null) { + test3Server.stopServer(); + } + if (test4Server != null) { + test4Server.stopServer(); + } + } +} diff --git a/integration-tests/oaipmh/src/test/java/org/apache/camel/quarkus/component/oaipmh/it/OaipmhTestServer.java b/integration-tests/oaipmh/src/test/java/org/apache/camel/quarkus/component/oaipmh/it/OaipmhTestServer.java new file mode 100644 index 0000000..a73cb18 --- /dev/null +++ b/integration-tests/oaipmh/src/test/java/org/apache/camel/quarkus/component/oaipmh/it/OaipmhTestServer.java @@ -0,0 +1,149 @@ +/* + * 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.quarkus.component.oaipmh.it; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; + +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.codec.digest.DigestUtils; +import org.apache.commons.io.IOUtils; +import org.eclipse.jetty.server.Connector; +import org.eclipse.jetty.server.HttpConfiguration; +import org.eclipse.jetty.server.HttpConnectionFactory; +import org.eclipse.jetty.server.SecureRequestCustomizer; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.ServerConnector; +import org.eclipse.jetty.server.SslConnectionFactory; +import org.eclipse.jetty.servlet.ServletContextHandler; +import org.eclipse.jetty.servlet.ServletHolder; +import org.eclipse.jetty.util.ssl.SslContextFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class OaipmhTestServer { + + private static final Logger LOG = LoggerFactory.getLogger(OaipmhTestServer.class); + private static final String PASSWORD = "changeit"; + private static Map<String, String> RESPONSE_CACHE; + + private String context; + private boolean useHttps; + private int port; + private Server server; + + public OaipmhTestServer(String context, int port) { + this(context, port, false); + } + + public OaipmhTestServer(String context, int port, boolean useHttps) { + this.context = context; + this.useHttps = useHttps; + this.port = port; + } + + private static synchronized Map<String, String> getResponseCache() throws IOException { + if (RESPONSE_CACHE == null) { + HashMap<String, String> responseCache = new HashMap<String, String>(); + + ZipInputStream zis = new ZipInputStream(OaipmhTestServer.class.getResourceAsStream("/data.zip")); + + ZipEntry entry = zis.getNextEntry(); + while (entry != null) { + if (!entry.isDirectory()) { + responseCache.put(entry.getName(), IOUtils.toString(zis, StandardCharsets.UTF_8)); + } + entry = zis.getNextEntry(); + } + RESPONSE_CACHE = Collections.unmodifiableMap(responseCache); + } + return RESPONSE_CACHE; + } + + public void startServer() { + server = new Server(port); + + if (useHttps) { + HttpConfiguration https = new HttpConfiguration(); + https.addCustomizer(new SecureRequestCustomizer()); + SslContextFactory.Server sslContextFactory = new SslContextFactory.Server(); + + String keyStorePath = OaipmhTestServer.class.getResource("/jettyKS/localhost.p12").toExternalForm(); + sslContextFactory.setKeyStorePath(keyStorePath); + sslContextFactory.setKeyStorePassword(PASSWORD); + sslContextFactory.setKeyManagerPassword(PASSWORD); + ServerConnector sslConnector = new ServerConnector( + server, + new SslConnectionFactory(sslContextFactory, "http/1.1"), + new HttpConnectionFactory(https)); + + sslConnector.setPort(port); + server.setConnectors(new Connector[] { sslConnector }); + } + + ServletContextHandler servletContext = new ServletContextHandler(ServletContextHandler.SESSIONS); + servletContext.setContextPath("/"); + server.setHandler(servletContext); + servletContext.addServlet(new ServletHolder(new OaipmhTestServlet(this.context)), "/*"); + + try { + server.start(); + } catch (Exception ex) { + LOG.error("An issue prevented an OaipmhTestServer from starting, so giving up", ex); + throw new RuntimeException("An issue prevented an OaipmhTestServer from starting", ex); + } + } + + public void stopServer() { + if (server != null) { + try { + server.stop(); + } catch (Exception ex) { + LOG.warn("An issue prevented an OaipmhTestServer from stopping, so ignoring", ex); + } finally { + server = null; + } + } + } + + private class OaipmhTestServlet extends HttpServlet { + + private static final long serialVersionUID = 5594945031962091041L; + + private String context; + + public OaipmhTestServlet(String context) { + this.context = context; + } + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { + String qs = req.getRequestURI() + "?" + req.getQueryString(); + String sha256Hex = DigestUtils.sha256Hex(qs); + resp.getWriter().write(getResponseCache().get("data/" + this.context + "/" + sha256Hex + ".xml")); + } + } + +} diff --git a/integration-tests/oaipmh/src/test/resources/data.zip b/integration-tests/oaipmh/src/test/resources/data.zip new file mode 100644 index 0000000..1c99b62 Binary files /dev/null and b/integration-tests/oaipmh/src/test/resources/data.zip differ diff --git a/integration-tests/oaipmh/src/test/resources/jettyKS/localhost.p12 b/integration-tests/oaipmh/src/test/resources/jettyKS/localhost.p12 new file mode 100644 index 0000000..5f6a30d Binary files /dev/null and b/integration-tests/oaipmh/src/test/resources/jettyKS/localhost.p12 differ diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index 899cdf8..fe70ae9 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -146,6 +146,7 @@ <module>nats</module> <module>netty</module> <module>nsq</module> + <module>oaipmh</module> <module>olingo4</module> <module>openapi-java</module> <module>opentracing</module> diff --git a/pom.xml b/pom.xml index 59c3e29..355004b 100644 --- a/pom.xml +++ b/pom.xml @@ -84,6 +84,7 @@ <java.xml.ws.version>2.3.1</java.xml.ws.version> <jcodings.version>1.0.55</jcodings.version><!-- used by hbase --> <joni.version>2.1.31</joni.version><!-- used by json-validator --> + <jsoup.version>1.12.1</jsoup.version><!-- used by oaipmh --> <jaxen.version>1.2.0</jaxen.version> <javassist.version>3.22.0-CR2</javassist.version><!-- debezium --> <jersey-sun.version>1.19.4</jersey-sun.version><!-- Spark --> diff --git a/poms/bom/pom.xml b/poms/bom/pom.xml index 5ae6e99..12d35c1 100644 --- a/poms/bom/pom.xml +++ b/poms/bom/pom.xml @@ -1560,6 +1560,11 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> + <artifactId>camel-oaipmh</artifactId> + <version>${camel.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> <artifactId>camel-ognl</artifactId> <version>${camel.version}</version> </dependency> @@ -4257,6 +4262,16 @@ </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-oaipmh</artifactId> + <version>${camel-quarkus.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-oaipmh-deployment</artifactId> + <version>${camel-quarkus.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-ognl</artifactId> <version>${camel-quarkus.version}</version> </dependency> @@ -5928,6 +5943,11 @@ <version>${joni.version}</version> </dependency> <dependency> + <groupId>org.jsoup</groupId> + <artifactId>jsoup</artifactId> + <version>${jsoup.version}</version> + </dependency> + <dependency> <groupId>org.kie.soup</groupId> <artifactId>kie-soup-commons</artifactId> <version>${optaplanner.version}</version> diff --git a/tooling/scripts/test-categories.yaml b/tooling/scripts/test-categories.yaml index eb3e39b..7c60ec1 100644 --- a/tooling/scripts/test-categories.yaml +++ b/tooling/scripts/test-categories.yaml @@ -130,6 +130,7 @@ misc: - jolt - mustache - nagios + - oaipmh - pdf - qute - shiro