Source Code Cross Referenced for MessageContextSaveBTest.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.om.util.UUIDGenerator;
025:        import org.apache.axiom.soap.SOAPFactory;
026:        import org.apache.axis2.AxisFault;
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.context.OperationContext;
031:        import org.apache.axis2.context.ServiceContext;
032:        import org.apache.axis2.context.ServiceGroupContext;
033:        import org.apache.axis2.description.AxisMessage;
034:        import org.apache.axis2.description.AxisOperation;
035:        import org.apache.axis2.description.AxisService;
036:        import org.apache.axis2.description.AxisServiceGroup;
037:        import org.apache.axis2.description.HandlerDescription;
038:        import org.apache.axis2.description.InOutAxisOperation;
039:        import org.apache.axis2.description.TransportInDescription;
040:        import org.apache.axis2.description.TransportOutDescription;
041:        import org.apache.axis2.dispatchers.AddressingBasedDispatcher;
042:        import org.apache.axis2.dispatchers.RequestURIBasedDispatcher;
043:        import org.apache.axis2.dispatchers.SOAPActionBasedDispatcher;
044:        import org.apache.axis2.dispatchers.SOAPMessageBodyBasedDispatcher;
045:        import org.apache.axis2.handlers.AbstractHandler;
046:        import org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver;
047:        import org.apache.axis2.receivers.RawXMLINOutMessageReceiver;
048:        import org.apache.axis2.transport.http.CommonsHTTPTransportSender;
049:        import org.apache.axis2.transport.http.SimpleHTTPServer;
050:        import org.apache.axis2.util.ObjectStateUtils;
051:        import org.apache.axis2.wsdl.WSDLConstants;
052:        import org.apache.commons.logging.Log;
053:        import org.apache.commons.logging.LogFactory;
054:
055:        import javax.xml.namespace.QName;
056:        import java.io.File;
057:        import java.io.FileInputStream;
058:        import java.io.FileOutputStream;
059:        import java.io.ObjectInputStream;
060:        import java.io.ObjectOutputStream;
061:        import java.util.ArrayList;
062:        import java.util.HashMap;
063:        import java.util.Iterator;
064:        import java.util.Map;
065:
066:        public class MessageContextSaveBTest extends TestCase {
067:            protected static final Log log = LogFactory
068:                    .getLog(MessageContextSaveBTest.class);
069:
070:            //-------------------------------------------------------------------------
071:            // test key-value pairs
072:            //-------------------------------------------------------------------------
073:            private String[] serviceKeys = { "serviceKey1", "serviceKey2",
074:                    "serviceKey3" };
075:
076:            private String[] serviceValues = { "serviceValue1",
077:                    "serviceValue2", "serviceValue3" };
078:
079:            //-------------------------------------------------------------------------
080:            // variables for the object graph 
081:            //-------------------------------------------------------------------------
082:            // used on a save/restore of the message context
083:            // has a full object graph with 3 sets of service groups 
084:            // and associated objects
085:            private ConfigurationContext configurationContext = null;
086:            private AxisConfiguration axisConfiguration = null;
087:
088:            //------------------------------
089:            // service group ABC
090:            //------------------------------
091:            private String serviceGroupName_ABC = "ABCServiceGroup";
092:
093:            private String serviceName_A = "ServiceA";
094:            private String serviceName_B = "ServiceB";
095:            private String serviceName_C = "ServiceC";
096:            private QName service_QName_A = new QName(serviceName_A);
097:            private QName service_QName_B = new QName(serviceName_B);
098:            private QName service_QName_C = new QName(serviceName_C);
099:
100:            private String operationName_A1 = "TestOperationA1";
101:            private String operationName_A2 = "TestOperationA2";
102:            private QName operation_QName_A1 = new QName(operationName_A1);
103:            private QName operation_QName_A2 = new QName(operationName_A2);
104:
105:            private ServiceGroupContext srvGrpCtx_ABC = null;
106:            private AxisServiceGroup axisSrvGrp_ABC = null;
107:
108:            private ServiceContext srvCtx_A = null;
109:            private ServiceContext srvCtx_B = null;
110:            private ServiceContext srvCtx_C = null;
111:            private AxisService axisSrv_A = null;
112:            private AxisService axisSrv_B = null;
113:            private AxisService axisSrv_C = null;
114:
115:            private OperationContext opCtx_A1 = null;
116:            private OperationContext opCtx_A2 = null;
117:            private AxisOperation axisOp_A1 = null;
118:            private AxisOperation axisOp_A2 = null;
119:
120:            private MessageContext msgCtx_A1 = null;
121:            private MessageContext msgCtx_A2 = null;
122:            //private AxisMessage          axisMsg_A1    = null;
123:            //private AxisMessage          axisMsg_A2    = null;
124:
125:            //------------------------------
126:            // service group 123
127:            //------------------------------
128:            private String serviceGroupName_123 = "123ServiceGroup";
129:
130:            private String serviceName_1 = "Service1";
131:            private String serviceName_2 = "Service2";
132:            private String serviceName_3 = "Service3";
133:            private String serviceName_4 = "Service4";
134:            private QName service_QName_1 = new QName(serviceName_1);
135:            private QName service_QName_2 = new QName(serviceName_2);
136:            private QName service_QName_3 = new QName(serviceName_3);
137:            private QName service_QName_4 = new QName(serviceName_4);
138:
139:            private String operationName_1_1 = "TestOperation1_1";
140:            private String operationName_1_2 = "TestOperation1_2";
141:            private QName operation_QName_1_1 = new QName(operationName_1_1);
142:            private QName operation_QName_1_2 = new QName(operationName_1_2);
143:
144:            private ServiceGroupContext srvGrpCtx_123 = null;
145:            private AxisServiceGroup axisSrvGrp_123 = null;
146:
147:            private ServiceContext srvCtx_1 = null;
148:            private ServiceContext srvCtx_2 = null;
149:            private ServiceContext srvCtx_3 = null;
150:            private ServiceContext srvCtx_4 = null;
151:            private AxisService axisSrv_1 = null;
152:            private AxisService axisSrv_2 = null;
153:            private AxisService axisSrv_3 = null;
154:            private AxisService axisSrv_4 = null;
155:
156:            private OperationContext opCtx_1_1 = null;
157:            private OperationContext opCtx_1_2 = null;
158:            private AxisOperation axisOp_1_1 = null;
159:            private AxisOperation axisOp_1_2 = null;
160:
161:            private MessageContext msgCtx_1_1 = null;
162:            private MessageContext msgCtx_1_2 = null;
163:            //private AxisMessage          axisMsg_1_1   = null;
164:            //private AxisMessage          axisMsg_1_2   = null;
165:
166:            //------------------------------
167:            // service group DAY
168:            //------------------------------
169:            private String serviceGroupName_DAY = "DayServiceGroup";
170:
171:            private String serviceName_Mon = "MondayService";
172:            private String serviceName_Tue = "TuesdayService";
173:            private String serviceName_Wed = "WednesdayService";
174:            private String serviceName_Thu = "ThursdayService";
175:            private String serviceName_Fri = "FridayService";
176:            private QName service_QName_Mon = new QName(serviceName_Mon);
177:            private QName service_QName_Tue = new QName(serviceName_Tue);
178:            private QName service_QName_Wed = new QName(serviceName_Wed);
179:            private QName service_QName_Thu = new QName(serviceName_Thu);
180:            private QName service_QName_Fri = new QName(serviceName_Fri);
181:
182:            private String operationName_Mon_1 = "TestOperation_Mon_1";
183:            private String operationName_Mon_2 = "TestOperation_Mon_2";
184:            private QName operation_QName_Mon_1 = new QName(operationName_Mon_1);
185:            private QName operation_QName_Mon_2 = new QName(operationName_Mon_2);
186:
187:            private ServiceGroupContext srvGrpCtx_DAY = null;
188:            private AxisServiceGroup axisSrvGrp_DAY = null;
189:
190:            private ServiceContext srvCtx_Mon = null;
191:            private ServiceContext srvCtx_Tue = null;
192:            private ServiceContext srvCtx_Wed = null;
193:            private ServiceContext srvCtx_Thu = null;
194:            private ServiceContext srvCtx_Fri = null;
195:            private AxisService axisSrv_Mon = null;
196:            private AxisService axisSrv_Tue = null;
197:            private AxisService axisSrv_Wed = null;
198:            private AxisService axisSrv_Thu = null;
199:            private AxisService axisSrv_Fri = null;
200:
201:            private OperationContext opCtx_Mon_1 = null;
202:            private OperationContext opCtx_Mon_2 = null;
203:            private AxisOperation axisOp_Mon_1 = null;
204:            private AxisOperation axisOp_Mon_2 = null;
205:
206:            private MessageContext msgCtx_Mon_1 = null;
207:            private MessageContext msgCtx_Mon_2 = null;
208:            //private AxisMessage          axisMsg_Mon_1 = null;
209:            //private AxisMessage          axisMsg_Mon_2 = null;
210:
211:            //-------------------------------------
212:            //  objects needed for message context
213:            //------------------------------------
214:
215:            private TransportOutDescription transportOut = null;
216:            private TransportOutDescription transportOut2 = null;
217:            private TransportOutDescription transportOut3 = null;
218:            private TransportInDescription transportIn = null;
219:            private TransportInDescription transportIn2 = null;
220:            private TransportInDescription transportIn3 = null;
221:
222:            private Phase phase1 = null;
223:
224:            private ArrayList executedHandlers = null;
225:
226:            private MessageContext restoredMessageContext = null;
227:
228:            //-------------------------------------------------------------------------
229:            // methods
230:            //-------------------------------------------------------------------------
231:
232:            public MessageContextSaveBTest(String arg0) {
233:                super (arg0);
234:
235:                try {
236:                    prepare();
237:                } catch (Exception e) {
238:                    log
239:                            .debug("MessageContextSaveBTest:constructor:  error in setting up object graph ["
240:                                    + e.getClass().getName()
241:                                    + " : "
242:                                    + e.getMessage() + "]");
243:                }
244:            }
245:
246:            //
247:            // prepare the object hierarchy for testing
248:            //
249:            private void prepare() throws Exception {
250:                //-----------------------------------------------------------------
251:                // setup the top-level objects
252:                //-----------------------------------------------------------------
253:
254:                axisConfiguration = new AxisConfiguration();
255:
256:                configurationContext = new ConfigurationContext(
257:                        axisConfiguration);
258:
259:                configurationContext.getAxisConfiguration().addMessageReceiver(
260:                        "http://www.w3.org/2004/08/wsdl/in-only",
261:                        new RawXMLINOnlyMessageReceiver());
262:                configurationContext.getAxisConfiguration().addMessageReceiver(
263:                        "http://www.w3.org/2004/08/wsdl/in-out",
264:                        new RawXMLINOutMessageReceiver());
265:
266:                DispatchPhase dispatchPhase = new DispatchPhase();
267:                dispatchPhase.setName("Dispatch");
268:
269:                AddressingBasedDispatcher abd = new AddressingBasedDispatcher();
270:                abd.initDispatcher();
271:
272:                RequestURIBasedDispatcher rud = new RequestURIBasedDispatcher();
273:                rud.initDispatcher();
274:
275:                SOAPActionBasedDispatcher sabd = new SOAPActionBasedDispatcher();
276:                sabd.initDispatcher();
277:
278:                SOAPMessageBodyBasedDispatcher smbd = new SOAPMessageBodyBasedDispatcher();
279:                smbd.initDispatcher();
280:
281:                dispatchPhase.addHandler(abd);
282:                dispatchPhase.addHandler(rud);
283:                dispatchPhase.addHandler(sabd);
284:                dispatchPhase.addHandler(smbd);
285:
286:                configurationContext.getAxisConfiguration().getInFlowPhases()
287:                        .add(dispatchPhase);
288:
289:                //----------------------------
290:                // transport-related objects
291:                //----------------------------
292:                transportOut = new TransportOutDescription("null");
293:                transportOut2 = new TransportOutDescription("happy");
294:                transportOut3 = new TransportOutDescription("golucky");
295:                transportOut.setSender(new CommonsHTTPTransportSender());
296:                transportOut2.setSender(new CommonsHTTPTransportSender());
297:                transportOut3.setSender(new CommonsHTTPTransportSender());
298:
299:                axisConfiguration.addTransportOut(transportOut3);
300:                axisConfiguration.addTransportOut(transportOut2);
301:                axisConfiguration.addTransportOut(transportOut);
302:
303:                transportIn = new TransportInDescription("null");
304:                transportIn2 = new TransportInDescription("always");
305:                transportIn3 = new TransportInDescription("thebest");
306:                transportIn.setReceiver(new SimpleHTTPServer());
307:                transportIn2.setReceiver(new SimpleHTTPServer());
308:                transportIn3.setReceiver(new SimpleHTTPServer());
309:
310:                axisConfiguration.addTransportIn(transportIn2);
311:                axisConfiguration.addTransportIn(transportIn);
312:                axisConfiguration.addTransportIn(transportIn3);
313:
314:                //----------------------------
315:                // phase-related objects
316:                //----------------------------
317:                phase1 = new Phase("Phase1");
318:                phase1.addHandler(new TempHandler(1, 2));
319:                phase1.addHandler(new HandlerMCS(2, true));
320:                phase1.addHandler(new TempHandler(3, 2));
321:
322:                ArrayList phases = new ArrayList();
323:                phases.add(phase1);
324:
325:                axisConfiguration
326:                        .setInPhasesUptoAndIncludingPostDispatch(phases);
327:
328:                //-----------------------------------------------------------------
329:                // setup the axis side of the hierachy
330:                //-----------------------------------------------------------------
331:                // ABC group
332:                //----------------------------
333:                axisSrvGrp_ABC = new AxisServiceGroup(axisConfiguration);
334:                axisSrvGrp_ABC.setServiceGroupName(serviceGroupName_ABC);
335:
336:                axisSrv_A = new AxisService(service_QName_A.getLocalPart());
337:                axisSrv_B = new AxisService(service_QName_B.getLocalPart());
338:                axisSrv_C = new AxisService(service_QName_C.getLocalPart());
339:
340:                axisSrvGrp_ABC.addService(axisSrv_A);
341:                axisSrvGrp_ABC.addService(axisSrv_B);
342:                axisSrvGrp_ABC.addService(axisSrv_C);
343:
344:                axisOp_A1 = new InOutAxisOperation(operation_QName_A1);
345:                axisOp_A2 = new InOutAxisOperation(operation_QName_A2);
346:
347:                axisOp_A1.setMessageReceiver(new MessageReceiver() {
348:                    public void receive(MessageContext messageCtx) {
349:                    }
350:                });
351:
352:                axisOp_A2.setMessageReceiver(new MessageReceiver() {
353:                    public void receive(MessageContext messageCtx) {
354:                    }
355:                });
356:
357:                axisSrv_A.addOperation(axisOp_A1);
358:                axisSrv_A.mapActionToOperation(operation_QName_A1
359:                        .getLocalPart(), axisOp_A1);
360:
361:                axisSrv_A.addOperation(axisOp_A2);
362:                axisSrv_A.mapActionToOperation(operation_QName_A2
363:                        .getLocalPart(), axisOp_A2);
364:
365:                axisConfiguration.addService(axisSrv_A);
366:                axisConfiguration.addService(axisSrv_B);
367:                axisConfiguration.addService(axisSrv_C);
368:
369:                axisOp_A1.getRemainingPhasesInFlow().add(phase1);
370:                axisOp_A2.getRemainingPhasesInFlow().add(phase1);
371:
372:                //----------------------------
373:                // 123 group
374:                //----------------------------
375:                axisSrvGrp_123 = new AxisServiceGroup(axisConfiguration);
376:                axisSrvGrp_123.setServiceGroupName(serviceGroupName_123);
377:
378:                axisSrv_1 = new AxisService(service_QName_1.getLocalPart());
379:                axisSrv_2 = new AxisService(service_QName_2.getLocalPart());
380:                axisSrv_3 = new AxisService(service_QName_3.getLocalPart());
381:                axisSrv_4 = new AxisService(service_QName_4.getLocalPart());
382:
383:                axisSrvGrp_123.addService(axisSrv_1);
384:                axisSrvGrp_123.addService(axisSrv_2);
385:                axisSrvGrp_123.addService(axisSrv_3);
386:                axisSrvGrp_123.addService(axisSrv_4);
387:
388:                axisOp_1_1 = new InOutAxisOperation(operation_QName_1_1);
389:                axisOp_1_2 = new InOutAxisOperation(operation_QName_1_2);
390:
391:                axisOp_1_1.setMessageReceiver(new MessageReceiver() {
392:                    public void receive(MessageContext messageCtx) {
393:                    }
394:                });
395:
396:                axisOp_1_2.setMessageReceiver(new MessageReceiver() {
397:                    public void receive(MessageContext messageCtx) {
398:                    }
399:                });
400:
401:                axisSrv_1.addOperation(axisOp_1_1);
402:                axisSrv_1.mapActionToOperation(operation_QName_1_1
403:                        .getLocalPart(), axisOp_1_1);
404:
405:                axisSrv_1.addOperation(axisOp_1_2);
406:                axisSrv_1.mapActionToOperation(operation_QName_1_2
407:                        .getLocalPart(), axisOp_1_2);
408:
409:                axisConfiguration.addService(axisSrv_1);
410:                axisConfiguration.addService(axisSrv_2);
411:                axisConfiguration.addService(axisSrv_3);
412:                axisConfiguration.addService(axisSrv_4);
413:
414:                axisOp_1_1.getRemainingPhasesInFlow().add(phase1);
415:                axisOp_1_2.getRemainingPhasesInFlow().add(phase1);
416:
417:                //----------------------------
418:                // DAY group
419:                //----------------------------
420:                axisSrvGrp_DAY = new AxisServiceGroup(axisConfiguration);
421:                axisSrvGrp_DAY.setServiceGroupName(serviceGroupName_DAY);
422:
423:                axisSrv_Mon = new AxisService(service_QName_Mon.getLocalPart());
424:                axisSrv_Tue = new AxisService(service_QName_Tue.getLocalPart());
425:                axisSrv_Wed = new AxisService(service_QName_Wed.getLocalPart());
426:                axisSrv_Thu = new AxisService(service_QName_Thu.getLocalPart());
427:                axisSrv_Fri = new AxisService(service_QName_Fri.getLocalPart());
428:
429:                axisSrvGrp_DAY.addService(axisSrv_Mon);
430:                axisSrvGrp_DAY.addService(axisSrv_Tue);
431:                axisSrvGrp_DAY.addService(axisSrv_Wed);
432:                axisSrvGrp_DAY.addService(axisSrv_Thu);
433:                axisSrvGrp_DAY.addService(axisSrv_Fri);
434:
435:                axisOp_Mon_1 = new InOutAxisOperation(operation_QName_Mon_1);
436:                axisOp_Mon_2 = new InOutAxisOperation(operation_QName_Mon_2);
437:
438:                axisOp_Mon_1.setMessageReceiver(new MessageReceiver() {
439:                    public void receive(MessageContext messageCtx) {
440:                    }
441:                });
442:
443:                axisOp_Mon_2.setMessageReceiver(new MessageReceiver() {
444:                    public void receive(MessageContext messageCtx) {
445:                    }
446:                });
447:
448:                axisSrv_Mon.addOperation(axisOp_Mon_1);
449:                axisSrv_Mon.mapActionToOperation(operation_QName_Mon_1
450:                        .getLocalPart(), axisOp_Mon_1);
451:
452:                axisSrv_Mon.addOperation(axisOp_Mon_2);
453:                axisSrv_Mon.mapActionToOperation(operation_QName_Mon_2
454:                        .getLocalPart(), axisOp_Mon_2);
455:
456:                axisConfiguration.addService(axisSrv_Mon);
457:                axisConfiguration.addService(axisSrv_Tue);
458:                axisConfiguration.addService(axisSrv_Wed);
459:                axisConfiguration.addService(axisSrv_Thu);
460:                axisConfiguration.addService(axisSrv_Fri);
461:
462:                axisOp_Mon_1.getRemainingPhasesInFlow().add(phase1);
463:                axisOp_Mon_2.getRemainingPhasesInFlow().add(phase1);
464:
465:                //-----------------------------------------------------------------
466:                // setup the context objects
467:                //-----------------------------------------------------------------
468:                srvGrpCtx_ABC = configurationContext
469:                        .createServiceGroupContext(axisSrvGrp_ABC);
470:                srvGrpCtx_ABC.setId(serviceGroupName_ABC);
471:
472:                srvGrpCtx_123 = configurationContext
473:                        .createServiceGroupContext(axisSrvGrp_123);
474:                srvGrpCtx_123.setId(serviceGroupName_ABC);
475:
476:                srvGrpCtx_DAY = configurationContext
477:                        .createServiceGroupContext(axisSrvGrp_DAY);
478:                srvGrpCtx_DAY.setId(serviceGroupName_DAY);
479:
480:                srvCtx_A = srvGrpCtx_ABC.getServiceContext(axisSrv_A);
481:                srvCtx_B = srvGrpCtx_ABC.getServiceContext(axisSrv_B);
482:                srvCtx_C = srvGrpCtx_ABC.getServiceContext(axisSrv_C);
483:
484:                srvCtx_1 = srvGrpCtx_123.getServiceContext(axisSrv_1);
485:                srvCtx_2 = srvGrpCtx_123.getServiceContext(axisSrv_2);
486:                srvCtx_3 = srvGrpCtx_123.getServiceContext(axisSrv_3);
487:                srvCtx_4 = srvGrpCtx_123.getServiceContext(axisSrv_4);
488:
489:                srvCtx_Mon = srvGrpCtx_DAY.getServiceContext(axisSrv_Mon);
490:                srvCtx_Tue = srvGrpCtx_DAY.getServiceContext(axisSrv_Tue);
491:                srvCtx_Wed = srvGrpCtx_DAY.getServiceContext(axisSrv_Wed);
492:                srvCtx_Thu = srvGrpCtx_DAY.getServiceContext(axisSrv_Thu);
493:                srvCtx_Fri = srvGrpCtx_DAY.getServiceContext(axisSrv_Fri);
494:
495:                opCtx_A1 = srvCtx_A.createOperationContext(operation_QName_A1);
496:                opCtx_A2 = srvCtx_A.createOperationContext(operation_QName_A2);
497:
498:                opCtx_1_1 = srvCtx_1
499:                        .createOperationContext(operation_QName_1_1);
500:                opCtx_1_2 = srvCtx_1
501:                        .createOperationContext(operation_QName_1_2);
502:
503:                opCtx_Mon_1 = srvCtx_Mon
504:                        .createOperationContext(operation_QName_Mon_1);
505:                opCtx_Mon_2 = srvCtx_Mon
506:                        .createOperationContext(operation_QName_Mon_2);
507:
508:                //----------------------------------------
509:                // message context objects
510:                //----------------------------------------
511:                msgCtx_A1 = createMessageContext(opCtx_A1);
512:                msgCtx_A2 = createMessageContext(opCtx_A2);
513:
514:                msgCtx_1_1 = createMessageContext(opCtx_1_1);
515:                msgCtx_1_2 = createMessageContext(opCtx_1_2);
516:
517:                msgCtx_Mon_1 = createMessageContext(opCtx_Mon_1);
518:                msgCtx_Mon_2 = createMessageContext(opCtx_Mon_2);
519:
520:                //-----------------------------------------------------------------
521:                // other objects
522:                //-----------------------------------------------------------------
523:                executedHandlers = new ArrayList();
524:            }
525:
526:            private MessageContext createMessageContext(OperationContext oc)
527:                    throws Exception {
528:                MessageContext mc = configurationContext.createMessageContext();
529:                mc.setTransportIn(transportIn);
530:                mc.setTransportOut(transportOut);
531:
532:                mc.setServerSide(true);
533:                //        mc.setProperty(MessageContext.TRANSPORT_OUT, System.out);
534:
535:                SOAPFactory omFac = OMAbstractFactory.getSOAP11Factory();
536:                mc.setEnvelope(omFac.getDefaultEnvelope());
537:
538:                AxisOperation axisOperation = oc.getAxisOperation();
539:                String action = axisOperation.getName().getLocalPart();
540:                mc.setSoapAction(action);
541:                //        System.out.flush();
542:
543:                mc.setMessageID(UUIDGenerator.getUUID());
544:
545:                axisOperation.registerOperationContext(mc, oc);
546:                mc.setOperationContext(oc);
547:
548:                ServiceContext sc = oc.getServiceContext();
549:                mc.setServiceContext(sc);
550:
551:                mc.setTo(new EndpointReference("axis2/services/NullService"));
552:                mc.setWSAAction("DummyOp");
553:
554:                AxisMessage axisMessage = axisOperation
555:                        .getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
556:                mc.setAxisMessage(axisMessage);
557:
558:                return mc;
559:            }
560:
561:            protected void setUp() throws Exception {
562:                //org.apache.log4j.BasicConfigurator.configure();
563:            }
564:
565:            public void testServiceProperties() throws Exception {
566:                String title = "MessageContextSaveBTest: testServiceProperties(): ";
567:
568:                AxisEngine engine = new AxisEngine(configurationContext);
569:
570:                MessageContext mc = msgCtx_1_1;
571:
572:                // add some service-level properties
573:                String suffix = "_before";
574:                addServiceProperties(mc, suffix);
575:
576:                // get the service level properties into a separate table
577:                Map properties_original = new HashMap(getServiceProperties(mc));
578:                showProperties(properties_original, "original properties");
579:
580:                log
581:                        .debug(title
582:                                + "start - - engine.receive(mc) - - - - - - - - - - - - - - - -");
583:                engine.receive(mc);
584:
585:                // get the service level properties into a separate table
586:                Map properties2 = new HashMap(
587:                        getServiceProperties(restoredMessageContext));
588:                showProperties(properties2, "restored properties");
589:
590:                // add some more properties
591:                suffix = "_postReceive";
592:                addServiceProperties(restoredMessageContext, suffix);
593:
594:                // resume the paused message context
595:                log
596:                        .debug(title
597:                                + "resume - - engine.resume(mc) - - - - - - - - - - - - - - - -");
598:                engine.resume(restoredMessageContext);
599:
600:                // get the service level properties into a separate table
601:                Map properties3 = new HashMap(
602:                        getServiceProperties(restoredMessageContext));
603:                showProperties(properties3,
604:                        "restored service properties post-resume");
605:
606:                // get the service level properties from the other message context
607:                // in the same service 
608:                Map properties4 = getServiceProperties(msgCtx_1_2);
609:                showProperties(properties4,
610:                        "service properties from other active MsgCtx");
611:
612:                // the service level properties should be the same
613:                boolean isOk = ObjectStateUtils.isEquivalent(properties3,
614:                        properties4, true);
615:                assertTrue(isOk);
616:
617:            }
618:
619:            private Map getServiceProperties(MessageContext mc) {
620:                Map properties = null;
621:
622:                // get the service context from the message context
623:                ServiceContext serviceContext = mc.getServiceContext();
624:
625:                if (serviceContext == null) {
626:                    // get the service context from the operation context
627:                    OperationContext operationContext = mc
628:                            .getOperationContext();
629:                    serviceContext = operationContext.getServiceContext();
630:                }
631:
632:                if (serviceContext != null) {
633:                    properties = serviceContext.getProperties();
634:                }
635:
636:                return properties;
637:            }
638:
639:            private void addServiceProperties(MessageContext mc, String suffix) {
640:                // get the service context from the message context
641:                ServiceContext serviceContext = mc.getServiceContext();
642:
643:                if (serviceContext == null) {
644:                    // get the service context from the operation context
645:                    OperationContext operationContext = mc
646:                            .getOperationContext();
647:                    serviceContext = operationContext.getServiceContext();
648:                }
649:
650:                if (serviceContext != null) {
651:                    for (int k = 0; k < serviceKeys.length; k++) {
652:                        String key = serviceKeys[k];
653:                        String value = serviceValues[k] + suffix;
654:
655:                        serviceContext.setProperty(key, value);
656:                    }
657:                }
658:            }
659:
660:            private void showProperties(Map map, String description) {
661:                log.debug(description
662:                        + " ======================================");
663:                if ((map == null) || (map.isEmpty())) {
664:                    log.debug(description + ": No properties");
665:                    log.debug(description
666:                            + " ======================================");
667:                    return;
668:                }
669:
670:                Iterator it = map.keySet().iterator();
671:
672:                while (it.hasNext()) {
673:                    String key = (String) it.next();
674:
675:                    String value = (String) map.get(key);
676:
677:                    log.debug(description + ": key-value pair [" + key + "]["
678:                            + value + "]");
679:                }
680:                log.debug(description
681:                        + " ======================================");
682:            }
683:
684:            /**
685:             * Gets the ID associated with the handler object.
686:             *
687:             * @param o The handler object
688:             * @return The ID associated with the handler,
689:             *         -1 otherwise
690:             */
691:            private int getHandlerID(Object o) {
692:                int id = -1;
693:
694:                if (o instanceof  TempHandler) {
695:                    id = ((TempHandler) o).getHandlerID();
696:                }
697:
698:                return id;
699:            }
700:
701:            //=========================================================================
702:            // Handler classes 
703:            //=========================================================================
704:
705:            /**
706:             * Performs a save and restore on the message context
707:             */
708:            public class HandlerMCS extends AbstractHandler {
709:                private Integer handlerID = null;
710:
711:                private File theFile = null;
712:                private String theFilename = null;
713:
714:                private boolean pause = false;
715:                private boolean savedOk = false;
716:                private boolean restoredOk = false;
717:                private boolean comparesOk = false;
718:
719:                //-----------------------------------------------------------------
720:                // constructors
721:                //-----------------------------------------------------------------
722:
723:                public HandlerMCS() {
724:                    this .handlerID = new Integer(-5);
725:                }
726:
727:                public HandlerMCS(int index, boolean pause) {
728:                    this .handlerID = new Integer(index);
729:                    this .pause = pause;
730:                    init(new HandlerDescription(new String("handler" + index)));
731:                }
732:
733:                public HandlerMCS(int index) {
734:                    this .handlerID = new Integer(index);
735:                    init(new HandlerDescription(new String("handler" + index)));
736:                }
737:
738:                //-----------------------------------------------------------------
739:                // methods
740:                //-----------------------------------------------------------------
741:
742:                public int getHandlerID() {
743:                    if (handlerID != null) {
744:                        return handlerID.intValue();
745:                    }
746:
747:                    return -5;
748:                }
749:
750:                public InvocationResponse invoke(MessageContext msgContext)
751:                        throws AxisFault {
752:                    String title = "HandlerMCS[" + getHandlerID()
753:                            + "]:invoke(): ";
754:                    log.debug(title + "pause = [" + pause + "]");
755:                    savedOk = false;
756:                    restoredOk = false;
757:
758:                    if (pause) {
759:                        log.debug(title + "msgContext.pause()");
760:                        msgContext.pause();
761:                        pause = false;
762:
763:                        try {
764:                            theFile = File.createTempFile("mcSave", null);
765:                            theFilename = theFile.getName();
766:                            log.debug(title + "temp file = [" + theFilename
767:                                    + "]");
768:                        } catch (Exception ex) {
769:                            log.debug(title + "error creating temp file = ["
770:                                    + ex.getMessage() + "]");
771:                            theFile = null;
772:                        }
773:
774:                        if (theFile != null) {
775:                            // ---------------------------------------------------------
776:                            // save to the temporary file
777:                            // ---------------------------------------------------------
778:                            try {
779:                                // setup an output stream to a physical file
780:                                FileOutputStream outStream = new FileOutputStream(
781:                                        theFile);
782:
783:                                // attach a stream capable of writing objects to the 
784:                                // stream connected to the file
785:                                ObjectOutputStream outObjStream = new ObjectOutputStream(
786:                                        outStream);
787:
788:                                // try to save the message context
789:                                log
790:                                        .debug(title
791:                                                + "saving message context.....");
792:                                savedOk = false;
793:                                outObjStream.writeObject(msgContext);
794:
795:                                // close out the streams
796:                                outObjStream.flush();
797:                                outObjStream.close();
798:                                outStream.flush();
799:                                outStream.close();
800:
801:                                savedOk = true;
802:                                log.debug(title
803:                                        + "....saved message context.....");
804:
805:                                long filesize = theFile.length();
806:                                log.debug(title + "file size after save ["
807:                                        + filesize + "]   temp file = ["
808:                                        + theFilename + "]");
809:
810:                            } catch (Exception ex2) {
811:                                log
812:                                        .debug(title
813:                                                + "error with saving message context = ["
814:                                                + ex2.getClass().getName()
815:                                                + " : " + ex2.getMessage()
816:                                                + "]");
817:                                ex2.printStackTrace();
818:                            }
819:
820:                            assertTrue(savedOk);
821:
822:                            // ---------------------------------------------------------
823:                            // restore from the temporary file
824:                            // ---------------------------------------------------------
825:                            try {
826:                                // setup an input stream to the file
827:                                FileInputStream inStream = new FileInputStream(
828:                                        theFile);
829:
830:                                // attach a stream capable of reading objects from the 
831:                                // stream connected to the file
832:                                ObjectInputStream inObjStream = new ObjectInputStream(
833:                                        inStream);
834:
835:                                // try to restore the message context
836:                                log.debug(title
837:                                        + "restoring a message context.....");
838:                                restoredOk = false;
839:
840:                                MessageContext msgContext2 = (MessageContext) inObjStream
841:                                        .readObject();
842:                                inObjStream.close();
843:                                inStream.close();
844:
845:                                msgContext2.activate(configurationContext);
846:
847:                                restoredOk = true;
848:                                log.debug(title
849:                                        + "....restored message context.....");
850:
851:                                // now put the restored message context in the global
852:                                // variable for the test 
853:                                restoredMessageContext = msgContext2;
854:                            } catch (Exception ex2) {
855:                                log
856:                                        .debug(title
857:                                                + "error with restoring message context = ["
858:                                                + ex2.getClass().getName()
859:                                                + " : " + ex2.getMessage()
860:                                                + "]");
861:                                ex2.printStackTrace();
862:                                restoredMessageContext = null;
863:                            }
864:
865:                            assertTrue(restoredOk);
866:
867:                            // if the save/restore of the message context succeeded,
868:                            // then don't keep the temporary file around
869:                            boolean removeTmpFile = savedOk && restoredOk;
870:                            if (removeTmpFile) {
871:                                try {
872:                                    theFile.delete();
873:                                } catch (Exception e) {
874:                                    // just absorb it
875:                                }
876:                            }
877:                        }
878:
879:                        return InvocationResponse.SUSPEND;
880:
881:                    } else {
882:                        log.debug(title + "executedHandlers.add(" + handlerID
883:                                + ")");
884:                        executedHandlers.add(handlerID);
885:                    }
886:
887:                    return InvocationResponse.CONTINUE;
888:                }
889:
890:            }
891:
892:            public class TempHandler extends AbstractHandler {
893:                private Integer handlerID = null;
894:                private int count = 0;
895:                private int numberProperties = 3;
896:                private String propertyKey = "Property";
897:                private String propertyValue = "ServiceLevelSetting";
898:
899:                //-----------------------------------------------------------------
900:                // constructors
901:                //-----------------------------------------------------------------
902:
903:                public TempHandler() {
904:                    this .handlerID = new Integer(-5);
905:                }
906:
907:                public TempHandler(int index) {
908:                    this .handlerID = new Integer(index);
909:                    init(new HandlerDescription(new String("handler" + index)));
910:                }
911:
912:                public TempHandler(int index, int number) {
913:                    this .handlerID = new Integer(index);
914:                    init(new HandlerDescription(new String("handler" + index)));
915:                    numberProperties = number;
916:                }
917:
918:                //-----------------------------------------------------------------
919:                // methods
920:                //-----------------------------------------------------------------
921:
922:                public int getHandlerID() {
923:                    if (handlerID != null) {
924:                        return handlerID.intValue();
925:                    }
926:
927:                    return -5;
928:                }
929:
930:                public InvocationResponse invoke(MessageContext msgContext)
931:                        throws AxisFault {
932:                    String title = "TempHandler[" + getHandlerID()
933:                            + "]:invoke(): ";
934:
935:                    // get the service context from the message context
936:                    ServiceContext serviceContext = msgContext
937:                            .getServiceContext();
938:
939:                    if (serviceContext == null) {
940:                        // get the service context from the operation context
941:                        OperationContext operationContext = msgContext
942:                                .getOperationContext();
943:                        serviceContext = operationContext.getServiceContext();
944:                    }
945:
946:                    if (serviceContext != null) {
947:                        for (int j = 0; j < numberProperties; j++) {
948:                            count++;
949:                            String key = new String(propertyKey + ".ID["
950:                                    + getHandlerID() + "]." + count);
951:                            String value = new String(propertyValue + "["
952:                                    + count + "]");
953:                            serviceContext.setProperty(key, value);
954:                        }
955:                    }
956:
957:                    log
958:                            .debug(title + "executedHandlers.add(" + handlerID
959:                                    + ")");
960:                    executedHandlers.add(handlerID);
961:
962:                    return InvocationResponse.CONTINUE;
963:                }
964:
965:            }
966:
967:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.