This is an automated email from the ASF dual-hosted git repository. JiriOndrusek pushed a commit to branch camel-main in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
commit b79b12392720dc52ea9c41f2c157aa047086300b Author: Jomin <[email protected]> AuthorDate: Fri May 8 07:09:14 2026 +0100 Fixes #8592. Add camel-quarkus-jsoup extension with native support Co-authored-by: jomin mathew <> --- catalog/pom.xml | 13 ++ docs/modules/ROOT/examples/others/jsoup.yml | 13 ++ docs/modules/ROOT/nav.adoc | 1 + .../ROOT/pages/reference/extensions/jsoup.adoc | 45 ++++++ extensions/jsoup/deployment/pom.xml | 61 ++++++++ .../component/jsoup/deployment/JsoupProcessor.java | 31 ++++ extensions/jsoup/pom.xml | 37 +++++ extensions/jsoup/runtime/pom.xml | 70 +++++++++ .../main/resources/META-INF/quarkus-extension.yaml | 32 ++++ extensions/pom.xml | 1 + integration-tests/jsoup/pom.xml | 144 ++++++++++++++++++ .../quarkus/component/jsoup/it/JsoupResource.java | 91 ++++++++++++ .../component/jsoup/it/JsoupRouteBuilder.java | 50 +++++++ .../src/main/resources/application.properties | 17 +++ .../src/main/resources/yaml/jsoup-routes.yaml | 40 +++++ .../camel/quarkus/component/jsoup/it/JsoupIT.java | 23 +++ .../quarkus/component/jsoup/it/JsoupTest.java | 161 +++++++++++++++++++++ integration-tests/pom.xml | 1 + poms/bom/pom.xml | 15 ++ poms/bom/src/main/generated/flattened-full-pom.xml | 15 ++ .../src/main/generated/flattened-reduced-pom.xml | 15 ++ .../generated/flattened-reduced-verbose-pom.xml | 15 ++ tooling/scripts/test-categories.yaml | 1 + 23 files changed, 892 insertions(+) diff --git a/catalog/pom.xml b/catalog/pom.xml index 177b138f4c..23fd15ff0a 100644 --- a/catalog/pom.xml +++ b/catalog/pom.xml @@ -2346,6 +2346,19 @@ </exclusion> </exclusions> </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-jsoup</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-jt400</artifactId> diff --git a/docs/modules/ROOT/examples/others/jsoup.yml b/docs/modules/ROOT/examples/others/jsoup.yml new file mode 100644 index 0000000000..f12e935c12 --- /dev/null +++ b/docs/modules/ROOT/examples/others/jsoup.yml @@ -0,0 +1,13 @@ +# Do not edit directly! +# This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page +cqArtifactId: camel-quarkus-jsoup +cqArtifactIdBase: jsoup +cqNativeSupported: true +cqStatus: Stable +cqDeprecated: false +cqJvmSince: 3.36.0 +cqNativeSince: 3.36.0 +cqCamelPartName: jsoup +cqCamelPartTitle: Jsoup +cqCamelPartDescription: Cleanup HTML content +cqExtensionPageTitle: Jsoup diff --git a/docs/modules/ROOT/nav.adoc b/docs/modules/ROOT/nav.adoc index c3a842616f..81c8d8e2ec 100644 --- a/docs/modules/ROOT/nav.adoc +++ b/docs/modules/ROOT/nav.adoc @@ -196,6 +196,7 @@ *** xref:reference/extensions/jira.adoc[Jira] *** xref:reference/extensions/jolokia.adoc[Jolokia] *** xref:reference/extensions/json-patch.adoc[JsonPatch] +*** xref:reference/extensions/jsoup.adoc[Jsoup] *** xref:reference/extensions/kafka.adoc[Kafka] *** xref:reference/extensions/kamelet.adoc[Kamelet] *** xref:reference/extensions/keycloak.adoc[Keycloak] diff --git a/docs/modules/ROOT/pages/reference/extensions/jsoup.adoc b/docs/modules/ROOT/pages/reference/extensions/jsoup.adoc new file mode 100644 index 0000000000..5f30aa7434 --- /dev/null +++ b/docs/modules/ROOT/pages/reference/extensions/jsoup.adoc @@ -0,0 +1,45 @@ +// Do not edit directly! +// This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page +[id="extensions-jsoup"] += Jsoup +:linkattrs: +:cq-artifact-id: camel-quarkus-jsoup +:cq-native-supported: true +:cq-status: Stable +:cq-status-deprecation: Stable +:cq-description: Parse HTML using jsoup +:cq-deprecated: false +:cq-jvm-since: 3.36.0 +:cq-native-since: 3.36.0 + +ifeval::[{doc-show-badges} == true] +[.badges] +[.badge-key]##JVM since##[.badge-supported]##3.36.0## [.badge-key]##Native since##[.badge-supported]##3.36.0## +endif::[] + +Parse HTML using jsoup + +[id="extensions-jsoup-whats-inside"] +== What's inside + +* xref:{cq-camel-components}:others:jsoup.adoc[Jsoup] + +Please refer to the above link for usage and configuration details. + +[id="extensions-jsoup-maven-coordinates"] +== Maven coordinates + +https://{link-quarkus-code-generator}/?extension-search=camel-quarkus-jsoup[Create a new project with this extension on {link-quarkus-code-generator}, window="_blank"] + +Or add the coordinates to your existing project: + +[source,xml] +---- +<dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-jsoup</artifactId> +</dependency> +---- +ifeval::[{doc-show-user-guide-link} == true] +Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications. +endif::[] diff --git a/extensions/jsoup/deployment/pom.xml b/extensions/jsoup/deployment/pom.xml new file mode 100644 index 0000000000..c3162bb9df --- /dev/null +++ b/extensions/jsoup/deployment/pom.xml @@ -0,0 +1,61 @@ +<?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-jsoup-parent</artifactId> + <version>3.36.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <artifactId>camel-quarkus-jsoup-deployment</artifactId> + <name>Camel Quarkus :: Jsoup :: 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-jsoup</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/jsoup/deployment/src/main/java/org/apache/camel/quarkus/component/jsoup/deployment/JsoupProcessor.java b/extensions/jsoup/deployment/src/main/java/org/apache/camel/quarkus/component/jsoup/deployment/JsoupProcessor.java new file mode 100644 index 0000000000..5ea9f5f77c --- /dev/null +++ b/extensions/jsoup/deployment/src/main/java/org/apache/camel/quarkus/component/jsoup/deployment/JsoupProcessor.java @@ -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. + */ +package org.apache.camel.quarkus.component.jsoup.deployment; + +import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.builditem.FeatureBuildItem; + +class JsoupProcessor { + + private static final String FEATURE = "camel-jsoup"; + + @BuildStep + FeatureBuildItem feature() { + return new FeatureBuildItem(FEATURE); + } + +} diff --git a/extensions/jsoup/pom.xml b/extensions/jsoup/pom.xml new file mode 100644 index 0000000000..d89e16eb88 --- /dev/null +++ b/extensions/jsoup/pom.xml @@ -0,0 +1,37 @@ +<?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-extensions</artifactId> + <version>3.36.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <artifactId>camel-quarkus-jsoup-parent</artifactId> + <name>Camel Quarkus :: Jsoup</name> + <packaging>pom</packaging> + + <modules> + <module>deployment</module> + <module>runtime</module> + </modules> +</project> diff --git a/extensions/jsoup/runtime/pom.xml b/extensions/jsoup/runtime/pom.xml new file mode 100644 index 0000000000..ae87b6bee8 --- /dev/null +++ b/extensions/jsoup/runtime/pom.xml @@ -0,0 +1,70 @@ +<?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-jsoup-parent</artifactId> + <version>3.36.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <artifactId>camel-quarkus-jsoup</artifactId> + <name>Camel Quarkus :: Jsoup :: Runtime</name> + <description>Parse HTML using jsoup</description> + + <properties> + <camel.quarkus.jvmSince>3.36.0</camel.quarkus.jvmSince> + <camel.quarkus.nativeSince>3.36.0</camel.quarkus.nativeSince> + </properties> + + <dependencies> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-core</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-jsoup</artifactId> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-extension-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> +</project> diff --git a/extensions/jsoup/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/extensions/jsoup/runtime/src/main/resources/META-INF/quarkus-extension.yaml new file mode 100644 index 0000000000..af79371e34 --- /dev/null +++ b/extensions/jsoup/runtime/src/main/resources/META-INF/quarkus-extension.yaml @@ -0,0 +1,32 @@ +# +# 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 Jsoup" +description: "Parse HTML using jsoup" +metadata: + icon-url: "https://raw.githubusercontent.com/apache/camel-website/main/antora-ui-camel/src/img/logo-d.svg" + sponsor: "Apache Software Foundation" + guide: "https://camel.apache.org/camel-quarkus/latest/reference/extensions/jsoup.html" + categories: + - "integration" + status: "stable" diff --git a/extensions/pom.xml b/extensions/pom.xml index c3899c3272..f4d729ff8a 100644 --- a/extensions/pom.xml +++ b/extensions/pom.xml @@ -170,6 +170,7 @@ <module>jsonata</module> <module>jsonb</module> <module>jsonpath</module> + <module>jsoup</module> <module>jt400</module> <module>jta</module> <module>kafka</module> diff --git a/integration-tests/jsoup/pom.xml b/integration-tests/jsoup/pom.xml new file mode 100644 index 0000000000..23bd3f4a0f --- /dev/null +++ b/integration-tests/jsoup/pom.xml @@ -0,0 +1,144 @@ +<?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-it</artifactId> + <version>3.36.0-SNAPSHOT</version> + <relativePath>../../poms/build-parent-it/pom.xml</relativePath> + </parent> + + <artifactId>camel-quarkus-integration-test-jsoup</artifactId> + <name>Camel Quarkus :: Integration Tests :: Jsoup</name> + <description>Integration tests for Camel Quarkus Jsoup extension</description> + + <dependencies> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-direct</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-jsoup</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-yaml-dsl</artifactId> + </dependency> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-resteasy</artifactId> + </dependency> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-junit</artifactId> + </dependency> + + <!-- test dependencies --> + <dependency> + <groupId>io.rest-assured</groupId> + <artifactId>rest-assured</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + + + <profiles> + <profile> + <id>native</id> + <activation> + <property> + <name>native</name> + </property> + </activation> + <properties> + <quarkus.native.enabled>true</quarkus.native.enabled> + </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> + <profile> + <id>virtualDependencies</id> + <activation> + <property> + <name>!noVirtualDependencies</name> + </property> + </activation> + <dependencies> + <!-- 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-jsoup-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-yaml-dsl-deployment</artifactId> + <version>${project.version}</version> + <type>pom</type> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>*</groupId> + <artifactId>*</artifactId> + </exclusion> + </exclusions> + </dependency> + </dependencies> + </profile> + </profiles> + +</project> diff --git a/integration-tests/jsoup/src/main/java/org/apache/camel/quarkus/component/jsoup/it/JsoupResource.java b/integration-tests/jsoup/src/main/java/org/apache/camel/quarkus/component/jsoup/it/JsoupResource.java new file mode 100644 index 0000000000..50477ae14c --- /dev/null +++ b/integration-tests/jsoup/src/main/java/org/apache/camel/quarkus/component/jsoup/it/JsoupResource.java @@ -0,0 +1,91 @@ +/* + * 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.jsoup.it; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; +import org.apache.camel.ProducerTemplate; + +@Path("/jsoup") +@ApplicationScoped +public class JsoupResource { + + @Inject + ProducerTemplate producerTemplate; + + @Path("/clean") + @POST + @Consumes(MediaType.TEXT_HTML) + @Produces(MediaType.TEXT_HTML) + public String clean(String html) { + return producerTemplate.requestBody("direct:clean", html, String.class); + } + + @Path("/decode") + @POST + @Consumes(MediaType.TEXT_HTML) + @Produces(MediaType.TEXT_PLAIN) + public String decode(String html) { + return producerTemplate.requestBody("direct:decode", html, String.class); + } + + @Path("/parse-title") + @POST + @Consumes(MediaType.TEXT_HTML) + @Produces(MediaType.TEXT_PLAIN) + public String parseTitle(String html) { + return producerTemplate.requestBody("direct:parse-title", html, String.class); + } + + @Path("/select-css") + @POST + @Consumes(MediaType.TEXT_HTML) + @Produces(MediaType.TEXT_PLAIN) + public String selectCss(String html) { + return producerTemplate.requestBody("direct:select-css", html, String.class); + } + + @Path("/clean-yaml") + @POST + @Consumes(MediaType.TEXT_HTML) + @Produces(MediaType.TEXT_HTML) + public String cleanYaml(String html) { + return producerTemplate.requestBody("direct:clean-yaml", html, String.class); + } + + @Path("/decode-yaml") + @POST + @Consumes(MediaType.TEXT_HTML) + @Produces(MediaType.TEXT_PLAIN) + public String decodeYaml(String html) { + return producerTemplate.requestBody("direct:decode-yaml", html, String.class); + } + + @Path("/parse-yaml") + @POST + @Consumes(MediaType.TEXT_HTML) + @Produces(MediaType.TEXT_HTML) + public String parseYaml(String html) { + org.jsoup.nodes.Document doc = producerTemplate.requestBody("direct:parse-yaml", html, org.jsoup.nodes.Document.class); + return doc != null ? doc.outerHtml() : ""; + } +} diff --git a/integration-tests/jsoup/src/main/java/org/apache/camel/quarkus/component/jsoup/it/JsoupRouteBuilder.java b/integration-tests/jsoup/src/main/java/org/apache/camel/quarkus/component/jsoup/it/JsoupRouteBuilder.java new file mode 100644 index 0000000000..53ba193fd5 --- /dev/null +++ b/integration-tests/jsoup/src/main/java/org/apache/camel/quarkus/component/jsoup/it/JsoupRouteBuilder.java @@ -0,0 +1,50 @@ +/* + * 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.jsoup.it; + +import org.apache.camel.builder.RouteBuilder; +import org.jsoup.nodes.Document; + +public class JsoupRouteBuilder extends RouteBuilder { + @Override + public void configure() { + // Test htmlClean() function + from("direct:clean") + .transform().simple("${htmlClean()}"); + + // Test htmlDecode() function + from("direct:decode") + .transform().simple("${htmlDecode()}"); + + // Test htmlParse() function - extract title + from("direct:parse-title") + .transform().simple("${htmlParse()}") + .process(exchange -> { + Document doc = exchange.getMessage().getBody(Document.class); + exchange.getMessage().setBody(doc.title()); + }); + + // Test htmlParse() with CSS selection + from("direct:select-css") + .transform().simple("${htmlParse()}") + .process(exchange -> { + Document doc = exchange.getMessage().getBody(Document.class); + String text = doc.select("p").text(); + exchange.getMessage().setBody(text); + }); + } +} diff --git a/integration-tests/jsoup/src/main/resources/application.properties b/integration-tests/jsoup/src/main/resources/application.properties new file mode 100644 index 0000000000..695ae2f5f3 --- /dev/null +++ b/integration-tests/jsoup/src/main/resources/application.properties @@ -0,0 +1,17 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- +camel.main.routes-include-pattern = classpath:yaml/jsoup-routes.yaml diff --git a/integration-tests/jsoup/src/main/resources/yaml/jsoup-routes.yaml b/integration-tests/jsoup/src/main/resources/yaml/jsoup-routes.yaml new file mode 100644 index 0000000000..c41fbc7394 --- /dev/null +++ b/integration-tests/jsoup/src/main/resources/yaml/jsoup-routes.yaml @@ -0,0 +1,40 @@ +# +# 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. +# + +- route: + id: "clean-yaml" + from: + uri: "direct:clean-yaml" + steps: + - setBody: + simple: "${htmlClean()}" + +- route: + id: "decode-yaml" + from: + uri: "direct:decode-yaml" + steps: + - setBody: + simple: "${htmlDecode()}" + +- route: + id: "parse-yaml" + from: + uri: "direct:parse-yaml" + steps: + - setBody: + simple: "${htmlParse()}" diff --git a/integration-tests/jsoup/src/test/java/org/apache/camel/quarkus/component/jsoup/it/JsoupIT.java b/integration-tests/jsoup/src/test/java/org/apache/camel/quarkus/component/jsoup/it/JsoupIT.java new file mode 100644 index 0000000000..ec130d2e54 --- /dev/null +++ b/integration-tests/jsoup/src/test/java/org/apache/camel/quarkus/component/jsoup/it/JsoupIT.java @@ -0,0 +1,23 @@ +/* + * 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.jsoup.it; + +import io.quarkus.test.junit.QuarkusIntegrationTest; + +@QuarkusIntegrationTest +class JsoupIT extends JsoupTest { +} diff --git a/integration-tests/jsoup/src/test/java/org/apache/camel/quarkus/component/jsoup/it/JsoupTest.java b/integration-tests/jsoup/src/test/java/org/apache/camel/quarkus/component/jsoup/it/JsoupTest.java new file mode 100644 index 0000000000..90701c5af7 --- /dev/null +++ b/integration-tests/jsoup/src/test/java/org/apache/camel/quarkus/component/jsoup/it/JsoupTest.java @@ -0,0 +1,161 @@ +/* + * 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.jsoup.it; + +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.RestAssured; +import io.restassured.http.ContentType; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.not; + +@QuarkusTest +class JsoupTest { + + @Test + void testHtmlClean() { + String maliciousHtml = "<p><a href='https://example.com/' onclick='stealCookies()'>Link</a></p>"; + + RestAssured.given() + .contentType(ContentType.HTML) + .body(maliciousHtml) + .post("/jsoup/clean") + .then() + .statusCode(200) + .body(containsString("<a href=\"https://example.com/\"")) + .body(containsString("Link")) + .body(not(containsString("onclick"))); + } + + @Test + void testHtmlDecode() { + String html = "<html><title>My Camel</title><body><p>Some blah blah</p></body></html>"; + + RestAssured.given() + .contentType(ContentType.HTML) + .body(html) + .post("/jsoup/decode") + .then() + .statusCode(200) + .body(equalTo("My Camel Some blah blah")); + } + + @Test + void testHtmlParseTitle() { + String html = "<html><title>Test Title</title><body><p>Content</p></body></html>"; + + RestAssured.given() + .contentType(ContentType.HTML) + .body(html) + .post("/jsoup/parse-title") + .then() + .statusCode(200) + .body(equalTo("Test Title")); + } + + @Test + void testCssSelection() { + String html = "<html><body><p>First paragraph</p><p>Second paragraph</p></body></html>"; + + RestAssured.given() + .contentType(ContentType.HTML) + .body(html) + .post("/jsoup/select-css") + .then() + .statusCode(200) + .body(equalTo("First paragraph Second paragraph")); + } + + @Test + void testHtmlCleanYaml() { + String maliciousHtml = "<p><a href='https://example.com/' onclick='stealCookies()'>Link</a></p>"; + + RestAssured.given() + .contentType(ContentType.HTML) + .body(maliciousHtml) + .post("/jsoup/clean-yaml") + .then() + .statusCode(200) + .body(containsString("<a href=\"https://example.com/\"")) + .body(containsString("Link")) + .body(not(containsString("onclick"))); + } + + @Test + void testHtmlDecodeYaml() { + String html = "<html><title>My Camel</title><body><p>Some blah blah</p></body></html>"; + + RestAssured.given() + .contentType(ContentType.HTML) + .body(html) + .post("/jsoup/decode-yaml") + .then() + .statusCode(200) + .body(equalTo("My Camel Some blah blah")); + } + + @Test + void testHtmlParseYaml() { + String html = "<html><title>Test Title</title><body><p>Content</p></body></html>"; + + RestAssured.given() + .contentType(ContentType.HTML) + .body(html) + .post("/jsoup/parse-yaml") + .then() + .statusCode(200) + .body(containsString("<title>Test Title</title>")) + .body(containsString("<p>Content</p>")); + } + + @Test + void testHtmlCleanEmptyInput() { + RestAssured.given() + .contentType(ContentType.HTML) + .body("") + .post("/jsoup/clean") + .then() + .statusCode(200) + .body(equalTo("")); + } + + @Test + void testHtmlDecodeEmptyInput() { + RestAssured.given() + .contentType(ContentType.HTML) + .body("") + .post("/jsoup/decode") + .then() + .statusCode(200) + .body(equalTo("")); + } + + @Test + void testHtmlParseNullBody() { + String html = "<html><body></body></html>"; + + RestAssured.given() + .contentType(ContentType.HTML) + .body(html) + .post("/jsoup/parse-title") + .then() + .statusCode(200) + .body(equalTo("")); + } +} diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index 31143241f5..18d8a55613 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -143,6 +143,7 @@ <module>json-validator</module> <module>jsonata</module> <module>jsonpath</module> + <module>jsoup</module> <module>jt400</module> <module>jt400-mocked</module> <module>jta</module> diff --git a/poms/bom/pom.xml b/poms/bom/pom.xml index 3669315dbd..7369091ef1 100644 --- a/poms/bom/pom.xml +++ b/poms/bom/pom.xml @@ -1963,6 +1963,11 @@ <artifactId>camel-jsonpath</artifactId> <version>${camel.version}</version> </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-jsoup</artifactId> + <version>${camel.version}</version> + </dependency> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-jt400</artifactId> @@ -5133,6 +5138,16 @@ <artifactId>camel-quarkus-jsonpath-deployment</artifactId> <version>${camel-quarkus.version}</version> </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-jsoup</artifactId> + <version>${camel-quarkus.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-jsoup-deployment</artifactId> + <version>${camel-quarkus.version}</version> + </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-jt400</artifactId> diff --git a/poms/bom/src/main/generated/flattened-full-pom.xml b/poms/bom/src/main/generated/flattened-full-pom.xml index f694f29afa..ab73f0cb4b 100644 --- a/poms/bom/src/main/generated/flattened-full-pom.xml +++ b/poms/bom/src/main/generated/flattened-full-pom.xml @@ -1876,6 +1876,11 @@ <artifactId>camel-jsonpath</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> <version>4.21.0-SNAPSHOT</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> </dependency> + <dependency> + <groupId>org.apache.camel</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + <artifactId>camel-jsoup</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + <version>4.21.0-SNAPSHOT</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + </dependency> <dependency> <groupId>org.apache.camel</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> <artifactId>camel-jt400</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> @@ -5018,6 +5023,16 @@ <artifactId>camel-quarkus-jsonpath-deployment</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> <version>3.36.0-SNAPSHOT</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + <artifactId>camel-quarkus-jsoup</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + <version>3.36.0-SNAPSHOT</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + <artifactId>camel-quarkus-jsoup-deployment</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + <version>3.36.0-SNAPSHOT</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> <artifactId>camel-quarkus-jt400</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> diff --git a/poms/bom/src/main/generated/flattened-reduced-pom.xml b/poms/bom/src/main/generated/flattened-reduced-pom.xml index a9b7605227..8a59d5048d 100644 --- a/poms/bom/src/main/generated/flattened-reduced-pom.xml +++ b/poms/bom/src/main/generated/flattened-reduced-pom.xml @@ -1871,6 +1871,11 @@ <artifactId>camel-jsonpath</artifactId> <version>4.21.0-SNAPSHOT</version> </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-jsoup</artifactId> + <version>4.21.0-SNAPSHOT</version> + </dependency> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-jt400</artifactId> @@ -4997,6 +5002,16 @@ <artifactId>camel-quarkus-jsonpath-deployment</artifactId> <version>3.36.0-SNAPSHOT</version> </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-jsoup</artifactId> + <version>3.36.0-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-jsoup-deployment</artifactId> + <version>3.36.0-SNAPSHOT</version> + </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-jt400</artifactId> diff --git a/poms/bom/src/main/generated/flattened-reduced-verbose-pom.xml b/poms/bom/src/main/generated/flattened-reduced-verbose-pom.xml index b2906da95d..9e26e64f2f 100644 --- a/poms/bom/src/main/generated/flattened-reduced-verbose-pom.xml +++ b/poms/bom/src/main/generated/flattened-reduced-verbose-pom.xml @@ -1871,6 +1871,11 @@ <artifactId>camel-jsonpath</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> <version>4.21.0-SNAPSHOT</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> </dependency> + <dependency> + <groupId>org.apache.camel</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + <artifactId>camel-jsoup</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + <version>4.21.0-SNAPSHOT</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + </dependency> <dependency> <groupId>org.apache.camel</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> <artifactId>camel-jt400</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> @@ -4997,6 +5002,16 @@ <artifactId>camel-quarkus-jsonpath-deployment</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> <version>3.36.0-SNAPSHOT</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + <artifactId>camel-quarkus-jsoup</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + <version>3.36.0-SNAPSHOT</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + <artifactId>camel-quarkus-jsoup-deployment</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + <version>3.36.0-SNAPSHOT</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> <artifactId>camel-quarkus-jt400</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> diff --git a/tooling/scripts/test-categories.yaml b/tooling/scripts/test-categories.yaml index 1c4804f4b3..358a8eb9c2 100644 --- a/tooling/scripts/test-categories.yaml +++ b/tooling/scripts/test-categories.yaml @@ -210,6 +210,7 @@ group-11: - google-secret-manager - grok - jolt + - jsoup - jsonata - langchain4j-tokenizer - milo
