Source Code Cross Referenced for TestUtilities.java in  » Web-Services » wsif » util » 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 » wsif » util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * The Apache Software License, Version 1.1
003:         *
004:         *
005:         * Copyright (c) 2002 The Apache Software Foundation.  All rights 
006:         * reserved.
007:         *
008:         * Redistribution and use in source and binary forms, with or without
009:         * modification, are permitted provided that the following conditions
010:         * are met:
011:         *
012:         * 1. Redistributions of source code must retain the above copyright
013:         *    notice, this list of conditions and the following disclaimer. 
014:         *
015:         * 2. Redistributions in binary form must reproduce the above copyright
016:         *    notice, this list of conditions and the following disclaimer in
017:         *    the documentation and/or other materials provided with the
018:         *    distribution.
019:         *
020:         * 3. The end-user documentation included with the redistribution,
021:         *    if any, must include the following acknowledgment:  
022:         *       "This product includes software developed by the
023:         *        Apache Software Foundation (http://www.apache.org/)."
024:         *    Alternately, this acknowledgment may appear in the software itself,
025:         *    if and wherever such third-party acknowledgments normally appear.
026:         *
027:         * 4. The names "WSIF" and "Apache Software Foundation" must
028:         *    not be used to endorse or promote products derived from this
029:         *    software without prior written permission. For written 
030:         *    permission, please contact apache@apache.org.
031:         *
032:         * 5. Products derived from this software may not be called "Apache",
033:         *    nor may "Apache" appear in their name, without prior written
034:         *    permission of the Apache Software Foundation.
035:         *
036:         * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037:         * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038:         * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039:         * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
040:         * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041:         * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042:         * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043:         * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044:         * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045:         * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046:         * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047:         * SUCH DAMAGE.
048:         * ====================================================================
049:         *
050:         * This software consists of voluntary contributions made by many
051:         * individuals on behalf of the Apache Software Foundation and was
052:         * originally based on software copyright (c) 2001, 2002, International
053:         * Business Machines, Inc., http://www.apache.org.  For more
054:         * information on the Apache Software Foundation, please see
055:         * <http://www.apache.org/>.
056:         */
057:
058:        package util;
059:
060:        /**
061:         * A mish-mash of various utilities useful in our JUnit tests
062:         * @author Mark Whitlock
063:         */
064:
065:        import java.io.InputStream;
066:        import java.util.Properties;
067:        import java.util.StringTokenizer;
068:
069:        import javax.jms.JMSException;
070:        import javax.jms.Message;
071:        import javax.jms.Queue;
072:        import javax.jms.QueueConnection;
073:        import javax.jms.QueueConnectionFactory;
074:        import javax.jms.QueueReceiver;
075:        import javax.jms.QueueSession;
076:        import javax.jms.Session;
077:
078:        import org.apache.wsif.WSIFException;
079:        import org.apache.wsif.base.WSIFDefaultCorrelationService;
080:        import org.apache.wsif.providers.soap.apacheaxis.WSIFDynamicProvider_ApacheAxis;
081:        import org.apache.wsif.providers.soap.apachesoap.WSIFDynamicProvider_ApacheSOAP;
082:        import org.apache.wsif.spi.WSIFProvider;
083:        import org.apache.wsif.util.WSIFCorrelationServiceLocator;
084:        import org.apache.wsif.util.WSIFPluggableProviders;
085:        import org.apache.wsif.util.WSIFProperties;
086:        import org.apache.wsif.util.jms.JMSAsyncListener;
087:        import org.apache.wsif.util.jms.NativeJMSRequestListener;
088:        import org.apache.wsif.util.jms.WSIFJMSFinder;
089:        import org.apache.wsif.util.jms.WSIFJMSFinderForJndi;
090:
091:        public class TestUtilities {
092:            private static final String WSIF_TEST_PROPERTIES = "wsif.test.properties";
093:            private static final String WSIF_PATH = "wsif.path";
094:            private static final String WSIF_TEST_COMPONENTS = "wsif.test.components";
095:            private static final String WSIF_SOAP_SERVER = "wsif.soapserver";
096:
097:            private static final String SOAP = "soap";
098:            private static final String AXIS = "axis";
099:
100:            private static BridgeThread jmsAb = null;
101:            private static BridgeThread jmsSq = null;
102:            private static JMSAsyncListener asyncListener = null;
103:            private static NativeJMSRequestListener nativeReqListener = null;
104:
105:            public static final int ADDRESSBOOK_LISTENER = 1;
106:            public static final int STOCKQUOTE_LISTENER = 2;
107:            public static final int ASYNC_LISTENER = 4;
108:            public static final int NATIVEJMS_LISTENER = 8;
109:            public static final int ALL_LISTENERS = 15;
110:
111:            public static final Class DEFAULT_SOAP_PROVIDER_CLASS = WSIFDynamicProvider_ApacheAxis.class;
112:            private static final String DEFAULT_SOAP_PROTOCOL = "axis";
113:            public static final Class NON_DEFAULT_SOAP_PROVIDER_CLASS = WSIFDynamicProvider_ApacheSOAP.class;
114:            private static final String NON_DEFAULT_SOAP_PROTOCOL = "soap";
115:
116:            /*
117:             public static final Class DEFAULT_SOAP_PROVIDER_CLASS = 
118:             WSIFDynamicProvider_ApacheSOAP.class;       
119:             private static final String DEFAULT_SOAP_PROTOCOL =
120:             "soap";
121:             public static final Class NON_DEFAULT_SOAP_PROVIDER_CLASS = 
122:             WSIFDynamicProvider_ApacheAxis.class;       
123:             private static final String NON_DEFAULT_SOAP_PROTOCOL =
124:             "axis";
125:             */
126:            public static String getWsdlPath(String relativePath) {
127:                String wsdlPath = getWsifProperty(WSIF_PATH);
128:                if (wsdlPath == null)
129:                    wsdlPath = new String("");
130:
131:                String slash = System.getProperty("file.separator");
132:
133:                if (!wsdlPath.equals("") && !wsdlPath.endsWith(slash))
134:                    wsdlPath += slash;
135:
136:                if (relativePath != null && relativePath.length() != 0) {
137:                    StringBuffer relativeBuff = new StringBuffer(relativePath);
138:                    for (int i = 0; i < relativeBuff.length(); i++) {
139:                        if (relativeBuff.charAt(i) == '\\'
140:                                || relativeBuff.charAt(i) == '/')
141:                            relativeBuff.setCharAt(i, slash.charAt(0));
142:                    }
143:
144:                    wsdlPath += relativeBuff;
145:
146:                    if (!wsdlPath.endsWith(slash))
147:                        wsdlPath += slash;
148:                }
149:                return wsdlPath;
150:            }
151:
152:            /**
153:             * Gets a property from the wsif.test.properties file
154:             */
155:            public static String getWsifProperty(String property) {
156:                try {
157:                    Properties prop = new Properties();
158:                    InputStream in = ClassLoader
159:                            .getSystemResourceAsStream(WSIF_TEST_PROPERTIES);
160:                    prop.load(in);
161:                    return prop.getProperty(property);
162:                } catch (Exception ignored) {
163:                    return null;
164:                }
165:            }
166:
167:            /**
168:             * Finds out from the wsif.test.properties file whether we are testing
169:             * a particular component (EJBs, JMS, etc) of WSIF. If not mentioned
170:             * in wsif.test.properties, the default is to test everything.
171:             */
172:            public static boolean areWeTesting(String component) {
173:                String prop = getWsifProperty(WSIF_TEST_COMPONENTS);
174:                if (prop == null)
175:                    return true; // test everything by default
176:
177:                StringTokenizer tokenizer = new StringTokenizer(prop, ",");
178:                String token;
179:                int eqPos;
180:                while (tokenizer.hasMoreTokens()) {
181:                    token = tokenizer.nextToken();
182:                    eqPos = token.indexOf('=');
183:                    if (eqPos == -1)
184:                        continue;
185:                    if (token.substring(0, eqPos).equals(component)
186:                            && token.substring(eqPos + 1).equals("off"))
187:                        return false;
188:                }
189:                return true;
190:            }
191:
192:            /**
193:             * Queries the soap server being used. Can be either Apache Soap or Apache Axis.
194:             * Default is soap.
195:             */
196:            public static String getSoapServer() {
197:                String prop = getWsifProperty(WSIF_SOAP_SERVER);
198:                if (prop == null)
199:                    return SOAP;
200:                if (SOAP.equals(prop) || AXIS.equals(prop))
201:                    return prop;
202:                return SOAP;
203:            }
204:
205:            public static boolean isJmsVerbose() {
206:                String strVerbose = TestUtilities
207:                        .getWsifProperty("wsif.jms.output");
208:                if ("verbose".equals(strVerbose))
209:                    return true;
210:                return false;
211:            }
212:
213:            public static void setProviderForProtocol(String protocol) {
214:                if (protocol.equals(NON_DEFAULT_SOAP_PROTOCOL)) {
215:                    try {
216:                        WSIFPluggableProviders.overrideDefaultProvider(
217:                                "http://schemas.xmlsoap.org/wsdl/soap/",
218:                                (WSIFProvider) NON_DEFAULT_SOAP_PROVIDER_CLASS
219:                                        .newInstance());
220:                    } catch (Exception ex) {
221:                        ex.printStackTrace();
222:                    }
223:                } else {
224:                    resetDefaultProviders();
225:                }
226:            }
227:
228:            public static void resetDefaultProviders() {
229:                WSIFPluggableProviders.setAutoLoadProviders(false);
230:                WSIFPluggableProviders.setAutoLoadProviders(true);
231:            }
232:
233:            public static void setUpExtensionsAndProviders() {
234:                //WSIFServiceImpl.addExtensionRegistry(new JavaExtensionRegistry()) ;    
235:                //WSIFServiceImpl.addExtensionRegistry(new FormatExtensionRegistry()) ;        
236:                //WSIFServiceImpl.addExtensionRegistry(new JmsExtensionRegistry()) ;
237:                //WSIFServiceImpl.addExtensionRegistry(new EJBExtensionRegistry());
238:                resetDefaultProviders();
239:            }
240:
241:            /**
242:             * This starts what listeners are required to run the testcases.
243:             * What listeners are needed depends on settings in the 
244:             * wsif.test.properties file.
245:             * Possible listeners are:
246:             *    JMS2HTTPBridge - for SOAP/JMS tests
247:             *    NativeJMSRequestListener - for the native JMS provider 
248:             *    JMSAsynListener - for asynchronous operation tests
249:             */
250:            public static void startListeners() {
251:                startListeners(ALL_LISTENERS);
252:            }
253:
254:            public static void startListeners(int which) {
255:                if (TestUtilities.areWeTesting("jms")) {
256:                    if ((which & ADDRESSBOOK_LISTENER) > 0) {
257:                        jmsAb = new BridgeThread("AddressBook");
258:                        jmsAb.start();
259:                    }
260:
261:                    if ((which & STOCKQUOTE_LISTENER) > 0) {
262:                        jmsSq = new BridgeThread("Stockquote");
263:                        jmsSq.start();
264:                    }
265:
266:                    if ((which & NATIVEJMS_LISTENER) > 0)
267:                        try {
268:                            nativeReqListener = new NativeJMSRequestListener(
269:                                    TestUtilities
270:                                            .getWsifProperty("wsif.nativejms.requestq"));
271:                        } catch (WSIFException ex) {
272:                            ex.printStackTrace();
273:                        }
274:                }
275:
276:                if ((which & ASYNC_LISTENER) > 0
277:                        && TestUtilities.areWeTesting("async"))
278:                    try {
279:                        asyncListener = new JMSAsyncListener(TestUtilities
280:                                .getWsifProperty("wsif.async.replytoq"));
281:                    } catch (Exception ex) {
282:                        ex.printStackTrace();
283:                    }
284:            }
285:
286:            /**
287:             * This starts whatever listeners have been started.
288:             * Possible listeners are:
289:             *    JMS2HTTPBridge - for SOAP/JMS tests
290:             *    NativeJMSRequestListener - for the native JMS provider 
291:             *    JMSAsynListener - for asynchronous operation tests
292:             */
293:            public static void stopListeners() {
294:                if (jmsAb != null)
295:                    jmsAb.interrupt();
296:                if (jmsSq != null)
297:                    jmsSq.interrupt();
298:                if (asyncListener != null)
299:                    asyncListener.stop();
300:                if (nativeReqListener != null)
301:                    nativeReqListener.stop();
302:                ((WSIFDefaultCorrelationService) WSIFCorrelationServiceLocator
303:                        .getCorrelationService()).shutdown();
304:            }
305:
306:            public static Message getJMSAsyncResponse(String id,
307:                    String queueName) throws WSIFException, JMSException {
308:
309:                WSIFJMSFinder finder = new WSIFJMSFinderForJndi(
310:                        null,
311:                        TestUtilities
312:                                .getWsifProperty("wsif.jms2httpbridge.initialcontextfactory"),
313:                        TestUtilities
314:                                .getWsifProperty("wsif.jms2httpbridge.jndiproviderurl"),
315:                        WSIFJMSFinder.STYLE_QUEUE,
316:                        TestUtilities
317:                                .getWsifProperty("wsif.jms2httpbridge.jndiconnectionfactoryname"),
318:                        null, null);
319:
320:                QueueConnectionFactory factory = finder.getFactory();
321:                QueueConnection connection = factory.createQueueConnection();
322:                connection.start();
323:                QueueSession session = connection.createQueueSession(false,
324:                        Session.AUTO_ACKNOWLEDGE);
325:                Queue readQ = session.createQueue(queueName);
326:                QueueReceiver receiver = session.createReceiver(readQ,
327:                        "JMSCorrelationID='" + id + "'");
328:                return receiver.receive(WSIFProperties.getAsyncTimeout());
329:            }
330:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.