RE: Struts2: How can I make a Filter redirecting to struts actions - SOLVED!

2006-12-08 Thread Ove.Oldberg
Hi Dariusz,
Thanks for the input. After some coding and reading in the Struts 2.0.2 
sourcecode I got this to work.

In general it seems that Struts2 uses two methods from the request to examine 
URI (in this order):

- request.getServletPath()
- request.getRequestURI()

The real trick is, as you suggested, to create my own instance of 
HttpServletRequest and implement set-methods for those two, manipulate the 
values and pass on the reference to filter.doFilter(req, res). The nice thing 
is that there is a javax.servlet.http.HttpServletRequestWrapper class that do a 
base implementation of the request. Extend that and implement 
setServletPath(String arg0) and setRequestURI(String arg0) methods.

Very nice!

--
Martin Gainty-
Thanks for your input to my question. As you understand of my answer above, a 
redirect from an JSP page is way to late in the request sequence. The thing 
with keywords is to implement Wiki functionallity into a normal Struts built 
website. If a client request http://somesite.com/keyword my filter ask the 
WikiEngine if it recognizes the keyword. If it does, I modify the request to my 
template.action instead. I store the Wiki keyword as an request attribute to be 
picked up and presented by the template. By this I can serve simple easy 
editable pages in Wiki format and use Struts for more advanced pages. An 
important goal is to hide the redirect for a web browser so when a user 
bookmarks a page, the url point to a keyword and not an ugly redirect.
--

Thanks again for the help!
Regards,
 Ove Oldberg



> -Ursprungligt meddelande-
> Från: Dariusz Wojtas [mailto:[EMAIL PROTECTED] 
> Skickat: den 7 december 2006 09:39
> Till: Struts Users Mailing List
> Ämne: Re: Struts2: How can I make a Filter redirecting to 
> struts actions
> 
> Hi,
> 
> If your filter is called before the struts filter, then what about
> preparing your own HttpServletRequest instance (some wrapper) and
> passing it deeper into doFilter(..)?
> You could copy all properties of the original request but change the
> URI (or whatever property is responsible for it).
> The next filter/servlet would be fooled by this switch and their
> calculations (ie. finding what action should be executed) would be
> done on data prepared by you.
> 
> Best regards
>   Dariusz Wojtas, Poland
> 
> On 12/7/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> > Hi everybody,
> > I have experimented with a filter that triggers for keywords on the
> > request URL
> > and when found it should redirect to a struts action that 
> processes the
> > keyword.
> >
> > My dilemma is that I don't want to use:
> > response.sendRedirect("/some.action");
> > becoz redirect should be done internally in the servlet 
> container, not
> > via browser.
> >
> > I have tested:
> > 
> request.getRequestDispatcher("/some.action").forward(request, 
> response);
> > and it don't work. I guess becoz an action mapping is not a 
> servlet, an
> > JSP page is.
> >
> > Does anyone have an idea how to solve this? Any input welcome!
> >
> > One approach could be to inherit:
> > org.apache.struts2.dispatcher.FilterDispatcher
> > and override doFilter() method and insert my keyword code. 
> Kinda ugly
> > thou.
> >
> > Regardings,
> >  Ove Oldberg, Sweden.
> 
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Struts2: How can I make a Filter redirecting to struts actions

2006-12-07 Thread Martin Gainty
Ove-

in your jsp
You can hook redirect-action to yout submit button as in

http://struts.apache.org/WW/actionmapper.html

code
in your Action class execute method
mapping.findForward("someAction")

where struts.xml has

someAction.jsp


bistå ?
Martin --
This e-mail communication and any attachments may contain confidential and 
privileged information for the use of the 
designated recipients named above. If you are not the intended recipient, you 
are hereby notified that you have received
this communication in error and that any review, disclosure, dissemination, 
distribution or copying of it or its 
contents
- Original Message - 
From: <[EMAIL PROTECTED]>
To: 
Sent: Thursday, December 07, 2006 3:32 AM
Subject: Struts2: How can I make a Filter redirecting to struts actions


Hi everybody,
I have experimented with a filter that triggers for keywords on the
request URL
and when found it should redirect to a struts action that processes the
keyword.

My dilemma is that I don't want to use:
response.sendRedirect("/some.action");
becoz redirect should be done internally in the servlet container, not
via browser.

I have tested:
request.getRequestDispatcher("/some.action").forward(request, response);
and it don't work. I guess becoz an action mapping is not a servlet, an
JSP page is.

Does anyone have an idea how to solve this? Any input welcome!

One approach could be to inherit:
org.apache.struts2.dispatcher.FilterDispatcher
and override doFilter() method and insert my keyword code. Kinda ugly
thou.

Regardings,
 Ove Oldberg, Sweden.

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Struts2: How can I make a Filter redirecting to struts actions

2006-12-07 Thread Dariusz Wojtas

Hi,

If your filter is called before the struts filter, then what about
preparing your own HttpServletRequest instance (some wrapper) and
passing it deeper into doFilter(..)?
You could copy all properties of the original request but change the
URI (or whatever property is responsible for it).
The next filter/servlet would be fooled by this switch and their
calculations (ie. finding what action should be executed) would be
done on data prepared by you.

Best regards
 Dariusz Wojtas, Poland

On 12/7/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

Hi everybody,
I have experimented with a filter that triggers for keywords on the
request URL
and when found it should redirect to a struts action that processes the
keyword.

My dilemma is that I don't want to use:
response.sendRedirect("/some.action");
becoz redirect should be done internally in the servlet container, not
via browser.

I have tested:
request.getRequestDispatcher("/some.action").forward(request, response);
and it don't work. I guess becoz an action mapping is not a servlet, an
JSP page is.

Does anyone have an idea how to solve this? Any input welcome!

One approach could be to inherit:
org.apache.struts2.dispatcher.FilterDispatcher
and override doFilter() method and insert my keyword code. Kinda ugly
thou.

Regardings,
 Ove Oldberg, Sweden.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]