Issue of Loading Invoker Servlet in Tomcat 6.0
I did some reading on Tomcat Invoker Servlet documentation and usage; and this all started when trying to fix an issue that I encountered when running a web application on tomcat from Eclipse IDE.
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: java.lang.SecurityException: Servlet of class org.apache.catalina.servlets.InvokerServlet is privileged and cannot be loaded by this web application
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1145)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:992)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4058)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4371)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
… 6 more
I spent a good amount of time figuring out this exception by checking CATALINA_HOME/conf/server.xml and CATALINA_HOME/conf/web.xml configuration files in tomcat. But the real culprit lies in CATALINA_HOME/conf/context.xml where the problem comes when privelges of Context is undefined.
1. context.xml: Context privileged=”true” reloadable=”true” and
2. Also this file may need to be copied to {Eclipse_Workspace}\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\conf directory.
After making these changes the web app can be started on tomcat server from Eclipse IDE; and this time Invoker Servlet Exception should disappear.
Taken from Apache documentation: The default servlet-invoking servlet for most web applications, used to serve requests to servlets that have not been registered in the web application deployment descriptor.
So an invoker servlet can be used for teaching or testing purposes esp used to perform quick testing of servlet class by copying into the /classes directory of the web app.
In a nut shell, it is a dirty way of deploying servlets in mass. The proper way to deploy servlets is to configure each and every servlet in the application’s configuration file. This is tedious and problematic esp when developing or testing of servlets on fly.
Suppose that we have a context “test” with document base of “/home/xxx/workspace”, and we have created a servlet called “ServletTest.class”. With the Invoker Servlet enabled, we could simply drop our servlet into the application’s “WEB-INF/classes” (i.e., “/home/xxx/workspace/WEB-INF/classes/ServletTest.class”). Users can request this servlet via URL http://hostname:8080/test/servlet/ServletTest. In other words, the URL path “servlet” is mapped to “WEB-INF\classes”.
So the quick fix is to check the Context priveleges in context.xml and if that doesn’t work then copy the $CATALINA_HOME/conf/context.xml to the above specified location.