JSPservletPkg
Class JSPservlet

JSPservletPkg.JSPservlet

public class JSPservlet

Class invoked by servlet container for a given context path. It forwards the requests to a compiled jsp or servlet loaded by JSPloader.

Copyright (c) 2000-2001

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; version 2
 of the License.
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 

Version:
1, 0, 4
Author:
Alexis Grandemange
See Also:
JSPhandler, JSPhandler.ClassEntry, JSPloader

Inner Class Summary
(package private)  class JSPservlet.IncludeWriter
          Helper class.
 
Field Summary
(package private) static int[] aReason
          Array of used HTTP codes.
static java.util.Map JSPhandlers
          Synchronized HashMap key: contextPath value: JSPhandler
private static java.text.SimpleDateFormat sdf
          SimpleDateFormat used to build RFC conformant strings
 
Constructor Summary
JSPservlet()
           
 
Method Summary
(package private) static void ()
           
static JSPhandler getHandler(JSPservletPkg.ServletConfig sc, java.lang.String contextPath, JSPservletPkg.ServletContext ctx, java.lang.String URI, java.lang.String URIRealPath)
          Returns the handling JSPhandler.
static java.lang.String getJAR(JSPservletPkg.HttpServletRequest request)
          service method for servlet using RequestDispatcher.
(package private) static java.lang.String getPathInfo(JSPservletPkg.HttpServletRequest request, boolean bContextPath)
          Version 1.0.2.
 java.lang.String getServletInfo()
           
private  java.io.PrintWriter getWriter(JSPservletPkg.HttpServletResponse response, JSPhandler jh)
          Version 1.0.3.
(package private)  void handleAbnormalCondition(JSPhandler handler, JSPservletPkg.HttpServletResponse response, int reason)
          If an error page is defined returns this page.
private  void hrefUpdate(JSPhandler jh, java.io.InputStream is, JSPservletPkg.HttpServletRequest request, JSPservletPkg.HttpServletResponse response, java.lang.String jarName, java.lang.String path, BackCheck backCheck)
          Version 1.0.3. href update of routing resources. Version 1.0.4. action update of routing resources.
private  int indexOfIgnoreCase(java.lang.String ln, java.lang.String key)
          Version 1.0.2.
private  void myService(JSPservletPkg.HttpServletRequest request, JSPservletPkg.HttpServletResponse response, java.lang.String contextPath, JSPhandler jh)
          invokes the target servlet or handles an update on behalf of JSPupdate.
private  void pwprintln(JSPhandler jh, java.io.PrintWriter pw, java.lang.String msg)
          Version 1.0.2.
 void service(JSPservletPkg.HttpServletRequest request, JSPservletPkg.HttpServletResponse response)
          Version 1.0.4.
static void setApplication()
          Servlet container specific initialization.
 

Field Detail

JSPhandlers

public static java.util.Map JSPhandlers
Synchronized HashMap key: contextPath value: JSPhandler

sdf

private static final java.text.SimpleDateFormat sdf
SimpleDateFormat used to build RFC conformant strings

aReason

static int[] aReason
Array of used HTTP codes. Indexed by JSPhandler.EP_*.
See Also:
JSPhandler
Constructor Detail

JSPservlet

public JSPservlet()
Method Detail

static void ()

getHandler

public static final JSPhandler getHandler(JSPservletPkg.ServletConfig sc,
                                          java.lang.String contextPath,
                                          JSPservletPkg.ServletContext ctx,
                                          java.lang.String URI,
                                          java.lang.String URIRealPath)
                                   throws JSPloaderException
Returns the handling JSPhandler. Creates it the first time. Synchronized method to protect the access to JSPhandlers.

In case of Resin, the JspFactory is normally not set at first call. This factory is used in JSPs compiled with Resin. I set it with Class.forName("com.caucho.jsp.QJspFactory").newInstance(). The code remains therefore portable across Java servers.

Parameters:
sc - ServletConfig used to initialize target classes.
contextPath - application prefix.
Returns:
the requested JSPhandler.
Throws:
JSPloaderException - JSPhandler constructor exception.
See Also:
JSPhandler

setApplication

public static final void setApplication()
Servlet container specific initialization. Current implementation usefull only in case of Resin to set up the default factory.

handleAbnormalCondition

final void handleAbnormalCondition(JSPhandler handler,
                                   JSPservletPkg.HttpServletResponse response,
                                   int reason)
                            throws java.io.IOException
If an error page is defined returns this page. Otherwise returns an HTTP error. The second method could be favoured if browsers and AS would behave the same way. As the page is specified in JSPservletPkg, I retrieve the page in the JSPservletPkg war. Technically it would be possible to retrieve it in the downloaded archive.
Parameters:
handler - JSPhandler.
response - HttpServletResponse.
reason - error code.
See Also:
JSPhandler

service

public void service(JSPservletPkg.HttpServletRequest request,
                    JSPservletPkg.HttpServletResponse response)
             throws JSPservletPkg.ServletException,
                    java.io.IOException
Version 1.0.4. Retrieves the URI (RequestURL). Used in ClassPathLoader.getResource.
Servlet container invoked service method.
Handles JSPloaderException
Parameters:
request - HttpServletRequest.
response - HttpServletResponse.
Throws:
JSPservletPkg.ServletException - from JSPservlet.

getWriter

private final java.io.PrintWriter getWriter(JSPservletPkg.HttpServletResponse response,
                                            JSPhandler jh)
                                     throws java.io.IOException
Version 1.0.3.

service method returning the response PrintWriter. Used in /ping and /info handling

Parameters:
response - HttpServletResponse.
jh - handling JSPhandler.

myService

private final void myService(JSPservletPkg.HttpServletRequest request,
                             JSPservletPkg.HttpServletResponse response,
                             java.lang.String contextPath,
                             JSPhandler jh)
                      throws JSPloaderException,
                             java.lang.ClassNotFoundException,
                             JSPservletPkg.ServletException,
                             java.io.IOException
invokes the target servlet or handles an update on behalf of JSPupdate.

myService is divided in:

  1. Checking for a JSPupdate invocation. In this case, it gets the jarName from parameters and issues a JSPHandler update.
  2. Checking for the extension. If there is no extension or the extension is .class, then JSPhandler is invoked to get the servlet.
  3. Otherwise JSPhandler is invoked to get the resource

a JSP can be invoked through RequestDispatcher.include. In this case request.getContextPath, request.getPathInfo point the including servlet and not the included server, whose info are returned by request.getAttribute("javax.servlet.include...").

So I first look at request.getAttribute("javax.servlet.include...") and then to request.getContextPath, request.getPathInfo.

Parameters:
request - HttpServletRequest.
response - HttpServletResponse.
contextPath - Context String retrieved from attribute (include) or from request.
jh - handling JSPhandler.
Throws:
JSPservletPkg.ServletException - internally raised.
JSPloaderException - from tool processing non recoverable.
See Also:
JSPhandler

hrefUpdate

private void hrefUpdate(JSPhandler jh,
                        java.io.InputStream is,
                        JSPservletPkg.HttpServletRequest request,
                        JSPservletPkg.HttpServletResponse response,
                        java.lang.String jarName,
                        java.lang.String path,
                        BackCheck backCheck)
Parameters:
jh - handling JSPhandler.
is - input stream on routing resource.
request - HttpServletRequest.
response - HttpServletResponse.
jarName - archive name.
path - path of routing resource.
comment - purpose of routing resource.

indexOfIgnoreCase

private final int indexOfIgnoreCase(java.lang.String ln,
                                    java.lang.String key)
Version 1.0.2. Service method to find a string both in upper and lower case. The key is in in lower case.
Parameters:
ln - string where to find the string.
key - string to find.
Returns:
index.

pwprintln

private final void pwprintln(JSPhandler jh,
                             java.io.PrintWriter pw,
                             java.lang.String msg)
Version 1.0.2. Service method to write both on writer and log.
Parameters:
jh - handling JSPhandler.
pw - current print writer.

getPathInfo

static final java.lang.String getPathInfo(JSPservletPkg.HttpServletRequest request,
                                          boolean bContextPath)
Version 1.0.2. Empirical: depending on the application server, URI stuff goes either to pathInfo or servlet path... The latter form fits better with 2.3 spec. I put in comments a modification for the case where contextPath is null. It could apply in case of Tomcat if you define JSPservlet in Tomcat web.xml. However you have to provide a special InvokerServlet. I don't know if it is a performance benefit to do so and it compromises portability.
Parameters:
request - HttpServletRequest.
bContextPath - HttpServletRequest. If true, returns contextPath. if false, returns pathInfo without context path.
Returns:
a path containing the archive name and the class path separated by slashes.

getJAR

public static final java.lang.String getJAR(JSPservletPkg.HttpServletRequest request)
service method for servlet using RequestDispatcher. Its use is optional. It returns the jar name part of the path. We recommend however its use as the servlet developer should not be aware of its packaging.

Parameters:
request - HttpServletRequest.
Returns:
the jar string.

getServletInfo

public java.lang.String getServletInfo()