camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hadr...@apache.org
Subject svn commit: r1373189 - in /camel/trunk/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, 15 Aug 2012 02:10:01 GMT
Author: hadrian
Date: Wed Aug 15 02:10:01 2012
New Revision: 1373189

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

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

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/xslt/XsltComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/xslt/XsltComponent.java?rev=1373189&r1=1373188&r2=1373189&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/xslt/XsltComponent.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/xslt/XsltComponent.java
Wed Aug 15 02:10:01 2012
@@ -117,8 +117,6 @@ public class XsltComponent extends Defau
         // 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);
 
-        configureXslt(xslt, uri, remaining, parameters);
-
         // if its a http uri, then append additional parameters as they are part of the uri
         if (ResourceHelper.isHttpUri(resourceUri)) {
             resourceUri = ResourceHelper.appendParameters(resourceUri, parameters);
@@ -136,6 +134,8 @@ public class XsltComponent extends Defau
         }
         // 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/trunk/camel-core/src/test/java/org/apache/camel/component/xslt/XsltCustomizeURIResolverTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/xslt/XsltCustomizeURIResolverTest.java?rev=1373189&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/xslt/XsltCustomizeURIResolverTest.java
(added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/xslt/XsltCustomizeURIResolverTest.java
Wed Aug 15 02:10:01 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/trunk/camel-core/src/test/java/org/apache/camel/component/xslt/XsltCustomizeURIResolverTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/camel-core/src/test/resources/org/apache/camel/component/xslt/include_not_existing_resource.xsl
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/resources/org/apache/camel/component/xslt/include_not_existing_resource.xsl?rev=1373189&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/resources/org/apache/camel/component/xslt/include_not_existing_resource.xsl
(added)
+++ camel/trunk/camel-core/src/test/resources/org/apache/camel/component/xslt/include_not_existing_resource.xsl
Wed Aug 15 02:10:01 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