Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions apache-camel/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1671,6 +1671,11 @@
<artifactId>camel-xslt</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-xslt-saxon</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-xstream</artifactId>
Expand Down Expand Up @@ -3160,6 +3165,11 @@
<artifactId>camel-xslt-starter</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-xslt-saxon-starter</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-xstream-starter</artifactId>
Expand Down
2 changes: 2 additions & 0 deletions apache-camel/src/main/descriptors/common-bin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@
<include>org.apache.camel:camel-xmpp</include>
<include>org.apache.camel:camel-xpath</include>
<include>org.apache.camel:camel-xslt</include>
<include>org.apache.camel:camel-xslt-saxon</include>
<include>org.apache.camel:camel-xstream</include>
<include>org.apache.camel:camel-yammer</include>
<include>org.apache.camel:camel-zendesk</include>
Expand Down Expand Up @@ -692,6 +693,7 @@
<include>org.apache.camel:camel-xmpp-starter</include>
<include>org.apache.camel:camel-xpath-starter</include>
<include>org.apache.camel:camel-xslt-starter</include>
<include>org.apache.camel:camel-xslt-saxon-starter</include>
<include>org.apache.camel:camel-xstream-starter</include>
<include>org.apache.camel:camel-yammer-starter</include>
<include>org.apache.camel:camel-zendesk-starter</include>
Expand Down
2 changes: 1 addition & 1 deletion components/camel-saxon/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-xslt</artifactId>
<artifactId>camel-xslt-saxon</artifactId>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

import net.sf.saxon.om.TreeInfo;
import org.w3c.dom.Node;

import net.sf.saxon.Configuration;
Expand Down Expand Up @@ -508,7 +509,7 @@ protected DynamicQueryContext createDynamicContext(Exchange exchange) throws Exc
if (item != null) {
dynamicQueryContext.setContextItem(item);
} else {
Object body = null;
Object body;
if (ObjectHelper.isNotEmpty(getHeaderName())) {
body = in.getHeader(getHeaderName());
} else {
Expand Down Expand Up @@ -536,8 +537,8 @@ protected DynamicQueryContext createDynamicContext(Exchange exchange) throws Exc
throw new NoTypeConversionAvailableException(body, Source.class);
}

DocumentInfo doc = config.buildDocument(source);
dynamicQueryContext.setContextItem(doc);
TreeInfo doc = config.buildDocumentTree(source);
dynamicQueryContext.setContextItem(doc.getRootNode());
} finally {
// can deal if is is null
IOHelper.close(is);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
package org.apache.camel.builder;

import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.component.xslt.XsltAggregationStrategy;
import org.apache.camel.component.xslt.saxon.XsltSaxonAggregationStrategy;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;

/**
* Unit test for the {@link XsltAggregationStrategy}.
* Unit test for the {@link XsltSaxonAggregationStrategy}.
* <p>
* Need to use Saxon to get a predictable result: We cannot rely on the JDK's XSLT processor as it can vary across
* platforms and JDK versions. Also, Xalan does not handle node-set properties well.
Expand Down Expand Up @@ -58,17 +58,16 @@ protected RouteBuilder createRouteBuilder() throws Exception {
public void configure() throws Exception {
from("file:src/test/resources/org/apache/camel/util/toolbox?noop=true&sortBy=file:name&antInclude=*.xml")
.routeId("route1").noAutoStartup()
.aggregate(new XsltAggregationStrategy("org/apache/camel/util/toolbox/aggregate.xsl")
.withSaxon())
.aggregate(new XsltSaxonAggregationStrategy("org/apache/camel/util/toolbox/aggregate.xsl"))
.constant(true)
.completionFromBatchConsumer()
.log("after aggregate body: ${body}")
.to("mock:transformed");

from("file:src/test/resources/org/apache/camel/util/toolbox?noop=true&sortBy=file:name&antInclude=*.xml")
.routeId("route2").noAutoStartup()
.aggregate(new XsltAggregationStrategy("org/apache/camel/util/toolbox/aggregate-user-property.xsl")
.withSaxon().withPropertyName("user-property"))
.aggregate(new XsltSaxonAggregationStrategy("org/apache/camel/util/toolbox/aggregate-user-property.xsl")
.withPropertyName("user-property"))
.constant(true)
.completionFromBatchConsumer()
.log("after aggregate body: ${body}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").to("xslt:org/apache/camel/component/xslt/transform.xsl");
from("direct:start").to("xslt-saxon:org/apache/camel/component/xslt/transform.xsl");
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void testInvalidStylesheet() throws Exception {
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
from("seda:a").to("xslt:org/apache/camel/component/xslt/notfound.xsl?transformerFactoryClass=net.sf.saxon.TransformerFactoryImpl");
from("seda:a").to("xslt-saxon:org/apache/camel/component/xslt/notfound.xsl?transformerFactoryClass=net.sf.saxon.TransformerFactoryImpl");
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected RouteBuilder createRouteBuilder() throws Exception {
@Override
public void configure() throws Exception {
from("direct:start")
.to("xslt:org/apache/camel/component/xslt/transform_includes_data.xsl")
.to("xslt-saxon:org/apache/camel/component/xslt/transform_includes_data.xsl")
.to("mock:result");
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@
*/
package org.apache.camel.component.xslt;

import org.apache.camel.component.xslt.saxon.XsltSaxonComponent;
import org.apache.camel.component.xslt.saxon.XsltSaxonEndpoint;
import org.apache.camel.test.spring.CamelSpringTestSupport;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SaxonXsltComponentConfigurationTest extends CamelSpringTestSupport {
@Test
public void testConfiguration() throws Exception {
XsltComponent component = context.getComponent("xslt", XsltComponent.class);
XsltEndpoint endpoint = context.getEndpoint("xslt:org/apache/camel/component/xslt/transform.xsl", XsltEndpoint.class);
XsltSaxonComponent component = context.getComponent("xslt-saxon", XsltSaxonComponent.class);
XsltSaxonEndpoint endpoint = context.getEndpoint("xslt-saxon:org/apache/camel/component/xslt/transform.xsl", XsltSaxonEndpoint.class);

assertNotNull(component.getSaxonConfiguration());
assertNotNull(component.getSaxonConfigurationProperties());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,18 @@ private void sendEntityMessage(Object message) throws Exception {
endpoint.reset();
endpoint.expectedMessageCount(1);

// reset stream before trying again
if (message instanceof InputStream) {
((InputStream) message).reset();
}
try {
template.sendBody("direct:start2", message);
list = endpoint.getReceivedExchanges();
exchange = list.get(0);
xml = exchange.getIn().getBody(String.class);
assertTrue("Get a wrong transformed message", xml.indexOf("<transformed subject=\"\">") > 0);
} catch (Exception ex) {
ex.printStackTrace();
// expect an exception here
assertTrue("Get a wrong exception", ex instanceof CamelExecutionException);
// the file could not be found
Expand All @@ -86,11 +91,11 @@ protected RouteBuilder createRouteBuilder() throws Exception {
public void configure() throws Exception {

from("direct:start1")
.to("xslt:org/apache/camel/component/xslt/transform_dtd.xsl")
.to("xslt-saxon:org/apache/camel/component/xslt/transform_dtd.xsl")
.to("mock:result");

from("direct:start2")
.to("xslt:org/apache/camel/component/xslt/transform_dtd.xsl?allowStAX=false")
.to("xslt-saxon:org/apache/camel/component/xslt/transform_dtd.xsl?allowStAX=false")
.to("mock:result");
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import net.sf.saxon.Configuration;
import org.apache.camel.Endpoint;
import org.apache.camel.component.xslt.saxon.XsltSaxonComponent;
import org.apache.camel.component.xslt.saxon.XsltSaxonEndpoint;
import org.apache.camel.test.spring.CamelSpringTestSupport;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
Expand All @@ -29,15 +31,15 @@ public class SaxonXsltEndpointConfigurationTest extends CamelSpringTestSupport {
public void testConfiguration() throws Exception {
Configuration configuration = context.getRegistry().lookupByNameAndType("saxon-configuration", Configuration.class);
Map<String, Object> properties = context.getRegistry().lookupByNameAndType("saxon-properties", Map.class);
XsltComponent component = context.getComponent("xslt", XsltComponent.class);
XsltEndpoint endpoint = null;
XsltSaxonComponent component = context.getComponent("xslt-saxon", XsltSaxonComponent.class);
XsltSaxonEndpoint endpoint = null;

assertNotNull(configuration);
assertNotNull(properties);

for (Endpoint ep : context.getEndpoints()) {
if (ep instanceof XsltEndpoint) {
endpoint = (XsltEndpoint)ep;
if (ep instanceof XsltSaxonEndpoint) {
endpoint = (XsltSaxonEndpoint)ep;
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ protected RouteBuilder createRouteBuilder() throws Exception {
@Override
public void configure() throws Exception {
from("direct:start1")
.to("xslt:org/apache/camel/component/xslt/transform_text_imported.xsl")
.to("xslt-saxon:org/apache/camel/component/xslt/transform_text_imported.xsl")
.to("mock:result");

from("direct:start2")
.to("xslt:org/apache/camel/component/xslt/transform_text.xsl")
.to("xslt-saxon:org/apache/camel/component/xslt/transform_text.xsl")
.to("mock:result");
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void configure() throws Exception {
errorHandler(deadLetterChannel("mock:dead"));

from("file:src/test/data/?fileName=terminate.xml&noop=true").routeId("foo").noAutoStartup()
.to("xslt:org/apache/camel/component/xslt/terminate.xsl?saxon=true")
.to("xslt-saxon:org/apache/camel/component/xslt/terminate.xsl")
.to("log:foo")
.to("mock:result");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/**
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.util.List;

import org.apache.camel.BindToRegistry;
import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.component.xquery.TestBean;
import org.apache.camel.converter.jaxp.XmlConverter;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;
import org.w3c.dom.Document;

public class XsltRouteAllowStAXTest extends CamelTestSupport {

@BindToRegistry
private TestBean testBean = new TestBean();

@Test
public void testSendStringMessage() throws Exception {
sendMessageAndHaveItTransformed("<mail><subject>Hey</subject><body>Hello world!</body></mail>");
}

@Test
public void testSendBytesMessage() throws Exception {
sendMessageAndHaveItTransformed("<mail><subject>Hey</subject><body>Hello world!</body></mail>".getBytes());
}

@Test
public void testSendDomMessage() throws Exception {
XmlConverter converter = new XmlConverter();
Document body = converter.toDOMDocument("<mail><subject>Hey</subject><body>Hello world!</body></mail>", null);
sendMessageAndHaveItTransformed(body);
}

private void sendMessageAndHaveItTransformed(Object body) throws Exception {
MockEndpoint endpoint = getMockEndpoint("mock:result");
endpoint.expectedMessageCount(1);

template.sendBody("direct:start", body);

assertMockEndpointsSatisfied();

List<Exchange> list = endpoint.getReceivedExchanges();
Exchange exchange = list.get(0);
String xml = exchange.getIn().getBody(String.class);

assertNotNull("The transformed XML should not be null", xml);
assertTrue(xml.indexOf("transformed") > -1);
// the cheese tag is in the transform.xsl
assertTrue(xml.indexOf("cheese") > -1);
assertTrue(xml.indexOf("<subject>Hey</subject>") > -1);
assertTrue(xml.indexOf("<body>Hello world!</body>") > -1);

TestBean bean = context.getRegistry().lookupByNameAndType("testBean", TestBean.class);
assertNotNull(bean);
assertEquals("bean.subject", "Hey", bean.getSubject());
}

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").to("xslt-saxon:org/apache/camel/component/xslt/transform.xsl?allowStAX=true").multicast().bean("testBean").to("mock:result");
}
};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected RouteBuilder createRouteBuilder() throws Exception {
@Override
public void configure() throws Exception {
from("direct:extensions")
.toF("xslt:%s?saxonExtensionFunctions=#function1,#function2", XSLT_PATH)
.toF("xslt-saxon:%s?saxonExtensionFunctions=#function1,#function2", XSLT_PATH)
.to("log:org.apache.camel.component.xslt.extensions?level=INFO");
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
">

<bean id="xslt" class="org.apache.camel.component.xslt.XsltComponent">
<property name="saxon" value="true"/>
<bean id="xslt-saxon" class="org.apache.camel.component.xslt.saxon.XsltSaxonComponent">
<property name="saxonConfiguration">
<bean class="net.sf.saxon.Configuration"/>
</property>
Expand All @@ -40,7 +39,7 @@
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="direct:start"/>
<to uri="xslt:org/apache/camel/component/xslt/transform.xsl"/>
<to uri="xslt-saxon:org/apache/camel/component/xslt/transform.xsl"/>
<multicast>
<to uri="mock:result"/>
</multicast>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="direct:start"/>
<to uri="xslt:org/apache/camel/component/xslt/transform.xsl?saxon=true&amp;saxonConfiguration=#saxon-configuration&amp;saxonConfigurationProperties=#saxon-properties"/>
<to uri="xslt-saxon:org/apache/camel/component/xslt/transform.xsl?saxonConfiguration=#saxon-configuration&amp;saxonConfigurationProperties=#saxon-properties"/>
<multicast>
<to uri="mock:result"/>
</multicast>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="direct:start"/>
<to uri="xslt:org/apache/camel/component/xslt/transform.xsl?transformerFactory=#factory"/>
<to uri="xslt-saxon:org/apache/camel/component/xslt/transform.xsl?transformerFactory=#factory"/>
<multicast>
<to uri="mock:result"/>
</multicast>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="direct:extensions"/>
<to uri="xslt:org/apache/camel/component/xslt/extensions/extensions.xslt?saxonExtensionFunctions=#function1,#function2"/>
<to uri="xslt-saxon:org/apache/camel/component/xslt/extensions/extensions.xslt?saxonExtensionFunctions=#function1,#function2"/>
<to uri="log:org.apache.camel.component.xslt.extensions?level=INFO"/>
</route>
</camelContext>
Expand Down
Loading