TKN Logo SelfSoft Logo

Total Knowledge

SelfSoft, Inc.

CPPSERV

[CPPSERV] [Documentation] [Download] [Contact] [Bug tracker] [News] [RSS Feed] [gitweb]

container::App Class Reference

#include <App.h>

Inheritance diagram for container::App:

Inheritance graph
[legend]
Collaboration diagram for container::App:

Collaboration graph
[legend]
List of all members.

Public Types

typedef ServletMap< ServletDescservletmap_t

Public Member Functions

 App (ServerConfig &cfg, time_t sessionTimeout, const std::string &name, const std::string &fileSaveDir, const std::string &uribase)
virtual ~App ()
ServletConfigImpladdServlet (const std::string &path, const std::string &name, const std::string &dso, bool hidden)
void delServlet (const std::string &path)
ServletContainergetServletContainer (const std::string &path)
void * getDso (const std::string &path)
void initServlets ()
void destroyServlets ()
HttpSessionImplgetSession (const std::string &sid, bool create)
const std::string & getSessionCookieName ()
void killSession (const std::string &sid)
void cleanSessions ()
bool isSessionValid (const std::string &sid)
void addInitParam (const std::string &name, const std::string &value)
void killAllSessions ()
const std::string & getFileSaveTemplate () const
const std::string & getUriBase () const
virtual servlet::ServletContextgetContext (const std::string &uripath)
virtual int getMajorVersion ()
virtual int getMinorVersion ()
virtual std::string getMimeType (const std::string &file)
virtual std::auto_ptr< std::set<
std::string > > 
getResourcePaths (const std::string &path)
virtual std::string getResource (const std::string &path)
virtual std::istream & getResourceAsStream (const std::string &path)
virtual servlet::RequestDispatchergetRequestDispatcher (const std::string &path)
virtual servlet::RequestDispatchergetNamedDispatcher (const std::string &name)
virtual void log (const std::string &msg) const
virtual void log (const std::string &message, const std::exception &e) const
virtual std::string getRealPath (const std::string &path)
virtual std::string getServerInfo ()
virtual std::string getInitParameter (const std::string &name)
virtual std::auto_ptr< std::vector<
std::string > > 
getInitParameterNames ()
virtual boost::shared_ptr<
void > 
getAttribute (const std::string &name)
virtual std::auto_ptr< std::vector<
std::string > > 
getAttributeNames ()
virtual void setAttribute (const std::string &name, boost::shared_ptr< void > object)
virtual void removeAttribute (const std::string &name)
virtual bool hasAttribute (const std::string &name) const
virtual std::string getServletContextName () const

Private Types

typedef servlet::Servlet *(*) servletcreatefunc_t ()
typedef std::map< std::string,
HttpSessionImpl * > 
sessionlist_t
typedef std::map< std::string,
boost::shared_ptr< void > > 
attr_t
typedef std::map< std::string,
std::string > 
param_t

Private Member Functions

void splitServPath (const std::string &path, std::string &dir, std::string &name)
void unloadServlet (const std::string &path)
bool addServlet (const std::string &path, ServletDesc *d)
ServletDescgetDesc (const std::string &path)
void initServlet (const std::string &path)
void destroyServlet (const std::string &path)
HttpSessionImplnewSession ()

Static Private Member Functions

static std::string makeSName (const std::string &name)

Private Attributes

servletmap_t maptop
ServerConfigcfg
SessionCleanercleaner
sessionlist_t sessions
std::string sessionCookieName
time_t sessionTimeout
std::string fileSaveTemplate
sptk::CWaiter sessionLock
std::string name
attr_t m_attrs
param_t m_params
std::string m_uribase

Friends

class ServerConfig

Classes

struct  ServletDesc
class  SessionCleaner

Detailed Description

Definition at line 20 of file App.h.


Member Typedef Documentation

Definition at line 23 of file App.h.

Definition at line 33 of file App.h.

typedef std::map<std::string, HttpSessionImpl*> container::App::sessionlist_t [private]

Definition at line 72 of file App.h.

typedef std::map<std::string,boost::shared_ptr<void> > container::App::attr_t [private]

Definition at line 79 of file App.h.

typedef std::map<std::string,std::string> container::App::param_t [private]

Definition at line 81 of file App.h.


Constructor & Destructor Documentation

container::App::App ( ServerConfig cfg,
time_t  sessionTimeout,
const std::string &  name,
const std::string &  fileSaveDir,
const std::string &  uribase 
)

Definition at line 187 of file App.cpp.

References cleaner.

container::App::~App (  )  [virtual]


Member Function Documentation

void container::App::splitServPath ( const std::string &  path,
std::string &  dir,
std::string &  name 
) [private]

Definition at line 90 of file App.cpp.

void container::App::unloadServlet ( const std::string &  name  )  [private]

Parameters:
name Name of servlet to unload, as specified in name= parameter in config file Stops servlet - that is removed it from mapper, and waits till all requests within this servlet are done.

Definition at line 120 of file App.cpp.

References delServlet(), container::ServletContainer::getConfig(), getDesc(), getServletContainer(), and container::App::ServletDesc::h.

Referenced by ~App().

Here is the call graph for this function:

bool container::App::addServlet ( const std::string &  path,
ServletDesc d 
) [private]

Definition at line 58 of file App.cpp.

References maptop.

Referenced by addServlet(), and container::ServerConfig::ServletContext::onPostComplete().

App::ServletDesc * container::App::getDesc ( const std::string &  path  )  [private]

Definition at line 64 of file App.cpp.

References container::ServletMap< T >::getServletDesc(), and maptop.

Referenced by getDso(), getServletContainer(), and unloadServlet().

Here is the call graph for this function:

void container::App::initServlet ( const std::string &  path  )  [private]

Definition at line 102 of file App.cpp.

References getServletContainer(), and container::ServletContainer::init().

Referenced by initServlets().

Here is the call graph for this function:

void container::App::destroyServlet ( const std::string &  path  )  [private]

Definition at line 108 of file App.cpp.

References container::ServletContainer::destroy(), and getServletContainer().

Referenced by destroyServlets().

Here is the call graph for this function:

ServletConfigImpl * container::App::addServlet ( const std::string &  path,
const std::string &  name,
const std::string &  dso,
bool  hidden 
)

Parameters:
path Path part of URL this servlet is mapped to, relative to App's base path
name the name of servlet. It should match what mod_servlet passes to us as first line of request
dso path to shared library that contains servlet initializer - DECLARE_SERVLET(ServletName) statement
hidden Do not allow direct calls to this servlet through http. Calls thourh RequestDispatcher interface are still allowed.

Definition at line 38 of file App.cpp.

References container::RequestHandler::addServlet(), addServlet(), and getServletContainer().

Here is the call graph for this function:

void container::App::delServlet ( const std::string &  path  ) 

Definition at line 69 of file App.cpp.

References maptop, and container::ServletMap< T >::removeDesc().

Referenced by unloadServlet().

Here is the call graph for this function:

ServletContainer * container::App::getServletContainer ( const std::string &  path  ) 

Definition at line 74 of file App.cpp.

References container::App::ServletDesc::cont, and getDesc().

Referenced by addServlet(), destroyServlet(), getNamedDispatcher(), getRequestDispatcher(), initServlet(), and unloadServlet().

Here is the call graph for this function:

void * container::App::getDso ( const std::string &  path  ) 

Definition at line 82 of file App.cpp.

References getDesc(), and container::App::ServletDesc::h.

Here is the call graph for this function:

void container::App::initServlets (  ) 

Definition at line 172 of file App.cpp.

References container::ServletMap< T >::forEachServletPath(), initServlet(), and maptop.

Referenced by container::ServerConfig::AppContext::onPostComplete().

Here is the call graph for this function:

void container::App::destroyServlets (  ) 

Definition at line 179 of file App.cpp.

References destroyServlet(), container::ServletMap< T >::forEachServletPath(), and maptop.

Referenced by ~App().

Here is the call graph for this function:

container::HttpSessionImpl * container::App::getSession ( const std::string &  sid,
bool  create 
)

Parameters:
sid Session ID. If empty string, new session is created
create Whether to create session if it doesn't exist
Returns:
Pointer to the session.
Note:
sets session state to not-new when sid is not empty This presumes session is only retrieved from Context once per request

Definition at line 208 of file App.cpp.

References newSession(), sessionLock, and sessions.

Referenced by container::HttpServletRequestImpl::getSession(), and container::HttpServletRequestImpl::isRequestedSessionIdValid().

Here is the call graph for this function:

container::App::getSessionCookieName (  )  [inline]

void container::App::killSession ( const std::string &  sid  ) 

Parameters:
sid ID of session to kill
Note:
This function should always be called with sessionLock held.

Definition at line 250 of file App.cpp.

References sessions.

Referenced by cleanSessions().

void container::App::cleanSessions (  ) 

Definition at line 264 of file App.cpp.

References killSession(), sessionLock, and sessions.

Referenced by container::App::SessionCleaner::threadFunction().

Here is the call graph for this function:

bool container::App::isSessionValid ( const std::string &  sid  ) 

Parameters:
sid Session ID, as retrieved from session cookie. Session is valid if it exists and did not expire.

Definition at line 344 of file App.cpp.

References sessions.

Referenced by container::HttpServletRequestImpl::isRequestedSessionIdValid().

void container::App::addInitParam ( const std::string &  name,
const std::string &  value 
)

Definition at line 354 of file App.cpp.

References m_params.

Referenced by container::ServerConfig::AppContext::onPreComplete().

void container::App::killAllSessions (  ) 

Removes all sessions in this context. It presumes no servlets in this context are going to use us.

Definition at line 397 of file App.cpp.

References sessionLock, and sessions.

Referenced by ~App().

const std::string& container::App::getFileSaveTemplate (  )  const [inline]

Definition at line 100 of file App.h.

References fileSaveTemplate.

Referenced by container::HttpServletRequestImpl::parsePart().

const std::string& container::App::getUriBase (  )  const [inline]

Definition at line 101 of file App.h.

References m_uribase.

Referenced by container::ServletContainer::forward(), and getContext().

servlet::ServletContext * container::App::getContext ( const std::string &  uripath  )  [virtual]

Returns a ServletContext object that corresponds to a specified URL on the server.

This method allows servlets to gain access to the context for various parts of the server, and as needed obtain servlet::RequestDispatcher objects from the context. The given path must be begin with "/", is interpreted relative to the server's document root and is matched against the context roots of other web applications hosted on this container.

In a security conscious environment, the servlet container may return null for a given URL.

Parameters:
uripath a String specifying the context path of another web application in the container.
Returns:
the ServletContext object that corresponds to the named URL, or null if either none exists or the container wishes to restrict this access.
See also:
RequestDispatcher

Implements servlet::ServletContext.

Definition at line 421 of file App.cpp.

References cfg, container::ServerConfig::getApp(), and getUriBase().

Here is the call graph for this function:

int container::App::getMajorVersion (  )  [virtual]

Returns the major version of the Java Servlet API that this servlet container supports. All implementations that comply with Version 2.4 must have this method return the integer 2.

Returns:
2

Implements servlet::ServletContext.

Definition at line 429 of file App.cpp.

int container::App::getMinorVersion (  )  [virtual]

Returns the minor version of the Servlet API that this servlet container supports. All implementations that comply with Version 2.4 must have this method return the integer 4.

Returns:
4

Implements servlet::ServletContext.

Definition at line 433 of file App.cpp.

std::string container::App::getMimeType ( const std::string &  file  )  [virtual]

Returns the MIME type of the specified file, or null if the MIME type is not known. The MIME type is determined by the configuration of the servlet container, and may be specified in a web application deployment descriptor. Common MIME types are "text/html" and "image/gif".

Parameters:
file a String specifying the name of a file
Returns:
a String specifying the file's MIME type

Implements servlet::ServletContext.

Definition at line 437 of file App.cpp.

std::auto_ptr< std::set< std::string > > container::App::getResourcePaths ( const std::string &  path  )  [virtual]

Returns a directory-like listing of all the paths to resources within the web application whose longest sub-path matches the supplied path argument. Paths indicating subdirectory paths end with a '/'. The returned paths are all relative to the root of the web application and have a leading '/'. For example, for a web application containing<br>

/welcome.html
/catalog/index.html
/catalog/products.html
/catalog/offers/books.html
/catalog/offers/music.html
/customer/login.jsp
/WEB-INF/web.xml
/WEB-INF/classes/com.acme.OrderServlet.class,

getResourcePaths("/") returns {"/welcome.html", "/catalog/", "/customer/", "/WEB-INF/"}
getResourcePaths("/catalog/") returns {"/catalog/index.html", "/catalog/products.html", "/catalog/offers/"}.

Parameters:
path the partial path used to match the resources, which must start with a /
Returns:
a Set containing the directory listing, or null if there are no resources in the web application whose path begins with the supplied path.
Since:
Servlet 2.3

Implements servlet::ServletContext.

Definition at line 443 of file App.cpp.

References container::ServletMap< T >::getPath(), container::ServletMap< T >::getServlets(), container::ServletMap< T >::getSubpaths(), and maptop.

Here is the call graph for this function:

std::string container::App::getResource ( const std::string &  path  )  [virtual]

Returns a URL to the resource that is mapped to a specified path. The path must begin with a "/" and is interpreted as relative to the current context root.

This method allows the servlet container to make a resource available to servlets from any source. Resources can be located on a local or remote file system, in a database, or in a .war file.

The servlet container must implement the URL handlers and URLConnection objects that are necessary to access the resource.

This method returns null if no resource is mapped to the pathname.

Some containers may allow writing to the URL returned by this method using the methods of the URL class.

The resource content is returned directly, so be aware that requesting a .jsp page returns the JSP source code. Use a RequestDispatcher instead to include results of an execution.

This method has a different purpose than java.lang.Class.getResource, which looks up resources based on a class loader. This method does not use class loaders.

Parameters:
path a String specifying the path to the resource
Returns:
the resource located at the named path, or null if there is no resource at that path
Exceptions:
MalformedURLException if the pathname is not given in the correct form

Implements servlet::ServletContext.

Definition at line 456 of file App.cpp.

std::istream & container::App::getResourceAsStream ( const std::string &  path  )  [virtual]

Returns the resource located at the named path as an InputStream object.

The data in the InputStream can be of any type or length. The path must be specified according to the rules given in getResource. This method returns null if no resource exists at the specified path.

Meta-information such as content length and content type that is available via getResource method is lost when using this method.

The servlet container must implement the URL handlers and URLConnection objects necessary to access the resource.

This method is different from java.lang.Class.getResourceAsStream, which uses a class loader. This method allows servlet containers to make a resource available to a servlet from any location, without using a class loader.

Parameters:
path a String specifying the path to the resource
Returns:
the InputStream returned to the servlet, or null if no resource exists at the specified path

Implements servlet::ServletContext.

Definition at line 461 of file App.cpp.

servlet::RequestDispatcher * container::App::getRequestDispatcher ( const std::string &  path  )  [virtual]

Returns a servlet::RequestDispatcher object that acts as a wrapper for the resource located at the given path. A RequestDispatcher object can be used to forward a request to the resource or to include the resource in a response. The resource can be dynamic or static.

The pathname must begin with a "/" and is interpreted as relative to the current context root. Use getContext to obtain a RequestDispatcher for resources in foreign contexts. This method returns null if the ServletContext cannot return a RequestDispatcher.

Parameters:
path a String specifying the pathname to the resource
Returns:
a RequestDispatcher object that acts as a wrapper for the resource at the specified path, or null if the ServletContext cannot return a RequestDispatcher
See also:
servlet::RequestDispatcher

servlet::ServletContext::getContext

Implements servlet::ServletContext.

Definition at line 465 of file App.cpp.

References getServletContainer(), and name.

Referenced by container::HttpServletRequestImpl::getRequestDispatcher().

Here is the call graph for this function:

servlet::RequestDispatcher * container::App::getNamedDispatcher ( const std::string &  name  )  [virtual]

Returns a servlet::RequestDispatcher object that acts as a wrapper for the named servlet.

Servlets (and JSP pages also) may be given names via server administration or via a web application deployment descriptor. A servlet instance can determine its name using servlet::ServletConfig#getServletName.

This method returns null if the ServletContext cannot return a RequestDispatcher for any reason.

Parameters:
name a String specifying the name of a servlet to wrap
Returns:
a RequestDispatcher object that acts as a wrapper for the named servlet, or null if the ServletContext cannot return a RequestDispatcher
See also:
RequestDispatcher

ServletContext::getContext

ServletConfig::getServletName

Implements servlet::ServletContext.

Definition at line 472 of file App.cpp.

References getServletContainer().

Here is the call graph for this function:

void container::App::log ( const std::string &  msg  )  const [virtual]

Writes the specified message to a servlet log file, usually an event log. The name and type of the servlet log file is specific to the servlet container.

Parameters:
msg a String specifying the message to be written to the log file

Implements servlet::ServletContext.

Definition at line 368 of file App.cpp.

Referenced by log().

void container::App::log ( const std::string &  message,
const std::exception &  e 
) const [virtual]

Writes an explanatory message and a stack trace for a given Throwable exception to the servlet log file. The name and type of the servlet log file is specific to the servlet container, usually an event log.

Parameters:
message a std::string that describes the error or exception
e the std::exception error or exception

Implements servlet::ServletContext.

Definition at line 373 of file App.cpp.

References log().

Here is the call graph for this function:

std::string container::App::getRealPath ( const std::string &  path  )  [virtual]

Returns a String containing the real path for a given virtual path. For example, the path "/index.html" returns the absolute file path on the server's filesystem would be served by a request for "http://host/contextPath/index.html", where contextPath is the context path of this ServletContext..

The real path returned will be in a form appropriate to the computer and operating system on which the servlet container is running, including the proper path separators. This method returns null if the servlet container cannot translate the virtual path to a real path for any reason (such as when the content is being made available from a .war archive).

Parameters:
path a String specifying a virtual path
Returns:
a String specifying the real path, or null if the translation cannot be performed

Implements servlet::ServletContext.

Definition at line 476 of file App.cpp.

std::string container::App::getServerInfo (  )  [virtual]

Returns the name and version of the servlet container on which the servlet is running.

The form of the returned string is servername/versionnumber. For example, the JavaServer Web Development Kit may return the string JavaServer Web Dev Kit/1.0.

The servlet container may return other optional information after the primary string in parentheses, for example, JavaServer Web Dev Kit/1.0 (JDK 1.1.6; Windows NT 4.0 x86).

Returns:
a String containing at least the servlet container name and version number

Implements servlet::ServletContext.

Definition at line 480 of file App.cpp.

References CPPSERV_VERSION.

std::string container::App::getInitParameter ( const std::string &  name  )  [virtual]

Returns a String containing the value of the named context-wide initialization parameter, or null if the parameter does not exist.

This method can make available configuration information useful to an entire "web application". For example, it can provide a webmaster's email address or the name of a system that holds critical data.

Parameters:
name a String containing the name of the parameter whose value is requested
Returns:
a String containing at least the servlet container name and version number
See also:
ServletConfig::getInitParameter

Implements servlet::ServletContext.

Definition at line 484 of file App.cpp.

References m_params.

std::auto_ptr< std::vector< std::string > > container::App::getInitParameterNames (  )  [virtual]

Returns the names of the context's initialization parameters as an Enumeration of String objects, or an empty Enumeration if the context has no initialization parameters.

Returns:
an Enumeration of String objects containing the names of the context's initialization parameters
See also:
ServletConfig::getInitParameter

Implements servlet::ServletContext.

Definition at line 492 of file App.cpp.

References container::util::getMapKeyNames(), and m_params.

Here is the call graph for this function:

boost::shared_ptr< void > container::App::getAttribute ( const std::string &  name  )  [virtual]

Returns the servlet container attribute with the given name, or null if there is no attribute by that name. An attribute allows a servlet container to give the servlet additional information not already provided by this interface. See your server documentation for information about its attributes. A list of supported attributes can be retrieved using getAttributeNames.

The attribute is returned as a java.lang.Object or some subclass. Attribute names should follow the same convention as package names. The Java Servlet API specification reserves names matching java.*, javax.*, and sun.*.

Parameters:
name a String specifying the name of the attribute
Returns:
an Object containing the value of the attribute, or null if no attribute exists matching the given name
See also:
ServletContext::getAttributeNames

Implements servlet::ServletContext.

Definition at line 496 of file App.cpp.

References m_attrs.

std::auto_ptr< std::vector< std::string > > container::App::getAttributeNames (  )  [virtual]

Returns an Enumeration containing the attribute names available within this servlet context. Use the getAttribute method with an attribute name to get the value of an attribute.

Returns:
an Enumeration of attribute names
See also:
getAttribute

Implements servlet::ServletContext.

Definition at line 504 of file App.cpp.

References container::util::getMapKeyNames(), and m_attrs.

Here is the call graph for this function:

void container::App::setAttribute ( const std::string &  name,
boost::shared_ptr< void >  object 
) [virtual]

Binds an object to a given attribute name in this servlet context. If the name specified is already used for an attribute, this method will replace the attribute with the new to the new attribute.

If listeners are configured on the ServletContext the container notifies them accordingly.

If a null value is passed, the effect is the same as calling removeAttribute().

Attribute names should follow the same convention as package names. The Java Servlet API specification reserves names matching java.*, javax.*, and sun.*.

Parameters:
name a String specifying the name of the attribute
object an Object representing the attribute to be bound

Implements servlet::ServletContext.

Definition at line 508 of file App.cpp.

References m_attrs.

void container::App::removeAttribute ( const std::string &  name  )  [virtual]

Removes the attribute with the given name from the servlet context. After removal, subsequent calls to getAttribute to retrieve the attribute's value will return null.

If listeners are configured on the ServletContext the container notifies them accordingly.

Parameters:
name a String specifying the name of the attribute to be removed

Implements servlet::ServletContext.

Definition at line 512 of file App.cpp.

References m_attrs.

bool container::App::hasAttribute ( const std::string &  name  )  const [virtual]

[C++ Servlet API Extention]

Returns the false if no attribute of the given name exists. Returns true otherwize

Parameters:
name a String specifying the name of the attribute
Returns:
false if the attribute does not exist. true otherwize

Implements servlet::ServletContext.

Definition at line 518 of file App.cpp.

References m_attrs.

std::string container::App::getServletContextName (  )  const [virtual]

Returns:
Contest's name (which is same as application name)

Implements servlet::ServletContext.

Definition at line 363 of file App.cpp.

References name.

Referenced by container::ServletContainer::forward(), and container::HttpServletRequestImpl::getContextPath().

container::HttpSessionImpl * container::App::newSession (  )  [private]

This function must always be called with sessionLock locked.

Definition at line 236 of file App.cpp.

References container::util::getRandomString(), sessions, and sessionTimeout.

Referenced by getSession().

Here is the call graph for this function:

std::string container::App::makeSName ( const std::string &  name  )  [static, private]

Definition at line 409 of file App.cpp.


Friends And Related Function Documentation

friend class ServerConfig [friend]

Definition at line 32 of file App.h.


Member Data Documentation

Definition at line 36 of file App.h.

Referenced by getContext().

Definition at line 70 of file App.h.

Referenced by App(), and ~App().

std::string container::App::sessionCookieName [private]

Definition at line 74 of file App.h.

Referenced by getSessionCookieName().

Definition at line 75 of file App.h.

Referenced by newSession().

std::string container::App::fileSaveTemplate [private]

Definition at line 76 of file App.h.

Referenced by getFileSaveTemplate().

sptk::CWaiter container::App::sessionLock [private]

Definition at line 77 of file App.h.

Referenced by cleanSessions(), getSession(), and killAllSessions().

std::string container::App::name [private]

Definition at line 78 of file App.h.

Referenced by getRequestDispatcher(), and getServletContextName().

Definition at line 82 of file App.h.

Referenced by addInitParam(), getInitParameter(), and getInitParameterNames().

std::string container::App::m_uribase [private]

Definition at line 83 of file App.h.

Referenced by getUriBase().


The documentation for this class was generated from the following files:

SourceForge.net Logo

Authoright © Total Knowledge: 2001-2004