Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

FOP Servlet - XSLTInputHandler error

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to run fop using a servlet using
http://127.0.0.1:8080/examples/servlet/FopTestServlet?xml=krusty.xml&xsl=krusty.xsl
but it is getting the error and code (this is example from FOP with some minor modifications) below.
Code compiles fine...
Server running tomcat 331 and jdk1.3.
Any suggestions anyone.
Internal Servlet Error:
java.lang.NoClassDefFoundError: org/apache/fop/apps/XSLTInputHandler
at java.lang.Class.newInstance0(Native Method)
at java.lang.Class.newInstance(Class.java:232)
at org.apache.tomcat.facade.ServletHandler.getServlet(ServletHandler.java:346)
at org.apache.tomcat.facade.ServletHandler.preInit(ServletHandler.java:439)
at org.apache.tomcat.facade.ServletHandler.init(ServletHandler.java:228)
at org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:472)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:917)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
at org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Http10Interceptor.java:176)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:516)
at java.lang.Thread.run(Thread.java:479)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import org.apache.fop.apps.Driver;
import org.apache.fop.apps.Version;
import org.apache.fop.apps.XSLTInputHandler;
import org.apache.log.*;
public class FopTestServlet extends HttpServlet {
public static final String FO_REQUEST_PARAM = "fo";
public static final String XML_REQUEST_PARAM = "xml";
public static final String XSL_REQUEST_PARAM = "xsl";
Logger log = null;
public void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException {
if(log == null) {
// Hierarchy hierarchy = Hierarchy.getDefaultHierarchy();
// log = hierarchy.getLoggerFor("fop");
// log.setPriority(Priority.WARN);
}
try {
String foParam = request.getParameter(FO_REQUEST_PARAM);
String xmlParam = request.getParameter(XML_REQUEST_PARAM);
String xslParam = request.getParameter(XSL_REQUEST_PARAM);
PrintWriter out = response.getWriter();
if (foParam != null) {
FileInputStream file = new FileInputStream(foParam);
// renderFO(new InputSource(file), response);
} else if((xmlParam != null) && (xslParam != null)) {
XSLTInputHandler input = new XSLTInputHandler(new File(xmlParam), new File(xslParam));
// renderXML(input, response);
} else {
// PrintWriter out = response.getWriter();
out.println("<html><head><title>Error</title></head>\n"+
"<body><h1>FopServlet Error</h1><h3>No 'fo' "+
"request param given.</body></html>");
}
out.println("<html><head><title>Test</title></head>\n"+
"<body><h1>FopServlet Error</h1><h3>xml: "+xmlParam+"<br>xsl: "+xslParam+"<br>fo: "+foParam+"</h3>"+
"</body></html>");
}
//catch (ServletException ex) {
// throw ex;
// }
catch (Exception ex) {
throw new ServletException(ex);
}
}
}
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
must be a classpath problem
 
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please add the necessary jar files that come with fop package into the lib folder of your context (examples/web-inf/lib)... escp the jar files like fop.jar,avalon-framework.jar...xalan.jar,..xerces or crimson etc.,,
/**
* Example servlet to generate a PDF from a servlet.
* Servlet param is:
* <ul>
* <li>fo: the path to a formatting object file to render
* </ul>
*
* Example URL: http://servername/servlet/FopServlet?fo=readme.fo
* Example URL: http://servername/servlet/FopServlet?xml=data.xml&xsl=format.xsl
* Compiling: you will need
* - servlet_2_2.jar
* - fop.jar
* - sax api
* - avalon-framework-x.jar (where x is the version found the FOP lib dir)
*
* Running: you will need in the WEB-INF/lib/ directory:
* - fop.jar
* - batik.jar
* - xalan-2.0.0.jar
* - avalon-framework-x.jar (where x is the version found the FOP lib dir)
*/
 
Matt Ricks
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've got those relevant jar files including fop.jar, avalon-frameworks-4.0.jar, xalan-2.0.0.jar, xerces-1.2.3.jar in the tomcat's lib directory and in tomcat.bat these are added to the classpath setting... so i think the classpath looks OK.
 
Balaji Loganathan
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Matt Ricks:
I've got those relevant jar files including fop.jar, avalon-frameworks-4.0.jar, xalan-2.0.0.jar, xerces-1.2.3.jar in the tomcat's lib directory and in tomcat.bat these are added to the classpath setting... so i think the classpath looks OK.


Please place them in the examples/web-inf/lib directory, placing in tomcat/lib folder is not a good idea,escp while shipping the product for implementation.
>> java.lang.NoClassDefFoundError: org/apache/fop/apps/XSLTInputHandler
But your error clearly shows that the fop.jar is not available classpath or can be located by tomcat.
If you still get the problem, better restart the tomcat.
 
Hey! Wanna see my flashlight? It looks like this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic