| [66] | 1 | <html><head><META http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>Catalina Functional Specifications - Invoker Servlet</title><meta value="Craig McClanahan" name="author"><meta value="craigmcc@apache.org" name="email"></head><body vlink="#525D76" alink="#525D76" link="#525D76" text="#000000" bgcolor="#ffffff"><table cellspacing="0" width="100%" border="0"><!--PAGE HEADER--><tr><td><!--PROJECT LOGO--><a href="http://tomcat.apache.org/"><img border="0" alt=" | 
|---|
|  | 2 | Catalina Functional Specifications | 
|---|
|  | 3 | " align="right" src="../../../images/tomcat.gif"></a></td><td><font face="arial,helvetica,sanserif"><h1>Apache Tomcat 6.0</h1></font></td><td><!--APACHE LOGO--><a href="http://www.apache.org/"><img border="0" alt="Apache Logo" align="right" src="../../../images/asf-logo.gif"></a></td></tr></table><table cellspacing="4" width="100%" border="0"><!--HEADER SEPARATOR--><tr><td colspan="2"><hr size="1" noshade></td></tr><tr><!--RIGHT SIDE MAIN BODY--><td align="left" valign="top" width="80%"><table cellspacing="4" width="100%" border="0"><tr><td valign="top" align="left"><h1>Catalina Functional Specifications</h1><h2>Invoker Servlet</h2></td><td nowrap="true" valign="top" align="right"><img border="0" hspace="0" vspace="0" height="1" width="1" src="../../../images/void.gif"></td></tr></table><table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#525D76"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="Overview"><strong>Overview</strong></a></font></td></tr><tr><td><blockquote> | 
|---|
|  | 4 |  | 
|---|
|  | 5 |  | 
|---|
|  | 6 | <table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#828DA6"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="Introduction"><strong>Introduction</strong></a></font></td></tr><tr><td><blockquote> | 
|---|
|  | 7 |  | 
|---|
|  | 8 | <p>The purpose of the <strong>Invoker Servlet</strong> is to allow a | 
|---|
|  | 9 | web application to dynamically register new <em>servlet definitions</em> | 
|---|
|  | 10 | that correspond with a <code><servlet></code> element in the | 
|---|
|  | 11 | <code>/WEB-INF/web.xml</code> deployment descriptor, and execute | 
|---|
|  | 12 | requests utilizing the new servlet definitions.  From the perspective | 
|---|
|  | 13 | of the newly registered servlets, all servlet lifecycle requirements | 
|---|
|  | 14 | of the Servlet Specification (such as calling <code>init()</code> and | 
|---|
|  | 15 | <code>destroy()</code> at the correct times) will be respected.</p> | 
|---|
|  | 16 |  | 
|---|
|  | 17 | </blockquote></td></tr></table> | 
|---|
|  | 18 |  | 
|---|
|  | 19 |  | 
|---|
|  | 20 | <table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#828DA6"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="External Specifications"><strong>External Specifications</strong></a></font></td></tr><tr><td><blockquote> | 
|---|
|  | 21 |  | 
|---|
|  | 22 | <p>I do not know of any formal specification of the behavior of an | 
|---|
|  | 23 | invoker servlet that is publicly available.  Anyone know of one?</p> | 
|---|
|  | 24 |  | 
|---|
|  | 25 | </blockquote></td></tr></table> | 
|---|
|  | 26 |  | 
|---|
|  | 27 |  | 
|---|
|  | 28 | <table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#828DA6"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="Implementation Requirements"><strong>Implementation Requirements</strong></a></font></td></tr><tr><td><blockquote> | 
|---|
|  | 29 |  | 
|---|
|  | 30 | <p>The implementation of this functionality shall conform to the | 
|---|
|  | 31 | following requirements:</p> | 
|---|
|  | 32 | <ul> | 
|---|
|  | 33 | <li>Implemented as a servlet.</li> | 
|---|
|  | 34 | <li>Exist in the <code>org.apache.catalina.servlets</code> package | 
|---|
|  | 35 | so that it can be loaded by the Catalina class loader.</li> | 
|---|
|  | 36 | <li>Implement the <code>org.apache.catalina.ContainerServlet</code> | 
|---|
|  | 37 | interface, so that it gains knowledge of the <code>Wrapper</code> | 
|---|
|  | 38 | that is responsible for itself and, therefore, access to other | 
|---|
|  | 39 | internal Catalina components.</li> | 
|---|
|  | 40 | <li>Support a configurable debugging detail level.</li> | 
|---|
|  | 41 | <li>Log debugging and operational messages (suitably internationalized) | 
|---|
|  | 42 | via the <code>getServletContext().log()</code> method.</li> | 
|---|
|  | 43 | </ul> | 
|---|
|  | 44 |  | 
|---|
|  | 45 | </blockquote></td></tr></table> | 
|---|
|  | 46 |  | 
|---|
|  | 47 |  | 
|---|
|  | 48 | </blockquote></td></tr></table><table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#525D76"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="Dependencies"><strong>Dependencies</strong></a></font></td></tr><tr><td><blockquote> | 
|---|
|  | 49 |  | 
|---|
|  | 50 |  | 
|---|
|  | 51 | <table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#828DA6"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="Environmental Dependencies"><strong>Environmental Dependencies</strong></a></font></td></tr><tr><td><blockquote> | 
|---|
|  | 52 |  | 
|---|
|  | 53 | <p>The following environmental dependencies must be met in order for | 
|---|
|  | 54 | the Invoker servlet to operate correctly:</p> | 
|---|
|  | 55 | <ul> | 
|---|
|  | 56 | <li>The invoker servlet must be registered in the application deployment | 
|---|
|  | 57 | descriptor (or the default deployment descriptor in file | 
|---|
|  | 58 | <code>$CATALINA_BASE/conf/web.xml</code>) using a "path mapped" | 
|---|
|  | 59 | servlet mapping.  The historical default mapping is to URL pattern | 
|---|
|  | 60 | "<code>/servlet/*</code>", although the invoker servlet must operate | 
|---|
|  | 61 | correctly with an arbitrary mapping.</li> | 
|---|
|  | 62 | </ul> | 
|---|
|  | 63 |  | 
|---|
|  | 64 | </blockquote></td></tr></table> | 
|---|
|  | 65 |  | 
|---|
|  | 66 |  | 
|---|
|  | 67 | <table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#828DA6"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="Container Dependencies"><strong>Container Dependencies</strong></a></font></td></tr><tr><td><blockquote> | 
|---|
|  | 68 |  | 
|---|
|  | 69 | <p>Correct operation of the invoker servlet depends on the following | 
|---|
|  | 70 | specific features of the surrounding container:</p> | 
|---|
|  | 71 | <ul> | 
|---|
|  | 72 | <li>Correct support for the <code>ContainerServlet</code> interface, | 
|---|
|  | 73 | including calling <code>setWrapper()</code> <strong>before</strong> | 
|---|
|  | 74 | the <code>init()</code> method of the invoker servlet is called.</li> | 
|---|
|  | 75 | <li>The web application class loader must be stored as the context | 
|---|
|  | 76 | class loader of the request processing thread.</li> | 
|---|
|  | 77 | </ul> | 
|---|
|  | 78 |  | 
|---|
|  | 79 | </blockquote></td></tr></table> | 
|---|
|  | 80 |  | 
|---|
|  | 81 |  | 
|---|
|  | 82 | </blockquote></td></tr></table><table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#525D76"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="Functionality"><strong>Functionality</strong></a></font></td></tr><tr><td><blockquote> | 
|---|
|  | 83 |  | 
|---|
|  | 84 |  | 
|---|
|  | 85 | <table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#828DA6"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="Initialization Functionality"><strong>Initialization Functionality</strong></a></font></td></tr><tr><td><blockquote> | 
|---|
|  | 86 |  | 
|---|
|  | 87 | <p>The following processing must be performed when the <code>init()</code> | 
|---|
|  | 88 | method of the invoker servlet is called:</p> | 
|---|
|  | 89 | <ul> | 
|---|
|  | 90 | <li>Ensure that the container has called <code>setWrapper()</code>.  If | 
|---|
|  | 91 | not, throw a permanent <code>UnavailableException</code>.</li> | 
|---|
|  | 92 | <li>Look up and cache the <code>Context</code> that corresponds to our | 
|---|
|  | 93 | <code>Wrapper</code>.  This is the component with which new servlet | 
|---|
|  | 94 | definitions and mappings will be registered.</li> | 
|---|
|  | 95 | </ul> | 
|---|
|  | 96 |  | 
|---|
|  | 97 | </blockquote></td></tr></table> | 
|---|
|  | 98 |  | 
|---|
|  | 99 |  | 
|---|
|  | 100 | <table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#828DA6"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="Per-Request Functionality"><strong>Per-Request Functionality</strong></a></font></td></tr><tr><td><blockquote> | 
|---|
|  | 101 |  | 
|---|
|  | 102 | <p>On each request, the following processing shall be performed:</p> | 
|---|
|  | 103 | <ol> | 
|---|
|  | 104 | <li>Calculate the <code>{ServletPath}</code> for this request, either from | 
|---|
|  | 105 | request attribute <code>javax.servlet.include.servlet_path</code> or | 
|---|
|  | 106 | by calling <code>request.getServletPath()</code>.</li> | 
|---|
|  | 107 | <li>Calculate the <code>{PathInfo}</code> for this request, either from | 
|---|
|  | 108 | request attribute <code>javax.servlet.include.path_info</code> or | 
|---|
|  | 109 | by calling <code>request.getPathInfo()</code>.  If the calculated | 
|---|
|  | 110 | <code>{PathInfo}</code> is null, return HTTP status 400 | 
|---|
|  | 111 | (bad request).</li> | 
|---|
|  | 112 | <li>Parse the calculated <code>{PathInfo}</code> value as follows: | 
|---|
|  | 113 | <ol> | 
|---|
|  | 114 | <li>Ignore the leading slash character.</li> | 
|---|
|  | 115 | <li>Accumulate characters up to the next '/' (if any) as the | 
|---|
|  | 116 | <code>{ServletSelector}</code>.</li> | 
|---|
|  | 117 | <li>If a '/' was encountered, accumulate all characters from that | 
|---|
|  | 118 | slash (inclusive) to the end of the string as | 
|---|
|  | 119 | <code>{PathRemainder}</code>.  If no slash was encountered, | 
|---|
|  | 120 | set <code>{PathRemainder}</code> to a zero-length string.</li> | 
|---|
|  | 121 | </ol></li> | 
|---|
|  | 122 | <li>Determine whether <code>{ServletSelector}</code> is the name of an | 
|---|
|  | 123 | existing servlet definition, and process it as follows: | 
|---|
|  | 124 | <ol> | 
|---|
|  | 125 | <li>Ask our associated <code>Context</code> to find and return a | 
|---|
|  | 126 | child <code>Wrapper</code> named <code>{ServletSelector}</code>. | 
|---|
|  | 127 | </li> | 
|---|
|  | 128 | <li>If there is no such child, skip to the next major step.</li> | 
|---|
|  | 129 | <li>Register a new servlet mapping for this <code>Wrapper</code>, | 
|---|
|  | 130 | using a URL pattern calculated as follows: | 
|---|
|  | 131 | <code>{ServletPath}</code> + "/" + <code>{ServletSelector}</code> | 
|---|
|  | 132 | + "/*"</li> | 
|---|
|  | 133 | <li>Create a request dispatcher using a path calculated as follows: | 
|---|
|  | 134 | <code>{ServletPath}</code> + "/" + <code>{ServletSelector}</code> | 
|---|
|  | 135 | + <code>{PathRemainder}</code></li> | 
|---|
|  | 136 | <li>Forward this request to the created request dispatcher, and | 
|---|
|  | 137 | exit from this request.</li> | 
|---|
|  | 138 | </ol></li> | 
|---|
|  | 139 | <li>Assume that <code>{ServletSelector}</code> is the fully qualified | 
|---|
|  | 140 | name of a Java class that implements <code>javax.servlet.Servlet</code> | 
|---|
|  | 141 | and process it as follows: | 
|---|
|  | 142 | <ol> | 
|---|
|  | 143 | <li>Synthesize a new <code>{ServletName}</code> for the servlet | 
|---|
|  | 144 | definition that will be created.</li> | 
|---|
|  | 145 | <li>If there is already a child <code>Wrapper</code> associated with | 
|---|
|  | 146 | this name, return HTTP status 500 (internal server error), because | 
|---|
|  | 147 | a mapping should have already been created for this servlet.</li> | 
|---|
|  | 148 | <li>Attempt to load a class named <code>{ServletSelector}</code> from | 
|---|
|  | 149 | the web application class loader (i.e. the context class loader | 
|---|
|  | 150 | for our current thread).  If this fails, return HTTP status 404 | 
|---|
|  | 151 | (not found).</li> | 
|---|
|  | 152 | <li>Instantiate an instance of this class.  If an error occurs, | 
|---|
|  | 153 | return HTTP status 404 (not found).</li> | 
|---|
|  | 154 | <li>If this class does not implement the | 
|---|
|  | 155 | <code>javax.servlet.Servlet</code> interface, return HTTP status | 
|---|
|  | 156 | 404 (not found).</li> | 
|---|
|  | 157 | <li>Create and register a new <code>Wrapper</code> child with our | 
|---|
|  | 158 | <code>Context</code>, under name <code>{ServletName}</code>.</li> | 
|---|
|  | 159 | <li>Register a new servlet mapping for this <code>Wrapper</code>, | 
|---|
|  | 160 | using a URL pattern calculated as follows: | 
|---|
|  | 161 | <code>{ServletPath}</code> + "/" + <code>{ServletSelector}</code> | 
|---|
|  | 162 | + "/*"</li> | 
|---|
|  | 163 | <li>Create a request dispatcher using a path calculated as follows: | 
|---|
|  | 164 | <code>{ServletPath}</code> + "/" + <code>{ServletSelector}</code> | 
|---|
|  | 165 | + <code>{PathRemainder}</code></li> | 
|---|
|  | 166 | <li>Forward this request to the created request dispatcher, and | 
|---|
|  | 167 | exit from this request.</li> | 
|---|
|  | 168 | </ol></li> | 
|---|
|  | 169 | </ol> | 
|---|
|  | 170 |  | 
|---|
|  | 171 | </blockquote></td></tr></table> | 
|---|
|  | 172 |  | 
|---|
|  | 173 |  | 
|---|
|  | 174 | <table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#828DA6"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="Finalization Functionality"><strong>Finalization Functionality</strong></a></font></td></tr><tr><td><blockquote> | 
|---|
|  | 175 |  | 
|---|
|  | 176 | <p>No specific processing is required when the <code>destroy()</code> | 
|---|
|  | 177 | method is called:</p> | 
|---|
|  | 178 |  | 
|---|
|  | 179 | </blockquote></td></tr></table> | 
|---|
|  | 180 |  | 
|---|
|  | 181 |  | 
|---|
|  | 182 | </blockquote></td></tr></table><table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#525D76"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="Testable Assertions"><strong>Testable Assertions</strong></a></font></td></tr><tr><td><blockquote> | 
|---|
|  | 183 |  | 
|---|
|  | 184 | <p>In addition the the assertions implied by the functionality requirements | 
|---|
|  | 185 | listed above, the following additional assertions shall be tested to | 
|---|
|  | 186 | validate the behavior of the invoker servlet:</p> | 
|---|
|  | 187 | <ul> | 
|---|
|  | 188 | <li>It is possible to access an existing servlet definition by name | 
|---|
|  | 189 | through the invoker.  The existing servlet definition can include | 
|---|
|  | 190 | either a <code><servlet-class></code> or | 
|---|
|  | 191 | <code><jsp-file></code> subelement.</li> | 
|---|
|  | 192 | <li>When an existing servlet definition is accessed by name, the request | 
|---|
|  | 193 | will be ultimately processed by the same servlet instance that would | 
|---|
|  | 194 | have processed it had a mapping to that servlet definition been used | 
|---|
|  | 195 | on the request directly.</li> | 
|---|
|  | 196 | <li>It is possible to access an anonymous servlet by class name | 
|---|
|  | 197 | through the invoker.</li> | 
|---|
|  | 198 | <li>When an anonymous servlet is accessed, the servlet instance is processed | 
|---|
|  | 199 | according to the lifecycle requirements of the Servlet Specification. | 
|---|
|  | 200 | </li> | 
|---|
|  | 201 | <li>When an anonymous servlet is accessed, the servlet instance receives | 
|---|
|  | 202 | a <code>ServletConfig</code> instance with no servlet initialization | 
|---|
|  | 203 | parameters.</li> | 
|---|
|  | 204 | <li>It is possible to utilize the invoker servlet via a direct request.</li> | 
|---|
|  | 205 | <li>It is possible to utilize the invoker servlet via a call to | 
|---|
|  | 206 | <code>RequestDispatcher.forward()</code>, or the corresponding | 
|---|
|  | 207 | <code><jsp:forward></code> tag in a JSP page.</li> | 
|---|
|  | 208 | <li>It is possible to utilize the invoker servlet via a call to | 
|---|
|  | 209 | <code>RequestDispatcher.include()</code>, or the corresponding | 
|---|
|  | 210 | <code><jsp:include></code> tag in a JSP page.</li> | 
|---|
|  | 211 | <li>It is possible to use any HTTP method (including GET and POST) that | 
|---|
|  | 212 | is supported by the Servlet class that is ultimately executed.</li> | 
|---|
|  | 213 | <li>The invoker servlet should never be asked to process a second or | 
|---|
|  | 214 | subsequent request for the same <code>{ServletSelector}</code> (because | 
|---|
|  | 215 | it will have registered an appropriate servlet mapping.</li> | 
|---|
|  | 216 | </ul> | 
|---|
|  | 217 |  | 
|---|
|  | 218 | </blockquote></td></tr></table></td></tr><!--FOOTER SEPARATOR--><tr><td colspan="2"><hr size="1" noshade></td></tr><!--PAGE FOOTER--><tr><td colspan="2"><div align="center"><font size="-1" color="#525D76"><em> | 
|---|
|  | 219 | Copyright © 1999-2008, Apache Software Foundation | 
|---|
|  | 220 | </em></font></div></td></tr></table></body></html> | 
|---|