You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Stephen Riek <st...@yahoo.co.uk> on 2002/11/27 06:55:11 UTC

Tomcat Filter with RequestDispatcher - IncompatibleClassChangeError

I've been at this for the better half of a day already 
without joy.  Am trying to create a Filter which accepts
a request for "/fr/Products/Toys/index.jsp" and forwards 
the request to "/Products/Toys/index.jsp" after setting
an attribute "lang" to "fr".  

However, no matter what I try, the following error is 
produced: "java.lang.IncompatibleClassChangeError".
I have tested the URL "/Products/Toys/index.jsp" directly
in a browser and there is no problem with it, and using
System.out.println calls, I have deduced that the error
lies in the rd.forward(request, response) line. 

Does anybody have any idea why this may be happening?
I'm using Tomcat4.0 


Filter Source Code
------------------

public final class LanguageFilter implements Filter {

private FilterConfig filterConfig = null;
 
public void init(FilterConfig filterConfig) {
   this.filterConfig = filterConfig;
}

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    String servletPath = ((HttpServletRequest) request).getServletPath();
    // If path starts with "/fr/", set the lang to "fr".
    if (servletPath.indexOf("/fr/") == 0) {
    request.setAttribute("lang", "fr");
    String targetURL = servletPath.substring(3);
    System.out.println("targetURL = " + targetURL);
    RequestDispatcher rd = null;
    ServletContext sc = this.filterConfig.getServletContext();
    rd = sc.getRequestDispatcher(targetURL);
    System.out.println("ok, RequestDispatcher created");
    if (rd!=null) {
        rd.forward(request, response);
        return;
    } 
    chain.doFilter(request, response);
}

 

Error Trace
-----------

java.lang.IncompatibleClassChangeError
at mas.TestFilter.doFilter(Store/LanguageFilter.java:35)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:213)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)

Thank you for helping,

Stephen.




---------------------------------
With Yahoo! Mail you can get a bigger mailbox -- choose a size that fits your needs

Re: Tomcat Filter with RequestDispatcher - IncompatibleClassChangeError

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Wed, 27 Nov 2002, Stephen Riek wrote:

>
> java.lang.LinkageError: Class javax/servlet/RequestDispatcher violates loader constraints

Sounds like you might have servlet.jar in your /WEB-INF directory, or in
your JDK extensions directory.  Don't do that.

Craig


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Tomcat Filter with RequestDispatcher - IncompatibleClassChangeError

Posted by Stephen Riek <st...@yahoo.co.uk>.
Dear Karthikeyan, 
I would have been willing to bet almost anything that your suggestion would 
not work. And I would have lost badly. 
Thank you indeed, I removed all the JAXP stuff (including Xerces.jar) from my
classpath and now the Filters work fine. 
Why on earth this should work is beyond me. I thought that Tomcat had its
own classloader and would use its own packages instead of those on the
classpath.  
This also leaves me wondering how I'm supposed to go about compiling all of
my classes that use XML/JAXP on my machine, now that I've removed it
all.  If only everybody used the same XML libraries it would be much easier.
Thanks again, you've made my day. 
Stephen.
 "karthikeyan.balasubramanian" <ka...@aspiresys.com> wrote:Dear Stephen,

You got to remove your xerces.jar from the classpath. This one should be
conflicting with your existing
jaxp classes. I had this problem when i moved xerces.jar into the classpath
and i couldnt able to run my
files.

Hope this helps.

karthikeyan.

----- Original Message -----
From: "Stephen Riek" 
To: "Tomcat Users List" 
Sent: Wednesday, November 27, 2002 2:54 PM
Subject: Re: Tomcat Filter with RequestDispatcher -
IncompatibleClassChangeError


>
> Ok, after further investigating, I realize I must have screwed up my
Tomcat
> installation somewhere along the line because a Request Dispatcher that
> worked several months ago no longer works and give the same errors below.
> Based on this, I can rule out the Filter code being wrong and turn my
attention
> to stuff I recently added.
> The prime suspect as always is the xml libraries. Would this affect it ?
> I hate the fact that adding JAXP to my system breaks some Tomcat things.
> Recently I added JAXP which means that I now have in /common/lib,
> - activation.jar
> - dom.jar
> - jaxp-api.jar
> - jdbc2_0_stdext.jar
> - jndi.jar
> - jta.jar
> - ldap.jar
> - mail.jar
> - mysql.jar
> - naming-common.jar
> - naming-resources.jar
> - sax.jar
> - servlet.jar
> - tools.jar
> - tyrex-0.9.7.0.jar
> - xalan.jar
> - xercesImpl.jar
> - xsltc.jar
> and in /jasper I have,
> - crimson.jar
> - jasper-compiler.jar
> - jaxp.jar
> In order to install JAXP I had to remove 'jaxp-api.jar' from
/jasper
> Could any of this be the cause, or should I really look at just
reinstalling
> the latest stable version of Tomcat4 ?
>
> If it helps, my classpath includes,
> commons-beanutils.jar; (jakarta)
> commons-collections.jar; (jakarta)
> jakarta-oro-2.0.6.jar; (jakarta)
> commons-digester.jar; (jakarta)
> commons-logging.jar; (jakarta)
> velocity-J2EE-dep-1.3-rc1.jar;
> activation.jar; (javamail)
> mail.jar; (javamail)
> \common\lib\servlet.jar;
> dom.jar; (jaxp)
> jaxp-api.jar; (jaxp)
> sax.jar; (jaxp)
> xalan.jar; (jaxp)
> xercesImpl.jar; (jaxp)
> xsltc.jar; (jaxp)
> turbine-2.2-b2-dev.jar; (jetspeed)
> jetspeed-1.4b1.jar; (jetspeed)
> ecs-1.4.1.jar; (jetspeed)
> but things in the classpath shouldn't affect Tomcat, I think.
> Stephen
>
> Stephen Riek wrote:
> Thanks for the reply, Craig.
> > > Error Trace
> > > -----------
> > >
> > > java.lang.IncompatibleClassChangeError
> >
> > This exception normally means you have made a change in a superclass and
> > recompiled it, but not recompiled a subclass that depends on the old
APIs.
>
> mmmmm, I have no idea which class this could be referring
> to then, unless it means one of Tomcat's distribution
> classes. To further debug, I removed ALL other classes
> under "WEB-INF/classes", so that I only have my one Filter
> there. I also removed all jars from WEB-INF/lib, then
> restarted Tomcat. Therefore, the only superclass involved
> is the Filter class.
>
> I recompiled my LanguageFilter.java and yet the error
> still occured.
>
>
> > > at mas.TestFilter.doFilter(Store/LanguageFilter.java:35)
> >
> > What is "Store"? Is that supposed to be the package name?
>
> Sorry, yes, I copied an earlier/older trace.
>
> > You should recompile *all* your classes to catch any cases
> > where you've made incompatible changes.
>
> I've done exactly that now (basically due to the fact that
> I only have the ONE class - the LanguageFilter.java)
>
> I have even deleted the entire contents of the "/work"
> directory and restarted Tomcat again to ensure that it
> is not an old class being cached in memory.
>
> Interestingly, the very first time that I make a request to
> the Filter, I get the following error message:
>
>
>
> java.lang.LinkageError: Class javax/servlet/RequestDispatcher violates
loader constraints
> at test.LanguageFilter.doFilter(test/LanguageFilter.java:36)
> at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application
FilterChain.java:213)
> at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh
ain.java:193)
> at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.ja
va:243)
> at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5
66)
> at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
> at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
> at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.ja
va:215)
> at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5
66)
> at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase
.java:472)
> at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5
64)
> at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
> at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
>
>
>
> Yet when I hit "reload" the error message changes to:
>
>
>
> java.lang.IncompatibleClassChangeError
> at test.LanguageFilter.doFilter(test/LanguageFilter.java:36)
> at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application
FilterChain.java:213)
> at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh
ain.java:193)
> at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.ja
va:243)
> at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5
66)
> at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
> at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
> at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.ja
va:215)
> at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5
66)
> at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase
.java:472)
> at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5
64)
> at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
> at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
> at
org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2366)
> at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164
)
> at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5
66)
>
>
>
> These error messages were created with this Filter code
> and I've added the check you suggested in your earlier
> reply.
>
>
>
> package test;
>
> import java.io.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
>
> public final class LanguageFilter implements Filter {
>
> private FilterConfig filterConfig = null;
>
> public void init(FilterConfig filterConfig) {
> this.filterConfig = filterConfig;
> }
>
> public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
> String servletPath = ((HttpServletRequest) request).getServletPath();
> // If the first element is '/en/' or '/fr/' :
> if (servletPath.indexOf("/en/") == 0 || servletPath.indexOf("/fr/") == 0)
{
> String lang = servletPath.substring(1,3);
> request.setAttribute("lang", lang);
> String targetURL = servletPath.substring(3);
> System.out.println(targetURL);
> RequestDispatcher rd = null;
> ServletContext sc = this.filterConfig.getServletContext();
> rd = sc.getRequestDispatcher(targetURL);
> System.out.println("ok, RequestDispatcher created");
> if (rd!=null) {
> rd.forward(request, response);
> }
> return;
> }
> // No language match, so just handle the request as normal.
> chain.doFilter(request, response);
> }
>
> public void destroy() {
> }
>
>
> }
>
>
>
> It works fine for URLs that do not start with /en/ or /fr/
> so it really does seem to be a RequestDispatcher and not
> Filter problem.
>
> Stephen.
>
>
>
>
> ---------------------------------
> With Yahoo! Mail you can get a bigger mailbox -- choose a size that fits
your needs
>
>
>
>
> ---------------------------------
> With Yahoo! Mail you can get a bigger mailbox -- choose a size that fits
your needs
>



--
To unsubscribe, e-mail: 
For additional commands, e-mail: 




---------------------------------
With Yahoo! Mail you can get a bigger mailbox -- choose a size that fits your needs

Re: Tomcat Filter with RequestDispatcher - IncompatibleClassChangeError

Posted by "karthikeyan.balasubramanian" <ka...@aspiresys.com>.
Dear Stephen,

  You got to remove your xerces.jar from the classpath.  This one should be
conflicting with your existing
jaxp classes.  I had this problem when i moved xerces.jar into the classpath
and i couldnt able to run my
files.

  Hope this helps.

karthikeyan.

----- Original Message -----
From: "Stephen Riek" <st...@yahoo.co.uk>
To: "Tomcat Users List" <to...@jakarta.apache.org>
Sent: Wednesday, November 27, 2002 2:54 PM
Subject: Re: Tomcat Filter with RequestDispatcher -
IncompatibleClassChangeError


>
> Ok, after further investigating, I realize I must have screwed up my
Tomcat
> installation somewhere along the line because a Request Dispatcher that
> worked several months ago no longer works and give the same errors below.
> Based on this, I can rule out the Filter code being wrong and turn my
attention
> to stuff I recently added.
> The prime suspect as always is the xml libraries. Would this affect it ?
> I hate the fact that adding JAXP to my system breaks some Tomcat things.
> Recently I added JAXP which means that I now have in <tomcat>/common/lib,
> - activation.jar
> - dom.jar
> - jaxp-api.jar
> - jdbc2_0_stdext.jar
> - jndi.jar
> - jta.jar
> - ldap.jar
> - mail.jar
> - mysql.jar
> - naming-common.jar
> - naming-resources.jar
> - sax.jar
> - servlet.jar
> - tools.jar
> - tyrex-0.9.7.0.jar
> - xalan.jar
> - xercesImpl.jar
> - xsltc.jar
> and in <tomcat>/jasper I have,
> - crimson.jar
> - jasper-compiler.jar
> - jaxp.jar
> In order to install JAXP I had to remove 'jaxp-api.jar' from
<tomcat>/jasper
> Could any of this be the cause, or should I really look at just
reinstalling
> the latest stable version of Tomcat4 ?
>
> If it helps, my classpath includes,
> commons-beanutils.jar;   (jakarta)
> commons-collections.jar; (jakarta)
> jakarta-oro-2.0.6.jar;   (jakarta)
> commons-digester.jar;    (jakarta)
> commons-logging.jar;     (jakarta)
> velocity-J2EE-dep-1.3-rc1.jar;
> activation.jar;          (javamail)
> mail.jar;                (javamail)
> <tomcat_home>\common\lib\servlet.jar;
> dom.jar;                  (jaxp)
> jaxp-api.jar;             (jaxp)
> sax.jar;                  (jaxp)
> xalan.jar;                (jaxp)
> xercesImpl.jar;           (jaxp)
> xsltc.jar;                (jaxp)
> turbine-2.2-b2-dev.jar;   (jetspeed)
> jetspeed-1.4b1.jar;       (jetspeed)
> ecs-1.4.1.jar;            (jetspeed)
> but things in the classpath shouldn't affect Tomcat, I think.
> Stephen
>
>  Stephen Riek <st...@yahoo.co.uk> wrote:
> Thanks for the reply, Craig.
> > > Error Trace
> > > -----------
> > >
> > > java.lang.IncompatibleClassChangeError
> >
> > This exception normally means you have made a change in a superclass and
> > recompiled it, but not recompiled a subclass that depends on the old
APIs.
>
> mmmmm, I have no idea which class this could be referring
> to then, unless it means one of Tomcat's distribution
> classes. To further debug, I removed ALL other classes
> under "WEB-INF/classes", so that I only have my one Filter
> there. I also removed all jars from WEB-INF/lib, then
> restarted Tomcat. Therefore, the only superclass involved
> is the Filter class.
>
> I recompiled my LanguageFilter.java and yet the error
> still occured.
>
>
> > > at mas.TestFilter.doFilter(Store/LanguageFilter.java:35)
> >
> > What is "Store"? Is that supposed to be the package name?
>
> Sorry, yes, I copied an earlier/older trace.
>
> > You should recompile *all* your classes to catch any cases
> > where you've made incompatible changes.
>
> I've done exactly that now (basically due to the fact that
> I only have the ONE class - the LanguageFilter.java)
>
> I have even deleted the entire contents of the "/work"
> directory and restarted Tomcat again to ensure that it
> is not an old class being cached in memory.
>
> Interestingly, the very first time that I make a request to
> the Filter, I get the following error message:
>
>
>
> java.lang.LinkageError: Class javax/servlet/RequestDispatcher violates
loader constraints
> at test.LanguageFilter.doFilter(test/LanguageFilter.java:36)
> at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application
FilterChain.java:213)
> at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh
ain.java:193)
> at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.ja
va:243)
> at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5
66)
> at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
> at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
> at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.ja
va:215)
> at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5
66)
> at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase
.java:472)
> at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5
64)
> at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
> at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
>
>
>
> Yet when I hit "reload" the error message changes to:
>
>
>
> java.lang.IncompatibleClassChangeError
> at test.LanguageFilter.doFilter(test/LanguageFilter.java:36)
> at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application
FilterChain.java:213)
> at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh
ain.java:193)
> at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.ja
va:243)
> at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5
66)
> at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
> at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
> at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.ja
va:215)
> at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5
66)
> at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase
.java:472)
> at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5
64)
> at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
> at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
> at
org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2366)
> at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164
)
> at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5
66)
>
>
>
> These error messages were created with this Filter code
> and I've added the check you suggested in your earlier
> reply.
>
>
>
> package test;
>
> import java.io.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
>
> public final class LanguageFilter implements Filter {
>
> private FilterConfig filterConfig = null;
>
> public void init(FilterConfig filterConfig) {
> this.filterConfig = filterConfig;
> }
>
> public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
> String servletPath = ((HttpServletRequest) request).getServletPath();
> // If the first element is '/en/' or '/fr/' :
> if (servletPath.indexOf("/en/") == 0 || servletPath.indexOf("/fr/") == 0)
{
> String lang = servletPath.substring(1,3);
> request.setAttribute("lang", lang);
> String targetURL = servletPath.substring(3);
> System.out.println(targetURL);
> RequestDispatcher rd = null;
> ServletContext sc = this.filterConfig.getServletContext();
> rd = sc.getRequestDispatcher(targetURL);
> System.out.println("ok, RequestDispatcher created");
> if (rd!=null) {
> rd.forward(request, response);
> }
> return;
> }
> // No language match, so just handle the request as normal.
> chain.doFilter(request, response);
> }
>
> public void destroy() {
> }
>
>
> }
>
>
>
> It works fine for URLs that do not start with /en/ or /fr/
> so it really does seem to be a RequestDispatcher and not
> Filter problem.
>
> Stephen.
>
>
>
>
> ---------------------------------
> With Yahoo! Mail you can get a bigger mailbox -- choose a size that fits
your needs
>
>
>
>
> ---------------------------------
> With Yahoo! Mail you can get a bigger mailbox -- choose a size that fits
your needs
>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Tomcat Filter with RequestDispatcher - IncompatibleClassChangeError

Posted by Stephen Riek <st...@yahoo.co.uk>.
Ok, after further investigating, I realize I must have screwed up my Tomcat 
installation somewhere along the line because a Request Dispatcher that 
worked several months ago no longer works and give the same errors below.
Based on this, I can rule out the Filter code being wrong and turn my attention
to stuff I recently added. 
The prime suspect as always is the xml libraries. Would this affect it ? 
I hate the fact that adding JAXP to my system breaks some Tomcat things. 
Recently I added JAXP which means that I now have in <tomcat>/common/lib,
- activation.jar
- dom.jar
- jaxp-api.jar
- jdbc2_0_stdext.jar
- jndi.jar
- jta.jar
- ldap.jar
- mail.jar
- mysql.jar
- naming-common.jar
- naming-resources.jar
- sax.jar
- servlet.jar
- tools.jar
- tyrex-0.9.7.0.jar
- xalan.jar
- xercesImpl.jar
- xsltc.jar
and in <tomcat>/jasper I have,
- crimson.jar
- jasper-compiler.jar
- jaxp.jar
In order to install JAXP I had to remove 'jaxp-api.jar' from <tomcat>/jasper
Could any of this be the cause, or should I really look at just reinstalling
the latest stable version of Tomcat4 ? 
 
If it helps, my classpath includes, 
commons-beanutils.jar;   (jakarta)
commons-collections.jar; (jakarta)
jakarta-oro-2.0.6.jar;   (jakarta)
commons-digester.jar;    (jakarta)
commons-logging.jar;     (jakarta)
velocity-J2EE-dep-1.3-rc1.jar;
activation.jar;          (javamail)
mail.jar;                (javamail)
<tomcat_home>\common\lib\servlet.jar;
dom.jar;                  (jaxp)
jaxp-api.jar;             (jaxp)
sax.jar;                  (jaxp)
xalan.jar;                (jaxp)
xercesImpl.jar;           (jaxp)
xsltc.jar;                (jaxp)
turbine-2.2-b2-dev.jar;   (jetspeed)
jetspeed-1.4b1.jar;       (jetspeed)
ecs-1.4.1.jar;            (jetspeed)
but things in the classpath shouldn't affect Tomcat, I think. 
Stephen
 
 Stephen Riek <st...@yahoo.co.uk> wrote:
Thanks for the reply, Craig. 
> > Error Trace
> > -----------
> >
> > java.lang.IncompatibleClassChangeError
> 
> This exception normally means you have made a change in a superclass and
> recompiled it, but not recompiled a subclass that depends on the old APIs.

mmmmm, I have no idea which class this could be referring 
to then, unless it means one of Tomcat's distribution 
classes. To further debug, I removed ALL other classes 
under "WEB-INF/classes", so that I only have my one Filter
there. I also removed all jars from WEB-INF/lib, then
restarted Tomcat. Therefore, the only superclass involved
is the Filter class.

I recompiled my LanguageFilter.java and yet the error 
still occured. 


> > at mas.TestFilter.doFilter(Store/LanguageFilter.java:35)
> 
> What is "Store"? Is that supposed to be the package name?

Sorry, yes, I copied an earlier/older trace. 

> You should recompile *all* your classes to catch any cases
> where you've made incompatible changes.

I've done exactly that now (basically due to the fact that
I only have the ONE class - the LanguageFilter.java) 

I have even deleted the entire contents of the "/work"
directory and restarted Tomcat again to ensure that it 
is not an old class being cached in memory.

Interestingly, the very first time that I make a request to 
the Filter, I get the following error message:



java.lang.LinkageError: Class javax/servlet/RequestDispatcher violates loader constraints
at test.LanguageFilter.doFilter(test/LanguageFilter.java:36)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:213)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:215)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)



Yet when I hit "reload" the error message changes to:



java.lang.IncompatibleClassChangeError
at test.LanguageFilter.doFilter(test/LanguageFilter.java:36)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:213)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:215)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2366)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)



These error messages were created with this Filter code
and I've added the check you suggested in your earlier 
reply.



package test;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public final class LanguageFilter implements Filter {

private FilterConfig filterConfig = null;

public void init(FilterConfig filterConfig) {
this.filterConfig = filterConfig;
}

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
String servletPath = ((HttpServletRequest) request).getServletPath();
// If the first element is '/en/' or '/fr/' :
if (servletPath.indexOf("/en/") == 0 || servletPath.indexOf("/fr/") == 0) {
String lang = servletPath.substring(1,3);
request.setAttribute("lang", lang);
String targetURL = servletPath.substring(3);
System.out.println(targetURL);
RequestDispatcher rd = null;
ServletContext sc = this.filterConfig.getServletContext();
rd = sc.getRequestDispatcher(targetURL);
System.out.println("ok, RequestDispatcher created");
if (rd!=null) {
rd.forward(request, response);
}
return;
}
// No language match, so just handle the request as normal.
chain.doFilter(request, response);
}

public void destroy() {
}


}



It works fine for URLs that do not start with /en/ or /fr/
so it really does seem to be a RequestDispatcher and not
Filter problem.

Stephen.




---------------------------------
With Yahoo! Mail you can get a bigger mailbox -- choose a size that fits your needs




---------------------------------
With Yahoo! Mail you can get a bigger mailbox -- choose a size that fits your needs

Re: Tomcat Filter with RequestDispatcher - IncompatibleClassChangeError

Posted by Stephen Riek <st...@yahoo.co.uk>.
Thanks for the reply, Craig. 
> > Error Trace
> > -----------
> >
> > java.lang.IncompatibleClassChangeError
> 
> This exception normally means you have made a change in a superclass and
> recompiled it, but not recompiled a subclass that depends on the old APIs.

mmmmm, I have no idea which class this could be referring 
to then, unless it means one of Tomcat's distribution 
classes. To further debug, I removed ALL other classes 
under "WEB-INF/classes", so that I only have my one Filter
there. I also removed all jars from WEB-INF/lib, then
 restarted Tomcat.  Therefore, the only superclass involved
is the Filter class.

I recompiled my LanguageFilter.java and yet the error 
still occured. 


> > at mas.TestFilter.doFilter(Store/LanguageFilter.java:35)
> 
> What is "Store"? Is that supposed to be the package name?

Sorry, yes, I copied an earlier/older trace. 

> You should recompile *all* your classes to catch any cases
> where you've  made incompatible changes.

I've done exactly that now (basically due to the fact that
I only have the ONE class - the LanguageFilter.java)  

I have even deleted the entire contents of the "<tomcat_home>/work"
 directory and restarted Tomcat again to ensure that it 
is not an old class being cached in memory.

Interestingly, the very first time that I make a request to 
the Filter, I get the following error message:

<snip>

java.lang.LinkageError: Class javax/servlet/RequestDispatcher violates loader constraints
 at test.LanguageFilter.doFilter(test/LanguageFilter.java:36)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:213)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
 at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
 at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
 at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:215)
 at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
 at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
 at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
 at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
 at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)

</snip>

Yet when I hit "reload" the error message changes to:

<snip>

java.lang.IncompatibleClassChangeError
	at test.LanguageFilter.doFilter(test/LanguageFilter.java:36)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:213)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
	at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:215)
	at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
	at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
	at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2366)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
	at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)

</snip>

These error messages were created with this Filter code
and I've added the check you suggested in your earlier 
reply.

<snip>

package test;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public final class LanguageFilter implements Filter {
    
 private FilterConfig filterConfig = null;
 
 public void init(FilterConfig filterConfig) {
  this.filterConfig = filterConfig;
 }
 
 public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
  String servletPath = ((HttpServletRequest) request).getServletPath();
  // If the first element is '/en/' or '/fr/' :
  if (servletPath.indexOf("/en/") == 0 || servletPath.indexOf("/fr/") == 0) {
   String lang = servletPath.substring(1,3);
   request.setAttribute("lang", lang);
   String targetURL = servletPath.substring(3);
   System.out.println(targetURL);
   RequestDispatcher rd = null;
   ServletContext sc = this.filterConfig.getServletContext();
   rd = sc.getRequestDispatcher(targetURL);
   System.out.println("ok, RequestDispatcher created");
   if (rd!=null) {
    rd.forward(request, response);
   }
   return;
  }
  // No language match, so just handle the request as normal.
  chain.doFilter(request, response);
 }

    public void destroy() {
    }


}

</snip>

It works fine for URLs that do not start with /en/ or /fr/
so it really does seem to be a RequestDispatcher and not
Filter problem.

Stephen.




---------------------------------
With Yahoo! Mail you can get a bigger mailbox -- choose a size that fits your needs

Re: Tomcat Filter with RequestDispatcher - IncompatibleClassChangeError

Posted by "Craig R. McClanahan" <cr...@apache.org>.
See below.

On Wed, 27 Nov 2002, Stephen Riek wrote:

> Date: Wed, 27 Nov 2002 05:55:11 +0000 (GMT)
> From: Stephen Riek <st...@yahoo.co.uk>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>
> To: Tomcat Users List <to...@jakarta.apache.org>
> Subject: Tomcat Filter with RequestDispatcher  -
>     IncompatibleClassChangeError
>
>
> I've been at this for the better half of a day already
> without joy.  Am trying to create a Filter which accepts
> a request for "/fr/Products/Toys/index.jsp" and forwards
> the request to "/Products/Toys/index.jsp" after setting
> an attribute "lang" to "fr".
>
> However, no matter what I try, the following error is
> produced: "java.lang.IncompatibleClassChangeError".
> I have tested the URL "/Products/Toys/index.jsp" directly
> in a browser and there is no problem with it, and using
> System.out.println calls, I have deduced that the error
> lies in the rd.forward(request, response) line.
>
> Does anybody have any idea why this may be happening?
> I'm using Tomcat4.0
>
>
> Filter Source Code
> ------------------
>
> public final class LanguageFilter implements Filter {
>
> private FilterConfig filterConfig = null;
>
> public void init(FilterConfig filterConfig) {
>    this.filterConfig = filterConfig;
> }
>
> public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
>     String servletPath = ((HttpServletRequest) request).getServletPath();
>     // If path starts with "/fr/", set the lang to "fr".
>     if (servletPath.indexOf("/fr/") == 0) {
>     request.setAttribute("lang", "fr");
>     String targetURL = servletPath.substring(3);

You probably don't want to do this *unless* the path starts with "/fr",
right?

>     System.out.println("targetURL = " + targetURL);
>     RequestDispatcher rd = null;
>     ServletContext sc = this.filterConfig.getServletContext();
>     rd = sc.getRequestDispatcher(targetURL);
>     System.out.println("ok, RequestDispatcher created");
>     if (rd!=null) {
>         rd.forward(request, response);
>         return;
>     }
>     chain.doFilter(request, response);
> }
>
>
>
> Error Trace
> -----------
>
> java.lang.IncompatibleClassChangeError

This exception normally means you have made a change in a superclass and
recompiled it, but not recompiled a subclass that depends on the old APIs.

> at mas.TestFilter.doFilter(Store/LanguageFilter.java:35)

What is "Store"?  Is that supposed to be the package name?

You should recompile *all* your classes to catch any cases where you've
made incompatible changes.

> at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:213)
> at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
> at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
> at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
> at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
> at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
>
> Thank you for helping,
>
> Stephen.
>

Craig


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>