aspose file tools*
The moose likes Struts and the fly likes Struts 2 wildcard matching issues Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 2 wildcard matching issues" Watch "Struts 2 wildcard matching issues" New topic
Author

Struts 2 wildcard matching issues

Pj Casaro
Ranch Hand

Joined: Jul 13, 2010
Posts: 47
I'm having some issues with wildcard mapping. I wanted to catch all attempts to visit anything behind "/secure".



This works if I try to visit "/secure/anything/anything/etc" and I'm not logged in, I get directed to the login page as per my interceptor. However if I just logged in and I'm at "http://localhost:8080/Struts2NewChapter8/secure/admin-portfolio" and I click a link to "http://localhost:8080/Struts2NewChapter8/secure/update/update-account-form" I get errors that look like this:

Here's my simple intercept method if you're curious:

Pj Casaro
Ranch Hand

Joined: Jul 13, 2010
Posts: 47
The problem happens I think at the call to .invoke() in my interceptor. If I print the action at this point it just says its of type ActionSupport. Then when invoke is called, there's that long stacktrace, and the result that gets returned is "success". However, then instead of trying to continue to where I was trying to go, I get a resource not found error. The resource exists, because I can access it, but I think the errors that are being thrown cause the problem.
Pj Casaro
Ranch Hand

Joined: Jul 13, 2010
Posts: 47
Hmm, ok, now I'm a little confused. I modified by intercept method by adding in this:



I think maybe there's a problem calling .invoke() for an URL that catches this interceptor but doesn't actually have an action to back it up. I figured that instead of calling invoke, I'd just return success. The error is gone BUT I still get resource unavailable. Probably I'm not supposed to do things like this so it doesn't work. Any thoughts?
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9304
    
  17

I'm a little confused with the design of your application. A single Action handling all the requests starting with /secure. Are you doing this only to execute your interceptor (and redirect the request to the appropriate action since you are using {1} as result)?? You can easily add your interceptor to the default interceptor stack of your application. I'm sure your application would have two packages, one for normal actions and one for secure actions. You can add your interceptor to the interceptor stack of the secure package...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Pj Casaro
Ranch Hand

Joined: Jul 13, 2010
Posts: 47
To clarify, there are cases where I DON'T HAVE an action. For example, I may want to access a secure image upload form, but that's so simple that I don't need an action. However, I still want it to be secure. So I'm trying to intercept all accesses to "/secure" that DON'T HAVE an action. Normally they would just pass right through but I'm trying to get them intercepted. Obviously, if there was an action the interceptor would get triggered. And my wildcard matching worked, ie, all my navigations to places under "/secure" that don't have a backing action get intercepted now. However, when the .invoke method is called in the interceptor, it gives me all those errors. I thought maybe it was because, you can't call invoke if you don't have a backing action class, so I made one to act as just an empty class for all of the accesses to "/secure/etc." that don't have their own actions. This didn't work either. I'm still getting errors AND the resource is always unavailable.

I don't think what I'm doing is that advanced. I'm surprised no one has seen this before.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9304
    
  17

Cross Post...
Pj Casaro
Ranch Hand

Joined: Jul 13, 2010
Posts: 47
Ah, thanks for reminding me. I solved the issue. You shouldn't do wildcard matching on the namespace I suppose and just limit it to the action itself. Don't ask me why.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts 2 wildcard matching issues