• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: https://coderanch.com/t/79094/Websphere/environment-variable-referance-Web-xml
 
Tomasz Szymanski
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
reply
    Bookmark Topic Watch Topic
  • New Topic