Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


FOP with weblogic 5.1

Posted on 2003-03-28
Medium Priority
Last Modified: 2008-01-09
I am trying to generate the PDF using FOP in weblogic 5.1

My program looks like this

        String pdfFileUri = xmlFileUri + ".pdf";
        XSLTInputHandler aHandler = new XSLTInputHandler( new File(xmlFileUri), new File(xslFileUri) );
        this.logDebug(methodName, "XSLTInputHandler.... ");

        org.apache.fop.apps.Driver aDriver = new org.apache.fop.apps.Driver();
        this.logDebug(methodName, "aDriver - got the driver instance.... ");

        aDriver.setRenderer( org.apache.fop.apps.Driver.RENDER_PDF );
        this.logDebug(methodName, "aDriver.... ");

        aDriver.setOutputStream( new FileOutputStream( new File(pdfFileUri) ) );
        this.logDebug(methodName, "aDriver OP Stream set... ");

        aDriver.render( aHandler.getParser(), aHandler.getInputSource() );

Code compiles properly, My problem here is while running, the debug prints

after that nothing happens. No error also. No PDF is generated.
I feel it is failing near the driver. I have kept the fop.jar in the classpath.

Is there any special thing I have to do to get the Driver instance.

Question by:anything-nothing

Accepted Solution

user1159 earned 200 total points
ID: 8298810
Here is the code i use, you must also specifi the fop.jar in the WEB-INF directory

package be.aqf.webEnabling.servlets.operaties.algemeen;

import be.aqf.webEnabling.classen.Cls_Tools;
import be.aqf.webEnabling.sessie.SessionObject;
import java.io.ByteArrayOutputStream;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.apache.avalon.framework.logger.ConsoleLogger;
import org.apache.avalon.framework.logger.Logger;
import org.apache.fop.apps.Driver;
import org.apache.fop.messaging.MessageHandler;
import org.xml.sax.InputSource;

public class Servlet_PrintPdf extends GenericServlet {
      public static final String XSL_TRANSFORMER_PARAM = "xsltransformer";
      public static final String XML_BYTES_PARAM = "xmlbytesparm";
      Logger log = null;

       * Deze servlet verwacht 2 attributen die in de request aanwezig moeten zijn:
       * enerzijds een object van het type javax.xml.transform.Transformer onder
       * attribuut XSL_TRANSFORMER_PARAM.
       * Anderzijds moet er een object van het type byte[] doorgegeven worden onder de naam XML_BYTES_PARAM, deze stelt
       * de xml-file voor die moet geprocessed worden. Dit wordt dus verkregen door een
       * xml document om te zetten naar zijn overeenkomstige byte[] bv dmv jdom en electric xml dmv
       * Document.getBytes();
      public void performTask(
            javax.servlet.http.HttpServletRequest request,
            javax.servlet.http.HttpServletResponse response)
            throws javax.servlet.ServletException, java.io.IOException {
            try {
                  //OutputStream respOut = response.getOutputStream();
                  if (log == null) {
                        log = new ConsoleLogger(ConsoleLogger.LEVEL_ERROR);

                  javax.xml.transform.Transformer transformer =
                        (javax.xml.transform.Transformer) request.getAttribute(XSL_TRANSFORMER_PARAM);
                  if (transformer == null) {
                        showErr(request, response, "Geen transformer aanwezig", "Kweenie");

                  byte[] xmlBytes = (byte[]) request.getAttribute(XML_BYTES_PARAM);
                  if (xmlBytes == null) {
                        showErr(request, response, "Geen bytes aanwezig", "Kweenie");
                  // onderstaand om een vb van het xml bestand te verkrijgen
                  java.io.FileOutputStream xml = new java.io.FileOutputStream("c:\\john.txt");

                  StreamSource xmlSource =
                        new StreamSource(new java.io.ByteArrayInputStream(xmlBytes));
                  //we gaan de xslt-translatie uitvoeren      
                  java.io.ByteArrayOutputStream outXSLT = new java.io.ByteArrayOutputStream();
                  StreamResult result = new StreamResult(outXSLT);
                  long begin = System.currentTimeMillis();
                  transformer.transform(xmlSource, result);
                  long end = System.currentTimeMillis();
                  System.err.println("XSLT transformation: " + (end-begin));

                  //in de out zullen de bytes komen voor de pfd
                  ByteArrayOutputStream out = new ByteArrayOutputStream();

                  InputSource fopSource =
                        new InputSource(new java.io.ByteArrayInputStream(outXSLT.toByteArray()));

                  Driver driver = new Driver(fopSource, out);
                  long end2 = System.currentTimeMillis();
                  System.err.println("Time to FOP " + (end2 -end));

                  byte[] content = out.toByteArray();
                  /* pdf op schijf te zetten
                  java.io.FileOutputStream fo = new java.io.FileOutputStream("c:\\Test.pdf");
                  String path = this.getServletContext().getRealPath("/pdfs");
                  String name = "" + System.currentTimeMillis() + ".pdf";
                  String url = "/pdfs/" + name;
                  path = path + java.io.File.separatorChar  + name;
                  SessionObject sessie =Cls_Tools.getSessionObject(request);                  
                  java.io.FileOutputStream fileout = new java.io.FileOutputStream(path);
                  //response.sendRedirect("http://localhost:8080/AQUA400" + url);
                  response.sendRedirect(request.getContextPath() + url);
            } catch (javax.xml.transform.TransformerException e) {
                  showErr(request, response, e.getMessage(), null);

            } catch (org.apache.fop.apps.FOPException e) {
                  showErr(request, response, e.getMessage(), null);


Expert Comment

ID: 9058422
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Post your closing recommendations!  No comment means you don't care.
LVL 15

Expert Comment

ID: 9735354
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept user1159's comment as answer.

Please leave any comments here within the next seven days.


EE Cleanup Volunteer

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
A solution for Fortify Path Manipulation.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month10 days, 18 hours left to enroll

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question