So after some experimentation I found following crucial line in log when I enabled tracing using:
config.setConfigurationProperty(FeatureKeys.TRACE_EXTERNAL_FUNCTIONS, true);

2013-04-18 11:16:17,546 ERROR [stderr] (Thread-78) Calls to extension functions are not permitted without a Saxon license

It is bad that this fatal error is logged only when tracing is enabled and otherwise it is hidden by some other confusing error....

So problem is again that Saxon is not able to load license on classpath in JBoss.

So I have to use:
config.setConfigurationProperty(FeatureKeys.LICENSE_FILE_LOCATION, "/home/mslama/saxon-license.lic");

but this is bad because when I have web app deployed on app server I do not want to depend on any file located on local filesystem.
I want to depend only on resource inside war. So it would be good to support URI like classpath:/saxon-license.lic or support input stream
or reader which will contain license file.

This time I get class loader problem:
013-04-18 11:26:17,142 ERROR [stderr] (Thread-78) Trying net.sf.saxon.functions.SystemFunctionLibrary
2013-04-18 11:26:17,334 ERROR [stderr] (Thread-78) Exception in thread "Thread-78" java.lang.NoClassDefFoundError: com/saxonica/bytecode/map/CompiledContextMappingFunction
2013-04-18 11:26:17,334 ERROR [stderr] (Thread-78)     at java.lang.ClassLoader.defineClass1(Native Method)
2013-04-18 11:26:17,335 ERROR [stderr] (Thread-78)     at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
2013-04-18 11:26:17,335 ERROR [stderr] (Thread-78)     at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
2013-04-18 11:26:17,335 ERROR [stderr] (Thread-78)     at net.sf.saxon.java.JavaPlatform$1.findClass(JavaPlatform.java:247)
2013-04-18 11:26:17,335 ERROR [stderr] (Thread-78)     at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
2013-04-18 11:26:17,335 ERROR [stderr] (Thread-78)     at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
2013-04-18 11:26:17,336 ERROR [stderr] (Thread-78)     at com.saxonica.bytecode.util.CompilerService.makeClass(CompilerService.java:859)
2013-04-18 11:26:17,336 ERROR [stderr] (Thread-78)     at com.saxonica.bytecode.SlashExpressionCompiler.generateMappingFunction(SlashExpressionCompiler.java:122)
2013-04-18 11:26:17,336 ERROR [stderr] (Thread-78)     at com.saxonica.bytecode.SlashExpressionCompiler.compileToIterator(SlashExpressionCompiler.java:56)
2013-04-18 11:26:17,336 ERROR [stderr] (Thread-78)     at com.saxonica.bytecode.util.CompilerService.compileToIterator(CompilerService.java:677)
2013-04-18 11:26:17,337 ERROR [stderr] (Thread-78)     at com.saxonica.bytecode.SlashExpressionCompiler.compileToPush(SlashExpressionCompiler.java:146)
2013-04-18 11:26:17,337 ERROR [stderr] (Thread-78)     at com.saxonica.bytecode.util.CompilerService.compileToPush(CompilerService.java:690)
2013-04-18 11:26:17,337 ERROR [stderr] (Thread-78)     at com.saxonica.bytecode.util.CompilerService.compileToByteCode(CompilerService.java:582)
2013-04-18 11:26:17,337 ERROR [stderr] (Thread-78)     at com.saxonica.expr.ee.OptimizerEE.compileToByteCode(OptimizerEE.java:1337)
2013-04-18 11:26:17,338 ERROR [stderr] (Thread-78)     at net.sf.saxon.style.XSLTemplate.optimize(XSLTemplate.java:454)
2013-04-18 11:26:17,338 ERROR [stderr] (Thread-78)     at net.sf.saxon.style.PrincipalStylesheetModule.compileStylesheet(PrincipalStylesheetModule.java:807)
2013-04-18 11:26:17,338 ERROR [stderr] (Thread-78)     at net.sf.saxon.PreparedStylesheet.setStylesheetDocument(PreparedStylesheet.java:360)
2013-04-18 11:26:17,338 ERROR [stderr] (Thread-78)     at net.sf.saxon.PreparedStylesheet.prepare(PreparedStylesheet.java:207)
2013-04-18 11:26:17,338 ERROR [stderr] (Thread-78)     at net.sf.saxon.PreparedStylesheet.compile(PreparedStylesheet.java:106)
2013-04-18 11:26:17,339 ERROR [stderr] (Thread-78)     at net.sf.saxon.s9api.XsltCompiler.compile(XsltCompiler.java:249)
2013-04-18 11:26:17,339 ERROR [stderr] (Thread-78)     at com.idc.publishing.commons.transformations.SaxonParserUtility.compileXslt(SaxonParserUtility.java:84)
2013-04-18 11:26:17,339 ERROR [stderr] (Thread-78)     at com.idc.publishing.commons.transformations.SaxonParserUtility.xsltTransformationToString(SaxonParserUtility.java:60)
2013-04-18 11:26:17,339 ERROR [stderr] (Thread-78)     at com.idc.publishing.commons.transformations.CreateFragment.extractData(CreateFragment.java:188)
2013-04-18 11:26:17,340 ERROR [stderr] (Thread-78)     at com.idc.publishing.commons.transformations.CreateFragment.manipulateDocXmlStream(CreateFragment.java:176)
2013-04-18 11:26:17,340 ERROR [stderr] (Thread-78)     at com.idc.publishing.commons.transformations.CreateFragment.run(CreateFragment.java:142)
2013-04-18 11:26:17,340 ERROR [stderr] (Thread-78)     at com.idc.publishing.commons.transformations.CreateFragment.createFactsheetFeeds(CreateFragment.java:65)
2013-04-18 11:26:17,340 ERROR [stderr] (Thread-78)     at com.idc.publishing.fact_sheet.events.PdfAddedListener$1.run(PdfAddedListener.java:75)
2013-04-18 11:26:17,341 ERROR [stderr] (Thread-78)     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
2013-04-18 11:26:17,341 ERROR [stderr] (Thread-78)     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
2013-04-18 11:26:17,341 ERROR [stderr] (Thread-78)     at java.lang.Thread.run(Thread.java:722)
2013-04-18 11:26:17,341 ERROR [stderr] (Thread-78) Caused by: java.lang.ClassNotFoundException: com.saxonica.bytecode.map.CompiledContextMappingFunction
2013-04-18 11:26:17,342 ERROR [stderr] (Thread-78)     at java.lang.ClassLoader.findClass(ClassLoader.java:522)
2013-04-18 11:26:17,342 ERROR [stderr] (Thread-78)     at net.sf.saxon.java.JavaPlatform$1.findClass(JavaPlatform.java:249)
2013-04-18 11:26:17,342 ERROR [stderr] (Thread-78)     at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
2013-04-18 11:26:17,342 ERROR [stderr] (Thread-78)     at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
2013-04-18 11:26:17,342 ERROR [stderr] (Thread-78)     ... 30 more

So it looks like Saxon had problem with loading classes at runtime on JBoss. I again must say it works correctly outside of JBoss in unit test.

Of course this class reported as missing is in saxon9ee-9.4.0.7.jar which is in WEB-INF/lib (if not nothing would work at all).

Thanks

Marek


On 17 Apr 2013, at 12:06, Marek Slama wrote:

This is method signature:
public class MediaHandler {

    private static final Logger logger = LoggerFactory.getLogger(MediaHandler.class);

    public static String processMediaFile(String inputDocxPath, String imagePath, String docNumber,
        String relationshipId, String counter) throws Exception {

In Jboss7 I get following error:

2013-04-17 12:51:57,141 ERROR [com.idc.publishing.commons.transformations.SaxonParserUtility] (Thread-78) SaxonParserUtilityErrorListener FATAL:: net.sf.saxon.trans.XPathException: Cannot find a matching 5-argument function named {com.idc.publishing.commons.transformations.mediahandler.MediaHandler}processMediaFile(). The namespace URI and local name are recognized, but the number of arguments is wrong

This looks to me like a version mismatch problem of some kind. If Saxon has found a method with the right name but the wrong number of arguments, then presumably it has found a different version than the one you are showing us.

The -TJ trace might be useful.

Michael Kay
Saxonica