This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

ServletActionContext getAction method returns null  RSS feed

 
Ranch Hand
Posts: 67
1
Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using a servlet filter where I am trying to get action associated with the current request.

Relevant sections of my filter:


My problem is that `action` ends up being null. Both of the context variables get populated with a value, but for some reason it cant find the action. Any ideas? Thanks!
 
Zahro Alfelpha
Ranch Hand
Posts: 67
1
Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Fixed



thanks! so is it even possible to edit/delete posts?
 
Bartender
Posts: 9506
12
Linux Mac OS X Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Zahro Alfelpha wrote:

Bear Bibeault wrote:Fixed



thanks! so is it even possible to edit/delete posts?



you should be able to edit your own posts.  I don't know if you can edit titles (I can, but I'm a moderator).
The reason your code isn't working is because you are creating your own context object instances instead of obtaining those that are available via the framework.  To get the current ServletActionContext instance, you should use the getActionContext method.
 
Zahro Alfelpha
Ranch Hand
Posts: 67
1
Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Joe Ess wrote:

Zahro Alfelpha wrote:

Bear Bibeault wrote:Fixed



thanks! so is it even possible to edit/delete posts?



You should be able to edit your own posts.  I don't know if you can edit titles (I can, but I'm a moderator).
The reason your code isn't working is because you are creating your own context object instances instead of obtaining those that are available via the framework.  To get the current ServletActionContext instance, you should use the getActionContext method.



This is the part where I cry and tell you that I'm using Java 5 and Struts 1.3....
 
Joe Ess
Bartender
Posts: 9506
12
Linux Mac OS X Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Zahro Alfelpha wrote:
This is the part where I cry and tell you that I'm using Java 5 and Struts 1.3....



Don't use Struts 1.x unless you have a very good reason.  It's dead.
That said, it appears that the Struts 1.x API works the same way as far as action context is concerned.
 
Zahro Alfelpha
Ranch Hand
Posts: 67
1
Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Joe Ess wrote:Don't use Struts 1.x unless you have a very good reason.



Unfortunately that is beyond my control at the moment but trust me I'd love to not be using Struts at all.

Joe Ess wrote:it appears that the Struts 1.x API works the same way as far as action context is concerned.



I'm not sure this is the case. I am finding no static getActionContext method in org.apache.struts.chain.contexts.ServletActionContext

I really appreciate your replies.
 
Joe Ess
Bartender
Posts: 9506
12
Linux Mac OS X Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Zahro Alfelpha wrote:

Joe Ess wrote:Don't use Struts 1.x unless you have a very good reason.



Unfortunately that is beyond my control at the moment but trust me I'd love to not be using Struts at all.

Joe Ess wrote:it appears that the Struts 1.x API works the same way as far as action context is concerned.



I'm not sure this is the case. I am finding no static getActionContext method in org.apache.struts.chain.contexts.ServletActionContext



I stand corrected, and I don't see an easy way to get the action.   One of the problems with Struts 1.x (hinted at in the link I posted earlier) is the design just isn't as flexible as we are used to in more modern frameworks. 
Exactly what do you want to accomplish with annotations? 
 
Zahro Alfelpha
Ranch Hand
Posts: 67
1
Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Joe Ess wrote: Exactly what do you want to accomplish with annotations?



I'm using a servlet filter to prevent unauthorized access to some pages. Currently the list of protected paths is kept in a list of strings and the filter compares the request path to the list.

What I would like to do is create an annotation to put on the Action classes themselves, and then simply check for that annotation on whichever Action is passing through the filter.
 
Joe Ess
Bartender
Posts: 9506
12
Linux Mac OS X Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Zahro Alfelpha wrote:

Joe Ess wrote: Exactly what do you want to accomplish with annotations?



I'm using a servlet filter to prevent unauthorized access to some pages. Currently the list of protected paths is kept in a list of strings and the filter compares the request path to the list.

What I would like to do is create an annotation to put on the Action classes themselves, and then simply check for that annotation on whichever Action is passing through the filter.



I would recommend using the standard​ JEE security mechanism built into the servlet container:
https://docs.oracle.com/javaee/7/tutorial/security-webtier.htm#BNCAS
It is better thought out, more thoroughly tested and more commonly used than any diy security solution.
 
Zahro Alfelpha
Ranch Hand
Posts: 67
1
Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Joe Ess wrote:I would recommend using the standard​ JEE security mechanism built into the servlet container



Thanks, I will look into this.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!