You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Youssef A. Mohammed" <ya...@ejada.com> on 2006/11/16 18:23:59 UTC

A Filter Action !

Folks;

            I want to set of action classes that should operate only when
user object in the session.  How can I add some filter action to forward to
some page (action forward) and bypass the main action classes.

Regards,

 

 

Youssef A. Mohammed Ali

Senior System Analyst

 

 <http://www.ejada.com.sa/>  

Tel.: + (966 1) 472 2277 Ext. 226

Fax: + (966 1) 472 4772

P. O. Box: 55471 Riyadh, 11534, KSA

 

 

 


Re: A Filter Action !

Posted by Wendy Smoak <ws...@gmail.com>.
On 11/18/06, Youssef A. Mohammed <ya...@ejada.com> wrote:

> Thank you but it seems that this method in never called in struts 1.3 that I
> am using.
>
> The default request processor class is ComposableRequestProcessor  which
> happened to override the process method and it never calls
> processPreproccessor.
>
> Thus the solution could be to override the process method of
> ComposableRequestProcessor   and do the hook, but I looking for much cleaner
> solution.

Here's the chain config file for Struts 1.3.5

http://svn.apache.org/repos/asf/struts/struts1/tags/STRUTS_1_3_5/core/src/main/resources/org/apache/struts/chain/chain-config.xml

Which says the processPreprocess' method was replaced by:

                                     LookupCommand with
optional="true".  Multiple
                                     occurrences of this can easily be added, to
                                     support additional processing hooks at any
                                     point in the chain without modifying the
                                     standard definition.

Further down, I see:

        <!-- Look up optional preprocess command -->
        <lookup
                catalogName="struts"
                name="servlet-standard-preprocess"
                optional="true"/>

I haven't tried this, but it looks like you should add a command (or
chain of commands) named 'servlet-standard-preprocess', and it will be
executed.

-- 
Wendy

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: A Filter Action !

Posted by "Youssef A. Mohammed" <ya...@ejada.com>.
Thank you but it seems that this method in never called in struts 1.3 that I
am using. 

The default request processor class is ComposableRequestProcessor  which
happened to override the process method and it never calls
processPreproccessor. 

 

Thus the solution could be to override the process method of
ComposableRequestProcessor   and do the hook, but I looking for much cleaner
solution. 

 

I am dreaming of some hook that returns ActionForward that will be processed
before all my action classes.

 

Regards,

            

 

  _____  

From: Venkata Phani Kumar [mailto:venkata.p@ocimumbio.com] 
Sent: Friday, November 17, 2006 8:58 AM
To: Struts Users Mailing List
Cc: yali@ejada.com
Subject: Re: A Filter Action ! 

 

Hi youssef,

You can override RequestProcessor instead.

The required steps are

1) in struts-config.xml    

    <controller>
          <set-property property="processorClass" value="your controller
class which extends RequestProcessor"/>
    </controller>

2)  Create a Class wich extends RequestProcessor

     If you are using Tile Framework you have extend from
TilesRequestProcessor

3) Then override method processPreprocess() and do your logic in that method

 

like 

        public class ModReqProcessor extends TilesRequestProcessor {

             @Override
             protected boolean processPreprocess(HttpServletRequest request,
HttpServletResponse response) {
                  HttpSession session = request.getSession(false);

                    // Check user object here 

                    // and return appropriate boolean variable

                    // if user object present return true

                    // otherwise forward to your error page using
RequestDispatcher.forward()

            }

        }

 

I hope this will help you

----- Original Message ----- 

From: Youssef A. Mohammed <ma...@ejada.com>  

To: 'Struts <ma...@struts.apache.org>  Users Mailing List' 

Sent: Thursday, November 16, 2006 10:53 PM

Subject: A Filter Action ! 

 

Folks;

            I want to set of action classes that should operate only when
user object in the session.  How can I add some filter action to forward to
some page (action forward) and bypass the main action classes.

Regards,

 

 

Youssef A. Mohammed Ali

Senior System Analyst

 

 <http://www.ejada.com.sa/>  

Tel.: + (966 1) 472 2277 Ext. 226

Fax: + (966 1) 472 4772

P. O. Box: 55471 Riyadh, 11534, KSA

 

 

 


Re: A Filter Action !

Posted by Venkata Phani Kumar <ve...@ocimumbio.com>.
Hi youssef,
You can override RequestProcessor instead.
The required steps are
1) in struts-config.xml    
    <controller>
          <set-property property="processorClass" value="your controller class which extends RequestProcessor"/>
    </controller>
2)  Create a Class wich extends RequestProcessor
     If you are using Tile Framework you have extend from TilesRequestProcessor
3) Then override method processPreprocess() and do your logic in that method

like 
        public class ModReqProcessor extends TilesRequestProcessor {
             @Override
             protected boolean processPreprocess(HttpServletRequest request, HttpServletResponse response) {
                  HttpSession session = request.getSession(false);
                    // Check user object here 
                    // and return appropriate boolean variable
                    // if user object present return true
                    // otherwise forward to your error page using RequestDispatcher.forward()
            }
        }

I hope this will help you
  ----- Original Message ----- 
  From: Youssef A. Mohammed 
  To: 'Struts Users Mailing List' 
  Sent: Thursday, November 16, 2006 10:53 PM
  Subject: A Filter Action ! 


  Folks;

              I want to set of action classes that should operate only when user object in the session.  How can I add some filter action to forward to some page (action forward) and bypass the main action classes.

  Regards,

   

   

  Youssef A. Mohammed Ali

  Senior System Analyst

   

   

  Tel.: + (966 1) 472 2277 Ext. 226

  Fax: + (966 1) 472 4772

  P. O. Box: 55471 Riyadh, 11534, KSA

   

   

   

RE: A Filter Action !

Posted by "Youssef A. Mohammed" <ya...@ejada.com>.
Thank you so much for you reply. 
   I am actually using 1.3.x and I thought about your (b) solution yet this
will required some manual effort (copy and paste the excecute code into the
realExcecute ones!) 

I highly appreciate if you shed some light on creating a Command and having
it fired in the chain before the action. 

Regards,

Youssef A. Mohammed Ali
Senior System Analyst
 
 
Tel.: + (966 1) 472 2277 Ext. 226
Fax: + (966 1) 472 4772
P. O. Box: 55471 Riyadh, 11534, KSA
 
 

> -----Original Message-----
> From: Frank W. Zammetti [mailto:fzlists@omnytex.com]
> Sent: Thursday, November 16, 2006 9:34 PM
> To: Struts Users Mailing List
> Cc: 'Struts Users Mailing List'
> Subject: RE: A Filter Action !
> 
> If your using S2, interceptors would be the way to go.  I assume your
> using S1 though...
> 
> If your using 1.3.x, you can create a Command and have it fire in the
> chain before your Action.
> 
> If your using < 1.3.x, either (a) extend RequestProcessor and put your
> filter code in there, or (b) subclass Action and have the fiter code in
> the subclass, then extend all your Actions from that.  It would go
> something like execute() in CustomAction (which extends from Action) does
> your check and forwards to a JSP of your choice if applicable, and if not,
> then it calls realExecute(), which would be a method defined in an Action
> extended from CustomAction, and has the same signature as execute().
> 
> Frank
> 
> 
> --
> Frank W. Zammetti
> Founder and Chief Software Architect
> Omnytex Technologies
> http://www.omnytex.com
> AIM/Yahoo: fzammetti
> MSN: fzammetti@hotmail.com
> Author of "Practical Ajax Projects With Java Technology"
>  (2006, Apress, ISBN 1-59059-695-1)
> Java Web Parts - http://javawebparts.sourceforge.net
>  Supplying the wheel, so you don't have to reinvent it!
> 
> On Thu, November 16, 2006 12:48 pm, Youssef A. Mohammed wrote:
> > Thank you for your reply ...  but I don't want to do this in a servlet
> > filter, I just want some action filter to work similar to a servlet
> filter
> > and make use of struts framework.
> > Regards,
> >
> >
> >> -----Original Message-----
> >> From: Mahmoud Saeed(RSW) [mailto:Mahmoud_Saeed@rayacorp.com]
> >> Sent: Thursday, November 16, 2006 8:46 PM
> >> To: Struts Users Mailing List
> >> Subject: RE: A Filter Action !
> >>
> >> Create a class that implements the Filter Interface and check in the
> >> doFilter method on the attribute , is it exist [user logged-in before]
> >> just call the doFilter(…) of the FilterChain object otherwise [user not
> >> logged-in before] make a request dispatcher to the login page or what
> >> ever.
> >>
> >> But, remember to apply the filter to all Actions by adding the
> following
> >> tag in you web description:
> >>
> >>
> >>
> >> <filter>
> >>       <filter-name>SecurityFilter</filter-name>
> >>       <display-name>SecurityFilter</display-name>
> >>       <filter-class> ....... </filter-class>
> >>   </filter>
> >> <filter-mapping>
> >>       <filter-name>SecurityFilter</filter-name>
> >>       <url-pattern>*.do</url-pattern>
> >>   </filter-mapping>
> >>   <filter-mapping>
> >>       <filter-name>SecurityFilter</filter-name>
> >>       <url-pattern>*.jsp</url-pattern>
> >>   </filter-mapping>
> >>
> >>
> >>
> >> ________________________________
> >>
> >> From: Youssef A. Mohammed [mailto:yali@ejada.com]
> >> Sent: 16 äæÝãÈÑ, 2006 07:24 ã
> >> To: 'Struts Users Mailing List'
> >> Subject: A Filter Action !
> >>
> >>
> >>
> >> Folks;
> >>
> >>             I want to set of action classes that should operate only
> >> when
> >> user object in the session.  How can I add some filter action to
> forward
> >> to some page (action forward) and bypass the main action classes.
> >>
> >> Regards,
> >>
> >>
> >>
> >>
> >>
> >> Youssef A. Mohammed Ali
> >>
> >> Senior System Analyst
> >>
> >>
> >>
> >>  <http://www.ejada.com.sa/>
> >>
> >> Tel.: + (966 1) 472 2277 Ext. 226
> >>
> >> Fax: + (966 1) 472 4772
> >>
> >> P. O. Box: 55471 Riyadh, 11534, KSA
> >>
> >>
> >>
> >>
> >>
> >>
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: A Filter Action !

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
If your using S2, interceptors would be the way to go.  I assume your
using S1 though...

If your using 1.3.x, you can create a Command and have it fire in the
chain before your Action.

If your using < 1.3.x, either (a) extend RequestProcessor and put your
filter code in there, or (b) subclass Action and have the fiter code in
the subclass, then extend all your Actions from that.  It would go
something like execute() in CustomAction (which extends from Action) does
your check and forwards to a JSP of your choice if applicable, and if not,
then it calls realExecute(), which would be a method defined in an Action
extended from CustomAction, and has the same signature as execute().

Frank


-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM/Yahoo: fzammetti
MSN: fzammetti@hotmail.com
Author of "Practical Ajax Projects With Java Technology"
 (2006, Apress, ISBN 1-59059-695-1)
Java Web Parts - http://javawebparts.sourceforge.net
 Supplying the wheel, so you don't have to reinvent it!

On Thu, November 16, 2006 12:48 pm, Youssef A. Mohammed wrote:
> Thank you for your reply ...  but I don't want to do this in a servlet
> filter, I just want some action filter to work similar to a servlet filter
> and make use of struts framework.
> Regards,
>
>
>> -----Original Message-----
>> From: Mahmoud Saeed(RSW) [mailto:Mahmoud_Saeed@rayacorp.com]
>> Sent: Thursday, November 16, 2006 8:46 PM
>> To: Struts Users Mailing List
>> Subject: RE: A Filter Action !
>>
>> Create a class that implements the Filter Interface and check in the
>> doFilter method on the attribute , is it exist [user logged-in before]
>> just call the doFilter(…) of the FilterChain object otherwise [user not
>> logged-in before] make a request dispatcher to the login page or what
>> ever.
>>
>> But, remember to apply the filter to all Actions by adding the following
>> tag in you web description:
>>
>>
>>
>> <filter>
>>       <filter-name>SecurityFilter</filter-name>
>>       <display-name>SecurityFilter</display-name>
>>       <filter-class> ....... </filter-class>
>>   </filter>
>> <filter-mapping>
>>       <filter-name>SecurityFilter</filter-name>
>>       <url-pattern>*.do</url-pattern>
>>   </filter-mapping>
>>   <filter-mapping>
>>       <filter-name>SecurityFilter</filter-name>
>>       <url-pattern>*.jsp</url-pattern>
>>   </filter-mapping>
>>
>>
>>
>> ________________________________
>>
>> From: Youssef A. Mohammed [mailto:yali@ejada.com]
>> Sent: 16 äæÝãÈÑ, 2006 07:24 ã
>> To: 'Struts Users Mailing List'
>> Subject: A Filter Action !
>>
>>
>>
>> Folks;
>>
>>             I want to set of action classes that should operate only
>> when
>> user object in the session.  How can I add some filter action to forward
>> to some page (action forward) and bypass the main action classes.
>>
>> Regards,
>>
>>
>>
>>
>>
>> Youssef A. Mohammed Ali
>>
>> Senior System Analyst
>>
>>
>>
>>  <http://www.ejada.com.sa/>
>>
>> Tel.: + (966 1) 472 2277 Ext. 226
>>
>> Fax: + (966 1) 472 4772
>>
>> P. O. Box: 55471 Riyadh, 11534, KSA
>>
>>
>>
>>
>>
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: A Filter Action !

Posted by "Youssef A. Mohammed" <ya...@ejada.com>.
Thank you for your reply ...  but I don't want to do this in a servlet
filter, I just want some action filter to work similar to a servlet filter
and make use of struts framework.
Regards,


> -----Original Message-----
> From: Mahmoud Saeed(RSW) [mailto:Mahmoud_Saeed@rayacorp.com]
> Sent: Thursday, November 16, 2006 8:46 PM
> To: Struts Users Mailing List
> Subject: RE: A Filter Action !
> 
> Create a class that implements the Filter Interface and check in the
> doFilter method on the attribute , is it exist [user logged-in before]
> just call the doFilter(…) of the FilterChain object otherwise [user not
> logged-in before] make a request dispatcher to the login page or what
> ever.
> 
> But, remember to apply the filter to all Actions by adding the following
> tag in you web description:
> 
> 
> 
> <filter>
>       <filter-name>SecurityFilter</filter-name>
>       <display-name>SecurityFilter</display-name>
>       <filter-class> ....... </filter-class>
>   </filter>
> <filter-mapping>
>       <filter-name>SecurityFilter</filter-name>
>       <url-pattern>*.do</url-pattern>
>   </filter-mapping>
>   <filter-mapping>
>       <filter-name>SecurityFilter</filter-name>
>       <url-pattern>*.jsp</url-pattern>
>   </filter-mapping>
> 
> 
> 
> ________________________________
> 
> From: Youssef A. Mohammed [mailto:yali@ejada.com]
> Sent: 16 نوفمبر, 2006 07:24 م
> To: 'Struts Users Mailing List'
> Subject: A Filter Action !
> 
> 
> 
> Folks;
> 
>             I want to set of action classes that should operate only when
> user object in the session.  How can I add some filter action to forward
> to some page (action forward) and bypass the main action classes.
> 
> Regards,
> 
> 
> 
> 
> 
> Youssef A. Mohammed Ali
> 
> Senior System Analyst
> 
> 
> 
>  <http://www.ejada.com.sa/>
> 
> Tel.: + (966 1) 472 2277 Ext. 226
> 
> Fax: + (966 1) 472 4772
> 
> P. O. Box: 55471 Riyadh, 11534, KSA
> 
> 
> 
> 
> 
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: A Filter Action !

Posted by "Mahmoud Saeed(RSW)" <Ma...@rayacorp.com>.
Create a class that implements the Filter Interface and check in the doFilter method on the attribute , is it exist [user logged-in before] just call the doFilter(…) of the FilterChain object otherwise [user not logged-in before] make a request dispatcher to the login page or what ever.

But, remember to apply the filter to all Actions by adding the following tag in you web description:

 

<filter>
      <filter-name>SecurityFilter</filter-name>
      <display-name>SecurityFilter</display-name>
      <filter-class> ....... </filter-class>
  </filter>
<filter-mapping>
      <filter-name>SecurityFilter</filter-name>
      <url-pattern>*.do</url-pattern>
  </filter-mapping>
  <filter-mapping>
      <filter-name>SecurityFilter</filter-name>
      <url-pattern>*.jsp</url-pattern>
  </filter-mapping>

 

________________________________

From: Youssef A. Mohammed [mailto:yali@ejada.com] 
Sent: 16 نوفمبر, 2006 07:24 م
To: 'Struts Users Mailing List'
Subject: A Filter Action ! 

 

Folks;

            I want to set of action classes that should operate only when user object in the session.  How can I add some filter action to forward to some page (action forward) and bypass the main action classes.

Regards,

 

 

Youssef A. Mohammed Ali

Senior System Analyst

 

 <http://www.ejada.com.sa/>  

Tel.: + (966 1) 472 2277 Ext. 226

Fax: + (966 1) 472 4772

P. O. Box: 55471 Riyadh, 11534, KSA