Source Code Cross Referenced for XUnreliableServiceServlet.java in  » XML-UI » xui32 » com » xoetrope » service » servlet » 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 » XML UI » xui32 » com.xoetrope.service.servlet 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.xoetrope.service.servlet;
002:
003:        import java.io.IOException;
004:        import java.io.PrintWriter;
005:        import java.net.URLEncoder;
006:        import javax.servlet.ServletException;
007:        import javax.servlet.http.HttpServletRequest;
008:        import javax.servlet.http.HttpServletResponse;
009:
010:        /**
011:         * Extends XServiceServlet by adding a reliability parameter that can be used to
012:         * control how the response is returned. This parameter is defined by a number
013:         * of constants and set with the setRiability method. The service is intended to
014:         * simulate the breakdown in communication services so that yo can test the 
015:         * resiliance of your application. Normally the class would not appear in 
016:         * anything other than a stress test environment.
017:         *
018:         * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
019:         * the GNU Public License (GPL), please see license.txt for more details. If
020:         * you make commercial use of this software you must purchase a commercial
021:         * license from Xoetrope.</p>
022:         * <p> $Revision: 1.5 $</p>
023:         */
024:        public class XUnreliableServiceServlet extends XServiceServlet {
025:            /**
026:             * A proper response is returned to the client as soon as is possible.
027:             */
028:            public final static int RELIABLE = 0x1;
029:
030:            /**
031:             * An incomplete response is returned to the client. The response will be
032:             * truncated by approximately 50 percent.
033:             */
034:            public final static int PARTIAL_RESPONSE = 0x2;
035:
036:            /**
037:             * Additional bytes are appended to an otherwise correct response
038:             */
039:            public final static int EXTRA_RESPONSE = 0x4;
040:
041:            /**
042:             * No response is made and the request returns immediately
043:             */
044:            public final static int NO_RESPONSE = 0x8;
045:
046:            /**
047:             * No response is made and nothing is returned to the client
048:             */
049:            public final static int TIME_OUT = 0x10;
050:
051:            /**
052:             * The returned values are corrupt.
053:             */
054:            public final static int CORRUPT_RESPONSE = 0x20;
055:
056:            /**
057:             * An http error is returned as part of the response
058:             */
059:            public final static int ERROR_RESPONSE = 0x40;
060:
061:            /**
062:             * The request is only processed on every fourth attempt
063:             */
064:            public final static int FOURTH_RESPONSE = 0x80;
065:
066:            /**
067:             * Construct a new servlet with the default options
068:             */
069:            public XUnreliableServiceServlet() {
070:            }
071:
072:            /**
073:             * Initialize the servlet
074:             */
075:            public void init() throws ServletException {
076:                super .init();
077:                getServletContext().setAttribute("reliability",
078:                        new Integer(RELIABLE).toString());
079:                getServletContext().setAttribute("requestCounter",
080:                        new Integer(0).toString());
081:            }
082:
083:            /**
084:             * Process the HTTP Get request
085:             * @param request the incoming request
086:             * @param response the response object
087:             */
088:            public void doGet(HttpServletRequest request,
089:                    HttpServletResponse response) throws ServletException,
090:                    IOException {
091:                int requestCounter = new Integer((String) getServletContext()
092:                        .getAttribute("requestCounter")).intValue();
093:                getServletContext().setAttribute("requestCounter",
094:                        new Integer(requestCounter + 1).toString());
095:                try {
096:                    Object reliability = request.getParameter("reliability");
097:                    if (reliability != null)
098:                        setReliability(reliability.toString());
099:                    else
100:                        reliability = getReliability();
101:
102:                    Object result = URLEncoder.encode((String) getResponse(
103:                            request, response), "UTF-8");
104:                    if (result != null) {
105:
106:                        PrintWriter out = response.getWriter();
107:                        response.setContentType(CONTENT_TYPE);
108:                        String resStr = result.toString();
109:                        int len = resStr.length();
110:                        int reliabilityValue = Integer.parseInt(reliability
111:                                .toString());
112:                        if ((reliabilityValue & RELIABLE) == RELIABLE)
113:                            out.print(resStr);
114:                        else if ((reliabilityValue & PARTIAL_RESPONSE) == PARTIAL_RESPONSE)
115:                            out.print(resStr.substring(0, len / 2));
116:                        else if ((reliabilityValue & EXTRA_RESPONSE) == EXTRA_RESPONSE) {
117:                            out.print(resStr);
118:                            out.print("EXTRA INSERTED DATA HERE BY REQUEST");
119:                        } else if ((reliabilityValue & NO_RESPONSE) == NO_RESPONSE)
120:                            response.reset();
121:                        else if ((reliabilityValue & CORRUPT_RESPONSE) == CORRUPT_RESPONSE) {
122:                            out.print(resStr.substring(len / 2));
123:                            out.print(resStr.substring(0, len / 2));
124:                        } else if ((reliabilityValue & FOURTH_RESPONSE) == FOURTH_RESPONSE) {
125:                            if ((requestCounter % 4) == 0)
126:                                out.print(resStr);
127:                            else
128:                                response
129:                                        .sendError(response.SC_INTERNAL_SERVER_ERROR);
130:                        }
131:
132:                        if ((reliabilityValue & ERROR_RESPONSE) == ERROR_RESPONSE)
133:                            response
134:                                    .sendError(response.SC_INTERNAL_SERVER_ERROR);
135:
136:                        if ((reliabilityValue & TIME_OUT) == TIME_OUT)
137:                            Thread.currentThread().sleep(100000000l);
138:
139:                        out.flush();
140:                    } else
141:                        response.sendError(response.SC_BAD_REQUEST);
142:                } catch (Exception ex) {
143:                    ex.printStackTrace();
144:                }
145:            }
146:
147:            /**
148:             * Sets a reliablity flag for the servlet to indicate how the servlet is to
149:             * handle the response
150:             * @param value the new reliability value
151:             */
152:            private void setReliability(String value) {
153:                getServletContext().setAttribute("reliability", value);
154:            }
155:
156:            /**
157:             * Gets the reliablity flag for the servlet to indicating how the servlet is to
158:             * handle the response
159:             * @return the new reliability value
160:             */
161:            private Object getReliability() {
162:                return getServletContext().getAttribute("reliability");
163:            }
164:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.