You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Peter Theissen <pe...@web.de> on 2008/04/08 23:16:52 UTC

Simple interceptor is not called

Hi everybody,

doese anybody see why the following (quite simple)
interceptor isnt called:
BTW: list.jsp seems to be called correctly.

struts.xml
 >>>
    <package name="registration" extends="struts-default">

        <interceptors>
             <interceptor name="simpleInterceptor" 
class="quickstart.interceptor.simpleInterceptor"/>
        </interceptors>       
     
        <action name="listRegistrationsWaiting" 
class="registrationWaitingAction" method="execute">
            <result>pages/list.jsp</result>
            <result name="input">pages/list.jsp</result>
            <interceptor-ref name="simpleInterceptor"/>           
        </action>
      ...
    </package>
<<<

SimpleInterceptor.java
 >>>
package quickstart.interceptor;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class SimpleInterceptor extends AbstractInterceptor{
   
    public String intercept(ActionInvocation invocation) throws Exception {
        System.out.println("The action is being intercepted!");
        return Action.SUCCESS;
    }
}
<<<

What am I missing?

Thanks and best regards
Peter

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


Re: Simple interceptor is not called

Posted by Nils-Helge Garli Hegvik <ni...@gmail.com>.
Which server are you running the application in? Are you sure you have
checked all the log files for the server? And are you sure you're
editing the struts.xml that is actually picked up at run time? I've
had some problems earlier with Eclipse not synchronizing resources
properly to the correct output build folder. If that's the case, a
"project clean" usually helps. And configuring log4j properly would
probably help giving some meaningful information messages.

Nils-H

On Tue, Apr 8, 2008 at 11:59 PM, Peter Theissen <pe...@web.de> wrote:
> Hi,
>
>
>
> >
> > Are you sure it isn't?
> >
> >
>  yes ;-)
>
>
> > What happens if you return something other than SUCCESS from your action?
> >
> >
>  Unfortunately, exactly the same happens.
>
>
> > That will test whether or not it's getting the result from the intercept
> call
> > or the action itself.
> >
>  Now I returned Action.NONE and the System.out.println statement before
> still didnt work.
>
>
> > Are you able to see other sysout statements across the
> > application? (Use a logger!)
> >
>  Yes, I guess  I can see them on the common Eclipse console
>
>
>
> > Are there any startup errors in your log?
> >
>  Warnings are there:
>  log4j:WARN No appenders could be found for logger
> (org.springframework.util.ClassUtils).
>  log4j:WARN Please initialize the log4j system properly.
>
>
> > Is the
> > action configured properly in Spring?
> >
> >
>  I hope so. But difficult to judge for a noob. Is there any part I should
> examine
>  especially?
>
>  Thanks for your time and help
>  Peter
>
>
>
>
>
>  ---------------------------------------------------------------------
>  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: Again: question to interceptors

Posted by Peter Theissen <pe...@web.de>.
Hi all, dear Ralf,

thanks a lot for your answer it was really helpful.
Honestly, I didnt understand the call-stack-principle
behind the interceptors at all. So your hint:
"To understand recursion, you must understand recursion"
was a good one and also this picture:
[1] http://struts.apache.org/2.0.11.1/docs/big-picture.html
I already knew that design from the event handling of
a Javascript API (Map24 AJAX API)

However, what I thought, was one has to determine the
order in that the interceptors are called, in the action tag:
all interceptors that are before the result are also called
before the action, then the action is called, then the result
and those the interceptors are called, which are written AFTER
the result tags. OK, in retrospect my idea was also not
so intelligent ;-)

Thx & best regards
Peter



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


Re: Again: question to interceptors

Posted by Ralf Fischer <th...@googlemail.com>.
Hi Peter,

On Thu, Apr 10, 2008 at 12:08 PM, Peter Theissen <pe...@web.de> wrote:
<snip />
>  I have the "SimpleInterceptor":
>  >>>
>  public String intercept(ActionInvocation invocation) throws Exception {
>   System.out.println("The action is being intercepted!");
>   return invocation.invoke();        //return Action.SUCCESS; (**)
>  }
>  <<<

You 'usually' don't return anything else from the intercept method
despite the return code of the action invocation itself. Anyway the
return of your interceptor leads back to the action invocation, which
then puts the resulting success-String into a local variable and
returns null. End of processing. So neither action nor result are
executed, as there never is a call to actionInvocation.invoke() at the
end of your interceptor stack, which whould do this. You only
understand what a recursion is, when you've understood recursion ;-)

>  and the struts.xml contains:
>  >>>
>  <action name="listRegistrationsWaiting" class="registrationWaitingAction"
> method="execute">
>   <result>pages/list.jsp</result>
>   <result name="input">pages/list.jsp</result>
>   <interceptor-ref name="simpleInterceptor"/>           </action>
>  <<<

You know this leaves you with only ONE interceptor on your interceptor
stack, the default stack is completely omitted! Means no configuration
parameters or URL parameters injected into your action, and lots of
other stuff you miss. Try something like

<action name="foo" class="org.bar.Foo">
  <result>/foo.jsp</result>
  <interceptor-ref name="defaultStack" />
  <interceptor-ref name="simpleInterceptor" />
</action>

>  When I comment in (**) instead of the return,
>  the result is not displayed (list.jsp) is not invoked.
>  I dont understand why, since the interceptor should
>  be called as the LAST step as far as I understand the
>  doc?! Therefore, there should be no influence of
>  the interceptor at the result at all!

Nope. actionInvocation.invoke() calls the next intercepter on the
interceptor stack until there are no more interceptors. THEN the call
to actionInvocation.invoke() from the last interceptor on the stack
invokes the action. Thus in your example above the action never should
be called.

>  But obvously, Im misunderstanding something, since I found
>  out that it works, when I just call return invocation.invoke();
>  But also in this case I wounder why the interceptor is called
>  BEFORE the DB Access (I can see that on the console),
>  since the interceptor is provided as the LAST part of the
>  action.

Check out some more docs in the wiki, especially take a look at the
big picture[1] and interceptors[2].

Cheers,
-Ralf


[1] http://struts.apache.org/2.0.11.1/docs/big-picture.html
[2] http://struts.apache.org/2.x/docs/interceptors.html

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


Again: question to interceptors

Posted by Peter Theissen <pe...@web.de>.
Hello,

first of all thanks for all your previous answers. Somehow,
I got the interceptor working for the simplest case, but
honestly I still dont know exactly why. Maybe it was a
caching issue.

Now I have some questions:

I have the "SimpleInterceptor":
 >>>
public String intercept(ActionInvocation invocation) throws Exception {
  System.out.println("The action is being intercepted!");
  return invocation.invoke();       
  //return Action.SUCCESS; (**)
}
<<<

and the struts.xml contains:
 >>>
<action name="listRegistrationsWaiting" 
class="registrationWaitingAction" method="execute">
  <result>pages/list.jsp</result>
  <result name="input">pages/list.jsp</result>
  <interceptor-ref name="simpleInterceptor"/>           
</action>
<<<

When I comment in (**) instead of the return,
the result is not displayed (list.jsp) is not invoked.
I dont understand why, since the interceptor should
be called as the LAST step as far as I understand the
doc?! Therefore, there should be no influence of
the interceptor at the result at all!

But obvously, Im misunderstanding something, since I found
out that it works, when I just call return invocation.invoke();
But also in this case I wounder why the interceptor is called
BEFORE the DB Access (I can see that on the console),
since the interceptor is provided as the LAST part of the
action.

Thanks for your help
Peter



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


Re: Simple interceptor is not called

Posted by Dave Newton <ne...@yahoo.com>.
I agree with Nils; I'd be double-checking the deployment etc.

There's nothing obviously wrong (except that you say it doesn't work ;)

What happens if you throw an exception in the interceptor? In a *different*
action? That could help diagnose a deployment issue, anyway.

Dave

--- Peter Theissen <pe...@web.de> wrote:

> Hi,
> 
> >
> > Are you sure it isn't?
> >   
> yes ;-)
> > What happens if you return something other than SUCCESS from your action?
> >   
> Unfortunately, exactly the same happens.
> > That will test whether or not it's getting the result from the intercept
> call
> > or the action itself. 
> Now I returned Action.NONE and the System.out.println statement before 
> still didnt work.
> > Are you able to see other sysout statements across the
> > application? (Use a logger!) 
> Yes, I guess  I can see them on the common Eclipse console
> 
> > Are there any startup errors in your log? 
> Warnings are there:
> log4j:WARN No appenders could be found for logger 
> (org.springframework.util.ClassUtils).
> log4j:WARN Please initialize the log4j system properly.
> > Is the
> > action configured properly in Spring?
> >   
> I hope so. But difficult to judge for a noob. Is there any part I should 
> examine
> especially?
> 
> Thanks for your time and help
> Peter
> 
> 
> 
> ---------------------------------------------------------------------
> 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: Simple interceptor is not called

Posted by Peter Theissen <pe...@web.de>.
Hi,

>
> Are you sure it isn't?
>   
yes ;-)
> What happens if you return something other than SUCCESS from your action?
>   
Unfortunately, exactly the same happens.
> That will test whether or not it's getting the result from the intercept call
> or the action itself. 
Now I returned Action.NONE and the System.out.println statement before 
still didnt work.
> Are you able to see other sysout statements across the
> application? (Use a logger!) 
Yes, I guess  I can see them on the common Eclipse console

> Are there any startup errors in your log? 
Warnings are there:
log4j:WARN No appenders could be found for logger 
(org.springframework.util.ClassUtils).
log4j:WARN Please initialize the log4j system properly.
> Is the
> action configured properly in Spring?
>   
I hope so. But difficult to judge for a noob. Is there any part I should 
examine
especially?

Thanks for your time and help
Peter



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


Re: Request scoped data in Struts2

Posted by Dave Newton <ne...@yahoo.com>.
--- Raghuveer Kumarakrishnan <kr...@yahoo.com> wrote:
> My point is just having getters for an Action property should suffice for
> it to be accessed in the view by any tag library.

I don't know as this is correct for *any* tag library.

It works for S2 tags that use OGNL, because S2 tags evalue OGNL.

It works for tag libraries that choose to interpret attribute values as JSP
EL and do the EL processing "by hand", because S2 provides a request wrapper
that maps EL expressions to the value stack (or the programmer uses a JSP EL
expression as the attribute value).

If an EL expression isn't used and the tag library doesn't assume EL or OGNL,
though, the tag library will just get a string, AFAIK (and whatever type
conversions are available to tags these days).

Dave

> Chris Pratt <th...@gmail.com> wrote:
>   You are correct. In that case,
> 
> 
> 
> is equivalent to calling
> 
> request.put("someName",action.getSomeName());
> 
> in an Action that implements RequestAware. So when Display Tag processes
> 
> 
> 
> The "someName" attribute is available when the JSP Tag Library
> (DisplayTag in this instance) calls
> pageContext.findAttribute("someName");
> 
> But you have to use the (or put the value in the request from
> the action) for DisplayTag to see it.
> 
> (*Chris*)
> 
> On Tue, Apr 8, 2008 at 3:12 PM, Raghuveer Kumarakrishnan
> wrote:
> > This doc seems to suggest that even request scoped data needs to
> explicitly set using
> > to be used by tag libraries like jsp taglib or displaytag
> >
> >
>
http://struts.apache.org/2.x/docs/exposing-framework-objects-to-jstl-with-a-jstl-and-displaytag-example.html
> >
> >
> > But for request scoped data you do not need to explicitly set it as a
> request attribute,just getters on the action will do ,so a tag library like
> displaytag will work out of the box
> >
> > 
> > ...
> > ..
> >
> > 
> >
> > where there is a getSomeName( ) method in the Struts2 Action class
> >
> >
> > Am I missing something or does the doc need to be updated?
> >
> > --Raghu
> >
> >
> > A Goal .......... Is a Dream with a Deadline
> >
> > ---------------------------------
> > You rock. That's why Blockbuster's offering you one month of Blockbuster
> Total Access, No Cost.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 
> 
> A Goal .......... Is a Dream with a Deadline
>        
> ---------------------------------
> You rock. That's why Blockbuster's offering you one month of Blockbuster
> Total Access, No Cost.


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


Re: Request scoped data in Struts2

Posted by Raghuveer Kumarakrishnan <kr...@yahoo.com>.
My point is just having getters for an Action property should suffice for it to be accessed in the view by any tag library.
  
Chris Pratt <th...@gmail.com> wrote:
  You are correct. In that case,



is equivalent to calling

request.put("someName",action.getSomeName());

in an Action that implements RequestAware. So when Display Tag processes



The "someName" attribute is available when the JSP Tag Library
(DisplayTag in this instance) calls
pageContext.findAttribute("someName");

But you have to use the (or put the value in the request from
the action) for DisplayTag to see it.

(*Chris*)

On Tue, Apr 8, 2008 at 3:12 PM, Raghuveer Kumarakrishnan
wrote:
> This doc seems to suggest that even request scoped data needs to explicitly set using
> to be used by tag libraries like jsp taglib or displaytag
>
> http://struts.apache.org/2.x/docs/exposing-framework-objects-to-jstl-with-a-jstl-and-displaytag-example.html
>
>
> But for request scoped data you do not need to explicitly set it as a request attribute,just getters on the action will do ,so a tag library like displaytag will work out of the box
>
> 
> ...
> ..
>
> 
>
> where there is a getSomeName( ) method in the Struts2 Action class
>
>
> Am I missing something or does the doc need to be updated?
>
> --Raghu
>
>
> A Goal .......... Is a Dream with a Deadline
>
> ---------------------------------
> You rock. That's why Blockbuster's offering you one month of Blockbuster Total Access, No Cost.

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




A Goal .......... Is a Dream with a Deadline
       
---------------------------------
You rock. That's why Blockbuster's offering you one month of Blockbuster Total Access, No Cost.

Re: Request scoped data in Struts2

Posted by Chris Pratt <th...@gmail.com>.
You are correct.  In that case,

<s:set name="someName" value="someName" scope="request"/>

is equivalent to calling

request.put("someName",action.getSomeName());

in an Action that implements RequestAware.  So when Display Tag processes

<display:table name="someName" ...>

The "someName" attribute is available when the JSP Tag Library
(DisplayTag in this instance) calls
pageContext.findAttribute("someName");

But you have to use the <s:set> (or put the value in the request from
the action) for DisplayTag to see it.

  (*Chris*)

On Tue, Apr 8, 2008 at 3:12 PM, Raghuveer Kumarakrishnan
<kr...@yahoo.com> wrote:
> This doc seems to  suggest that even request scoped data needs to explicitly set using
>   <s:set....> to be used by tag libraries like jsp taglib or displaytag
>
>   http://struts.apache.org/2.x/docs/exposing-framework-objects-to-jstl-with-a-jstl-and-displaytag-example.html
>
>
>   But for request scoped data you do not need to explicitly set it as a request attribute,just getters on the action will do ,so a tag library like displaytag  will work out of the box
>
>     <display:table name="someName" ....>
>   ...
>   ..
>
>     </display:table>
>
>   where there is a getSomeName( )  method in the Struts2 Action class
>
>
>   Am I missing something or does the doc need to be updated?
>
>   --Raghu
>
>
>  A Goal .......... Is a Dream with a Deadline
>
>  ---------------------------------
>  You rock. That's why Blockbuster's offering you one month of Blockbuster Total Access, No Cost.

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


Request scoped data in Struts2

Posted by Raghuveer Kumarakrishnan <kr...@yahoo.com>.
This doc seems to  suggest that even request scoped data needs to explicitly set using 
  <s:set....> to be used by tag libraries like jsp taglib or displaytag
   
  http://struts.apache.org/2.x/docs/exposing-framework-objects-to-jstl-with-a-jstl-and-displaytag-example.html
   
   
  But for request scoped data you do not need to explicitly set it as a request attribute,just getters on the action will do ,so a tag library like displaytag  will work out of the box
   
    <display:table name="someName" ....>
  ...
  .. 

    </display:table>
   
  where there is a getSomeName( )  method in the Struts2 Action class 

   
  Am I missing something or does the doc need to be updated?
   
  --Raghu


A Goal .......... Is a Dream with a Deadline
       
---------------------------------
You rock. That's why Blockbuster's offering you one month of Blockbuster Total Access, No Cost.

Re: Simple interceptor is not called

Posted by Dave Newton <ne...@yahoo.com>.
--- Peter Theissen <pe...@web.de> wrote:
> doese anybody see why the following (quite simple)
> interceptor isnt called:
> BTW: list.jsp seems to be called correctly.
> 
> struts.xml
>  >>>
>     <package name="registration" extends="struts-default">
> 
>         <interceptors>
>              <interceptor name="simpleInterceptor" 
> class="quickstart.interceptor.simpleInterceptor"/>
>         </interceptors>       
>      
>         <action name="listRegistrationsWaiting" 
> class="registrationWaitingAction" method="execute">
>             <result>pages/list.jsp</result>
>             <result name="input">pages/list.jsp</result>
>             <interceptor-ref name="simpleInterceptor"/>           
>         </action>
>       ...
>     </package>
> <<<
> 
> SimpleInterceptor.java
>  >>>
> package quickstart.interceptor;
> 
> import com.opensymphony.xwork2.Action;
> import com.opensymphony.xwork2.ActionInvocation;
> import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
> 
> public class SimpleInterceptor extends AbstractInterceptor{
>    
>     public String intercept(ActionInvocation invocation) throws Exception {
>         System.out.println("The action is being intercepted!");
>         return Action.SUCCESS;
>     }
> }
> <<<
> 
> What am I missing?

Are you sure it isn't?

What happens if you return something other than SUCCESS from your action?
That will test whether or not it's getting the result from the intercept call
or the action itself. Are you able to see other sysout statements across the
application? (Use a logger!) Are there any startup errors in your log? Is the
action configured properly in Spring?

Dave



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