Source Code Cross Referenced for EnginePausingTest.java in  » Web-Services-AXIS2 » kernal » org » apache » axis2 » engine » 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 » Web Services AXIS2 » kernal » org.apache.axis2.engine 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements. See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership. The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License. You may obtain a copy of the License at
009:         *
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied. See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.
018:         */
019:
020:        package org.apache.axis2.engine;
021:
022:        import junit.framework.TestCase;
023:        import org.apache.axiom.om.OMAbstractFactory;
024:        import org.apache.axiom.soap.SOAPFactory;
025:        import org.apache.axis2.AxisFault;
026:        import org.apache.axis2.Constants;
027:        import org.apache.axis2.addressing.EndpointReference;
028:        import org.apache.axis2.context.ConfigurationContext;
029:        import org.apache.axis2.context.MessageContext;
030:        import org.apache.axis2.description.AxisBinding;
031:        import org.apache.axis2.description.AxisBindingOperation;
032:        import org.apache.axis2.description.AxisEndpoint;
033:        import org.apache.axis2.description.AxisOperation;
034:        import org.apache.axis2.description.AxisService;
035:        import org.apache.axis2.description.HandlerDescription;
036:        import org.apache.axis2.description.InOutAxisOperation;
037:        import org.apache.axis2.description.TransportInDescription;
038:        import org.apache.axis2.description.TransportOutDescription;
039:        import org.apache.axis2.dispatchers.AddressingBasedDispatcher;
040:        import org.apache.axis2.dispatchers.RequestURIBasedDispatcher;
041:        import org.apache.axis2.dispatchers.SOAPActionBasedDispatcher;
042:        import org.apache.axis2.dispatchers.SOAPMessageBodyBasedDispatcher;
043:        import org.apache.axis2.handlers.AbstractHandler;
044:        import org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver;
045:        import org.apache.axis2.receivers.RawXMLINOutMessageReceiver;
046:        import org.apache.axis2.transport.http.CommonsHTTPTransportSender;
047:
048:        import javax.xml.namespace.QName;
049:        import java.util.ArrayList;
050:
051:        public class EnginePausingTest extends TestCase {
052:
053:            public static final String FAULT_IDX = "FaultIndex";
054:            public static final String FAULT_REASON = "I faulted because I was told to!";
055:
056:            private QName serviceName = new QName("NullService");
057:            private QName operationName = new QName("DummyOp");
058:            private ConfigurationContext configContext;
059:
060:            private TransportOutDescription transportOut;
061:            private TransportInDescription transportIn;
062:            private MessageContext mc;
063:            private ArrayList executedHandlers;
064:
065:            public EnginePausingTest(String arg0) {
066:                super (arg0);
067:                executedHandlers = new ArrayList();
068:                AxisConfiguration engineRegistry = new AxisConfiguration();
069:                configContext = new ConfigurationContext(engineRegistry);
070:                configContext.setServicePath(Constants.DEFAULT_SERVICES_PATH);
071:                configContext.setContextRoot("axis2");
072:                transportOut = new TransportOutDescription("null");
073:                transportOut.setSender(new CommonsHTTPTransportSender());
074:                transportIn = new TransportInDescription("null");
075:
076:            }
077:
078:            protected void setUp() throws Exception {
079:
080:                AxisService service = new AxisService(serviceName
081:                        .getLocalPart());
082:                configContext.getAxisConfiguration().addService(service);
083:                configContext.getAxisConfiguration().addMessageReceiver(
084:                        "http://www.w3.org/2004/08/wsdl/in-only",
085:                        new RawXMLINOnlyMessageReceiver());
086:                configContext.getAxisConfiguration().addMessageReceiver(
087:                        "http://www.w3.org/2004/08/wsdl/in-out",
088:                        new RawXMLINOutMessageReceiver());
089:
090:                DispatchPhase dispatchPhase = new DispatchPhase();
091:
092:                dispatchPhase.setName("Dispatch");
093:
094:                AddressingBasedDispatcher abd = new AddressingBasedDispatcher();
095:
096:                abd.initDispatcher();
097:
098:                RequestURIBasedDispatcher rud = new RequestURIBasedDispatcher();
099:
100:                rud.initDispatcher();
101:
102:                SOAPActionBasedDispatcher sabd = new SOAPActionBasedDispatcher();
103:
104:                sabd.initDispatcher();
105:
106:                SOAPMessageBodyBasedDispatcher smbd = new SOAPMessageBodyBasedDispatcher();
107:
108:                smbd.initDispatcher();
109:
110:                dispatchPhase.addHandler(abd);
111:                dispatchPhase.addHandler(rud);
112:                dispatchPhase.addHandler(sabd);
113:                dispatchPhase.addHandler(smbd);
114:                configContext.getAxisConfiguration().getInFlowPhases().add(
115:                        dispatchPhase);
116:                AxisOperation axisOp = new InOutAxisOperation(operationName);
117:                axisOp.setMessageReceiver(new MessageReceiver() {
118:                    public void receive(MessageContext messageCtx) {
119:
120:                    }
121:                });
122:                service.addOperation(axisOp);
123:
124:                AxisEndpoint endpoint = new AxisEndpoint();
125:                endpoint.setName("NullService");
126:
127:                AxisBinding binding = new AxisBinding();
128:                AxisBindingOperation bindingOp = new AxisBindingOperation();
129:
130:                bindingOp.setAxisOperation(axisOp);
131:                binding.addChild(bindingOp);
132:                endpoint.setBinding(binding);
133:                service.addEndpoint(endpoint.getName(), endpoint);
134:                service.setEndpointName(endpoint.getName());
135:
136:                service.mapActionToOperation(operationName.getLocalPart(),
137:                        axisOp);
138:
139:                mc = configContext.createMessageContext();
140:                mc.setTransportIn(transportIn);
141:                mc.setTransportOut(transportOut);
142:
143:                mc.setTransportOut(transportOut);
144:                mc.setServerSide(true);
145:                //        mc.setProperty(MessageContext.TRANSPORT_OUT, System.out);
146:                SOAPFactory omFac = OMAbstractFactory.getSOAP11Factory();
147:                mc.setEnvelope(omFac.getDefaultEnvelope());
148:
149:                Phase phase1 = new Phase("1");
150:                phase1.addHandler(new TempHandler(1));
151:                phase1.addHandler(new TempHandler(2));
152:                phase1.addHandler(new TempHandler(3));
153:                phase1.addHandler(new TempHandler(4));
154:                phase1.addHandler(new TempHandler(5));
155:                phase1.addHandler(new TempHandler(6));
156:                phase1.addHandler(new TempHandler(7));
157:                phase1.addHandler(new TempHandler(8));
158:                phase1.addHandler(new TempHandler(9));
159:
160:                Phase phase2 = new Phase("2");
161:                phase2.addHandler(new TempHandler(10));
162:                phase2.addHandler(new TempHandler(11));
163:                phase2.addHandler(new TempHandler(12));
164:                phase2.addHandler(new TempHandler(13));
165:                phase2.addHandler(new TempHandler(14));
166:                phase2.addHandler(new TempHandler(15, true));
167:                phase2.addHandler(new TempHandler(16));
168:                phase2.addHandler(new TempHandler(17));
169:                phase2.addHandler(new TempHandler(18));
170:
171:                Phase phase3 = new Phase("3");
172:                phase3.addHandler(new TempHandler(19));
173:                phase3.addHandler(new TempHandler(20));
174:                phase3.addHandler(new TempHandler(21));
175:                phase3.addHandler(new TempHandler(22));
176:                phase3.addHandler(new TempHandler(23));
177:                phase3.addHandler(new TempHandler(24));
178:                phase3.addHandler(new TempHandler(25));
179:                phase3.addHandler(new TempHandler(26));
180:                phase3.addHandler(new TempHandler(27));
181:
182:                //TODO
183:                axisOp.getRemainingPhasesInFlow().add(phase1);
184:                axisOp.getRemainingPhasesInFlow().add(phase2);
185:                axisOp.getRemainingPhasesInFlow().add(phase3);
186:
187:                mc.setWSAAction(operationName.getLocalPart());
188:                mc.setSoapAction(operationName.getLocalPart());
189:                //        System.out.flush();
190:
191:            }
192:
193:            public void testReceive() throws Exception {
194:                mc.setTo(new EndpointReference("/axis2/services/NullService"));
195:                mc.setWSAAction("DummyOp");
196:                AxisEngine.receive(mc);
197:                assertEquals(14, executedHandlers.size());
198:                for (int i = 0; i < 14; i++) {
199:                    assertEquals(
200:                            ((Integer) executedHandlers.get(i)).intValue(),
201:                            i + 1);
202:                }
203:                AxisEngine.resume(mc);
204:
205:                assertEquals(27, executedHandlers.size());
206:                for (int i = 15; i < 27; i++) {
207:                    assertEquals(
208:                            ((Integer) executedHandlers.get(i)).intValue(),
209:                            i + 1);
210:                }
211:            }
212:
213:            public void testFlowComplete() throws Exception {
214:                mc.setTo(new EndpointReference("/axis2/services/NullService"));
215:                mc.setWSAAction("DummyOp");
216:
217:                // Fault on Handler #5
218:                mc.setProperty(FAULT_IDX, new Integer(5));
219:
220:                try {
221:                    AxisEngine.receive(mc);
222:                } catch (AxisFault axisFault) {
223:                    // Expected this fault.
224:                    assertEquals(4, executedHandlers.size());
225:                    return;
226:                }
227:                fail("Expected fault did not occur");
228:            }
229:
230:            public class TempHandler extends AbstractHandler {
231:                private Integer index;
232:                private boolean pause = false;
233:
234:                public TempHandler(int index, boolean pause) {
235:                    this .index = new Integer(index);
236:                    this .pause = pause;
237:                    init(new HandlerDescription("handler" + index));
238:                }
239:
240:                public TempHandler(int index) {
241:                    this .index = new Integer(index);
242:                    init(new HandlerDescription("handler" + index));
243:                }
244:
245:                public InvocationResponse invoke(MessageContext msgContext)
246:                        throws AxisFault {
247:                    if (pause) {
248:                        msgContext.pause();
249:                        pause = false;
250:                        return InvocationResponse.SUSPEND;
251:                    }
252:
253:                    Integer faultIndex = (Integer) msgContext
254:                            .getProperty(FAULT_IDX);
255:                    if (faultIndex != null && faultIndex.equals(index)) {
256:                        throw new AxisFault(FAULT_REASON);
257:                    }
258:
259:                    executedHandlers.add(index);
260:                    return InvocationResponse.CONTINUE;
261:                }
262:
263:                public void flowComplete(MessageContext msgContext) {
264:                    if (msgContext.getProperty(FAULT_IDX) != null) {
265:                        // If we're here on an invocation where someone was supposed to fault...
266:                        AxisFault fault = (AxisFault) msgContext
267:                                .getFailureReason();
268:                        assertNotNull("No fault!", fault);
269:
270:                        // Make sure it's the right fault.
271:                        assertEquals(FAULT_REASON, fault.getReason());
272:                    }
273:                }
274:            }
275:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.