Project

General

Profile

ModjyEntireUriSpace » History » Version 2

Alan Kennedy, 2015-07-04 05:32 PM
Updated tomcat links to Tomcat 8

1 1 Alan Kennedy
h1. Serving an entire uri space with modjy
2 1 Alan Kennedy
3 1 Alan Kennedy
There are two main ways that you can configure a modjy web application to respond to the entire URI space of a virtual host.
4 1 Alan Kennedy
5 1 Alan Kennedy
h2. Rename the web application.
6 1 Alan Kennedy
7 1 Alan Kennedy
Under Apache Tomcat, a web application that is called *ROOT* is treated specially, and is called to service all requests to the root of the URI space. So a simple way for modjy web applications to service an entire URL space under Apache Tomcat is rename the *modjy_webapp* directory to *ROOT*, and then copy that into the *webapps* subdirectory as before.
8 1 Alan Kennedy
9 1 Alan Kennedy
If you follow this strategy, then you don't need to read any further on this page.
10 1 Alan Kennedy
11 1 Alan Kennedy
h2. By configuring your container.
12 1 Alan Kennedy
13 1 Alan Kennedy
Alternatively, if you want to configure modjy to serve requests for all URIs, i.e. */** then you cannot do so in the modjy_servlet web.xml file. Instead you can move the servlet up the configuration hierarchy.
14 1 Alan Kennedy
15 1 Alan Kennedy
Every servlet container has a container-wide configuration file where container-wide servlets are configured. Some, such as Tomcat, split this function across multiple configuration files. Under Tomcat 6, this file is located at *$tomcat_home/conf/web.xml*. Other containers, e.g. "Caucho Resin":http://www.caucho.com, permit this kind of configuration directly in the main server configuration file, i.e. *resin.conf*.
16 1 Alan Kennedy
17 1 Alan Kennedy
You will need to configure a declaration for the modjy servlet in this higher level configuration file. You can probably copy this definition directly from the web.xml file that comes with modjy. After that, you will need to make the container map all URIs to the modjy servlet. The servlet definition will look something like this
18 1 Alan Kennedy
19 1 Alan Kennedy
<pre><code>
20 1 Alan Kennedy
<servlet>
21 1 Alan Kennedy
    <servlet-name>modjy</servlet-name>
22 1 Alan Kennedy
    <servlet-class>com.xhaus.modjy.ModjyJServlet</servlet-class>
23 1 Alan Kennedy
    <!-- Parameters omitted -->
24 1 Alan Kennedy
    <load-on-startup>1</load-on-startup>
25 1 Alan Kennedy
</servlet></code>
26 1 Alan Kennedy
</pre>
27 1 Alan Kennedy
28 1 Alan Kennedy
h3. Creating a mapping for the entire uri space
29 1 Alan Kennedy
30 1 Alan Kennedy
Possibly your container will have a default servlet to which requests are sent when they are not mapped to any other servlet. Under Tomcat, this is called the *default* servlet, and is implemented by the java class *org.apache.catalina.servlets.DefaultServlet*. The *servlet-mapping* for this servlet will contain a *<url-pattern>/</url-pattern>*. You could change this servlet-mapping to reference the modjy servlet definition you defined above, or create a new servlet mapping if one does not already exist. That mapping should look something like this.
31 1 Alan Kennedy
32 1 Alan Kennedy
<pre><code>
33 1 Alan Kennedy
<servlet-mapping>
34 1 Alan Kennedy
    <servlet-name>modjy</servlet-name>
35 1 Alan Kennedy
    <url-pattern>/</url-pattern>
36 1 Alan Kennedy
</servlet-mapping></code>
37 1 Alan Kennedy
</pre>
38 1 Alan Kennedy
39 1 Alan Kennedy
h3. Placing jython.jar
40 1 Alan Kennedy
41 2 Alan Kennedy
However, you're not finished yet! Because you've moved the modjy servlet up the container hierarchy, you must also move the jython.jar file up the classloader hierarchy. Such matters tend to be container specific, and so you may need to read on the classloader hierarchy of your container to know where to place the jython.jar file. Under the "Tomcat classloader hierarchy":http://tomcat.apache.org//tomcat-8.0-doc/class-loader-howto.html, the level that is appropriate for container-wide servlets is *$tomcat_home/lib*.
42 1 Alan Kennedy
43 1 Alan Kennedy
So hopefully now you've got modjy/WSGI taking care of your entire URI space, i.e. *SCRIPT_NAME=""*. Cool!
Add picture from clipboard (Maximum size: 10 MB)