Source Code Cross Referenced for MessageLossSimulator.java in  » ESB » celtix-1.0 » org » objectweb » celtix » systest » ws » rm » 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 » ESB » celtix 1.0 » org.objectweb.celtix.systest.ws.rm 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.objectweb.celtix.systest.ws.rm;
002:
003:        import java.util.Iterator;
004:        import java.util.Map;
005:        import java.util.Set;
006:
007:        import javax.xml.namespace.QName;
008:        import javax.xml.soap.Name;
009:        import javax.xml.soap.Node;
010:        import javax.xml.soap.SOAPException;
011:        import javax.xml.soap.SOAPHeader;
012:        import javax.xml.soap.SOAPHeaderElement;
013:        import javax.xml.ws.handler.MessageContext;
014:        import javax.xml.ws.handler.soap.SOAPHandler;
015:        import javax.xml.ws.handler.soap.SOAPMessageContext;
016:
017:        import static javax.xml.ws.handler.MessageContext.MESSAGE_OUTBOUND_PROPERTY;
018:
019:        /**
020:         * Discards a protion of inbound application-level messages to simulate 
021:         * message loss. Note that out-of-band WS-RM protocol messages are always
022:         * left intact.  
023:         */
024:        public class MessageLossSimulator implements 
025:                SOAPHandler<SOAPMessageContext> {
026:            protected static final String WSA_NAMESPACE_URI = "http://schemas.xmlsoap.org/ws/2004/08/addressing";
027:            protected static final String WSA_ACTION = "Action";
028:            protected static final String WSRM_NAMESPACE_URI = "http://schemas.xmlsoap.org/ws/2005/02/rm";
029:
030:            /**
031:             * Discard every second message
032:             */
033:            private static final int LOSS_FACTOR = 2;
034:            private int inboundMessageCount;
035:
036:            public void init(Map<String, Object> map) {
037:            }
038:
039:            public Set<QName> getHeaders() {
040:                return null;
041:            }
042:
043:            public void close(MessageContext context) {
044:            }
045:
046:            public void destroy() {
047:            }
048:
049:            public boolean handleMessage(SOAPMessageContext context) {
050:                System.out.println("*** MessageLoss: handling message");
051:                return continueProcessing(context);
052:            }
053:
054:            public boolean handleFault(SOAPMessageContext context) {
055:                return true;
056:            }
057:
058:            /**
059:             * @return true if the current message is outbound
060:             */
061:            protected boolean isOutbound(SOAPMessageContext context) {
062:                Boolean outbound = (Boolean) context
063:                        .get(MESSAGE_OUTBOUND_PROPERTY);
064:                return outbound != null && outbound.booleanValue();
065:            }
066:
067:            /**
068:             * @return the WS-A Action header
069:             */
070:            protected String getAction(SOAPMessageContext context) {
071:                String action = null;
072:                try {
073:                    SOAPHeader header = context.getMessage().getSOAPPart()
074:                            .getEnvelope().getHeader();
075:                    Iterator headerElements = header.examineAllHeaderElements();
076:                    while (headerElements.hasNext()) {
077:                        SOAPHeaderElement headerElement = (SOAPHeaderElement) headerElements
078:                                .next();
079:                        Name headerName = headerElement.getElementName();
080:                        if (WSA_NAMESPACE_URI.equals(headerName.getURI())
081:                                && WSA_ACTION.equals(headerName.getLocalName())) {
082:                            Iterator children = headerElement
083:                                    .getChildElements();
084:                            if (children.hasNext()) {
085:                                action = ((Node) children.next()).getValue();
086:                            }
087:                        }
088:                    }
089:                } catch (SOAPException e) {
090:                    System.out.println("*** failed to determine WS-A Action: "
091:                            + e);
092:                }
093:                return action;
094:            }
095:
096:            /**
097:             * @return true if the current message should not be discarded
098:             */
099:            private synchronized boolean continueProcessing(
100:                    SOAPMessageContext context) {
101:                System.out.println("*** inboundMessageCount: "
102:                        + inboundMessageCount);
103:                if (!(isOutbound(context) || isRMOutOfBand(context))
104:                        && ++inboundMessageCount % LOSS_FACTOR == 0
105:                        && inboundMessageCount <= 4) {
106:                    discardWSHeaders(context);
107:                    discardBody(context);
108:                    System.out
109:                            .println("*** Discarding current inbound message ***");
110:                    return false;
111:                }
112:                return true;
113:            }
114:
115:            /**
116:             * @return true if this is a WS-RM out-of-band protocol message
117:             */
118:            protected boolean isRMOutOfBand(SOAPMessageContext context) {
119:                String action = getAction(context);
120:                return action != null && action.startsWith(WSRM_NAMESPACE_URI);
121:            }
122:
123:            /**
124:             * Discard any WS-* headers from the message
125:             */
126:            private void discardWSHeaders(SOAPMessageContext context) {
127:                try {
128:                    SOAPHeader header = context.getMessage().getSOAPPart()
129:                            .getEnvelope().getHeader();
130:                    Iterator headerElements = header.examineAllHeaderElements();
131:                    while (headerElements.hasNext()) {
132:                        SOAPHeaderElement headerElement = (SOAPHeaderElement) headerElements
133:                                .next();
134:                        Name headerName = headerElement.getElementName();
135:                        if (WSRM_NAMESPACE_URI.equals(headerName.getURI())
136:                                || WSRM_NAMESPACE_URI.equals(headerName
137:                                        .getURI())) {
138:                            headerElement.detachNode();
139:                        }
140:                    }
141:                } catch (SOAPException e) {
142:                    System.out.println("*** discard WS headers failed: " + e);
143:                }
144:            }
145:
146:            /**
147:             * Discard the body from the message to avoid assertion failure when
148:             * unmarshaling partial response (occuring when system tests are run in
149:             * fork mode 'none')
150:             */
151:            private void discardBody(SOAPMessageContext context) {
152:                try {
153:                    context.getMessage().getSOAPBody().removeContents();
154:                } catch (SOAPException e) {
155:                    System.out.println("*** discard body failed: " + e);
156:                }
157:            }
158:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.