Source Code Cross Referenced for TestServlet.java in  » ERP-CRM-Financial » Kuali-Financial-System » edu » iu » uis » eden » test » web » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » Kuali Financial System » edu.iu.uis.eden.test.web 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2005-2007 The Kuali Foundation.
003:         * 
004:         * 
005:         * Licensed under the Educational Community License, Version 1.0 (the "License");
006:         * you may not use this file except in compliance with the License.
007:         * You may obtain a copy of the License at
008:         * 
009:         * http://www.opensource.org/licenses/ecl1.php
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        // Created on May 8, 2006
018:        package edu.iu.uis.eden.test.web;
019:
020:        import java.io.IOException;
021:        import java.util.Arrays;
022:        import java.util.Date;
023:        import java.util.Iterator;
024:        import java.util.List;
025:        import java.util.Map;
026:        import java.util.Random;
027:
028:        import javax.servlet.ServletException;
029:        import javax.servlet.ServletOutputStream;
030:        import javax.servlet.http.HttpServlet;
031:        import javax.servlet.http.HttpServletRequest;
032:        import javax.servlet.http.HttpServletResponse;
033:
034:        /**
035:         * A trivial servlet which echoes back request params, and inserts a few
036:         * other parameters which can be used for testing purposes, into parseable response metadata.
037:         * @author Aaron Hamid (arh14 at cornell dot edu)
038:         */
039:        public class TestServlet extends HttpServlet {
040:            private static final Random RANDOM = new Random();
041:
042:            private static String getValue(Object value) {
043:                if (value instanceof  String[]) {
044:                    String[] va = (String[]) value;
045:                    if (va.length > 0) {
046:                        value = va[0];
047:                    } else {
048:                        value = "";
049:                    }
050:                }
051:                return String.valueOf(value);
052:            }
053:
054:            private static String redact(Object o) {
055:                return "<!-- [transient start] -->" + String.valueOf(o)
056:                        + "<!-- [transient end] -->";
057:            }
058:
059:            protected void service(HttpServletRequest request,
060:                    HttpServletResponse response) throws ServletException,
061:                    IOException {
062:                Map params = request.getParameterMap();
063:                /* some data to redact */
064:                Date date = new Date();
065:                int rand = RANDOM.nextInt(10000);
066:                /* some data that we will persist accross requests */
067:                String s = request.getParameter("persist_num");
068:                boolean first_creation;
069:                int persist_num;
070:                if (s == null) {
071:                    persist_num = RANDOM.nextInt(10000);
072:                    first_creation = true;
073:                } else {
074:                    persist_num = Integer.parseInt(s);
075:                    first_creation = false;
076:                }
077:
078:                /* list of incoming params we know to be "variable" and thus need to be redacted
079:                 * We only need this because we are iterating through and printing all the incoming
080:                 * params arbitrarily...so we need to know which ones to skip.  A real servlet wouldn't be
081:                 * arbitrarily echoing parameters and would intrinsically know about output that needs to be redacted 
082:                 */
083:                final List redact_params = Arrays.asList(new String[] {
084:                        "persist_num",
085:                        "TheRandomNumberWeGotFromTheInitialRequest" });
086:
087:                ServletOutputStream out = response.getOutputStream();
088:
089:                out.println("Method: " + request.getMethod() + "\r\n\r\n");
090:
091:                Iterator it = params.entrySet().iterator();
092:                /* first print out parameters for human interpretation */
093:                out.println("Request parameters:\r\n");
094:                while (it.hasNext()) {
095:                    Map.Entry entry = (Map.Entry) it.next();
096:                    out.print(entry.getKey() + ": ");
097:                    boolean redact = redact_params.contains(entry.getKey());
098:                    if (redact) {
099:                        out.print("<!-- [transient start] -->");
100:                    }
101:                    out.print(getValue(entry.getValue()));
102:                    if (redact) {
103:                        out.print("<!-- [transient end] -->");
104:                    }
105:                    out.print("\r\n");
106:                }
107:
108:                /* now let's put print the data that should be redacted before comparison */
109:                out.print("\r\nSome data to redact:\r\n");
110:                out.print("Date: " + redact(date) + "\r\n");
111:                out.print("Random number: " + redact(new Integer(rand))
112:                        + "\r\n");
113:                /* now print the persistent number */
114:                out.print("Persistent number: "
115:                        + redact(new Integer(persist_num))
116:                        + (first_creation ? " (created)"
117:                                : " (taken from input parameters)"));
118:
119:                /* then use meta-data notation to print those parameters in a format that can be interpreted
120:                 * by the script
121:                 */
122:                out
123:                        .print("\r\n<!-- Meta-data block for automation/testing\r\n");
124:                it = params.entrySet().iterator();
125:                while (it.hasNext()) {
126:                    Map.Entry entry = (Map.Entry) it.next();
127:                    boolean redact = redact_params.contains(entry.getKey());
128:                    if (redact) {
129:                        out.print("redacting: " + entry.getKey() + "\r\n");
130:                        out.print("[transient start]\r\n");
131:                    }
132:                    out.print("[var " + entry.getKey() + "="
133:                            + getValue(entry.getValue()) + "]\r\n");
134:                    if (redact) {
135:                        out.print("[transient end]\r\n");
136:                    }
137:                }
138:                /* now let's put some data to be redacted in there
139:                 * the script knows to redact anything between [transient start]/[transient end]
140:                 * (maybe that is not the best choice of words)
141:                 */
142:                out.print("some data to redact follows\r\n");
143:                out.print("[transient start]\r\n");
144:                out.print("[var date=" + date + "]\r\n");
145:                out.print("[var random_number=" + rand + "]\r\n");
146:                /* finally write that number we want to persist accross requests
147:                 * This is just a normal variable.  We will configure our script to
148:                 * look for it, and resend it, to simulate, for example, a docId.
149:                 * It is in the "transient" block because it is random (so perhaps
150:                 * "transient" should be changed to "variable" or "dynamic" or simply "redact"
151:                 * to contrast against "static" unchanging content which can be easily
152:                 * compared for verification.  The redaction will occur AFTER
153:                 * the variable is parsed.
154:                 */
155:                out.print("[var persist_num=" + persist_num + "]\r\n");
156:                out.print("[transient end]\r\n");
157:                out.print("-->");
158:            }
159:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.