org.mortbay.jetty.servlet
Class ServletHttpContext

java.lang.Object
  extended byorg.mortbay.http.ResourceCache
      extended byorg.mortbay.http.HttpContext
          extended byorg.mortbay.jetty.servlet.ServletHttpContext
All Implemented Interfaces:
HttpHandler, LifeCycle, java.io.Serializable
Direct Known Subclasses:
WebApplicationContext

public class ServletHttpContext
extends HttpContext

ServletHttpContext. Extends HttpContext with conveniance methods for adding servlets. Enforces a single ServletHandler per context.

Version:
$Id: ServletHttpContext.java,v 1.20 2004/07/02 12:39:09 gregwilkins Exp $
Author:
Greg Wilkins (gregw)
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class org.mortbay.http.ResourceCache
ResourceCache.ResourceMetaData
 
Field Summary
 
Fields inherited from class org.mortbay.http.HttpContext
__ErrorHandler, __fileClassPathAttr
 
Constructor Summary
ServletHttpContext()
          Constructor.
 
Method Summary
 void addLocaleEncoding(java.lang.String locale, java.lang.String encoding)
           
 ServletHolder addServlet(java.lang.String pathSpec, java.lang.String className)
          Add a servlet to the context.
 ServletHolder addServlet(java.lang.String name, java.lang.String pathSpec, java.lang.String className)
          Add a servlet to the context.
 boolean checkSecurityConstraints(java.lang.String pathInContext, HttpRequest request, HttpResponse response)
           
 java.lang.String getLocaleEncoding(java.util.Locale locale)
          Get the character encoding for a locale.
 ServletContext getServletContext()
           
 ServletHandler getServletHandler()
          Get the context ServletHandler.
 void sendError(HttpResponse response, int code, java.lang.String msg)
          Send an error response.
 void stop()
          Stop the context.
 java.lang.String toString()
           
 
Methods inherited from class org.mortbay.http.HttpContext
addClassPath, addClassPaths, addHandler, addHandler, addPermission, addSecurityConstraint, addVirtualHost, addWelcomeFile, canonicalContextPathSpec, clearSecurityConstraints, destroy, enterContextScope, flushCache, getAttribute, getAttributeNames, getAttributes, getAuthenticator, getClassLoader, getClassPath, getContextPath, getFileClassPath, getHandler, getHandlerIndex, getHandlers, getHosts, getHttpConnection, getHttpContext, getHttpContextName, getHttpServer, getInitParameter, getInitParameterNames, getName, getParentClassLoader, getPermissions, getRealm, getRealmName, getRequestLog, getRequests, getRequestsActive, getRequestsActiveMax, getResponses1xx, getResponses2xx, getResponses3xx, getResponses4xx, getResponses5xx, getStatsOn, getStatsOnMs, getTempDirectory, getVirtualHosts, getWelcomeFile, getWelcomeFiles, handle, handle, initialize, isClassLoaderJava2Compliant, isRedirectNullPath, isStarted, leaveContextScope, loadClass, log, removeAttribute, removeHandler, removeHandler, removeVirtualHost, removeWelcomeFile, sendContextError, setAttribute, setAttributes, setAuthenticator, setClassLoader, setClassLoaderJava2Compliant, setClassPath, setContextPath, setHandlers, setHosts, setHttpContextName, setInitParameter, setParentClassLoader, setPermissions, setRealm, setRealmName, setRedirectNullPath, setRequestLog, setStatsOn, setTempDirectory, setVirtualHosts, setWelcomeFiles, start, statsReset, stop, toString
 
Methods inherited from class org.mortbay.http.ResourceCache
getBaseResource, getEncodingByMimeType, getEncodingMap, getMaxCachedFileSize, getMaxCacheSize, getMimeByExtension, getMimeMap, getResource, getResourceBase, getResourceMetaData, setBaseResource, setEncodingMap, setMaxCachedFileSize, setMaxCacheSize, setMimeMap, setMimeMapping, setResourceBase, setTypeEncoding
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ServletHttpContext

public ServletHttpContext()
Constructor.

Method Detail

getServletContext

public ServletContext getServletContext()
Returns:
The ServletContext.

getServletHandler

public ServletHandler getServletHandler()
Get the context ServletHandler. Conveniance method. If no ServletHandler exists, a new one is added to the context.

Returns:
ServletHandler

addServlet

public ServletHolder addServlet(java.lang.String pathSpec,
                                java.lang.String className)
                         throws java.lang.ClassNotFoundException,
                                java.lang.InstantiationException,
                                java.lang.IllegalAccessException
Add a servlet to the context. Conveniance method. If no ServletHandler is found in the context, a new one is added.

Parameters:
pathSpec - The pathspec within the context
className - The classname of the servlet.
Returns:
The ServletHolder.
Throws:
java.lang.ClassNotFoundException
java.lang.InstantiationException
java.lang.IllegalAccessException

addServlet

public ServletHolder addServlet(java.lang.String name,
                                java.lang.String pathSpec,
                                java.lang.String className)
                         throws java.lang.ClassNotFoundException,
                                java.lang.InstantiationException,
                                java.lang.IllegalAccessException
Add a servlet to the context. If no ServletHandler is found in the context, a new one is added.

Parameters:
name - The name of the servlet.
pathSpec - The pathspec within the context
className - The classname of the servlet.
Returns:
The ServletHolder.
Throws:
java.lang.ClassNotFoundException
java.lang.InstantiationException
java.lang.IllegalAccessException

checkSecurityConstraints

public boolean checkSecurityConstraints(java.lang.String pathInContext,
                                        HttpRequest request,
                                        HttpResponse response)
                                 throws HttpException,
                                        java.io.IOException
Overrides:
checkSecurityConstraints in class HttpContext
Throws:
HttpException
java.io.IOException

addLocaleEncoding

public void addLocaleEncoding(java.lang.String locale,
                              java.lang.String encoding)

getLocaleEncoding

public java.lang.String getLocaleEncoding(java.util.Locale locale)
Get the character encoding for a locale. The full locale name is first looked up in the map of encodings. If no encoding is found, then the locale language is looked up.

Parameters:
locale - a Locale value
Returns:
a String representing the character encoding for the locale or null if none found.

stop

public void stop()
          throws java.lang.InterruptedException
Description copied from class: HttpContext
Stop the context.

Specified by:
stop in interface LifeCycle
Overrides:
stop in class HttpContext
Throws:
java.lang.InterruptedException

toString

public java.lang.String toString()
Overrides:
toString in class HttpContext

sendError

public void sendError(HttpResponse response,
                      int code,
                      java.lang.String msg)
               throws java.io.IOException
Description copied from class: HttpContext
Send an error response. This method may be specialized to provide alternative error handling for errors generated by the container. The default implemenation calls HttpResponse.sendError

Overrides:
sendError in class HttpContext
Parameters:
response - the response to send
code - The error code
msg - The message for the error or null for the default
Throws:
java.io.IOException - Problem sending response.


Copyright © 2004 Mortbay Consulting Pty. Ltd. All Rights Reserved.