Configuring an ESB route with Saxon to allow use of external functions

Question

How do I configure an ESB route with XSLT URI (Saxon) to allow the use of external functions?

 

Answer

You need to use a user-defined transformer factory where secure processing is already turned off.

 

To do that, the transformer factory should be defined in the route's Spring configuration (click the Spring tab of the route) by adding the following element:

<bean id="myTransformerFactory" class="net.sf.saxon.TransformerFactoryImpl">
</bean>

Then, the factory myTransformerFactory should be passed at the end of the XSLT URI parameter, as follows:

"xslt://file:///opt/test/test.xslt?transformerFactory=#myTransformerFactory"
Version history
Revision #:
5 of 5
Last update:
‎09-29-2018 12:15 AM
Updated by:
 
Labels (3)
Comments
Four Stars

I have the same need with saxon.

I'm on talend 6.4.1 and since I added the bean declaration I have following message when I try to deploy the route into the karaf. I tried to add Saxon-HE-9.8.0-6.jar into the route with a cConfig but I still have the stack below : 

 

2017-11-21T17:00:30,254 | INFO  | SpringOsgiExtenderThread-53 | pport.AbstractApplicationContext  518 | 137 - org.apache.servicemix.bundles.spring-context - 3.2.18.RELEASE_1 | Refreshing OsgiBundleXmlApplicationContext(bundle=master.test_saxon_extension, config=osgibundle:/META-INF/spring/*.xml): startup date [Tue Nov 21 17:00:30 CET 2017]; root of context hierarchy
2017-11-21T17:00:30,254 | INFO  | SpringOsgiExtenderThread-53 | ractOsgiBundleApplicationContext  365 | 137 - org.apache.servicemix.bundles.spring-context - 3.2.18.RELEASE_1 | Application Context service already unpublished
2017-11-21T17:00:30,257 | INFO  | SpringOsgiExtenderThread-53 | tory.xml.XmlBeanDefinitionReader  316 | 136 - org.apache.servicemix.bundles.spring-beans - 3.2.18.RELEASE_1 | Loading XML bean definitions from URL [bundleentry://366.fwk214313531/META-INF/spring/route.xml]
2017-11-21T17:00:30,271 | INFO  | SpringOsgiExtenderThread-53 | tory.xml.XmlBeanDefinitionReader  316 | 136 - org.apache.servicemix.bundles.spring-beans - 3.2.18.RELEASE_1 | Loading XML bean definitions from URL [bundleentry://366.fwk214313531/META-INF/spring/test_saxon_extension.xml]
2017-11-21T17:00:30,275 | INFO  | SpringOsgiExtenderThread-53 | WaiterApplicationContextExecutor  243 | 184 - org.springframework.osgi.extender - 1.2.1 | No outstanding OSGi service dependencies, completing initialization for OsgiBundleXmlApplicationContext(bundle=master.test_saxon_extension, config=osgibundle:/META-INF/spring/*.xml)
2017-11-21T17:00:30,278 | INFO  | SpringOsgiExtenderThread-54 | pport.DefaultListableBeanFactory  605 | 136 - org.apache.servicemix.bundles.spring-beans - 3.2.18.RELEASE_1 | Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@4075ae70: defining beans [test_saxon_extension.properties,route,master.test_saxon_extension_0_1.test_saxon_extension:beanPostProcessor,master.test_saxon_extension_0_1.test_saxon_extension,jmxEventNotifier,myTransformerFactory]; root of factory hierarchy
2017-11-21T17:00:30,282 | INFO  | SpringOsgiExtenderThread-54 | ort.DefaultSingletonBeanRegistry  444 | 136 - org.apache.servicemix.bundles.spring-beans - 3.2.18.RELEASE_1 | Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@4075ae70: defining beans [test_saxon_extension.properties,route,master.test_saxon_extension_0_1.test_saxon_extension:beanPostProcessor,master.test_saxon_extension_0_1.test_saxon_extension,jmxEventNotifier,myTransformerFactory]; root of factory hierarchy
2017-11-21T17:00:30,282 | ERROR | SpringOsgiExtenderThread-54 | BundleApplicationContextListener   50 | 184 - org.springframework.osgi.extender - 1.2.1 | Application context refresh failed (OsgiBundleXmlApplicationContext(bundle=master.test_saxon_extension, config=osgibundle:/META-INF/spring/*.xml))
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'master.test_saxon_extension_0_1.test_saxon_extension': Invocation of init method failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [net.sf.saxon.TransformerFactoryImpl] for bean with name 'myTransformerFactory' defined in URL [bundleentry://366.fwk214313531/META-INF/spring/test_saxon_extension.xml]; nested exception is java.lang.ClassNotFoundException: net.sf.saxon.TransformerFactoryImpl not found from bundle [master.test_saxon_extension]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1514) [136:org.apache.servicemix.bundles.spring-beans:3.2.18.RELEASE_1]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) [136:org.apache.servicemix.bundles.spring-beans:3.2.18.RELEASE_1]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) [136:org.apache.servicemix.bundles.spring-beans:3.2.18.RELEASE_1]
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293) [136:org.apache.servicemix.bundles.spring-beans:3.2.18.RELEASE_1]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) [136:org.apache.servicemix.bundles.spring-beans:3.2.18.RELEASE_1]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290) [136:org.apache.servicemix.bundles.spring-beans:3.2.18.RELEASE_1]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:191) [136:org.apache.servicemix.bundles.spring-beans:3.2.18.RELEASE_1]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:283) [136:org.apache.servicemix.bundles.spring-beans:3.2.18.RELEASE_1]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:191) [136:org.apache.servicemix.bundles.spring-beans:3.2.18.RELEASE_1]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:638) [136:org.apache.servicemix.bundles.spring-beans:3.2.18.RELEASE_1]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:942) [137:org.apache.servicemix.bundles.spring-context:3.2.18.RELEASE_1]
	at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$1600(AbstractDelegatedExecutionApplicationContext.java:69) [183:org.springframework.osgi.core:1.2.1]
	at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:355) [183:org.springframework.osgi.core:1.2.1]
	at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85) [183:org.springframework.osgi.core:1.2.1]
	at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:320) [183:org.springframework.osgi.core:1.2.1]
	at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:132) [184:org.springframework.osgi.extender:1.2.1]
	at java.lang.Thread.run(Thread.java:748) [?:?]
Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [net.sf.saxon.TransformerFactoryImpl] for bean with name 'myTransformerFactory' defined in URL [bundleentry://366.fwk214313531/META-INF/spring/test_saxon_extension.xml]; nested exception is java.lang.ClassNotFoundException: net.sf.saxon.TransformerFactoryImpl not found from bundle [master.test_saxon_extension]
	at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1278) ~[?:?]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:573) ~[?:?]
	at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1347) ~[?:?]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:358) ~[?:?]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:335) ~[?:?]
	at org.springframework.context.support.AbstractApplicationContext.getBeanNamesForType(AbstractApplicationContext.java:1188) ~[?:?]
	at org.apache.camel.spring.CamelContextFactoryBean.getBeanForType(CamelContextFactoryBean.java:207) ~[?:?]
	at org.apache.camel.core.xml.AbstractCamelContextFactoryBean.afterPropertiesSet(AbstractCamelContextFactoryBean.java:159) ~[?:?]
	at org.apache.camel.spring.CamelContextFactoryBean.afterPropertiesSet(CamelContextFactoryBean.java:262) ~[?:?]
	at org.apache.camel.osgi.CamelContextFactoryBean.afterPropertiesSet(CamelContextFactoryBean.java:64) ~[?:?]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1573) ~[?:?]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1511) ~[?:?]
	... 16 more

 

Community Manager

Hi sylpri,

For help with your issue, please post your question to one of the discussion forums, or contact Support at https://www.talend.com/services/technical-support/.

Hope that helps,

Alyce