How to find location of an action

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

How to find location of an action

Dave Weis
I'm having an odd interaction/problem with Struts, eclipse, and Tomcat.

I have this in my struts.xml file:

<package name="auth" extends="default" namespace="/auth">

<action name="logout2">
<result>/landing.jsp</result>
</action>
<action name="logout"
class="com.subecon.actions.auth.LogoutAction">
<result>/landing.jsp</result>
</action>
<action name="reload"
class="com.subecon.actions.store.ReloadAction">
<result name="success">/reload.jsp</result>
</action>

</package>

I can access /auth/logout2 correctly and can access /auth/reload correctly.

The body of the execute method in both actions is nearly identical:

public class LogoutAction extends ActionSupport {

private static final Logger logger =
LogManager.getLogger(LogoutAction.class);

public String execute()  throws Exception {
logger.error("THIS IS THE LOGOUT ACTION");
logger.error("THE TEXT IS " + "success");
return SUCCESS;

}

public class ReloadAction extends ActionSupport {

    private static final Logger logger =
LogManager.getLogger(ReloadAction.class);
public String execute() throws Exception {
logger.error("in reload action");
ConfigurationManager
configMan=Dispatcher.getInstance().getConfigurationManager();
configMan.reload();

return SUCCESS;
}
}

It just seems like something is sitting on the /auth/logout path but the
only instances of the word logout in my struts.xml file is the snippet
above.

Where it gets odd is that if I change that action definition to the
following and completely stop and start Tomcat from Eclipse  I still get an
error:

<action name="logout2">
<result>/landing.jsp</result>
</action>
<action name="logout">
<result>/landing.jsp</result>
</action>

Struts Problem Report

Struts has detected an unhandled exception:
*Messages*:
- No result defined for action com.subecon.actions.auth.LogoutAction and
result success
------------------------------
Stacktraces
*No result defined for action com.subecon.actions.auth.LogoutAction and
result success*

    com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:375)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:277)
    org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:253)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:247)

.... rest omitted.

You can see there is no mention of LogoutAction in the struts.xml file yet
it's still being called. This is with a complete stop and restart of Tomcat.

Then I change it to this:
<action name="reload"
class="com.subecon.actions.auth.LogoutAction">
<result name="success">/reload.jsp</result>
</action>

/auth/reload calls LogoutAction correctly and I don't get a stack trace.

In every case LogoutAction is actually being called shown by the logger
messages showing up in the console.

There seems to be something about the 'logout' being in the URL.

There's no other webapps running on this instance of Tomcat - it's
completely managed by Eclipse.

Where do I start with this? I've stared and compared and cannot figure out
where it's breaking.

Thanks
dave
Reply | Threaded
Open this post in threaded view
|

Re: How to find location of an action

Yasser Zamani-2


On 12/27/2017 7:01 PM, Dave Weis wrote:

> Where it gets odd is that if I change that action definition to the
> following and completely stop and start Tomcat from Eclipse  I still get an
> error:
>
> <action name="logout2">
> <result>/landing.jsp</result>
> </action>
> <action name="logout">
> <result>/landing.jsp</result>
> </action>
>
> Struts Problem Report
>
> Struts has detected an unhandled exception:
> *Messages*:
> - No result defined for action com.subecon.actions.auth.LogoutAction and
> result success
> ------------------------------
> Stacktraces
> *No result defined for action com.subecon.actions.auth.LogoutAction and
> result success*
>
>      com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:375)
>      com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:277)
>      org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:253)
>      com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:247)
>
> .... rest omitted.
>
> You can see there is no mention of LogoutAction in the struts.xml file yet
> it's still being called. This is with a complete stop and restart of Tomcat.


Maybe you have struts-convention-plugin and it automatically maps
/auth/logout to LogoutAction.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: How to find location of an action

Dave Weis
On Wed, Dec 27, 2017 at 10:14 AM, Yasser Zamani <[hidden email]>
wrote:

> On 12/27/2017 7:01 PM, Dave Weis wrote:
> > Where it gets odd is that if I change that action definition to the
> > following and completely stop and start Tomcat from Eclipse  I still get
> an
> > error:
> >
> > You can see there is no mention of LogoutAction in the struts.xml file
> yet
> > it's still being called. This is with a complete stop and restart of
> Tomcat.
>
> Maybe you have struts-convention-plugin and it automatically maps
> /auth/logout to LogoutAction.
>

I do have the struts-convention plugin loaded and removing it fixed my
problem!!

Where was it trying to find the success forward?

Thank you so much!
Reply | Threaded
Open this post in threaded view
|

Re: How to find location of an action

Yasser Zamani-2


On 12/27/2017 7:52 PM, Dave Weis wrote:
> I do have the struts-convention plugin loaded and removing it fixed my
> problem!!
>
> Where was it trying to find the success forward?
>
> Thank you so much!

Glad to hear this :)

At [1] I saw it will look for `WEB-INF/content/logout.jsp` or
`WEB-INF/content/logout-success.jsp`.

[1] http://struts.apache.org/plugins/convention/#results-and-result-codes

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: How to find location of an action

Dave Weis
On Wed, Dec 27, 2017 at 10:41 AM, Yasser Zamani <[hidden email]>
wrote:

> On 12/27/2017 7:52 PM, Dave Weis wrote:
> > I do have the struts-convention plugin loaded and removing it fixed my
> > problem!!
> >
> > Where was it trying to find the success forward?
> >
> > Thank you so much!
>
> Glad to hear this :)
>
> At [1] I saw it will look for `WEB-INF/content/logout.jsp` or
> `WEB-INF/content/logout-success.jsp`.
>

I'm torn whether or not to use this. It would make things substantially
more convenient but I like the declarative method so there's no question as
to intention.

Which direction would you recommend? I'll probably have around 100 actions
on this project and 300 or so JSP pages. I am using tiles extensively also.

dave
Reply | Threaded
Open this post in threaded view
|

Re: How to find location of an action

Yasser Zamani-2


On 12/27/2017 8:42 PM, Dave Weis wrote:
> It would make things substantially
> more convenient but I like the declarative method so there's no question as
> to intention.

If I understood your high level English well  ;) you are worry about if
convention plugin ties your hand on results? No, you can explicitly
define your result when you need or wish via @Result annotation [1].

[1]
https://struts.apache.org/maven/struts2-plugins/struts2-convention-plugin/apidocs/org/apache/struts2/convention/annotation/Result.html

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: How to find location of an action

Dave Weis
On Wed, Dec 27, 2017 at 11:43 AM, Yasser Zamani <[hidden email]>
wrote:

> On 12/27/2017 8:42 PM, Dave Weis wrote:
> > It would make things substantially
> > more convenient but I like the declarative method so there's no question
> as
> > to intention.
>
> If I understood your high level English well  ;) you are worry about if
> convention plugin ties your hand on results? No, you can explicitly
> define your result when you need or wish via @Result annotation [1].
>

Sorry ;-)

The reason I like using struts.xml is that when someone sits down to my
code base there's a single file to look at to see every action and result
definition. I'm worried about what's fastest for development versus what's
going to be easiest to understand for someone (or me) in a year when they
try to figure out why auth.LogoutAction is getting called when there's
nothing referencing it in the configuration files.

dave
Reply | Threaded
Open this post in threaded view
|

Re: How to find location of an action

Yasser Zamani-2


On 12/27/2017 9:16 PM, Dave Weis wrote:

> On Wed, Dec 27, 2017 at 11:43 AM, Yasser Zamani <[hidden email]>
> wrote:
>
>> On 12/27/2017 8:42 PM, Dave Weis wrote:
>>> It would make things substantially
>>> more convenient but I like the declarative method so there's no question
>> as
>>> to intention.
>>
>> If I understood your high level English well  ;) you are worry about if
>> convention plugin ties your hand on results? No, you can explicitly
>> define your result when you need or wish via @Result annotation [1].
>>
>
> Sorry ;-)
>
> The reason I like using struts.xml is that when someone sits down to my
> code base there's a single file to look at to see every action and result
> definition. I'm worried about what's fastest for development versus what's
> going to be easiest to understand for someone (or me) in a year when they
> try to figure out why auth.LogoutAction is getting called when there's
> nothing referencing it in the configuration files.

As far as I see, it seems convention plugin does not make it harder to
understand because it doesn't have a lot and complex rules. Even maybe
it makes easier to navigate for new team members who know rules.

I think if you wish to decrease number of decisions your developers can
make, then use it, and if you wish to give your developers more freedom
:) then don't use it. If you like `defaults` and you usually on
defaults, then use it as default and override when needed not usually,
but if you usually to override, then don't use.

>
> dave
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: How to find location of an action

Lukasz Lenart
In reply to this post by Dave Weis
2017-12-27 18:12 GMT+01:00 Dave Weis <[hidden email]>:
> Which direction would you recommend? I'll probably have around 100 actions
> on this project and 300 or so JSP pages. I am using tiles extensively also.

I would recommend using the Convention plugin for a fast development,
when prototyping things. Or if the number of actions is somehow lower
than 100. In your case, using xml files should be sufficient and a
safer choice.


Regards
--
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: How to find location of an action

Dave Weis
On Wed, Dec 27, 2017 at 1:22 PM, Lukasz Lenart <[hidden email]>
wrote:

> 2017-12-27 18:12 GMT+01:00 Dave Weis <[hidden email]>:
> > Which direction would you recommend? I'll probably have around 100
> actions
> > on this project and 300 or so JSP pages. I am using tiles extensively
> also.
>
> I would recommend using the Convention plugin for a fast development,
> when prototyping things. Or if the number of actions is somehow lower
> than 100. In your case, using xml files should be sufficient and a
> safer choice.
>
> Would it be a correct assumption that changing the property
struts.convention.relative.result.types to add 'tiles' would let me use my
tiles definitions? There's no mention at all of tiles in the document at
http://struts.apache.org/plugins/convention/ .

I did find some posts that you (Lukasz) wrote but they are from 2012 and I
would hope things have advanced since then :-)

Thank you
dave
Reply | Threaded
Open this post in threaded view
|

Re: How to find location of an action

Lukasz Lenart
2017-12-27 21:06 GMT+01:00 Dave Weis <[hidden email]>:
> Would it be a correct assumption that changing the property
> struts.convention.relative.result.types to add 'tiles' would let me use my
> tiles definitions? There's no mention at all of tiles in the document at
> http://struts.apache.org/plugins/convention/ .

Not really, because the location of @Result annotation will be
appended to "struts.convention.result.path" which means it will be by
default:

/WEB-INF/content/<namespace>/<location>

You can try to setup "struts.convention.result.path" to "" but you
will end up with

/<namespace>/<location>

> I did find some posts that you (Lukasz) wrote but they are from 2012 and I
> would hope things have advanced since then :-)

I'm using a custom UnknownHandler [1] to resolve Tiles definitions
using namespace, action name and result name

[1] https://github.com/lukaszlenart/gruuf-webapp/blob/master/src/main/java/com/gruuf/web/TilesUnknownHandler.java


Regards
--
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: How to find location of an action

Dave Weis
On Thu, Dec 28, 2017 at 1:55 AM, Lukasz Lenart <[hidden email]>
wrote:

> 2017-12-27 21:06 GMT+01:00 Dave Weis <[hidden email]>:
> > Would it be a correct assumption that changing the property
> > struts.convention.relative.result.types to add 'tiles' would let me use
> my
> > tiles definitions? There's no mention at all of tiles in the document at
> > http://struts.apache.org/plugins/convention/ .
>
> I'm using a custom UnknownHandler [1] to resolve Tiles definitions
> using namespace, action name and result name
>

That's a nice and elegant way to handle it, thank you!
dave