alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Tomcat example source code file (fs-invoker.xml)

This example Tomcat source code file (fs-invoker.xml) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Tomcat tags/keywords

dependencies, functionality, http, http, if, if, license, license, pathremainder, servlet, servletpath, servletselector, servletselector, url

The Tomcat fs-invoker.xml source code

<?xml version="1.0"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<!DOCTYPE document [
  <!ENTITY project SYSTEM "project.xml">
]>
<document url="fs-invoker.html">

  &project;

  <properties>
    <author email="craigmcc@apache.org">Craig McClanahan
    <title>Invoker Servlet
    <revision>$Id: fs-invoker.xml 562814 2007-08-05 03:52:04Z markt $
  </properties>

<body>


<section name="Overview">


  <subsection name="Introduction">

    <p>The purpose of the Invoker Servlet is to allow a
    web application to dynamically register new <em>servlet definitions
    that correspond with a <code><servlet> element in the
    <code>/WEB-INF/web.xml deployment descriptor, and execute
    requests utilizing the new servlet definitions.  From the perspective
    of the newly registered servlets, all servlet lifecycle requirements
    of the Servlet Specification (such as calling <code>init() and
    <code>destroy() at the correct times) will be respected.

</subsection> <subsection name="External Specifications"> <p>I do not know of any formal specification of the behavior of an invoker servlet that is publicly available. Anyone know of one?</p> </subsection> <subsection name="Implementation Requirements"> <p>The implementation of this functionality shall conform to the following requirements:</p> <ul> <li>Implemented as a servlet. <li>Exist in the org.apache.catalina.servlets package so that it can be loaded by the Catalina class loader.</li> <li>Implement the org.apache.catalina.ContainerServlet interface, so that it gains knowledge of the <code>Wrapper that is responsible for itself and, therefore, access to other internal Catalina components.</li> <li>Support a configurable debugging detail level. <li>Log debugging and operational messages (suitably internationalized) via the <code>getServletContext().log() method. </ul> </subsection> </section> <section name="Dependencies"> <subsection name="Environmental Dependencies"> <p>The following environmental dependencies must be met in order for the Invoker servlet to operate correctly:</p> <ul> <li>The invoker servlet must be registered in the application deployment descriptor (or the default deployment descriptor in file <code>$CATALINA_HOME/conf/web.xml) using a "path mapped" servlet mapping. The historical default mapping is to URL pattern "<code>/servlet/*", although the invoker servlet must operate correctly with an arbitrary mapping.</li> </ul> </subsection> <subsection name="Container Dependencies"> <p>Correct operation of the invoker servlet depends on the following specific features of the surrounding container:</p> <ul> <li>Correct support for the ContainerServlet interface, including calling <code>setWrapper() before the <code>init() method of the invoker servlet is called. <li>The web application class loader must be stored as the context class loader of the request processing thread.</li> </ul> </subsection> </section> <section name="Functionality"> <subsection name="Initialization Functionality"> <p>The following processing must be performed when the init() method of the invoker servlet is called:</p> <ul> <li>Ensure that the container has called setWrapper(). If not, throw a permanent <code>UnavailableException. <li>Look up and cache the Context that corresponds to our <code>Wrapper. This is the component with which new servlet definitions and mappings will be registered.</li> </ul> </subsection> <subsection name="Per-Request Functionality"> <p>On each request, the following processing shall be performed:

<ol> <li>Calculate the {ServletPath} for this request, either from request attribute <code>javax.servlet.include.servlet_path or by calling <code>request.getServletPath(). <li>Calculate the {PathInfo} for this request, either from request attribute <code>javax.servlet.include.path_info or by calling <code>request.getPathInfo(). If the calculated <code>{PathInfo} is null, return HTTP status 400 (bad request).</li> <li>Parse the calculated {PathInfo} value as follows: <ol> <li>Ignore the leading slash character. <li>Accumulate characters up to the next '/' (if any) as the <code>{ServletSelector}. <li>If a '/' was encountered, accumulate all characters from that slash (inclusive) to the end of the string as <code>{PathRemainder}. If no slash was encountered, set <code>{PathRemainder} to a zero-length string. </ol> <li>Determine whether {ServletSelector} is the name of an existing servlet definition, and process it as follows: <ol> <li>Ask our associated Context to find and return a child <code>Wrapper named {ServletSelector}. </li> <li>If there is no such child, skip to the next major step. <li>Register a new servlet mapping for this Wrapper, using a URL pattern calculated as follows: <code>{ServletPath} + "/" + {ServletSelector} + "/*"</li> <li>Create a request dispatcher using a path calculated as follows: <code>{ServletPath} + "/" + {ServletSelector} + <code>{PathRemainder} <li>Forward this request to the created request dispatcher, and exit from this request.</li> </ol> <li>Assume that {ServletSelector} is the fully qualified name of a Java class that implements <code>javax.servlet.Servlet and process it as follows: <ol> <li>Synthesize a new {ServletName} for the servlet definition that will be created.</li> <li>If there is already a child Wrapper associated with this name, return HTTP status 500 (internal server error), because a mapping should have already been created for this servlet.</li> <li>Attempt to load a class named {ServletSelector} from the web application class loader (i.e. the context class loader for our current thread). If this fails, return HTTP status 404 (not found).</li> <li>Instantiate an instance of this class. If an error occurs, return HTTP status 404 (not found).</li> <li>If this class does not implement the <code>javax.servlet.Servlet interface, return HTTP status 404 (not found).</li> <li>Create and register a new Wrapper child with our <code>Context, under name {ServletName}. <li>Register a new servlet mapping for this Wrapper, using a URL pattern calculated as follows: <code>{ServletPath} + "/" + {ServletSelector} + "/*"</li> <li>Create a request dispatcher using a path calculated as follows: <code>{ServletPath} + "/" + {ServletSelector} + <code>{PathRemainder} <li>Forward this request to the created request dispatcher, and exit from this request.</li> </ol> </ol> </subsection> <subsection name="Finalization Functionality"> <p>No specific processing is required when the destroy() method is called:</p> </subsection> </section> <section name="Testable Assertions"> <p>In addition the the assertions implied by the functionality requirements listed above, the following additional assertions shall be tested to validate the behavior of the invoker servlet:</p> <ul> <li>It is possible to access an existing servlet definition by name through the invoker. The existing servlet definition can include either a <code><servlet-class> or <code><jsp-file> subelement. <li>When an existing servlet definition is accessed by name, the request will be ultimately processed by the same servlet instance that would have processed it had a mapping to that servlet definition been used on the request directly.</li> <li>It is possible to access an anonymous servlet by class name through the invoker.</li> <li>When an anonymous servlet is accessed, the servlet instance is processed according to the lifecycle requirements of the Servlet Specification. </li> <li>When an anonymous servlet is accessed, the servlet instance receives a <code>ServletConfig instance with no servlet initialization parameters.</li> <li>It is possible to utilize the invoker servlet via a direct request. <li>It is possible to utilize the invoker servlet via a call to <code>RequestDispatcher.forward(), or the corresponding <code><jsp:forward> tag in a JSP page. <li>It is possible to utilize the invoker servlet via a call to <code>RequestDispatcher.include(), or the corresponding <code><jsp:include> tag in a JSP page. <li>It is possible to use any HTTP method (including GET and POST) that is supported by the Servlet class that is ultimately executed.</li> <li>The invoker servlet should never be asked to process a second or subsequent request for the same <code>{ServletSelector} (because it will have registered an appropriate servlet mapping.</li> </ul> </section> </body> </document>

Other Tomcat examples (source code examples)

Here is a short list of links related to this Tomcat fs-invoker.xml source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.