You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Toni Lyytikäinen <to...@gmail.com> on 2008/02/20 12:40:55 UTC

How to get method name in interceptor

Hi,

I'm trying to access the ActionMapping from an interceptor, like the
following test stub:

public String intercept(ActionInvocation invocation) throws Exception {
    ActionMapping am=ServletActionContext.getActionMapping();
    log.info("The method is "+am.getMethod());
    return invocation.invoke();
    }

According to the javadocs am.getMethod() should return a String (the
method), but for some reason am.getMethod() always returns null. The
am.getName() and am.getNamespace() methods seem to work correctly however.
Is there a way (that works) to extract the name of the method that is going
to be executed?

Re: How to get method name in interceptor

Posted by Maurizio Cucchiara <mc...@apache.org>.
You're welcome.

Re: How to get method name in interceptor

Posted by SudhirSahoo <su...@gmail.com>.
That works like a charm.

Thanks a lot. 



Thanks,
Sudhir

--
View this message in context: http://struts.1045723.n5.nabble.com/How-to-get-method-name-in-interceptor-tp3476096p5709802.html
Sent from the Struts - User mailing list archive at Nabble.com.

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


Re: How to get method name in interceptor

Posted by Maurizio Cucchiara <mc...@apache.org>.
You should be able to get it through:

invocation.getProxy().getMethod();


Twitter     :http://www.twitter.com/m_cucchiara
G+          :https://plus.google.com/107903711540963855921
Linkedin    :http://www.linkedin.com/in/mauriziocucchiara

Maurizio Cucchiara


On 17 May 2012 19:02, SudhirSahoo <su...@gmail.com> wrote:

> Hi,
>
> It seems the url (http://strutsschool.com/downloads/downloads.action) is
> not
> working now.
> Can you please post here the logic how to get the method name in
> interceptor.
>
>
> Thanks,
> Sudhir
>
> --
> View this message in context:
> http://struts.1045723.n5.nabble.com/How-to-get-method-name-in-interceptor-tp3476096p5709800.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: How to get method name in interceptor

Posted by SudhirSahoo <su...@gmail.com>.
Hi,

It seems the url (http://strutsschool.com/downloads/downloads.action) is not
working now.
Can you please post here the logic how to get the method name in
interceptor.


Thanks,
Sudhir

--
View this message in context: http://struts.1045723.n5.nabble.com/How-to-get-method-name-in-interceptor-tp3476096p5709800.html
Sent from the Struts - User mailing list archive at Nabble.com.

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


Re: How to get method name in interceptor

Posted by st...@gmail.com.
Right on!  Rather than bale out of the interceptor stack, do this:

<action ...>
   <result name="success">${destination}</result>

and provide a get/set destination in your Action class that determines where
to go next.  It's much cleaner and intuitive than burying controller logic
in the interceptor stack.  Holler if you have questions, as there is more
love where this comes from.

Peace,
Scott

Re: How to get method name in interceptor

Posted by Toni Lyytikäinen <to...@gmail.com>.
I'm trying to write an interceptor that makes redirecting decisions based on
an annotation on the method on that is going to be executed. Like this:


public class MyAction extends ActionSupport {
...
   @SomeAnnotation(value="value")
   public String list() {
   ...
   return SUCCESS;
   }
}

public class MyInterceptor extends AbstractInterceptor {
...
   public String intercept(ActionInvocation invocation) throws Exception {
       // check if there is an annotation on the method that is going to be
executed
       // redirect based on that:
      if (something) invocation.invoke()
      else return "someresult";
   }
}

For this reason it would be nice to get the method, or at least the name of
the method, so that the interceptor could do method.getAnnotation(
SomeAnnotation.class).

On Thu, Feb 21, 2008 at 2:59 PM, <st...@gmail.com> wrote:

> Tell me more.  One thing I have learned using Struts 2 is if you think it
> should be possible, it probably is!  What are you trying?
>
> On Thu, Feb 21, 2008 at 1:29 AM, Toni Lyytikäinen <to...@gmail.com>
> wrote:
>
> > Thanks. This approach works, but isn't quite as elegant as I was hoping.
> >
> > On Wed, Feb 20, 2008 at 2:47 PM, <st...@gmail.com> wrote:
> >
> > > download the breadcrumb
> > > <http://strutsschool.com/downloads/downloads.action>interceptor
> > > and look at the intercept method.  You will see what's happening right
> > > away.
> > >
> > >
> > >
> > > On Wed, Feb 20, 2008 at 5:40 AM, Toni Lyytikäinen <to...@gmail.com>
> > > wrote:
> > >
> > > > Hi,
> > > >
> > > > I'm trying to access the ActionMapping from an interceptor, like the
> > > > following test stub:
> > > >
> > > > public String intercept(ActionInvocation invocation) throws
> Exception
> > {
> > > >    ActionMapping am=ServletActionContext.getActionMapping();
> > > >    log.info("The method is "+am.getMethod());
> > > >    return invocation.invoke();
> > > >    }
> > > >
> > > > According to the javadocs am.getMethod() should return a String (the
> > > > method), but for some reason am.getMethod() always returns null. The
> > > > am.getName() and am.getNamespace() methods seem to work correctly
> > > however.
> > > > Is there a way (that works) to extract the name of the method that
> is
> > > > going
> > > > to be executed?
> > > >
> > >
> > >
> > >
> > > --
> > > Scott
> > > stanlick@gmail.com
> > >
> >
>
>
>
> --
> Scott
> stanlick@gmail.com
>

Re: How to get method name in interceptor

Posted by st...@gmail.com.
Tell me more.  One thing I have learned using Struts 2 is if you think it
should be possible, it probably is!  What are you trying?

On Thu, Feb 21, 2008 at 1:29 AM, Toni Lyytikäinen <to...@gmail.com> wrote:

> Thanks. This approach works, but isn't quite as elegant as I was hoping.
>
> On Wed, Feb 20, 2008 at 2:47 PM, <st...@gmail.com> wrote:
>
> > download the breadcrumb
> > <http://strutsschool.com/downloads/downloads.action>interceptor
> > and look at the intercept method.  You will see what's happening right
> > away.
> >
> >
> >
> > On Wed, Feb 20, 2008 at 5:40 AM, Toni Lyytikäinen <to...@gmail.com>
> > wrote:
> >
> > > Hi,
> > >
> > > I'm trying to access the ActionMapping from an interceptor, like the
> > > following test stub:
> > >
> > > public String intercept(ActionInvocation invocation) throws Exception
> {
> > >    ActionMapping am=ServletActionContext.getActionMapping();
> > >    log.info("The method is "+am.getMethod());
> > >    return invocation.invoke();
> > >    }
> > >
> > > According to the javadocs am.getMethod() should return a String (the
> > > method), but for some reason am.getMethod() always returns null. The
> > > am.getName() and am.getNamespace() methods seem to work correctly
> > however.
> > > Is there a way (that works) to extract the name of the method that is
> > > going
> > > to be executed?
> > >
> >
> >
> >
> > --
> > Scott
> > stanlick@gmail.com
> >
>



-- 
Scott
stanlick@gmail.com

Re: How to get method name in interceptor

Posted by Toni Lyytikäinen <to...@gmail.com>.
Thanks. This approach works, but isn't quite as elegant as I was hoping.

On Wed, Feb 20, 2008 at 2:47 PM, <st...@gmail.com> wrote:

> download the breadcrumb
> <http://strutsschool.com/downloads/downloads.action>interceptor
> and look at the intercept method.  You will see what's happening right
> away.
>
>
>
> On Wed, Feb 20, 2008 at 5:40 AM, Toni Lyytikäinen <to...@gmail.com>
> wrote:
>
> > Hi,
> >
> > I'm trying to access the ActionMapping from an interceptor, like the
> > following test stub:
> >
> > public String intercept(ActionInvocation invocation) throws Exception {
> >    ActionMapping am=ServletActionContext.getActionMapping();
> >    log.info("The method is "+am.getMethod());
> >    return invocation.invoke();
> >    }
> >
> > According to the javadocs am.getMethod() should return a String (the
> > method), but for some reason am.getMethod() always returns null. The
> > am.getName() and am.getNamespace() methods seem to work correctly
> however.
> > Is there a way (that works) to extract the name of the method that is
> > going
> > to be executed?
> >
>
>
>
> --
> Scott
> stanlick@gmail.com
>

Re: How to get method name in interceptor

Posted by st...@gmail.com.
download the breadcrumb
<http://strutsschool.com/downloads/downloads.action>interceptor
and look at the intercept method.  You will see what's happening right away.



On Wed, Feb 20, 2008 at 5:40 AM, Toni Lyytikäinen <to...@gmail.com> wrote:

> Hi,
>
> I'm trying to access the ActionMapping from an interceptor, like the
> following test stub:
>
> public String intercept(ActionInvocation invocation) throws Exception {
>    ActionMapping am=ServletActionContext.getActionMapping();
>    log.info("The method is "+am.getMethod());
>    return invocation.invoke();
>    }
>
> According to the javadocs am.getMethod() should return a String (the
> method), but for some reason am.getMethod() always returns null. The
> am.getName() and am.getNamespace() methods seem to work correctly however.
> Is there a way (that works) to extract the name of the method that is
> going
> to be executed?
>



-- 
Scott
stanlick@gmail.com