Base Class
#include <rwsf/servlet/Servlet.h>
rwsf::Servlet is an abstract base class for servlets. A servlet is a small piece of code that executes inside an Agent running on a server. Users will typically use one of the derived classes for creating their own servlets. To create a generic servlet use the rwsf::GenericServlet class. To create a servlet that uses the HTTP protocol use rwsf::HttpServlet.
virtual ~Servlet();
Destructor.
virtual void destroy() = 0;
Pure virtual function. In derived classes, warns the servlet that the Agent has removed the servlet. The destroy() function gives the servlet a chance to perform cleanup tasks and deallocate resources. The Agent will not forward requests to the servlet after calling this function. A servlet should perform all resource deallocation and cleanup tasks in the destroy() method rather than the servlet destructor.
virtual rwsf::ServletConfig getServletConfig() const;
Returns the rwsf::ServletConfig object that was used to initialize this servlet. The rwsf::ServletConfig object contains initialization and startup parameters for this servlet.
virtual std::string getServletInfo() const = 0;
Returns a string describing this servlet. By convention, the string typically includes information on the servlet author, version, and copyright.
virtual void init(const rwsf::ServletConfig& config) = 0;
Pure virtual function. In derived classes, initializes the servlet. After this function returns, the Agent is free to call the service() method with requests. The config object contains initialization and startup parameters. A servlet should perform all resource allocation in the init() method.
Derived classes should throw rwsf::ServletUnavailableException to indicate failure. If this function throws an exception, the Agent will not place the servlet into service and the servlet will not receive requests.
virtual void service(rwsf::ServletRequest& request, rwsf::ServletResponse& response) = 0;
Pure virtual function. In derived classes, the Agent calls this method when a request arrives for this servlet. The Agent will only forward requests after calling the init() method. This method may be called by multiple threads, so applications should take care to guard resources that might be shared across multiple threads.
rwsf_DEFINE_SERVLET(servletName)
Defines a function that returns an instance of servletName. The macro names the function by prefacing servletName with the word "create". The Agent uses the function to construct an instance of the servlet. For example, to deploy a servlet that uses the macro below:
rwsf_DEFINE_SERVLET(MyServlet)
the deployment descriptor for the servlet should contain the following line, where theDLL is the name of the shared library containing the servlet:
<servlet-class>theDLL.createMyServlet</servlet-class>
rwsf_DEFINE_SERVLET_NAME(servletName, createMethod)
Defines a function named createMethod that returns an instance of servletName. The Agent uses the function to construct an instance of the servlet. For example, to deploy a servlet that uses the macro below:
rwsf_DEFINE_SERVLET_NAME(MyServlet, createMyServletInstance)
the deployment descriptor for the servlet should contain the following line, where theDLL is the name of the shared library containing the servlet:
<servlet-class>theDLL.createMyServletInstance</servlet-class>
rwsf::GenericServletrwsf::HttpServletrwsf::ServletConfig
©2004-2007 Copyright Quovadx, Inc. All Rights Reserved.
Quovadx and Rogue Wave are registered trademarks of Quovadx, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.