4 Replies Latest reply on Jan 19, 2012 9:13 PM by Jon Finke

    APEX FOP.WAR TOMCAT 6 problem

    760008
      Hi,

      My Configuration:
      Tomcat 6.0.29 (also i've tested od Tomcat 7.0.4 it's the same problem)
      Apex 4.0.1

      I have a problem in deploying fop.war (with apex package contains in utilities/fop) onTomcat. When I run the http://host:port/fop/apex_fop.jsp
      appears errors:

      org.apache.jasper.JasperException: Unable to compile class for JSP:

      An error occurred at line: 10 in the generated java file
      Only a type can be imported. oracle.xml.parser.v2.XMLDocument resolves to a package

      An error occurred at line: 11 in the generated java file
      Only a type can be imported. oracle.xml.parser.v2.XSLProcessor resolves to a package

      An error occurred at line: 12 in the generated java file
      Only a type can be imported. oracle.xml.parser.v2.XSLStylesheet resolves to a package

      An error occurred at line: 13 in the generated java file
      Only a type can be imported. oracle.xml.parser.v2.DOMParser resolves to a package

      An error occurred at line: 12 in the jsp file: /apex_fop.jsp
      XMLDocument cannot be resolved to a type
      9: <%
      10: response.setContentType("application/pdf");
      11:
      12: XMLDocument v_doc;
      13: XSLStylesheet v_xsl = null;
      14: String v_fop;
      15: DOMParser parser = new DOMParser();


      An error occurred at line: 13 in the jsp file: /apex_fop.jsp
      XSLStylesheet cannot be resolved to a type
      10: response.setContentType("application/pdf");
      11:
      12: XMLDocument v_doc;
      13: XSLStylesheet v_xsl = null;
      14: String v_fop;
      15: DOMParser parser = new DOMParser();
      16: XSLProcessor processor = new XSLProcessor();


      An error occurred at line: 15 in the jsp file: /apex_fop.jsp
      DOMParser cannot be resolved to a type
      12: XMLDocument v_doc;
      13: XSLStylesheet v_xsl = null;
      14: String v_fop;
      15: DOMParser parser = new DOMParser();
      16: XSLProcessor processor = new XSLProcessor();
      17: // set the encoding for the XML Processing
      18: String v_encode = "UTF-8";


      An error occurred at line: 15 in the jsp file: /apex_fop.jsp
      DOMParser cannot be resolved to a type
      12: XMLDocument v_doc;
      13: XSLStylesheet v_xsl = null;
      14: String v_fop;
      15: DOMParser parser = new DOMParser();
      16: XSLProcessor processor = new XSLProcessor();
      17: // set the encoding for the XML Processing
      18: String v_encode = "UTF-8";


      An error occurred at line: 16 in the jsp file: /apex_fop.jsp
      XSLProcessor cannot be resolved to a type
      13: XSLStylesheet v_xsl = null;
      14: String v_fop;
      15: DOMParser parser = new DOMParser();
      16: XSLProcessor processor = new XSLProcessor();
      17: // set the encoding for the XML Processing
      18: String v_encode = "UTF-8";
      19:


      An error occurred at line: 16 in the jsp file: /apex_fop.jsp
      XSLProcessor cannot be resolved to a type
      13: XSLStylesheet v_xsl = null;
      14: String v_fop;
      15: DOMParser parser = new DOMParser();
      16: XSLProcessor processor = new XSLProcessor();
      17: // set the encoding for the XML Processing
      18: String v_encode = "UTF-8";
      19:


      An error occurred at line: 21 in the jsp file: /apex_fop.jsp
      XSLStylesheet cannot be resolved to a type
      18: String v_encode = "UTF-8";
      19:
      20: // get the XSL
      21: v_xsl = new XSLStylesheet(new java.io.StringReader(request.getParameter("template")),null);
      22:
      23: // get the XML String from the form which was posted
      24: parser.parse(new java.io.StringReader(request.getParameter("xml")));


      Stacktrace:
           org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
           org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
           org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
           org.apache.jasper.compiler.Compiler.compile(Compiler.java:349)
           org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)
           org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)
           org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592)
           org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
           org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
           org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
           javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


      Can somebody help me out with this?
        • 1. Re: APEX FOP.WAR TOMCAT 6 problem
          760008
          I have done two things and it rather works:

          1. Copy xmlparserv2.jar to fop/WEB-INF/lib
          2. At the end of the apex_fop.jsp put the follow code just before the driver.run(); line:
          out.clear();
          out = pageContext.pushBody();


          Does anybody know it is a good solution ?
          • 2. Re: APEX FOP.WAR TOMCAT 6 problem
            Dramus
            I don't know if it's a good solution. I'm not a JAVA programmer, but I can tell you that it fixed my problem with not being able to create PDF files from APEX!.
            • 3. Re: APEX FOP.WAR TOMCAT 6 problem
              834657
              Hello,
              I had similar problem using Tomcat 7.0.8, render failed because of the missing oracle.xml.parser.v2.* packages in apex_fop.jsp.

              My solution was to replace them to use the javax.xml.transform.* packages this way:
              -----
              <%@ page import='java.io.*'%>
              <%@ page import='javax.xml.transform.Transformer'%>
              <%@ page import='javax.xml.transform.TransformerFactory'%>
              <%@ page import='javax.xml.transform.Source'%>
              <%@ page import='javax.xml.transform.Result'%>
              <%@ page import='javax.xml.transform.stream.StreamSource'%>
              <%@ page import='javax.xml.transform.sax.SAXResult'%>

              <%@ page import='org.apache.fop.apps.Driver'%>
              <%@ page import='org.apache.fop.apps.Options'%>


              <%
              Driver driver = new Driver();

              driver.setRenderer(Driver.RENDER_PDF);

              ByteArrayOutputStream v_out = new ByteArrayOutputStream();
              driver.setOutputStream(v_out);

              Source xsltSrc = new StreamSource(new java.io.StringReader(request.getParameter("template")));
              TransformerFactory factory = TransformerFactory.newInstance();
              Transformer transformer = factory.newTransformer(xsltSrc);

              Result res = new SAXResult(driver.getContentHandler());
              Source src = new StreamSource(new java.io.StringReader(request.getParameter("xml")));

              transformer.transform(src, res);

              response.setContentType("application/pdf");
              response.setContentLength(v_out.size());

              response.getOutputStream().write(v_out.toByteArray());
              response.getOutputStream().flush();

              %>
              -----

              Note: do not replace the included FOP library, rendering works only with v0.20.5 - newer versions will not validate the XSL received from APEX...

              Hope this helps.

              Janos
              • 4. Re: APEX FOP.WAR TOMCAT 6 problem
                Jon Finke
                Thanks for the code - it worked for me!