Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can I access System Properties to determine a param-value for a context-param in Web.xml?

 
George Andrews
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am currently trying to use System Properties to determine which property file to load for a Generic Servlet as described below. I would like to access the System Property "platform.type" in particular, though if this is possible, I will also use others such as "serverName".



I have already been through multiple posts regarding the following: ContextLoaderListener and ContextLoaderServlet. They will not work for this case because I need those properties accessible when the Generic Servlet accesses the above listed Context Parameter.

I have even created a Wrapper Servlet, let's call it GenericInitializationServlet, in which I attempt to replace the properties by: using a ServletConfig Proxy to access the Context Properties using the getContextParameter method and then substituting the property value with the matching System Property.

Example:



Does anyone know of a way to accomplish this? To reiterate, I need to perform property replacement on a Context Parameter that will be used by a Servlet.

Thanks!
 
Tomasz Szymanski
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm pretty sure you can't manipulate the init parameters in a container-independent way. There is simply no standard API for this.

One of the things I can think of is using your own ServletContext implementation, that would wrap the original one and implement the getInitParameter method appropriately. Is that what you meant by "proxy"? Have you tried it?
 
George Andrews
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Below you can find the code I was able to get to work:

web.xml:



WrapperServlet.java:



ParameterSubstituter.java:



Props to M Simpson in this post for giving me some direction: http://www.coderanch.com/t/79094/Websphere/environment-variable-referance-Web-xml
 
Tomasz Szymanski
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, so you're constructing a real proxy. I was thinking of a simple wrapper, something like ServletRequestWrapper or ServletResponseWrapper. Something like:



But actually that would be a much longer piece of code than yours, I guess So... what's the problem anyway? Isn't your solution sufficient?
 
George Andrews
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Below you can find the code I was able to get to work:


Hi Tomasz,

Actually, I was able to get this to work and posted the solution I am currently using. Thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic