?
Solved

FOP with weblogic 5.1

Posted on 2003-03-28
4
Medium Priority
?
343 Views
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
XSLTInputHandler....

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.

Thanks
vus
0
Comment
Question by:anything-nothing
[X]
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
4 Comments
 

Accepted Solution

by:
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);
                        MessageHandler.setScreenLogger(log);
                  }

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

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


                  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()));

                  response.setContentType("application/pdf");
                  
                  Driver driver = new Driver(fopSource, out);
                  driver.setLogger(log);
                  driver.setRenderer(Driver.RENDER_PDF);
                  driver.run();
                  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");
                  fo.write(content);
                  fo.flush();
                  fo.close();
                  */
                  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);                  
                  
                  sessie.addTempFile(path);
                  java.io.FileOutputStream fileout = new java.io.FileOutputStream(path);
                  
                  fileout.write(content);
                  fileout.flush();
                  fileout.close();
                  //request.getRequestDispatcher(url).forward(request,response);
                  //response.sendRedirect("http://localhost:8080/AQUA400" + url);
                  response.sendRedirect(request.getContextPath() + url);
                  
                  /*
                  response.setContentLength(content.length);
                  response.setBufferSize(content.length+300);
                  respOut.write(content);
                  respOut.flush();
                  */
            } 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);
            }
      }

}
0
 

Expert Comment

by:CleanupPing
ID: 9058422
anything-nothing:
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 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 15

Expert Comment

by:jimmack
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.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jimmack
EE Cleanup Volunteer
0

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