6

my existing conf/context.xml file has already a element; WEB-INF/web.xml

I would like to add another to allow localhost access to the /manager/status location to my monitoring, however adding a new Context element like so;

conf/context.xml

----
<Context>
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>
<Context path="/manager" privileged="true"
         docBase="/usr/share/tomcat6/webapps/manager">
         <Valve className="org.apache.catalina.valves.RemoteAddrValve"
                allow="127\.0\.0\.1"/>
</Context>
----

breaks the xml, as I presume that file needs a single root element to lint/parse ok SEVERE: Parse Fatal Error at line 6 column 2: The markup in the document following the root element must be well-formed.

org.xml.sax.SAXParseException: The markup in the document following the root element must be well-formed.
        at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)

2 Answers 2

5

The details in the context.xml file are used for all contexts. If you want to specify specific details for one particular context create a file with a context tag in $CATALINA_BASE/conf/[enginename]/[hostname]/

eg. conf/catalina/localhost/manager.xml that contains:

<Context privileged="true"
         docBase="/usr/share/tomcat6/webapps/manager">
         <Valve className="org.apache.catalina.valves.RemoteAddrValve"
                allow="127\.0\.0\.1"/>
</Context>

note that we don't need the path as the file is called manager.xml

read this for more details: http://tomcat.apache.org/tomcat-6.0-doc/config/context.html

1
  • I get a 401 if I call manager/status from localhost and a 403 if I call from some other host... so it looks like manager/status still wants Basic authentication
    – Tom
    Sep 3, 2010 at 18:23
1

For Tomcat 5, unlike Tomcat 4.x, it is NOT recommended to place elements directly in the server.xml file. This is because it makes modifying the Context configuration more invasive since the main conf/server.xml file cannot be reloaded without restarting Tomcat.

Context elements may be explicitly defined:

In the $CATALINA_HOME/conf/context.xml file: the Context element information will be loaded by all webapps. In the $CATALINA_HOME/conf/[enginename]/[hostname]/context.xml.default file: the Context element information will be loaded by all webapps of that host. In individual files (with a ".xml" extension) in the $CATALINA_HOME/conf/[enginename]/[hostname]/ directory. The name of the file (less the .xml) extension will be used as the context path. Multi-level context paths may be defined using #, e.g. foo#bar.xml for a context path of /foo/bar. The default web application may be defined by using a file called ROOT.xml. Only if a context file does not exist for the application in the $CATALINA_HOME/conf/[enginename]/[hostname]/; in an individual file at /META-INF/context.xml inside the application files. If the web application is packaged as a WAR then /META-INF/context.xml will be copied to $CATALINA_HOME/conf/[enginename]/[hostname]/ and renamed to match the application's context path. Once this file exists, it will not be replaced if a new WAR with a newer /META-INF/context.xml is placed in the host's appBase. inside a Host element in the main conf/server.xml

With the exception of server.xml, files that define Context elements may only define a single Context element.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .