CPPSERV


Home Projects Jobs Clientele Contact

cppserv


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Added test functionality for Util.h servlet



From: Sergey Jukov <sergey@total-knowledge.com>

---
 utils/utils.cpp |   60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 utils/utils.h   |   42 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 102 insertions(+), 0 deletions(-)

diff --git a/utils/utils.cpp b/utils/utils.cpp
new file mode 100644
index 0000000..f3c7f44
--- /dev/null
+++ b/utils/utils.cpp
@@ -0,0 +1,60 @@
+/***************************************************************************
+ *   Copyright (C) 2004 by Ilya A. Volynets-Evenbakh                       *
+ *   ilya@total-knowledge.com                                              *
+ *                                                                         *
+ *   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 "utils.h"
+#include <servlet/Util.h>
+
+void UtilServlet::service(servlet::HttpServletRequest& req, servlet::HttpServletResponse& resp)
+{
+	std::ostream &out=resp.getOutputStream();
+	std::string myUrl=req.getParameter("param");
+
+	utilHeader(out);
+
+	out << "<br><form name=\"testurl\" action=\"#\"><b>Please enter URL:</b>";
+
+	out << "&nbsp;&nbsp;<input type=\"text\" name=\"param\">" << "&nbsp;&nbsp;<input type=\"submit\" name=\"submit\"><br><br>";
+
+	if(myUrl != ""){
+
+	  std::string dest = "";
+	  std::string myEncodedUrl = servlet::util::urlEncode(myUrl, dest);
+	  std::string myDecodedUrl = servlet::util::urlDecode(myUrl);
+	  servlet::util::urlInPlaceDecode(myDecodedUrl);
+
+	  out << "<b>Original URL</b> = " << myUrl << "<br><br>";
+	  out << "<b>Decoded URL</b> = " << myDecodedUrl << "<br><br>";
+	  out << "<b>Encoded URL</b> = " << myEncodedUrl << "\n";
+
+	}
+
+	utilFooter(out);
+}
+
+void UtilServlet::utilHeader(std::ostream& out)
+{
+	out << "<html>\n <head>\n  <title>Sample Util Servlet for CPPSERV</title>\n </head>\n <body>";
+}
+
+void UtilServlet::utilFooter(std::ostream& out)
+{
+	out << "\n </form></body>\n</html>";
+}
+
+EXPORT_SERVLET(UtilServlet)
diff --git a/utils/utils.h b/utils/utils.h
new file mode 100644
index 0000000..f82a1d4
--- /dev/null
+++ b/utils/utils.h
@@ -0,0 +1,42 @@
+/***************************************************************************
+ *   Copyright (C) 2004 by Ilya A. Volynets-Evenbakh                       *
+ *   ilya@total-knowledge.com                                              *
+ *                                                                         *
+ *   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 TESTSERVLET2_H
+#define TESTSERVLET2_H
+
+#include <servlet/HttpServlet.h>
+#include <servlet/HttpServletRequest.h>
+#include <servlet/HttpServletResponse.h>
+#include <iostream>
+
+/**
+This servlet demonstrates work of URL decode/encode functions.
+
+@author Sergey Jukov
+*/
+class UtilServlet : public servlet::HttpServlet
+{
+private:
+	void utilHeader(std::ostream&);
+	void utilFooter(std::ostream&);
+public:
+	virtual void service(servlet::HttpServletRequest& req, servlet::HttpServletResponse& resp);
+};
+
+#endif
-- 
1.4.2


Authoright © Total Knowledge: 2001-2008