You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Tremal Naik <tr...@gmail.com> on 2007/09/06 12:43:08 UTC
How to get Request from RequestFacade
Hello,
I'v been using a valve to perform license checking in my web
application. The method invoke(Request request, Response response) had
access to the Request and Response objects, allowing me to perform
some advanced operations. For instance, I made use of instructions
like:
Session catalinaSession = request.getSessionInternal(false);
catalinaSession.access();
or
Session[] managedSessions = request.getContext().getManager().findSessions();
Now, I'm moving the license validation code to a Filter. How do I
access org.apache.catalina.connector.Request/Response in the method
doFilter()? I see that I can only cast to a RequestFacade object:
public void doFilter(ServletRequest sRequest, ServletResponse
sResponse, FilterChain chain)
throws IOException, ServletException
{
RequestFacade cRequest = (RequestFacade) sRequest;
......
but now, I cannot use the Facade to access the Request. How can I
solve this problem? Is it desirable accessing Catalina specific object
from a Filter? Should I rewrite my code/ redesign my license
validation framework? It is a very complex one, hance it may require
some effort. May you redirect me to some useful articles/resources?
Many thanks
--
TREMALNAIK
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: How to get Request from RequestFacade
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Tremal,
Tremal Naik wrote:
> yes, I noticed it's quite hard. That's why I suspected that was not
> the best way to proceed. The Valve solution works quite fine. I was
> trying to switch to a Filter-based one since the license validation
> code is quite complex and I have to duplicate much of my webapp code
> into the server/lib folder.
I guess the real question is why you need access to TC's internals... I
can't seem to understand it. The only example you provided was that you
want to have instant access to sessions (does not require TC internals),
you wanted to be able to 'touch' the session to update it's 'last access
time' (not sure why you need that), and that you wanted access to the Realm.
What are you actually doing with all those things?
If you tell us what you're actually trying to do, we might be able to
give you some ideas for how to do it /another way/.
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFG4WzH9CaO5/Lv0PARAtXxAJ9RYVOWfOkdgQnpJaPcRRwaZyM7wQCfYf9q
3YN5lq8K0H+azV3qmu3r95I=
=5SrZ
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: How to get Request from RequestFacade
Posted by Tremal Naik <tr...@gmail.com>.
2007/9/7, Bill Barker <wb...@wilshire.com>:
> From his examples below, it looks like he wants access to the TC internals.
yes, you're right
> For the OP's original problem, for obvious security reasons TC makes it very
> hard to access the internal TC objects behind the various Facades from a
> webapps code (e.g. a Filter). It should be pretty much impossible if you
yes, I noticed it's quite hard. That's why I suspected that was not
the best way to proceed. The Valve solution works quite fine. I was
trying to switch to a Filter-based one since the license validation
code is quite complex and I have to duplicate much of my webapp code
into the server/lib folder.
I'll try to redesign it better.
Thanks
--
TREMALNAIK
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: How to get Request from RequestFacade
Posted by Bill Barker <wb...@wilshire.com>.
"David Smith" <dn...@cornell.edu> wrote in message
news:46DFE9E0.1050109@cornell.edu...
> Ok... do you need them to modify the request and/or response? Or are you
> trying to pull some information from the original tomcat internals?
>
>From his examples below, it looks like he wants access to the TC internals.
For the OP's original problem, for obvious security reasons TC makes it very
hard to access the internal TC objects behind the various Facades from a
webapps code (e.g. a Filter). It should be pretty much impossible if you
are running in a sandbox with the default TC security settings. Overall, if
you really need access to the internal TC objects, IMHO you are better off
using a Valve, since the potential need to modify it when you upgrade TC
versions doesn't go away. If you can do what you need to do with the
operations and properties exposed via JMX on the Manager, then that is
probably cleanest. Otherwise, you would probably need to use introspection.
> I first assumed you were attempting to modify the request or response, so
> a wrapper is ideal. All you have to do is create a class that extends
> HttpServletRequestWrapper or HttpServletResponseWrapper and override the
> methods you want. Then in the filter, just instantiate your request or
> response class with the original request or response in the constructor.
> When you chain to the next filter, just pass on the new request and
> response objects.
>
> --David
>
> Tremal Naik wrote:
>
>>That's the point, I don't know much about request/response wrapping.
>>
>>I don't need the Facade itself, what I need are the "real" Catalina
>>Request/Response objects hidden behind it. I don't know how to get
>>them from inside a Filter.
>>
>>Thanks,
>>
>>TN
>>
>>2007/9/6, David Smith <dn...@cornell.edu>:
>>
>>>May I ask what exactly you want to do with the facade? Seems like you
>>>could do what you want with a request or response wrapper instead.
>>>
>>>--David
>>>
>>>Tremal Naik wrote:
>>>
>>>
>>>>Hello,
>>>>I'v been using a valve to perform license checking in my web
>>>>application. The method invoke(Request request, Response response) had
>>>>access to the Request and Response objects, allowing me to perform
>>>>some advanced operations. For instance, I made use of instructions
>>>>like:
>>>>
>>>>Session catalinaSession = request.getSessionInternal(false);
>>>>catalinaSession.access();
>>>>
>>>>or
>>>>
>>>>Session[] managedSessions =
>>>>request.getContext().getManager().findSessions();
>>>>
>>>>Now, I'm moving the license validation code to a Filter. How do I
>>>>access org.apache.catalina.connector.Request/Response in the method
>>>>doFilter()? I see that I can only cast to a RequestFacade object:
>>>>
>>>>public void doFilter(ServletRequest sRequest, ServletResponse
>>>>sResponse, FilterChain chain)
>>>> throws IOException, ServletException
>>>> {
>>>> RequestFacade cRequest = (RequestFacade) sRequest;
>>>> ......
>>>>
>>>>
>>>>but now, I cannot use the Facade to access the Request. How can I
>>>>solve this problem? Is it desirable accessing Catalina specific object
>>>>
>>>>from a Filter? Should I rewrite my code/ redesign my license
>>>
>>>>validation framework? It is a very complex one, hance it may require
>>>>some effort. May you redirect me to some useful articles/resources?
>>>>
>>>>
>>>>Many thanks
>>>>
>>>>
>>>>
>>>>
>>>---------------------------------------------------------------------
>>>To start a new topic, e-mail: users@tomcat.apache.org
>>>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>>For additional commands, e-mail: users-help@tomcat.apache.org
>>>
>>>
>>>
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: How to get Request from RequestFacade
Posted by Tremal Naik <tr...@gmail.com>.
2007/9/6, David Smith <dn...@cornell.edu>:
> help. I'm still unclear as to why you need access those object. If you
> could say more about that, someone might be able to offer a better way
> to do what you want.
ok,
I need to access some of the Catalina Session specific features. In
the Valve invoke() method I perform a call like the following:
// update last access for this session
Session catalinaSession = request.getSessionInternal(false);
catalinaSession.access();
This is very easy to do with an HttpSession as well, but there are
other things that come easy with Catalina objects and I'm not able to
realise using J2EE specific interfaces, i.e.:
// get all sessions active for this manager
Session[] managedSessions = request.getContext().getManager().findSessions();
// find a session by ID
Session session = request.getContext().getManager().findSession(id);
// access the security realm
Realm realm = request.getContext().getRealm();
Hence, I'd like to know if I can perform the above operations in a
J2ee Filter doFilter() method.
Thanks
TN
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: How to get Request from RequestFacade
Posted by David Smith <dn...@cornell.edu>.
Don't know -- maybe one of the devs that monitor the list can offer some
help. I'm still unclear as to why you need access those object. If you
could say more about that, someone might be able to offer a better way
to do what you want.
--David
Tremal Naik wrote:
>2007/9/6, Tremal Naik <tr...@gmail.com>:
>
>
>>ok, I don't need to modify the Request or Response. I'm trying to read them.
>>
>>
>
>by the way, I'd be glad if I was able to read the StandardSession. I
>mean, even if it's not possible reading the Request, maybe it's easier
>accessing the Session behind the StandardSessionFacade.
>
>Thanks,
>
>
>
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: How to get Request from RequestFacade
Posted by Tremal Naik <tr...@gmail.com>.
2007/9/6, Tremal Naik <tr...@gmail.com>:
> ok, I don't need to modify the Request or Response. I'm trying to read them.
by the way, I'd be glad if I was able to read the StandardSession. I
mean, even if it's not possible reading the Request, maybe it's easier
accessing the Session behind the StandardSessionFacade.
Thanks,
--
TREMALNAIK
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: How to get Request from RequestFacade
Posted by Tremal Naik <tr...@gmail.com>.
2007/9/6, David Smith <dn...@cornell.edu>:
> Ok... do you need them to modify the request and/or response? Or are
> you trying to pull some information from the original tomcat internals?
ok, I don't need to modify the Request or Response. I'm trying to read them.
Maybe a Wrapper is too much...
TN
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: How to get Request from RequestFacade
Posted by David Smith <dn...@cornell.edu>.
Ok... do you need them to modify the request and/or response? Or are
you trying to pull some information from the original tomcat internals?
I first assumed you were attempting to modify the request or response,
so a wrapper is ideal. All you have to do is create a class that
extends HttpServletRequestWrapper or HttpServletResponseWrapper and
override the methods you want. Then in the filter, just instantiate
your request or response class with the original request or response in
the constructor. When you chain to the next filter, just pass on the
new request and response objects.
--David
Tremal Naik wrote:
>That's the point, I don't know much about request/response wrapping.
>
>I don't need the Facade itself, what I need are the "real" Catalina
>Request/Response objects hidden behind it. I don't know how to get
>them from inside a Filter.
>
>Thanks,
>
>TN
>
>2007/9/6, David Smith <dn...@cornell.edu>:
>
>
>>May I ask what exactly you want to do with the facade? Seems like you
>>could do what you want with a request or response wrapper instead.
>>
>>--David
>>
>>Tremal Naik wrote:
>>
>>
>>
>>>Hello,
>>>I'v been using a valve to perform license checking in my web
>>>application. The method invoke(Request request, Response response) had
>>>access to the Request and Response objects, allowing me to perform
>>>some advanced operations. For instance, I made use of instructions
>>>like:
>>>
>>>Session catalinaSession = request.getSessionInternal(false);
>>>catalinaSession.access();
>>>
>>>or
>>>
>>>Session[] managedSessions = request.getContext().getManager().findSessions();
>>>
>>>Now, I'm moving the license validation code to a Filter. How do I
>>>access org.apache.catalina.connector.Request/Response in the method
>>>doFilter()? I see that I can only cast to a RequestFacade object:
>>>
>>>public void doFilter(ServletRequest sRequest, ServletResponse
>>>sResponse, FilterChain chain)
>>> throws IOException, ServletException
>>> {
>>> RequestFacade cRequest = (RequestFacade) sRequest;
>>> ......
>>>
>>>
>>>but now, I cannot use the Facade to access the Request. How can I
>>>solve this problem? Is it desirable accessing Catalina specific object
>>>
>>>
>>>from a Filter? Should I rewrite my code/ redesign my license
>>
>>
>>>validation framework? It is a very complex one, hance it may require
>>>some effort. May you redirect me to some useful articles/resources?
>>>
>>>
>>>Many thanks
>>>
>>>
>>>
>>>
>>>
>>---------------------------------------------------------------------
>>To start a new topic, e-mail: users@tomcat.apache.org
>>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>>
>>
>
>
>
>
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: How to get Request from RequestFacade
Posted by Tremal Naik <tr...@gmail.com>.
That's the point, I don't know much about request/response wrapping.
I don't need the Facade itself, what I need are the "real" Catalina
Request/Response objects hidden behind it. I don't know how to get
them from inside a Filter.
Thanks,
TN
2007/9/6, David Smith <dn...@cornell.edu>:
> May I ask what exactly you want to do with the facade? Seems like you
> could do what you want with a request or response wrapper instead.
>
> --David
>
> Tremal Naik wrote:
>
> >Hello,
> >I'v been using a valve to perform license checking in my web
> >application. The method invoke(Request request, Response response) had
> >access to the Request and Response objects, allowing me to perform
> >some advanced operations. For instance, I made use of instructions
> >like:
> >
> >Session catalinaSession = request.getSessionInternal(false);
> >catalinaSession.access();
> >
> >or
> >
> >Session[] managedSessions = request.getContext().getManager().findSessions();
> >
> >Now, I'm moving the license validation code to a Filter. How do I
> >access org.apache.catalina.connector.Request/Response in the method
> >doFilter()? I see that I can only cast to a RequestFacade object:
> >
> >public void doFilter(ServletRequest sRequest, ServletResponse
> >sResponse, FilterChain chain)
> > throws IOException, ServletException
> > {
> > RequestFacade cRequest = (RequestFacade) sRequest;
> > ......
> >
> >
> >but now, I cannot use the Facade to access the Request. How can I
> >solve this problem? Is it desirable accessing Catalina specific object
> >from a Filter? Should I rewrite my code/ redesign my license
> >validation framework? It is a very complex one, hance it may require
> >some effort. May you redirect me to some useful articles/resources?
> >
> >
> >Many thanks
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
--
TREMALNAIK
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: How to get Request from RequestFacade
Posted by David Smith <dn...@cornell.edu>.
May I ask what exactly you want to do with the facade? Seems like you
could do what you want with a request or response wrapper instead.
--David
Tremal Naik wrote:
>Hello,
>I'v been using a valve to perform license checking in my web
>application. The method invoke(Request request, Response response) had
>access to the Request and Response objects, allowing me to perform
>some advanced operations. For instance, I made use of instructions
>like:
>
>Session catalinaSession = request.getSessionInternal(false);
>catalinaSession.access();
>
>or
>
>Session[] managedSessions = request.getContext().getManager().findSessions();
>
>Now, I'm moving the license validation code to a Filter. How do I
>access org.apache.catalina.connector.Request/Response in the method
>doFilter()? I see that I can only cast to a RequestFacade object:
>
>public void doFilter(ServletRequest sRequest, ServletResponse
>sResponse, FilterChain chain)
> throws IOException, ServletException
> {
> RequestFacade cRequest = (RequestFacade) sRequest;
> ......
>
>
>but now, I cannot use the Facade to access the Request. How can I
>solve this problem? Is it desirable accessing Catalina specific object
>from a Filter? Should I rewrite my code/ redesign my license
>validation framework? It is a very complex one, hance it may require
>some effort. May you redirect me to some useful articles/resources?
>
>
>Many thanks
>
>
>
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org