XML Transform fails with akitogo-xml

Hi there,

we’ve a strange issue.

Following case: We’ve a third party library which will manage some XML manipulation. This library is provided as jar.
We’ve added this jar to runtime, but the manipuliation fails (Lucee 4.5.5, Ubuntu 16.04, JRE 1.8.121) if the call is initialized from Lucee.

The same library works fine if the call is done directly from terminal (java -jar akitogo-xml-run.jar) without Lucee.

For better understanding I’ve compressed the lines of code to one function.

Simple Call:

akitogo.xmlbug.Test.test( "<div></div>" )

Expected output:

"<div/>"

Output correct started via console. Started from Lucee an empty string is the result.
After spending multiple days to thins issue, I’m dispairing.

Download for Library, also with plain java source code:
http://www.akibase.com/akitogo-xml.zip

Matze

Which version of Lucee are you using? How are you instantiating the class?

The following appears to work under Lucee 5.2.5, dynamically loading the class from the jar in the same directory, without adding it to the classpath:

object = CreateObject( "java", "akitogo.xmlbug.Test", ExpandPath( "./akitogo-xml.jar" ) );
dump( object.Test( "<div></div>" ) );

Output: <div/>

Hi, we are using 4.5 latest. The class can be called , the problem is that the xml transform doesn’t work.

Here is the source to make it more clear:

package pixy.util;

import java.io.StringReader;
import java.io.StringWriter;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Result;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Document;
import org.xml.sax.InputSource;

public class Simple {
	
	public static String test( String xml ) {
		
		String output	= "";
		
		try {
			DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
			DocumentBuilder builder = factory.newDocumentBuilder();
			InputSource source = new InputSource( new StringReader( xml ) );
			Document document = builder.parse( source );
			
			TransformerFactory tFactory = TransformerFactory.newInstance();
			Transformer transformer = tFactory.newTransformer();
			
			transformer.setOutputProperty(OutputKeys.INDENT, "no");
			transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
			
			String encoding = document.getInputEncoding();
				if(encoding == null) encoding = "UTF-8";
				
			transformer.setOutputProperty(OutputKeys.ENCODING, encoding);
			DOMSource domsource = new DOMSource( document );
			
			StringWriter writer = new StringWriter();
			Result result = new StreamResult( writer );
			
			transformer.transform( domsource, result );
			output	= writer.getBuffer().toString();
			
			
			
			
		} catch ( Exception e ) {
			output =  "Error " + e.getMessage();
		}
		
		return output;
	}

}

BTW, the class works on Windows?! For whatever reason the problem exists only on Linux

Sorry, I don’t use Linux, but perhaps… case sensitivity? Test vs test or similar?

I don’t think this is an issue with an case sensitive call or somthing like this.
We’ve also tried to load the xml content from a file. In this case the filename was the passing parameter, not the xml string. Even in this case the same result with empty string. The content of the file was loaded correctly.
The same class works fine on the same linux machine, but started on terminal.

SOLVED

We’ve solved our issue.
If the provided class is called by java directly, the Transformer factory com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl will be used. On Lucee oracle.xml.jaxp.JXTransformer. It looks like the transformer has some issues with the transormation. It’s possible to set a system property to choose the transformer explicitly.

System.setProperty("javax.xml.transform.TransformerFactory", "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl");

Hint in the documentation:

The system property that determines which Factory implementation to create is named “javax.xml.transform.TransformerFactory”. This property names a concrete subclass of the TransformerFactory abstract class. If the property is not defined, a platform default is be used.

In this case, the transformation works fine.

Thanks for help!

1 Like