简体   繁体   中英

Deployed war in Tomcat 7 behaves differently on Linux than it does on Windows

I'm not even sure how to ask this question, but: I have two servers, one is a Linux VM running Ubuntu 13.10, the other Windows 7. I have Apache Tomcat 7.0.42 running on both. I have Java 1.8.0_66 running on both. I have built an application as a .war file and have deployed that same .war in both Tomcats. This war file reads xml files and performs transforms on them using an xsl file. I am using the exact same files as input on both installs - all files placed in identical folder structures in the Tomcat environment.

The problem: The generated transformed files differ on each machine. Both generated versions are well-formed, but they contain different content. Not wildly different, but one (the one generated on Linux) has extra elements in it than the Windows one.

Does anyone have any suggestions as to what the source of this different behavior might be, given that both installations and data sources are identical?

One thing to note: the results generated by the .war running on Windows is the expected result.

Here is the method that performs the transform, and gives different results in Windows v. Linux (using the exact same files on each.)

// Performs an XSLT transformation on the source stream using the transform stream and writes the result to
// an output file stream.
//
protected OutputStream performTransform(InputStream source, InputStream transform, OutputStream outputFile) {

    // Force the use of Saxon for the transformer
    TransformerFactory factory = new net.sf.saxon.TransformerFactoryImpl();
    Transformer transformer;
    logger.info("Perform Transform: " + source + " using " + transform + " to " + outputFile);
    try {
        try {
            transformer = factory.newTransformer(new StreamSource(transform));
            transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
            transformer.setOutputProperty(OutputKeys.INDENT, "yes");

            try {
                transformer.transform(new StreamSource(source), new StreamResult(outputFile)); 
            } catch (TransformerException e) {
                logger.error("Transform Exception ", e);
            }
        } catch (TransformerConfigurationException e) {
            logger.error("Transform Configurtion Exception ", e);
        }

        try {
            outputFile.close();
        } catch (IOException e) {
            logger.error("Exception closing output stream ", e);
        }
    } catch (Exception e) {
        logger.error("Catchall Exception performing transform ", e);
    } finally {
        try {
            outputFile.close();
        } catch (IOException e) {
            logger.error("Exception closing output stream a second time ", e);
        }
    }

    return outputFile;
}

I believe this can point you in the right direction. Basically, it's saying to make sure that you're enforcing the same encoding (best to use UTF-8 in this case) to standardize the output. Linux and Windows have different newlines (\\n vs. \\r\\n respectively), which can also cause whitespace differences between the resultant files (which could break the transform because the position() function is confused ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM