You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2019/11/21 14:06:39 UTC
[camel-quarkus] branch master updated: Fix #455 Support only
classpath: XSLT URIs
This is an automated email from the ASF dual-hosted git repository.
lburgazzoli 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 54ff524 Fix #455 Support only classpath: XSLT URIs
54ff524 is described below
commit 54ff524775dc25d52c121efe946fc141cfe3ba7f
Author: Peter Palaga <pp...@redhat.com>
AuthorDate: Thu Nov 21 11:53:29 2019 +0100
Fix #455 Support only classpath: XSLT URIs
---
.../xslt/deployment/BuildTimeUriResolver.java | 63 +++++++---------------
.../component/xslt/deployment/XsltProcessor.java | 4 +-
.../quarkus/component/xslt/it/XsltResource.java | 11 ----
.../camel/quarkus/component/xslt/it/XsltRoute.java | 3 --
.../xslt/src/main/resources/application.properties | 2 +-
.../xslt/src/main/xslt/file-transform.xsl | 41 --------------
.../camel/quarkus/component/xslt/it/XsltTest.java | 14 -----
7 files changed, 20 insertions(+), 118 deletions(-)
diff --git a/extensions/xslt/deployment/src/main/java/org/apache/camel/quarkus/component/xslt/deployment/BuildTimeUriResolver.java b/extensions/xslt/deployment/src/main/java/org/apache/camel/quarkus/component/xslt/deployment/BuildTimeUriResolver.java
index 9bb7e62..2904231 100644
--- a/extensions/xslt/deployment/src/main/java/org/apache/camel/quarkus/component/xslt/deployment/BuildTimeUriResolver.java
+++ b/extensions/xslt/deployment/src/main/java/org/apache/camel/quarkus/component/xslt/deployment/BuildTimeUriResolver.java
@@ -17,13 +17,9 @@
package org.apache.camel.quarkus.component.xslt.deployment;
import java.io.IOException;
-import java.net.MalformedURLException;
import java.net.URL;
-import java.nio.file.Files;
-import java.nio.file.Path;
import javax.xml.transform.Source;
-import javax.xml.transform.TransformerException;
import javax.xml.transform.stream.StreamSource;
import org.apache.camel.support.ResourceHelper;
@@ -32,14 +28,7 @@ import org.apache.camel.util.StringHelper;
public class BuildTimeUriResolver {
- /** A directory to use as a base for resolving {@code file:} URIs */
- private final Path baseDir;
-
- public BuildTimeUriResolver(Path baseDir) {
- this.baseDir = baseDir;
- }
-
- public ResolutionResult resolve(String templateUri) throws TransformerException {
+ public ResolutionResult resolve(String templateUri) {
if (templateUri == null) {
throw new RuntimeException("href parameter cannot be null");
}
@@ -48,42 +37,26 @@ public class BuildTimeUriResolver {
final String scheme = ResourceHelper.getScheme(templateUri);
final String effectiveScheme = scheme == null ? "classpath:" : scheme;
- final String transletName;
- final Source src;
- if ("file:".equals(effectiveScheme)) {
- final String compacted = compact(templateUri, scheme);
- transletName = toTransletName(compacted);
- final Path resolvedPath = baseDir.resolve(compacted);
- try {
- src = new StreamSource(Files.newInputStream(resolvedPath));
- } catch (IOException e) {
- throw new TransformerException("Could not read from file " + templateUri, e);
- }
- } else if ("classpath:".equals(effectiveScheme)) {
- final String compacted = compact(templateUri, scheme);
- transletName = toTransletName(compacted);
- final URL url = getClass().getClassLoader().getResource(compacted);
- try {
- src = new StreamSource(url.openStream());
- } catch (IOException e) {
- throw new TransformerException("Could not read the class path resource " + templateUri, e);
- }
+ if (!"classpath:".equals(effectiveScheme)) {
+ throw new RuntimeException("URI scheme '" + effectiveScheme
+ + "' not supported for build time compilation of XSL templates. Only 'classpath:' URIs are supported");
+ }
+ final String compacted = compact(templateUri, scheme);
+ final String transletName = toTransletName(compacted);
+ final URL url = getClass().getClassLoader().getResource(compacted);
+ if (url == null) {
+ throw new IllegalStateException("Could not find the XSLT resource " + compacted + " in the classpath");
+ }
+ try {
+ final Source src = new StreamSource(url.openStream());
// TODO: if the XSLT file is under target/classes of the current project we should mark it for exclusion
- // from the application archive. See https://github.com/apache/camel-quarkus/issues/438
- } else {
- try {
- final URL url = new URL(templateUri);
- final String path = url.getPath();
- transletName = toTransletName(path);
- src = new StreamSource(url.openStream());
- } catch (MalformedURLException e) {
- throw new TransformerException("Invalid URL " + templateUri, e);
- } catch (IOException e) {
- throw new TransformerException("Could not read from URL " + templateUri, e);
- }
+ // from the application archive. See https://github.com/apache/camel-quarkus/issues/438
+ return new ResolutionResult(templateUri, transletName, src);
+ } catch (IOException e) {
+ throw new RuntimeException("Could not read the class path resource " + templateUri, e);
}
- return new ResolutionResult(templateUri, transletName, src);
+
}
private String toTransletName(final String compacted) {
diff --git a/extensions/xslt/deployment/src/main/java/org/apache/camel/quarkus/component/xslt/deployment/XsltProcessor.java b/extensions/xslt/deployment/src/main/java/org/apache/camel/quarkus/component/xslt/deployment/XsltProcessor.java
index c566c9b..8e4d1c5 100644
--- a/extensions/xslt/deployment/src/main/java/org/apache/camel/quarkus/component/xslt/deployment/XsltProcessor.java
+++ b/extensions/xslt/deployment/src/main/java/org/apache/camel/quarkus/component/xslt/deployment/XsltProcessor.java
@@ -90,9 +90,7 @@ class XsltProcessor {
Path destination = Files.createTempDirectory(XsltFeature.FEATURE);
final Set<String> translets = new LinkedHashSet<>();
try {
- // TODO: figure out a better way to get the baseDir, see https://github.com/apache/camel-quarkus/issues/439
- final Path baseDir = archiveRoot.getArchiveRoot().getParent().getParent();
- final BuildTimeUriResolver resolver = new BuildTimeUriResolver(baseDir);
+ final BuildTimeUriResolver resolver = new BuildTimeUriResolver();
for (String uri : config.sources) {
ResolutionResult resolvedUri = resolver.resolve(uri);
uriResolverEntries.produce(resolvedUri.toBuildItem());
diff --git a/integration-tests/xslt/src/main/java/org/apache/camel/quarkus/component/xslt/it/XsltResource.java b/integration-tests/xslt/src/main/java/org/apache/camel/quarkus/component/xslt/it/XsltResource.java
index f07eaaf..1624da1 100644
--- a/integration-tests/xslt/src/main/java/org/apache/camel/quarkus/component/xslt/it/XsltResource.java
+++ b/integration-tests/xslt/src/main/java/org/apache/camel/quarkus/component/xslt/it/XsltResource.java
@@ -18,21 +18,17 @@ package org.apache.camel.quarkus.component.xslt.it;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
-import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.apache.camel.ProducerTemplate;
-import org.jboss.logging.Logger;
@Path("/xslt")
@ApplicationScoped
public class XsltResource {
- private static final Logger LOG = Logger.getLogger(XsltResource.class);
-
@Inject
ProducerTemplate producerTemplate;
@@ -43,11 +39,4 @@ public class XsltResource {
return producerTemplate.requestBody("direct:classpath-xsl", body, String.class);
}
- @Path("/file-xsl")
- @POST
- @Produces(MediaType.TEXT_PLAIN)
- public String file(String body) throws Exception {
- return producerTemplate.requestBody("direct:file-xsl", body, String.class);
- }
-
}
diff --git a/integration-tests/xslt/src/main/java/org/apache/camel/quarkus/component/xslt/it/XsltRoute.java b/integration-tests/xslt/src/main/java/org/apache/camel/quarkus/component/xslt/it/XsltRoute.java
index 9a93dfd..c053642 100644
--- a/integration-tests/xslt/src/main/java/org/apache/camel/quarkus/component/xslt/it/XsltRoute.java
+++ b/integration-tests/xslt/src/main/java/org/apache/camel/quarkus/component/xslt/it/XsltRoute.java
@@ -24,8 +24,5 @@ public class XsltRoute extends RouteBuilder {
public void configure() throws Exception {
from("direct:classpath-xsl")
.to("xslt:xslt/classpath-transform.xsl");
-
- from("direct:file-xsl")
- .to("xslt:file:src/main/xslt/file-transform.xsl");
}
}
diff --git a/integration-tests/xslt/src/main/resources/application.properties b/integration-tests/xslt/src/main/resources/application.properties
index 4ce8f41..58fc158 100644
--- a/integration-tests/xslt/src/main/resources/application.properties
+++ b/integration-tests/xslt/src/main/resources/application.properties
@@ -23,4 +23,4 @@ quarkus.log.category."org.apache.camel.quarkus.core.deployment".level = INFO
#
# Quarkus - Camel
#
-quarkus.camel.xslt.sources = xslt/classpath-transform.xsl,file:src/main/xslt/file-transform.xsl
+quarkus.camel.xslt.sources = xslt/classpath-transform.xsl
diff --git a/integration-tests/xslt/src/main/xslt/file-transform.xsl b/integration-tests/xslt/src/main/xslt/file-transform.xsl
deleted file mode 100644
index 3a4b44c..0000000
--- a/integration-tests/xslt/src/main/xslt/file-transform.xsl
+++ /dev/null
@@ -1,41 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
-
- 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.
-
--->
-<xsl:stylesheet
- xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
- version='1.0'>
-
- <xsl:output method="xml" indent="yes" encoding="ISO-8859-1"/>
-
- <xsl:template match="/">
- <file-xsl subject="{/mail/subject}">
- <cheese>
- <xsl:apply-templates select="*|@*"/>
- </cheese>
- </file-xsl>
- </xsl:template>
-
- <xsl:template match="*">
- <xsl:copy>
- <xsl:copy-of select="attribute::*"/>
- <xsl:apply-templates/>
- </xsl:copy>
- </xsl:template>
-
-</xsl:stylesheet>
diff --git a/integration-tests/xslt/src/test/java/org/apache/camel/quarkus/component/xslt/it/XsltTest.java b/integration-tests/xslt/src/test/java/org/apache/camel/quarkus/component/xslt/it/XsltTest.java
index 24e0a91..2d04599 100644
--- a/integration-tests/xslt/src/test/java/org/apache/camel/quarkus/component/xslt/it/XsltTest.java
+++ b/integration-tests/xslt/src/test/java/org/apache/camel/quarkus/component/xslt/it/XsltTest.java
@@ -40,18 +40,4 @@ class XsltTest {
actual);
}
- @Test
- public void file() {
- final String actual = RestAssured.given()
- .body(BODY)
- .post("/xslt/file-xsl")
- .then()
- .statusCode(200)
- .extract().body().asString().trim().replaceAll(">\\s+<", "><");
-
- Assertions.assertEquals(
- "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><file-xsl subject=\"Hey\"><cheese><mail><subject>Hey</subject><body>Hello world!</body></mail></cheese></file-xsl>",
- actual);
- }
-
}