Search code examples
javatomcatgwtrpcbatik

Deploying GWT application on Apache Tomcat


On a server side I have a class that I use for convertion SVG file to PDF.

public class PdfHandler {
    private File savedFile;
    private File svgTempFile;

    public PdfHandler(String fileName) {
        this.savedFile = new File(File.separator + "documents" + File.separator + fileName);
    }

    public void convertToPdf(String inputFileName) {
        this.svgTempFile = new File(inputFileName);
        System.out.println(inputFileName);
        if (this.svgTempFile.exists()){
            System.out.println("Svg File exists");
        }
        else {
            System.out.println("Svg File not exists");
        }

        try {
            Transcoder transcoder = new PDFTranscoder();
            System.out.println("Transcoder created");
            FileInputStream fis = new FileInputStream(this.svgTempFile);
            System.out.println("Input stream created");
            FileOutputStream fos = new FileOutputStream(this.savedFile);
            System.out.println("Output stream created");
            TranscoderInput transcoderInput = new TranscoderInput(fis);
            System.out.println("Transcoder input created");
            TranscoderOutput transcoderOutput = new TranscoderOutput(fos);
            System.out.println("Transcoder output created");
            transcoder.transcode(transcoderInput, transcoderOutput);
            System.out.println("Conversion finished");

            fis.close();
            fos.close();
        } catch (Exception ex) {
            ex.printStackTrace();
            System.out.println("Exception");
        } finally {
            this.svgTempFile.delete();
            System.out.println("File deleted");
        }
            System.out.println("End of method");
    }
}

And I have a method that called by RPC.

public String generatePdf(PayDoc filledDoc) {
    //String svgFileName = this.generateSvg(filledDoc);
    //String pdfFileName = this.generateFileName("pdf");
    PdfHandler pdfHandler = new PdfHandler("myPdf.pdf");
    pdfHandler.convertToPdf(File.separator + "documents" + File.separator + "mySvg.svg");
        return null;//pdfFileName;
}

In eclipse all works fine, but not on Tomcat. RPC fails when I call it on Tomcat This is Tomcat console output:

\documents\mySvg.svg
Svg File exists
Transcoder created
Input stream created
Output stream created
Transcoder input created
Transcoder output created
File deleted

After that in "documents" folder I have "mySvg.svg"(still not deleted) and "myPdf.pdf"(it is empty).


Solution

  • Looks like you're not including the required library in your deployed application.

    ElementTraversal is part of xml-apis-X.XX.X.jar and has to be bundled with your application.

    As there are loads of build tools and I don't know which one you're using, I can't suggest changes.