Update of /cvsroot/sharedaemon/sharedaemon-ui-web/src/server/http/servlet In directory sc8-pr-cvs1:/tmp/cvs-serv19348/src/server/http/servlet Added Files: HttpServletResponse.h HttpServletResponse.cpp HttpServletRequest.h HttpServlet.cpp HttpServlet.h HttpServletRequest.cpp Log Message: 30/12/2003 Mikael Barbeaux * Implemented first versions of HttpServletRequest, HttpServletResponse and ServletException. * Implemented HttpServlet object. --- NEW FILE: HttpServletResponse.h --- /* * This file is part of webInterface. * Copyright (C) 2003 Mikael Barbeaux <mik...@us...> * * 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; either version 2 of the License, or * (at your option) any later version. * * 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. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef _HTTP_SERVLET_RESPONSE_H_ #define _HTTP_SERVLET_RESPONSE_H_ #include "../HttpResponse.h" class HttpServletResponse : public HttpResponse { public: HttpServletResponse(); ~HttpServletResponse(); }; #endif --- NEW FILE: HttpServletResponse.cpp --- #include "HttpServletResponse.h" HttpServletResponse::HttpServletResponse() {} HttpServletResponse::~HttpServletResponse() {} --- NEW FILE: HttpServletRequest.h --- /* * This file is part of webInterface. * Copyright (C) 2003 Mikael Barbeaux <mik...@us...> * * 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; either version 2 of the License, or * (at your option) any later version. * * 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. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef _HTTP_SERVLET_REQUEST_H_ #define _HTTP_SERVLET_REQUEST_H_ #include "../HttpRequest.h" class HttpServletRequest : public HttpRequest { public: HttpServletRequest(); ~HttpServletRequest(); }; #endif --- NEW FILE: HttpServlet.cpp --- /* * This file is part of webInterface. * Copyright (C) 2003 Mikael Barbeaux <mik...@us...> * * 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; either version 2 of the License, or * (at your option) any later version. * * 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. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "HttpServlet.h" #include "../HttpConstants.h" #include "../TextWriter.h" /** * Constructor for HttpServlet. * Does nothing. */ HttpServlet::HttpServlet() { } /** * Destructor for HttpServlet. * Does nothing. */ HttpServlet::~HttpServlet() { } /** * Inits the servlet. * Put here the code you want the servlet to execute at * loading. */ void HttpServlet::init() throw (ServletException) { } /** * Destroys the servlet. * Put here the code you want the servlet to execute at * unloading. */ void HttpServlet::destroy() throw (ServletException) { } /** * Processes the servlet execution. * This method is typically used to dispatch requests * to the doXXX methods, but you can override this method * if you want the same process to be executed for each * method. */ void HttpServlet::service(HttpServletRequest request, HttpServletResponse response) throw (ServletException, WriterException) { HttpMethod method = request.getMethod(); if(method == GET) doGet(request, response); else if(method == POST) doPost(request, response); else if(method == HEAD) doHead(request, response); else throw ServletException(BadServletRequestExcp, "The received request isn't Servlet compliant.", "HttpServlet::service"); } /** * Processes a GET http method. * This method is called by the servlet service() method * to process the execution of a GET http method. */ void HttpServlet::doGet(HttpServletRequest request, HttpServletResponse response) throw (ServletException, WriterException) { // Create a simple response TextWriter *writer = (TextWriter*) response.getWriter(); *writer << "<html><body>GET method received</body></html>"; writer->close(); } /** * Processes a POST http method. * This method is called by the servlet service() method * to process the execution of a POST http method. */ void HttpServlet::doPost(HttpServletRequest request, HttpServletResponse response) throw (ServletException, WriterException) { // Create a simple response TextWriter *writer = (TextWriter*) response.getWriter(); *writer << "<html><body>POST method received</body></html>"; writer->close(); } /** * Processes a HEAD http method. * This method is called by the servlet service() method * to process the execution of a HEAD http method. */ void HttpServlet::doHead(HttpServletRequest request, HttpServletResponse response) throw (ServletException, WriterException) { // Create a simple response TextWriter *writer = (TextWriter*) response.getWriter(); *writer << "<html><body>HEAD method received</body></html>"; writer->close(); } --- NEW FILE: HttpServlet.h --- /* * This file is part of webInterface. * Copyright (C) 2003 Mikael Barbeaux <mik...@us...> * * 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; either version 2 of the License, or * (at your option) any later version. * * 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. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef _HTTP_SERVLET_H_ #define _HTTP_SERVLET_H_ #include "HttpServletRequest.h" #include "HttpServletResponse.h" #include "../../../exceptions/ServletException.h" #include "../../../exceptions/WriterException.h" /** * Defines an abstract Http servlet. * This servlet can respond to GET, HEAD and POST http methods, * and needs to be extended in another class. */ class HttpServlet{ public: /** * Constructor for HttpServlet. * Does nothing. */ HttpServlet(); /** * Destructor for HttpServlet. * Does nothing. */ virtual ~HttpServlet(); /** * Inits the servlet. * Put here the code you want the servlet to execute at * loading. */ virtual void init() throw (ServletException); /** * Destroys the servlet. * Put here the code you want the servlet to execute at * unloading. */ virtual void destroy() throw (ServletException); /** * Processes the servlet execution. * This method is typically used to dispatch requests * to the doXXX methods, but you can override this method * if you want the same process to be executed for each * method. * * @param request - The request received * @param response - The response to build */ virtual void service(HttpServletRequest request, HttpServletResponse response) throw (ServletException, WriterException); /** * Processes a GET http method. * This method is called by the servlet service() method * to process the execution of a GET http method. * * @param request - The request received * @param response - The response to build */ virtual void doGet(HttpServletRequest request, HttpServletResponse response) throw (ServletException, WriterException); /** * Processes a POST http method. * This method is called by the servlet service() method * to process the execution of a POST http method. * * @param request - The request received * @param response - The response to build */ virtual void doPost(HttpServletRequest request, HttpServletResponse response) throw (ServletException, WriterException); /** * Processes a HEAD http method. * This method is called by the servlet service() method * to process the execution of a HEAD http method. * * @param request - The request received * @param response - The response to build */ virtual void doHead(HttpServletRequest request, HttpServletResponse response) throw (ServletException, WriterException); }; #endif --- NEW FILE: HttpServletRequest.cpp --- #include "HttpServletRequest.h" HttpServletRequest::HttpServletRequest() {} HttpServletRequest::~HttpServletRequest() {} |