Setting up and using context.xml
In your META-INF directory, you should have a context.xml file. If not, just create one.
Here's an example of using a secure-context.xml file to store passwords in. It's useful if you are working on a project in subversion (or whatever) and don't want to exclude it.
META-INF/context.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE doc
[
<!ENTITY SECURECONTEXT SYSTEM "file:/path/to/secure-context.xml">
]
>
<Context>
&SECURECONTEXT;
</Context>
<!DOCTYPE doc
[
<!ENTITY SECURECONTEXT SYSTEM "file:/path/to/secure-context.xml">
]
>
<Context>
&SECURECONTEXT;
</Context>
This context.xml file includes another xml file called secure-context.xml which contains all of the usernames and passwords for whatever.
/path/to/secure-context.xml'''
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Parameter name="FullPathToSecurity" value="/path/to/and/including/trailing/slash/to/location/of/secure-context.xml/but/dont/put/secure-context.xml/in/this/path/" override="false" />
<Parameter name="SecretUsername" value="putUsernameHere" override="false" />
<Parameter name="SecretPassword" value="putPasswordHere" override="false" />
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Parameter name="FullPathToSecurity" value="/path/to/and/including/trailing/slash/to/location/of/secure-context.xml/but/dont/put/secure-context.xml/in/this/path/" override="false" />
<Parameter name="SecretUsername" value="putUsernameHere" override="false" />
<Parameter name="SecretPassword" value="putPasswordHere" override="false" />
In a class, you can get those parameters out with the following,
ServletContext ctx = config.getServletContext();
String username = ctx.getInitParameter("SecretUsername");
String password = ctx.getInitParameter("SecretPassword");
String username = ctx.getInitParameter("SecretUsername");
String password = ctx.getInitParameter("SecretPassword");
[Click to add or edit comments])
Please prepend comments below including a date