Solved

HELP! Tomcat giving weird error

Posted on 2003-12-04
25
687 Views
Last Modified: 2013-11-24
hi,
    i'm working on a project, and for one part, a user can click on a link ,and enter and
cut and paste an XML file into a textarea. That info is sent and I attempt to translate
the contents in xml to html using an xml stylesheet. I use the j2ee apis of StreamSource,
TransformerFactory and Transformer to do it.  The problem is where I attempt
to create a new Transformer from TransformerFactory.  I get a cannot inherit from final class error. I also try and create a new Tranformer without passing in a source,and get and exception. when i comment out the line, there is no error. Any thought? This is baffiling because I got the idea for the code from a book ,as well I have queried similar examples on the web. Here is the error, thanks in advance.
-zania22
/**************************************************/
org.apache.jasper.JasperException: Cannot inherit from final class
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:248)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
      at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:98)
      at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:176)
      at java.security.AccessController.doPrivileged(Native Method)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:172)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:260)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:432)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:386)
      at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:534)
      at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:530)
      at java.lang.Thread.run(Thread.java:536)


root cause

javax.servlet.ServletException: Cannot inherit from final class
      at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:533)
      at org.apache.jsp.t_jsp._jspService(t_jsp.java:80)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:204)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
      at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:98)
      at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:176)
      at java.security.AccessController.doPrivileged(Native Method)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:172)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:260)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:432)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:386)
      at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:534)
      at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:530)
      at java.lang.Thread.run(Thread.java:536)

/**************************************************************/

here is the code...............

/************************************************************/
<%@ page import="java.io.*,javax.xml.transform.*,javax.xml.transform.stream.*" %>

<%
try{

 //get xsl file for translation
  StreamSource xsl = new StreamSource(new File("prices.xsl"));
  //get xml file from user pasted in textarea
  StreamSource xml= new StreamSource(request.getInputStream());

//results will go to his jsp
StreamResult result = new StreamResult(out);

TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer(xsl);<---THE PROBLEM
transformer.transform(xml,result);
}

catch(Exception e){
  out.println("EXCEPTIONS!!!!..."+e);
}

%>


0
Comment
Question by:zania22
  • 13
  • 6
  • 5
  • +1
25 Comments
 
LVL 92

Expert Comment

by:objects
ID: 9880161
If a class is declared as final then you cannot extend it.
0
 
LVL 92

Expert Comment

by:objects
ID: 9880216
what version tomcat?
what version jdk?

do you havce any other xml parsers installed with either tomcat or your jdk?
0
 
LVL 92

Expert Comment

by:objects
ID: 9880222
the stack trace of the actual error would also be useful.
0
 
LVL 92

Expert Comment

by:objects
ID: 9880231
Looks though like some classes/libraries are clashing.
Check that you don't have any additional XML parsers installed in your JDK or tomcat.
0
 
LVL 4

Expert Comment

by:vk33
ID: 9880267
Hi!

1. This code seems quite ok except xsl source definition. I would suggest this instead:
Source xsl = new StreamSource(application.getResourceAsStream("prices.xsl"));

In this case your code will be more flexible as you're referencing the application context. With your line tomcat behaves differently on different platforms, mainly it will look for the xsl file in the home folder of the user owning tomcat daemon process.

2. How does your form look like? I would suggest using request parameters rather than input stream (supposedly that your textarea name is "xml"):

String xmlString = request.getParameter("xml");
Source xml = new StreamSource(new StringReader(xmlString));

It works fine here this way!

Regards!
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 50 total points
ID: 9882445
Try making sure Tomcat is looking at the right version of xercesImpl.jar
0
 
LVL 1

Author Comment

by:zania22
ID: 9884487
CEHJ,

The tomcat version is 4.18
I'm pretty sure the jdk version is 1.4.2
Unfortunately, tomcat and the javac that I'm using are on my college's server, and I have limited access.  I cannot look at a log of a stack trace. But, I can create my own web.xml file in my WEB-INF folder.  How would I find out what version of xercesImpl.jar that tomcat is looking at,and can i specify in my own web.xml? I did the same code as above, and compiled it in a regular java program and got no errors. Checking the j2ee documentation of TransformerFactory, the newTransformer() function returns an abstract class. But I don't think that's the problem.
-zania22
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9884712
This xercesImpl.jar is only an investigation/experiment btw. But you could try putting a recent version of xercesImpl.jar into the WEB-INF/lib of your application
0
 
LVL 92

Expert Comment

by:objects
ID: 9884918
> Try making sure Tomcat is looking at the right version of xercesImpl.jar

as i already mentioned :)
0
 
LVL 92

Expert Comment

by:objects
ID: 9884935
> tomcat and the javac that I'm using are on my college's server, and I have limited access.

I'd say the problem is they are setup incorrectly, probably with some clashing libraries installed.
0
 
LVL 92

Expert Comment

by:objects
ID: 9885639
It's worth mentioning the problem to the sys admin of the college server, they may be able to fix the config of the server for you.
0
 
LVL 1

Author Comment

by:zania22
ID: 9885852
CEHJ,
     Here is some sleuthing I have put together(I am so annoyed :( ),anyway

-From a textbook i have, you need Xerces(XML Parser),Xalan(XSLT Processor), and JAXP (Generic XML Processing), for these annoying 5 lines of code.

-Xerces and JAXP come bundled in Tomcat,but Xalan you must download and I must place in the /lib folder of my WEB-INF.

-The current versions of Xalan ,come with the current versions of xerces.

-xerces is compromised of xercesImpl.jar and xml-apis.jar, currently

-xml-apis.jar used to be called xmlParserAPIs(now depracated).

-The version they have of tomcat is 4.1.18,
In its %TocmatHome%/common/endorsed it has the following:
xercesImpl.jar and xmlParserAPIs.jar,

So, they have the depracated xmlParserAPIs.jar, but you must have xml-apis.jar, for xerces to work. I wonder if this is causing the problem?  I guess I need the latest version of xalan.jar, xercesImpl.jar, and xml-apis.jar? I will put them in my Web-inf/lib. But I'm wondering are they then clashing with the xercesImpl.jar and xmlParserAPIs.jar in the common/endorsed do  you think?
-zania22
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 92

Expert Comment

by:objects
ID: 9885921
> But I'm wondering are they then clashing with the xercesImpl.jar and
> xmlParserAPIs.jar in the common/endorsed do  you think?

As I've said a few times, yes they probably are.
There may also be stuff installed in the jdk that is clashing.

0
 
LVL 92

Expert Comment

by:objects
ID: 9885967
> I will put them in my Web-inf/lib

that won't help, as tomcats parser will get loaded first.
0
 
LVL 92

Expert Comment

by:objects
ID: 9885984
what version of xalan are you running?
0
 
LVL 92

Accepted Solution

by:
objects earned 450 total points
ID: 9886059
from the tomcat class loader doc:

XML Parsers and JDK 1.4
Among many other changes, the JDK 1.4 release packages the JAXP APIs, and a version of Xerces, inside the JDK. This has impacts on applications that wish to use their own XML parser.

In previous versions of Tomcat 4, you could simply replace the XML parser in the $CATALINA_HOME/common/lib directory to change the parser used by all web applications. However, this technique will not be effective when you are running on JDK 1.4, because the usual class loader delegation process will always choose the implementation inside the JDK in preference to this one.

JDK 1.4 supports a mechanism called the "Endorsed Standards Override Mechanism" to allow replacement of APIs created outside of the JCP (i.e. DOM and SAX from W3C). It can also be used to update the XML parser implementation. For more information, see: http://java.sun.com/j2se/1.4/docs/guide/standards/index.html.

Tomcat utilizes this mechanism by including the system property setting -Djava.endorsed.dirs=$CATALINA_HOME/common/endorsed in the command line that starts the container. Therefore, you can replace the parser that is installed in this directory, and it will get used even on a JDK 1.4 system.
 
0
 
LVL 1

Author Comment

by:zania22
ID: 9886291
objects,
       I just took a look at the link. So, basically my plea to the admins is correct, though I place the new .jars in my lib, the class loader is looking in the commons/endorsed with the depracated .jar file.
thanks,
I'll see
0
 
LVL 1

Author Comment

by:zania22
ID: 9886315
>what version of xalan are you running?

I have xalan2.5.2 which includes xercesImpl.jar and xml-apis.jar for Xerces 2.4.0.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9888354
>>as i already mentioned :)

To be fair, you didn't mention anything specific ;-)
0
 
LVL 1

Author Comment

by:zania22
ID: 9890336
CEHJ,
        do you know how to "restart my webapps folder". A peer of mine once helped me out by saying he did so. I know we don't have the authority to restart tomcat, so i'm not sure how he did it,and he has not gotten back to me on how to do so. I just added a web.xml file, and tomcat is now saying it cannot fetch my servlets. so I'm thinking I need to "restart my webapps".thanks in advance.
-zania22
0
 
LVL 92

Expert Comment

by:objects
ID: 9890365
you need the admin webapp to be running.
You're webapp may also be setup to restart when classes changes.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9892023
AFAIK, this can be done through the manager web app:

http://jakarta.apache.org/tomcat/tomcat-4.0-doc/manager-howto.html
0
 
LVL 1

Author Comment

by:zania22
ID: 9899457
thanks everyone (especially objects)
         for your help, today the admin people added new versions of xercesImpl.jar, and xml-apis.jar to replaces xmlParsersApis.jar. Now, I don't have any tomcat errors, but I have an excpetion for this servlet,and another that i'm using msv(sun validator) to validate xml files against schemas. Expect a random new question post this evening possibly.
-zania22
0
 
LVL 92

Expert Comment

by:objects
ID: 9899586
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9900197
8-)
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now