Source Code Cross Referenced for OptionsSaveTest.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.soap.SOAP12Constants;
024:        import org.apache.axis2.addressing.AddressingConstants;
025:        import org.apache.axis2.addressing.EndpointReference;
026:        import org.apache.axis2.client.Options;
027:        import org.apache.axis2.context.ConfigurationContext;
028:        import org.apache.axis2.description.TransportInDescription;
029:        import org.apache.axis2.description.TransportOutDescription;
030:        import org.apache.axis2.transport.http.CommonsHTTPTransportSender;
031:        import org.apache.axis2.transport.http.SimpleHTTPServer;
032:        import org.apache.commons.logging.Log;
033:        import org.apache.commons.logging.LogFactory;
034:
035:        import javax.xml.namespace.QName;
036:        import java.io.File;
037:        import java.io.FileInputStream;
038:        import java.io.FileOutputStream;
039:        import java.io.ObjectInputStream;
040:        import java.io.ObjectOutputStream;
041:
042:        public class OptionsSaveTest extends TestCase {
043:            protected static final Log log = LogFactory
044:                    .getLog(OptionsSaveTest.class);
045:
046:            private transient QName serviceName = new QName("NullService");
047:            private transient QName operationName = new QName("DummyOp");
048:
049:            private String testArg = null;
050:
051:            public OptionsSaveTest(String arg0) {
052:                super (arg0);
053:                testArg = new String(arg0);
054:
055:                initAll();
056:            }
057:
058:            protected void initAll() {
059:            }
060:
061:            protected void setUp() throws Exception {
062:                //org.apache.log4j.BasicConfigurator.configure();
063:            }
064:
065:            public void testSaveAndRestore() throws Exception {
066:                File theFile = null;
067:                String theFilename = null;
068:                boolean saved = false;
069:                boolean restored = false;
070:                boolean done = false;
071:                boolean comparesOk = false;
072:
073:                AxisConfiguration axisConfiguration = new AxisConfiguration();
074:                ConfigurationContext configurationContext = new ConfigurationContext(
075:                        axisConfiguration);
076:
077:                log
078:                        .debug("OptionsSaveTest:testSaveAndRestore():  BEGIN ---------------");
079:
080:                // ---------------------------------------------------------
081:                // setup an options object to use
082:                // ---------------------------------------------------------
083:                Options options = new Options();
084:
085:                options
086:                        .setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
087:                options.setExceptionToBeThrownOnSOAPFault(true);
088:                options.setTimeOutInMilliSeconds(5000L);
089:                options.setUseSeparateListener(false);
090:                options.setAction("SoapAction");
091:                options.setFaultTo(new EndpointReference(
092:                        "http://ws.apache.org/axis2/faultTo"));
093:                options.setFrom(new EndpointReference(
094:                        "http://ws.apache.org/axis2/from"));
095:                options.setTo(new EndpointReference(
096:                        "http://ws.apache.org/axis2/to"));
097:                options.setReplyTo(new EndpointReference(
098:                        AddressingConstants.Final.WSA_ANONYMOUS_URL));
099:
100:                TransportOutDescription transportOut = new TransportOutDescription(
101:                        "null");
102:                TransportOutDescription transportOut2 = new TransportOutDescription(
103:                        "happy");
104:                TransportOutDescription transportOut3 = new TransportOutDescription(
105:                        "golucky");
106:                transportOut.setSender(new CommonsHTTPTransportSender());
107:                transportOut2.setSender(new CommonsHTTPTransportSender());
108:                transportOut3.setSender(new CommonsHTTPTransportSender());
109:                options.setTransportOut(transportOut);
110:                axisConfiguration.addTransportOut(transportOut3);
111:                axisConfiguration.addTransportOut(transportOut2);
112:                axisConfiguration.addTransportOut(transportOut);
113:
114:                TransportInDescription transportIn = new TransportInDescription(
115:                        "null");
116:                TransportInDescription transportIn2 = new TransportInDescription(
117:                        "always");
118:                TransportInDescription transportIn3 = new TransportInDescription(
119:                        "thebest");
120:                transportIn.setReceiver(new SimpleHTTPServer());
121:                transportIn2.setReceiver(new SimpleHTTPServer());
122:                transportIn3.setReceiver(new SimpleHTTPServer());
123:                options.setTransportIn(transportIn);
124:                axisConfiguration.addTransportIn(transportIn2);
125:                axisConfiguration.addTransportIn(transportIn);
126:                axisConfiguration.addTransportIn(transportIn3);
127:
128:                options.setMessageId("msgId012345");
129:
130:                options.setProperty("key01", "value01");
131:                options.setProperty("key02", "value02");
132:                options.setProperty("key03", "value03");
133:                options.setProperty("key04", "value04");
134:                options.setProperty("key05", "value05");
135:                options.setProperty("key06", "value06");
136:                options.setProperty("key07", "value07");
137:                options.setProperty("key08", "value08");
138:                options.setProperty("key09", "value09");
139:                options.setProperty("key10", "value10");
140:
141:                // TODO: setup a parent
142:
143:                // ---------------------------------------------------------
144:                // setup a temporary file to use
145:                // ---------------------------------------------------------
146:                try {
147:                    theFile = File.createTempFile("optionsSave", null);
148:                    theFilename = theFile.getName();
149:                    log
150:                            .debug("OptionsSaveTest:testSaveAndRestore(): temp file = ["
151:                                    + theFilename + "]");
152:                } catch (Exception ex) {
153:                    log
154:                            .debug("OptionsSaveTest:testSaveAndRestore(): error creating temp file = ["
155:                                    + ex.getMessage() + "]");
156:                    theFile = null;
157:                }
158:
159:                if (theFile != null) {
160:                    // ---------------------------------------------------------
161:                    // save to the temporary file
162:                    // ---------------------------------------------------------
163:                    try {
164:                        // setup an output stream to a physical file
165:                        FileOutputStream outStream = new FileOutputStream(
166:                                theFile);
167:
168:                        // attach a stream capable of writing objects to the 
169:                        // stream connected to the file
170:                        ObjectOutputStream outObjStream = new ObjectOutputStream(
171:                                outStream);
172:
173:                        // try to save the message context
174:                        log
175:                                .debug("OptionsSaveTest:testSaveAndRestore(): saving .....");
176:                        saved = false;
177:                        outObjStream.writeObject(options);
178:
179:                        // close out the streams
180:                        outObjStream.flush();
181:                        outObjStream.close();
182:                        outStream.flush();
183:                        outStream.close();
184:
185:                        saved = true;
186:                        log
187:                                .debug("OptionsSaveTest:testSaveAndRestore(): ....save operation completed.....");
188:
189:                        long filesize = theFile.length();
190:                        log
191:                                .debug("OptionsSaveTest:testSaveAndRestore(): file size after save ["
192:                                        + filesize
193:                                        + "]   temp file = ["
194:                                        + theFilename + "]");
195:                    } catch (Exception ex2) {
196:                        if (saved != true) {
197:                            log
198:                                    .debug("OptionsSaveTest:testSaveAndRestore(): error during save ["
199:                                            + ex2.getClass().getName()
200:                                            + " : "
201:                                            + ex2.getMessage() + "]");
202:                            ex2.printStackTrace();
203:                        } else {
204:                            log
205:                                    .debug("OptionsSaveTest:testSaveAndRestore(): error during restore ["
206:                                            + ex2.getClass().getName()
207:                                            + " : "
208:                                            + ex2.getMessage() + "]");
209:                            ex2.printStackTrace();
210:                        }
211:                    }
212:
213:                    assertTrue(saved);
214:
215:                    // ---------------------------------------------------------
216:                    // restore from the temporary file
217:                    // ---------------------------------------------------------
218:                    try {
219:                        // setup an input stream to the file
220:                        FileInputStream inStream = new FileInputStream(theFile);
221:
222:                        // attach a stream capable of reading objects from the 
223:                        // stream connected to the file
224:                        ObjectInputStream inObjStream = new ObjectInputStream(
225:                                inStream);
226:
227:                        // try to restore the options
228:                        log
229:                                .debug("OptionsSaveTest:testSaveAndRestore(): restoring .....");
230:                        restored = false;
231:                        Options options_restored = (Options) inObjStream
232:                                .readObject();
233:                        inObjStream.close();
234:                        inStream.close();
235:
236:                        options_restored.activate(configurationContext);
237:
238:                        restored = true;
239:                        log
240:                                .debug("OptionsSaveTest:testSaveAndRestore(): ....restored operation completed.....");
241:
242:                        comparesOk = options_restored.isEquivalent(options);
243:                        log
244:                                .debug("OptionsSaveTest:testSaveAndRestore():   Options equivalency ["
245:                                        + comparesOk + "]");
246:                    } catch (Exception ex2) {
247:                        log
248:                                .debug("OptionsSaveTest:testSaveAndRestore(): error during restore ["
249:                                        + ex2.getClass().getName()
250:                                        + " : "
251:                                        + ex2.getMessage() + "]");
252:                        ex2.printStackTrace();
253:                    }
254:
255:                    assertTrue(restored);
256:
257:                    assertTrue(comparesOk);
258:
259:                    // if the save/restore of the object succeeded,
260:                    // then don't keep the temporary file around
261:                    boolean removeTmpFile = saved && restored && comparesOk;
262:                    if (removeTmpFile) {
263:                        try {
264:                            theFile.delete();
265:                        } catch (Exception e) {
266:                            // just absorb it
267:                        }
268:                    }
269:
270:                    // indicate that the temp file was created ok
271:                    done = true;
272:                }
273:
274:                // this is false when there are problems with the temporary file
275:                assertTrue(done);
276:
277:                log
278:                        .debug("OptionsSaveTest:testSaveAndRestore():  END ---------------");
279:            }
280:
281:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.