Filter request wrapper ClassCastException
Hi all:
I want to implement a filter that process the servlet request, then I was implement
a filter and a class that extend the HttpServletRequestWrapper class. The problem
is that when I class the doFilter method with my new class the server throw java.langClassCastException.
I don't know if I'm doing something wrong because there's a lot of references
and examples to wrap the response but not so many to wrap the request.
I simplify the code to test what's the problem and this is my wrapper class and
the relevant servlet code.
// Wrapper class
public class CompressionServletRequestWrapper extends HttpServletRequestWrapper
{
public CompressionServletRequestWrapper(HttpServletRequest request) throws
IOException{
super(request);
}
}
// Filter servlet
CompressionServletRequestWrapper wrappedRequest =null;
boolean entradaComprimida=false;
wrappedRequest=new CompressionServletRequestWrapper( httpRequest);
chain.doFilter(wrappedRequest, response);
Best Regards
Miguel Angel
Re: Filter request wrapper ClassCastException
I bet your consumer is a JSP, eh? I hear the wrappers work going to a
Servlet but not to a JSP (that gets turned into a Servlet when compiled...).
I tried a sample I found for the Response wrapper from a compression filter
This looks like it will do what you want to do....
[url]http://www.orionserver.com/tutorials/filters/GZIPFilter.html[/url]
I want to make a filter that allows me to set/modify a Request Header (not a
Request Attribute nor a Response Header) and ran into the same issue, lots
of people saying "Use the HttpServletRequestWrapper" and "look at the
specs"; but no one with a code sample that actually WORKS!!!
Doris Chen from Sun just sent me this link to one of her code camps:
[url]http://developer.java.sun.com/developer/onlineTraining/webcasts/35plus/dchen1/dchen1.html[/url]
and suggests Mary Hall's book "More Servlets and JavaServer Pages" (and the
filters section in Servlets2.3 spec too - figures...)
I haven't checked out the code camp nor the book yet. Post back if you
figure this out.
Thanks,
--
Michael J. Geiser
"Miguel Ángel" <mamltdv@hotmail.com> wrote in message
news:3f26674a$1@newsgroups.bea.com...
Hi all:
I want to implement a filter that process the servlet request, then I was
implement
a filter and a class that extend the HttpServletRequestWrapper class. The
problem
is that when I class the doFilter method with my new class the server throw
java.langClassCastException.
I don't know if I'm doing something wrong because there's a lot of
references
and examples to wrap the response but not so many to wrap the request.
I simplify the code to test what's the problem and this is my wrapper class
and
the relevant servlet code.
// Wrapper class
public class CompressionServletRequestWrapper extends
HttpServletRequestWrapper
{
public CompressionServletRequestWrapper(HttpServletRequest request)
throws
IOException{
super(request);
}
}
// Filter servlet
CompressionServletRequestWrapper wrappedRequest =null;
boolean entradaComprimida=false;
wrappedRequest=new CompressionServletRequestWrapper( httpRequest);
chain.doFilter(wrappedRequest, response);
Best Regards
Miguel Angel
Re: Filter request wrapper ClassCastException
That was a problem in 6.1 ... are you on 6.1?
Peace,
Cameron Purdy
Tangosol, Inc.
[url]http://www.tangosol.com/coherence.jsp[/url]
Tangosol Coherence: Clustered Replicated Cache for Weblogic
"Miguel Ángel" <mamltdv@hotmail.com> wrote in message
news:3f26674a$1@newsgroups.bea.com...[color=blue]
>
> Hi all:
>
> I want to implement a filter that process the servlet request, then I was[/color]
implement[color=blue]
> a filter and a class that extend the HttpServletRequestWrapper class. The[/color]
problem[color=blue]
> is that when I class the doFilter method with my new class the server[/color]
throw java.langClassCastException.[color=blue]
>
> I don't know if I'm doing something wrong because there's a lot of[/color]
references[color=blue]
> and examples to wrap the response but not so many to wrap the request.
>
> I simplify the code to test what's the problem and this is my wrapper[/color]
class and[color=blue]
> the relevant servlet code.
>
> // Wrapper class
> public class CompressionServletRequestWrapper extends[/color]
HttpServletRequestWrapper[color=blue]
> {
>
> public CompressionServletRequestWrapper(HttpServletRequest request)[/color]
throws[color=blue]
> IOException{
> super(request);
> }
>
> }
>
> // Filter servlet
> CompressionServletRequestWrapper wrappedRequest =null;
> boolean entradaComprimida=false;
> wrappedRequest=new CompressionServletRequestWrapper( httpRequest);
> chain.doFilter(wrappedRequest, response);
>
>
> Best Regards
>
> Miguel Angel
>
>[/color]
Re: Filter request wrapper ClassCastException
No, I'm on 7.0 SP3. What was the problem in that version and what is the solution?
Perhaps the problem still remain.
Thank you
"Cameron Purdy" <cpurdy@tangosol.com> wrote:[color=blue]
>That was a problem in 6.1 ... are you on 6.1?
>
>Peace,
>
>Cameron Purdy
>Tangosol, Inc.
>[url]http://www.tangosol.com/coherence.jsp[/url]
>Tangosol Coherence: Clustered Replicated Cache for Weblogic
>
>
>"Miguel Ángel" <mamltdv@hotmail.com> wrote in message
>news:3f26674a$1@newsgroups.bea.com...[color=green]
>>
>> Hi all:
>>
>> I want to implement a filter that process the servlet request, then[/color]
>I was
>implement[color=green]
>> a filter and a class that extend the HttpServletRequestWrapper class.[/color]
>The
>problem[color=green]
>> is that when I class the doFilter method with my new class the server[/color]
>throw java.langClassCastException.[color=green]
>>
>> I don't know if I'm doing something wrong because there's a lot of[/color]
>references[color=green]
>> and examples to wrap the response but not so many to wrap the request.
>>
>> I simplify the code to test what's the problem and this is my wrapper[/color]
>class and[color=green]
>> the relevant servlet code.
>>
>> // Wrapper class
>> public class CompressionServletRequestWrapper extends[/color]
>HttpServletRequestWrapper[color=green]
>> {
>>
>> public CompressionServletRequestWrapper(HttpServletRequest request)[/color]
>throws[color=green]
>> IOException{
>> super(request);
>> }
>>
>> }
>>
>> // Filter servlet
>> CompressionServletRequestWrapper wrappedRequest =null;
>> boolean entradaComprimida=false;
>> wrappedRequest=new CompressionServletRequestWrapper( httpRequest);
>> chain.doFilter(wrappedRequest, response);
>>
>>
>> Best Regards
>>
>> Miguel Angel
>>
>>[/color]
>
>[/color]
Re: Filter request wrapper ClassCastException
>>> I want to implement a filter that process the servlet request, then[color=blue][color=green][color=darkred]
>>> I was implement a filter and a class that extend the
>>> HttpServletRequestWrapper class. The problem is that when I class
>>> the doFilter method with my new class the server
>>> throw java.langClassCastException.[/color][/color][/color]
[color=blue][color=green]
>> That was a problem in 6.1 ... are you on 6.1?[/color][/color]
[color=blue]
> No, I'm on 7.0 SP3. What was the problem in that version and what is
> the solution? Perhaps the problem still remain.[/color]
The problem was that WL code casted the request object to a specific WL
implementation of request, which was a bug.
Can you post the full stack trace of the exception? That should provide a
clue or two.
Peace,
Cameron Purdy
Tangosol, Inc.
[url]http://www.tangosol.com/coherence.jsp[/url]
Tangosol Coherence: Clustered Replicated Cache for Weblogic
"Miguel Angel" <mamltdv@hotmail.com> wrote in message
news:3f27d507$1@newsgroups.bea.com...[color=blue]
>[/color]