• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Interceptor messes up action class in Struts2

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have been following this tutorial Struts 2 + Spring 2 + JPA + AJAX. So I installed the app and it worked fine. Then, I added an authentication interceptor using an example from Struts2 in Action. At this poing, the server threw out 404 error on /list.action once the interceptor is added. It seems that the interceptor has prevented the executed() method in PersonAction from being executed.

I have been scraching my head and couldn't find an answer. I would greately appreciate it if anyone could throw some light on it.

Below are some relevant code and struts2.xml
=======================================

list.jsp


PersonAction


The interceptor

struts2.xml


 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you get the error before or after (or both) you've logged in? You're also going to the "login" action, but you'll be going to main.action when you do, unless you're doing something not shown to get yourself to the "input" result with the form.

I'd also use a "redirectAction" result and simply go to "main".
 
Richard Vagner
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi David,

Thanks. yes I do have error before logging in.
"No result defined for action com.test.action.PersonAction and result login"


<action name="list" method="execute" class="personAction">
<result>/pages/list.jsp</result>
<result name="input">pages/list.jsp</result>


After logging in, I got 404 error

The login is not intercepted by the interceptor becuase it is in a different package.

When you say "I'd also use a "redirectAction" result and simply go to "main"." , are you talking about the page you should see right after login? That is what it does now.

Any ideas would be greately appreciated.

Thanks,
Rich

 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are they in different packages? It's easy enough to set the action-specific interceptor-ref for the login action to just be "defaultStack" (as opposed to "secureStack").

Using "redirectAction" allows you to just specify the action name as the result's location rather than having to append the action suffix, that's all.
 
Richard Vagner
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I remember tried that -- put everything in one package that means login will subject to the power of interceptor. It keeps kicking you back to the login page even after you logged in. Maybe I didn't do it properly... just starts learning...

I did try this --redirect. But it does not have any effect. The error page look a different:

Error 404: SRVE0190E: File not found: /list.action

<action name="list" method="execute" class="personAction">
<result name="success" type="redirect">pages/list.jsp</result>
<result name="input">pages/list.jsp</result>
</action>

Thanks
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's why I said to override the login action's interceptor ref to be "defaultStack" instead of "secureStack".

Actions can define their own interceptor ref.
 
Richard Vagner
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you David. Following you suggestion, I put everything in one package and set interceptor ref to the login. It works like a charm. Thank you!

I also tried redirectAction.


I got a blank page on login. Is this the correct way of using redirectAction?

Thank you so much!
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, "redirectAction" is for redirecting to an action. You originally had a redirect result to "main.action". A redirectAction result's location would be "main".
 
Richard Vagner
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thougt this would work but it doesn't. Anything wrong with this? Still gets a blank screen. Typing http://xxx/loginForm.action directly, gets Error 404: SRVE0190E: File not found: /loginForm.action. Thanks a lot.

 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your original code shows the interceptor returning "login" when there's no user in session. I don't, however, see a global result named "login", nor individual "login" results for each action (obviously the first would be preferred). Remember, the return value of an action invocation is the name of a result--not the name of an action.

Two asides: you should be able to use "redirectAction" as below, w/o using the <param...> element.

Secondly, since you're getting a fresh user object from the DB to set on UserAware actions you might as well set the fresh user to the session as well, assuming you're getting the DB user for a reason.

Dave
 
Richard Vagner
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are right. I added login globle result. I have put below an updated struts.xml. Thanks.

1. I still see a blank page when I replace <result type="redirect">main.action</result>
with <result type="redirectAction">main</result>. Strange.

2. The interceptor has added the user to session in ((UserAware)action).setUser(freshUser);

3. /list.action still not working. If I add <interceptor-ref name="defaultStack" /> to it, it works instantly.
It seems that actionInvocation.invoke() only returns a string "success". How would that alter the behavior of list.action?

I know you wrote a Struts2 book. Does it talk about interceptor? Maybe I should go grab your book.

Thanks so much.

 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is the list action the only one that doesn't work?
 
Richard Vagner
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried remove.action, it has the same problem: "Error 404: SRVE0190E: File not found: /remove.action"
The actions that work are main.action and apps.action.

Thanks
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That leads me to think it's a Struts/Spring issue, since those actions aren't defined as Spring beans.

That doesn't help explain why changing the interceptor stack triggers the problem, though, and that the interceptor stack appears to be the problem points in a different direction... So the actions defined as Spring beans work w/ "defaultStack"?
 
Richard Vagner
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, these actions work only with "defaultStack". Once in secureStack with the interceptor, they all stop working. Still can't figure out why.
 
Look! I laid an egg! Why does it smell like that? Tiny ad, does this smell weird to you?
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic