camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hadr...@apache.org
Subject svn commit: r1376111 - in /camel/branches/camel-2.9.x/camel-core/src: main/java/org/apache/camel/component/xslt/ test/java/org/apache/camel/component/xslt/ test/resources/org/apache/camel/component/xslt/
Date Wed, 22 Aug 2012 16:01:00 GMT
Author: hadrian
Date: Wed Aug 22 16:00:59 2012
New Revision: 1376111

URL: http://svn.apache.org/viewvc?rev=1376111&view=rev
Log:
CAMEL-5505. Patch applied with thanks to Alexander Titov

Added:
    camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/component/xslt/XsltCustomizeURIResolverTest.java
  (with props)
    camel/branches/camel-2.9.x/camel-core/src/test/resources/org/apache/camel/component/xslt/include_not_existing_resource.xsl
Modified:
    camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/component/xslt/XsltComponent.java

Modified: camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/component/xslt/XsltComponent.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/component/xslt/XsltComponent.java?rev=1376111&r1=1376110&r2=1376111&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/component/xslt/XsltComponent.java
(original)
+++ camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/component/xslt/XsltComponent.java
Wed Aug 22 16:00:59 2012
@@ -27,6 +27,7 @@ import org.apache.camel.builder.xml.Xslt
 import org.apache.camel.converter.jaxp.XmlConverter;
 import org.apache.camel.impl.DefaultComponent;
 import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.ResourceHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -98,19 +99,6 @@ public class XsltComponent extends Defau
             xslt.getConverter().setTransformerFactory(factory);
         }
 
-        // lookup custom resolver to use
-        URIResolver resolver = resolveAndRemoveReferenceParameter(parameters, "uriResolver",
URIResolver.class);
-        if (resolver == null) {
-            // not in endpoint then use component specific resolver
-            resolver = getUriResolver();
-        }
-        if (resolver == null) {
-            // fallback to use a Camel specific resolver
-            resolver = new XsltUriResolver(getCamelContext().getClassResolver(), remaining);
-        }
-        // set resolver before input stream as resolver is used when loading the input stream
-        xslt.setUriResolver(resolver);
-
         ResultHandlerFactory resultHandlerFactory = resolveAndRemoveReferenceParameter(parameters,
"resultHandlerFactory", ResultHandlerFactory.class);
         if (resultHandlerFactory != null) {
             xslt.setResultHandlerFactory(resultHandlerFactory);
@@ -126,11 +114,24 @@ public class XsltComponent extends Defau
         Integer cs = getAndRemoveParameter(parameters, "transformerCacheSize", Integer.class,
Integer.valueOf(0));
         xslt.transformerCacheSize(cs);
 
-        configureXslt(xslt, uri, remaining, parameters);
-
         // default to use the cache option from the component if the endpoint did not have
the contentCache parameter
         boolean cache = getAndRemoveParameter(parameters, "contentCache", Boolean.class,
contentCache);
 
+        // lookup custom resolver to use
+        URIResolver resolver = resolveAndRemoveReferenceParameter(parameters, "uriResolver",
URIResolver.class);
+        if (resolver == null) {
+            // not in endpoint then use component specific resolver
+            resolver = getUriResolver();
+        }
+        if (resolver == null) {
+            // fallback to use a Camel specific resolver
+            resolver = new XsltUriResolver(getCamelContext().getClassResolver(), remaining);
+        }
+        // set resolver before input stream as resolver is used when loading the input stream
+        xslt.setUriResolver(resolver);
+        
+        configureXslt(xslt, uri, remaining, parameters);
+
         return new XsltEndpoint(uri, this, xslt, resourceUri, cache);
     }
 

Added: camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/component/xslt/XsltCustomizeURIResolverTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/component/xslt/XsltCustomizeURIResolverTest.java?rev=1376111&view=auto
==============================================================================
--- camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/component/xslt/XsltCustomizeURIResolverTest.java
(added)
+++ camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/component/xslt/XsltCustomizeURIResolverTest.java
Wed Aug 22 16:00:59 2012
@@ -0,0 +1,85 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.xslt;
+
+import java.io.ByteArrayInputStream;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.URIResolver;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.JndiRegistry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ */
+public class XsltCustomizeURIResolverTest extends ContextTestSupport {
+
+	private static final transient Logger LOG = LoggerFactory
+			.getLogger(XsltCustomizeURIResolverTest.class);
+
+	private final String EXPECTED_XML_CONSTANT = "<data>FOO DATA</data>";
+
+	public void testXsltCustomURIResolverDirectInRouteUri() throws Exception {
+		MockEndpoint mock = getMockEndpoint("mock:resultURIResolverDirect");
+		mock.expectedMessageCount(1);
+
+		mock.message(0).body().contains(EXPECTED_XML_CONSTANT);
+
+		assertMockEndpointsSatisfied();
+	}
+
+	@Override
+	protected RouteBuilder createRouteBuilder() throws Exception {
+		return new RouteBuilder() {
+			@Override
+			public void configure() throws Exception {
+				from("file:src/test/data/?fileName=staff.xml&noop=true")
+						.to("xslt:org/apache/camel/component/xslt/include_not_existing_resource.xsl?uriResolver=#customURIResolver")
+						.to("mock:resultURIResolverDirect");
+			}
+		};
+	}
+
+	private URIResolver getCustomURIResolver() {
+		return new URIResolver() {
+
+			@Override
+			public Source resolve(String href, String base)
+					throws TransformerException {
+				Source constantResult = new StreamSource(
+						new ByteArrayInputStream(
+								EXPECTED_XML_CONSTANT.getBytes()));
+				return constantResult;
+			}
+		};
+	}
+
+	@Override
+	protected JndiRegistry createRegistry() throws Exception {
+		JndiRegistry registry = super.createRegistry();
+		URIResolver customURIResolver = getCustomURIResolver();
+		registry.bind("customURIResolver", customURIResolver);
+		return registry;
+	}
+}

Propchange: camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/component/xslt/XsltCustomizeURIResolverTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/branches/camel-2.9.x/camel-core/src/test/resources/org/apache/camel/component/xslt/include_not_existing_resource.xsl
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/test/resources/org/apache/camel/component/xslt/include_not_existing_resource.xsl?rev=1376111&view=auto
==============================================================================
--- camel/branches/camel-2.9.x/camel-core/src/test/resources/org/apache/camel/component/xslt/include_not_existing_resource.xsl
(added)
+++ camel/branches/camel-2.9.x/camel-core/src/test/resources/org/apache/camel/component/xslt/include_not_existing_resource.xsl
Wed Aug 22 16:00:59 2012
@@ -0,0 +1,25 @@
+<?xml version="1.0"?>
+<!--
+    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:template match="/">
+    	Data in file:
+        <xsl:copy-of select="document('notExistingExternalFile.xml')"/>
+    </xsl:template>
+    
+</xsl:stylesheet>
\ No newline at end of file



Mime
View raw message