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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month9 days, 22 hours left to enroll

762 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