org.mortbay.jetty.servlet
Class ServletHttpContext

java.lang.Object
  extended byorg.mortbay.util.Container
      extended byorg.mortbay.http.HttpContext
          extended byorg.mortbay.jetty.servlet.ServletHttpContext
All Implemented Interfaces:
EventProvider, 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.27 2005/04/13 16:30:47 janb Exp $
Author:
Greg Wilkins (gregw)
See Also:
Serialized Form

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)
           
 void destroy()
          Destroy a context.
 java.lang.Object enterContextScope(HttpRequest request, HttpResponse response)
          Enter the context scope.
 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.
 java.lang.String toString()
           
 
Methods inherited from class org.mortbay.http.HttpContext
addClassPath, addClassPaths, addHandler, addHandler, addPermission, addSecurityConstraint, addVirtualHost, addWelcomeFile, canonicalContextPathSpec, clearSecurityConstraints, flushCache, getAttribute, getAttributeNames, getAttributes, getAuthenticator, getBaseResource, getClassLoader, getClassPath, getContextPath, getEncodingByMimeType, getEncodingMap, getFileClassPath, getHandler, getHandlerIndex, getHandlers, getHosts, getHttpConnection, getHttpContext, getHttpContextName, getHttpServer, getInitParameter, getInitParameterNames, getMaxCachedFileSize, getMaxCacheSize, getMimeByExtension, getMimeMap, getName, getParentClassLoader, getPermissions, getRealm, getRealmName, getRequestLog, getRequests, getRequestsActive, getRequestsActiveMax, getResource, getResourceBase, getResourceMetaData, getResponses1xx, getResponses2xx, getResponses3xx, getResponses4xx, getResponses5xx, getServerClasses, getStatsOn, getStatsOnMs, getStopGracefully, getSystemClasses, getTempDirectory, getVirtualHosts, getWelcomeFile, getWelcomeFiles, handle, handle, initialize, isClassLoaderJava2Compliant, isRedirectNullPath, leaveContextScope, loadClass, log, removeAttribute, removeHandler, removeHandler, removeVirtualHost, removeWelcomeFile, sendContextError, setAttribute, setAttributes, setAuthenticator, setBaseResource, setClassLoader, setClassLoaderJava2Compliant, setClassPath, setContextPath, setEncodingMap, setHandlers, setHosts, setHttpContextName, setInitParameter, setMaxCachedFileSize, setMaxCacheSize, setMimeMap, setMimeMapping, setParentClassLoader, setPermissions, setRealm, setRealmName, setRedirectNullPath, setRequestLog, setResourceBase, setServerClasses, setStatsOn, setStopGracefully, setSystemClasses, setTempDirectory, setTypeEncoding, setVirtualHosts, setWelcomeFiles, statsReset, stop, toString
 
Methods inherited from class org.mortbay.util.Container
addEventListener, getComponents, isStarted, removeEventListener, start, stop
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.mortbay.util.LifeCycle
isStarted, start, stop
 
Methods inherited from interface org.mortbay.util.EventProvider
addEventListener, removeEventListener
 

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.

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.

destroy

public void destroy()
Description copied from class: HttpContext
Destroy a context. Destroy a context and remove it from the HttpServer. The HttpContext must be stopped before it can be destroyed.

Overrides:
destroy in class HttpContext

enterContextScope

public java.lang.Object enterContextScope(HttpRequest request,
                                          HttpResponse response)
Description copied from class: HttpContext
Enter the context scope. This method is called (by handle or servlet dispatchers) to indicate that request handling is entering the scope of this context. The opaque scope object returned, should be passed to the leaveContextScope method.

Overrides:
enterContextScope in class HttpContext


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