Source Code Cross Referenced for StringDispatch.java in  » Web-Services-AXIS2 » jax-ws » org » apache » axis2 » jaxws » dispatch » 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 » jax ws » org.apache.axis2.jaxws.dispatch 
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:        package org.apache.axis2.jaxws.dispatch;
020:
021:        import java.net.UnknownHostException;
022:        import java.util.concurrent.ExecutionException;
023:        import java.util.concurrent.Future;
024:
025:        import javax.xml.ws.Dispatch;
026:        import javax.xml.ws.ProtocolException;
027:        import javax.xml.ws.Response;
028:        import javax.xml.ws.Service;
029:        import javax.xml.ws.WebServiceException;
030:
031:        import junit.framework.TestCase;
032:        import org.apache.axis2.jaxws.TestLogger;
033:
034:        public class StringDispatch extends TestCase {
035:
036:            /**
037:             * Invoke a sync Dispatch<String> in PAYLOAD mode
038:             */
039:            public void testSyncPayloadMode() throws Exception {
040:                TestLogger.logger
041:                        .debug("---------------------------------------");
042:                TestLogger.logger.debug("test: " + getName());
043:
044:                // Initialize the JAX-WS client artifacts
045:                Service svc = Service
046:                        .create(DispatchTestConstants.QNAME_SERVICE);
047:                svc.addPort(DispatchTestConstants.QNAME_PORT, null,
048:                        DispatchTestConstants.URL);
049:                Dispatch<String> dispatch = svc.createDispatch(
050:                        DispatchTestConstants.QNAME_PORT, String.class,
051:                        Service.Mode.PAYLOAD);
052:
053:                // Invoke the Dispatch
054:                TestLogger.logger.debug(">> Invoking sync Dispatch");
055:                String response = dispatch
056:                        .invoke(DispatchTestConstants.sampleBodyContent);
057:
058:                assertNotNull("dispatch invoke returned null", response);
059:                TestLogger.logger.debug(response);
060:
061:                // Check to make sure the content is correct
062:                assertTrue(!response.contains("soap"));
063:                assertTrue(!response.contains("Envelope"));
064:                assertTrue(!response.contains("Body"));
065:                assertTrue(response.contains("echoStringResponse"));
066:            }
067:
068:            /**
069:             * Invoke a sync Dispatch<String> in PAYLOAD mode
070:             * Server response with exception.  Section 4.3.2
071:             * says we should get a ProtocolException, not a
072:             * WebServiceException.
073:             */
074:            public void testSyncPayloadMode_exception() throws Exception {
075:                TestLogger.logger
076:                        .debug("---------------------------------------");
077:                TestLogger.logger.debug("test: " + getName());
078:
079:                // Initialize the JAX-WS client artifacts
080:                Service svc = Service
081:                        .create(DispatchTestConstants.QNAME_SERVICE);
082:                svc.addPort(DispatchTestConstants.QNAME_PORT, null,
083:                        DispatchTestConstants.URL);
084:                Dispatch<String> dispatch = svc.createDispatch(
085:                        DispatchTestConstants.QNAME_PORT, String.class,
086:                        Service.Mode.PAYLOAD);
087:
088:                // Invoke the Dispatch
089:                TestLogger.logger.debug(">> Invoking sync Dispatch");
090:                Exception e = null;
091:                try {
092:                    // The _bad string passes "THROW EXCEPTION", which causes the echo function on the
093:                    // server to throw a RuntimeException.  We should get a ProtocolException here on the client
094:                    String response = dispatch
095:                            .invoke(DispatchTestConstants.sampleBodyContent_bad);
096:                } catch (Exception ex) {
097:                    e = ex;
098:                }
099:
100:                assertNotNull("No exception received", e);
101:                assertTrue("'e' should be of type ProtocolException",
102:                        e instanceof  ProtocolException);
103:
104:            }
105:
106:            /**
107:             * Invoke a sync Dispatch<String> in MESSAGE mode
108:             */
109:            public void testSyncWithMessageMode() throws Exception {
110:                TestLogger.logger
111:                        .debug("---------------------------------------");
112:                TestLogger.logger.debug("test: " + getName());
113:
114:                // Initialize the JAX-WS client artifacts
115:                Service svc = Service
116:                        .create(DispatchTestConstants.QNAME_SERVICE);
117:                svc.addPort(DispatchTestConstants.QNAME_PORT, null,
118:                        DispatchTestConstants.URL);
119:                Dispatch<String> dispatch = svc.createDispatch(
120:                        DispatchTestConstants.QNAME_PORT, String.class,
121:                        Service.Mode.MESSAGE);
122:
123:                // Invoke the Dispatch
124:                TestLogger.logger.debug(">> Invoking sync Dispatch");
125:                String response = dispatch
126:                        .invoke(DispatchTestConstants.sampleSoapMessage);
127:
128:                assertNotNull("dispatch invoke returned null", response);
129:                TestLogger.logger.debug(response);
130:
131:                // Check to make sure the content is correct
132:                assertTrue(response.contains("soap"));
133:                assertTrue(response.contains("Envelope"));
134:                assertTrue(response.contains("Body"));
135:                assertTrue(response.contains("echoStringResponse"));
136:            }
137:
138:            /**
139:             * Invoke a Dispatch<String> using the async callback API in PAYLOAD mode
140:             */
141:            public void testAsyncCallbackPayloadMode() throws Exception {
142:                TestLogger.logger
143:                        .debug("---------------------------------------");
144:                TestLogger.logger.debug("test: " + getName());
145:
146:                // Initialize the JAX-WS client artifacts
147:                Service svc = Service
148:                        .create(DispatchTestConstants.QNAME_SERVICE);
149:                svc.addPort(DispatchTestConstants.QNAME_PORT, null,
150:                        DispatchTestConstants.URL);
151:                Dispatch<String> dispatch = svc.createDispatch(
152:                        DispatchTestConstants.QNAME_PORT, String.class,
153:                        Service.Mode.PAYLOAD);
154:
155:                // Create the callback for async responses
156:                AsyncCallback<String> callback = new AsyncCallback<String>();
157:
158:                TestLogger.logger
159:                        .debug(">> Invoking async (callback) Dispatch");
160:                Future<?> monitor = dispatch.invokeAsync(
161:                        DispatchTestConstants.sampleBodyContent, callback);
162:
163:                while (!monitor.isDone()) {
164:                    TestLogger.logger
165:                            .debug(">> Async invocation still not complete");
166:                    Thread.sleep(1000);
167:                }
168:
169:                String response = callback.getValue();
170:                assertNotNull("dispatch invoke returned null", response);
171:                TestLogger.logger.debug(response);
172:
173:                // Check to make sure the content is correct
174:                assertTrue(!response.contains("soap"));
175:                assertTrue(!response.contains("Envelope"));
176:                assertTrue(!response.contains("Body"));
177:                assertTrue(response.contains("echoStringResponse"));
178:            }
179:
180:            /**
181:             * Invoke a Dispatch<String> using the async callback API in MESSAGE mode
182:             */
183:            public void testAsyncCallbackMessageMode() throws Exception {
184:                TestLogger.logger
185:                        .debug("---------------------------------------");
186:                TestLogger.logger.debug("test: " + getName());
187:
188:                // Initialize the JAX-WS client artifacts
189:                Service svc = Service
190:                        .create(DispatchTestConstants.QNAME_SERVICE);
191:                svc.addPort(DispatchTestConstants.QNAME_PORT, null,
192:                        DispatchTestConstants.URL);
193:                Dispatch<String> dispatch = svc.createDispatch(
194:                        DispatchTestConstants.QNAME_PORT, String.class,
195:                        Service.Mode.MESSAGE);
196:
197:                // Create the callback for async responses
198:                AsyncCallback<String> callback = new AsyncCallback<String>();
199:
200:                TestLogger.logger
201:                        .debug(">> Invoking async (callback) Dispatch with Message Mode");
202:                Future<?> monitor = dispatch.invokeAsync(
203:                        DispatchTestConstants.sampleSoapMessage, callback);
204:
205:                while (!monitor.isDone()) {
206:                    TestLogger.logger
207:                            .debug(">> Async invocation still not complete");
208:                    Thread.sleep(1000);
209:                }
210:
211:                String response = callback.getValue();
212:                assertNotNull("dispatch invoke returned null", response);
213:                TestLogger.logger.debug(response);
214:
215:                // Check to make sure the content is correct
216:                assertTrue(response.contains("soap"));
217:                assertTrue(response.contains("Envelope"));
218:                assertTrue(response.contains("Body"));
219:                assertTrue(response.contains("echoStringResponse"));
220:            }
221:
222:            /**
223:             * Invoke a Dispatch<String> using the async polling API in PAYLOAD mode
224:             */
225:            public void testAsyncPollingPayloadMode() throws Exception {
226:                TestLogger.logger
227:                        .debug("---------------------------------------");
228:                TestLogger.logger.debug("test: " + getName());
229:
230:                // Initialize the JAX-WS client artifacts
231:                Service svc = Service
232:                        .create(DispatchTestConstants.QNAME_SERVICE);
233:                svc.addPort(DispatchTestConstants.QNAME_PORT, null,
234:                        DispatchTestConstants.URL);
235:                Dispatch<String> dispatch = svc.createDispatch(
236:                        DispatchTestConstants.QNAME_PORT, String.class,
237:                        Service.Mode.PAYLOAD);
238:
239:                TestLogger.logger.debug(">> Invoking async (polling) Dispatch");
240:                Response<String> asyncResponse = dispatch
241:                        .invokeAsync(DispatchTestConstants.sampleBodyContent);
242:
243:                while (!asyncResponse.isDone()) {
244:                    TestLogger.logger
245:                            .debug(">> Async invocation still not complete");
246:                    Thread.sleep(1000);
247:                }
248:
249:                String response = asyncResponse.get();
250:                assertNotNull("dispatch invoke returned null", response);
251:                TestLogger.logger.debug(response);
252:
253:                // Check to make sure the content is correct
254:                assertTrue(!response.contains("soap"));
255:                assertTrue(!response.contains("Envelope"));
256:                assertTrue(!response.contains("Body"));
257:                assertTrue(response.contains("echoStringResponse"));
258:            }
259:
260:            /**
261:             * Invoke a Dispatch<String> using the async polling API in MESSAGE mode
262:             */
263:            public void testAsyncPollingMessageMode() throws Exception {
264:                TestLogger.logger
265:                        .debug("---------------------------------------");
266:                TestLogger.logger.debug("test: " + getName());
267:
268:                // Initialize the JAX-WS client artifacts
269:                Service svc = Service
270:                        .create(DispatchTestConstants.QNAME_SERVICE);
271:                svc.addPort(DispatchTestConstants.QNAME_PORT, null,
272:                        DispatchTestConstants.URL);
273:                Dispatch<String> dispatch = svc.createDispatch(
274:                        DispatchTestConstants.QNAME_PORT, String.class,
275:                        Service.Mode.MESSAGE);
276:
277:                TestLogger.logger
278:                        .debug(">> Invoking async (polling) Dispatch with Message Mode");
279:                Response<String> asyncResponse = dispatch
280:                        .invokeAsync(DispatchTestConstants.sampleSoapMessage);
281:
282:                while (!asyncResponse.isDone()) {
283:                    TestLogger.logger
284:                            .debug(">> Async invocation still not complete");
285:                    Thread.sleep(1000);
286:                }
287:
288:                String response = asyncResponse.get();
289:                assertNotNull("dispatch invoke returned null", response);
290:                TestLogger.logger.debug(response);
291:
292:                // Check to make sure the content is correct
293:                assertTrue(response.contains("soap"));
294:                assertTrue(response.contains("Envelope"));
295:                assertTrue(response.contains("Body"));
296:                assertTrue(response.contains("echoStringResponse"));
297:            }
298:
299:            /**
300:             * Invoke a Dispatch<String> one-way in PAYLOAD mode 
301:             */
302:            public void testOneWayPayloadMode() throws Exception {
303:                TestLogger.logger
304:                        .debug("---------------------------------------");
305:                TestLogger.logger.debug("test: " + getName());
306:
307:                // Initialize the JAX-WS client artifacts
308:                Service svc = Service
309:                        .create(DispatchTestConstants.QNAME_SERVICE);
310:                svc.addPort(DispatchTestConstants.QNAME_PORT, null,
311:                        DispatchTestConstants.URL);
312:                Dispatch<String> dispatch = svc.createDispatch(
313:                        DispatchTestConstants.QNAME_PORT, String.class,
314:                        Service.Mode.PAYLOAD);
315:
316:                TestLogger.logger.debug(">> Invoking one-way Dispatch");
317:                dispatch.invokeOneWay(DispatchTestConstants.sampleBodyContent);
318:            }
319:
320:            /**
321:             * Invoke a Dispatch<String> one-way in MESSAGE mode 
322:             */
323:            public void testOneWayMessageMode() throws Exception {
324:                TestLogger.logger
325:                        .debug("---------------------------------------");
326:                TestLogger.logger.debug("test: " + getName());
327:
328:                // Initialize the JAX-WS client artifacts
329:                Service svc = Service
330:                        .create(DispatchTestConstants.QNAME_SERVICE);
331:                svc.addPort(DispatchTestConstants.QNAME_PORT, null,
332:                        DispatchTestConstants.URL);
333:                Dispatch<String> dispatch = svc.createDispatch(
334:                        DispatchTestConstants.QNAME_PORT, String.class,
335:                        Service.Mode.MESSAGE);
336:
337:                TestLogger.logger.debug(">> Invoking one-way Dispatch");
338:                dispatch.invokeOneWay(DispatchTestConstants.sampleSoapMessage);
339:            }
340:
341:            public void testSyncPayloadMode_badHostName() {
342:                TestLogger.logger
343:                        .debug("---------------------------------------");
344:                TestLogger.logger.debug("test: " + getName());
345:
346:                // Initialize the JAX-WS client artifacts
347:                Service svc = Service
348:                        .create(DispatchTestConstants.QNAME_SERVICE);
349:                svc.addPort(DispatchTestConstants.QNAME_PORT, null,
350:                        DispatchTestConstants.BADURL);
351:                Dispatch<String> dispatch = svc.createDispatch(
352:                        DispatchTestConstants.QNAME_PORT, String.class,
353:                        Service.Mode.PAYLOAD);
354:
355:                // Invoke the Dispatch
356:                Throwable ttemp = null;
357:                try {
358:                    TestLogger.logger.debug(">> Invoking sync Dispatch");
359:                    String response = dispatch
360:                            .invoke(DispatchTestConstants.sampleBodyContent);
361:                } catch (Throwable t) {
362:                    assertTrue(t instanceof  WebServiceException);
363:                    assertTrue(t.getCause() instanceof  UnknownHostException);
364:                    ttemp = t;
365:                }
366:                assertNotNull(ttemp);
367:
368:            }
369:
370:            public void testAsyncCallbackMessageMode_badHostName()
371:                    throws Exception {
372:                TestLogger.logger
373:                        .debug("---------------------------------------");
374:                TestLogger.logger.debug("test: " + getName());
375:
376:                // Initialize the JAX-WS client artifacts
377:                Service svc = Service
378:                        .create(DispatchTestConstants.QNAME_SERVICE);
379:                svc.addPort(DispatchTestConstants.QNAME_PORT, null,
380:                        DispatchTestConstants.BADURL);
381:                Dispatch<String> dispatch = svc.createDispatch(
382:                        DispatchTestConstants.QNAME_PORT, String.class,
383:                        Service.Mode.MESSAGE);
384:
385:                // Create the callback for async responses
386:                AsyncCallback<String> callback = new AsyncCallback<String>();
387:
388:                TestLogger.logger
389:                        .debug(">> Invoking async (callback) Dispatch with Message Mode");
390:                Future<?> monitor = dispatch.invokeAsync(
391:                        DispatchTestConstants.sampleSoapMessage, callback);
392:
393:                while (!monitor.isDone()) {
394:                    TestLogger.logger
395:                            .debug(">> Async invocation still not complete");
396:                    Thread.sleep(1000);
397:                }
398:
399:                if (callback.hasError()) {
400:                    Throwable t = callback.getError();
401:                    t.printStackTrace();
402:
403:                    assertTrue(
404:                            t.getClass().getName()
405:                                    + " does not match expected type ExecutionException",
406:                            t instanceof  ExecutionException);
407:
408:                    Throwable cause = t.getCause();
409:                    assertNotNull(
410:                            "There must be a cause under the ExecutionException",
411:                            cause);
412:                    assertTrue(
413:                            cause.getClass().getName()
414:                                    + " does not match expected type WebServiceException",
415:                            cause instanceof  WebServiceException);
416:
417:                    Throwable hostException = t.getCause().getCause();
418:                    assertNotNull(
419:                            "There must be a cause under the WebServiceException",
420:                            hostException);
421:                    assertTrue(
422:                            hostException.getClass().getName()
423:                                    + " does not match expected type UnknownHostException",
424:                            hostException instanceof  UnknownHostException);
425:                } else {
426:                    fail("No fault thrown.  Should have retrieved an UnknownHostException from callback");
427:                }
428:            }
429:
430:            public void testAsyncPollingPayloadMode_badHostName()
431:                    throws Exception {
432:                TestLogger.logger
433:                        .debug("---------------------------------------");
434:                TestLogger.logger.debug("test: " + getName());
435:
436:                // Initialize the JAX-WS client artifacts
437:                Service svc = Service
438:                        .create(DispatchTestConstants.QNAME_SERVICE);
439:                svc.addPort(DispatchTestConstants.QNAME_PORT, null,
440:                        DispatchTestConstants.BADURL);
441:                Dispatch<String> dispatch = svc.createDispatch(
442:                        DispatchTestConstants.QNAME_PORT, String.class,
443:                        Service.Mode.PAYLOAD);
444:
445:                TestLogger.logger.debug(">> Invoking async (polling) Dispatch");
446:                Response<String> asyncResponse = dispatch
447:                        .invokeAsync(DispatchTestConstants.sampleBodyContent);
448:
449:                while (!asyncResponse.isDone()) {
450:                    TestLogger.logger
451:                            .debug(">> Async invocation still not complete");
452:                    Thread.sleep(1000);
453:                }
454:
455:                Throwable ttemp = null;
456:                try {
457:                    asyncResponse.get();
458:                } catch (Throwable t) {
459:                    assertTrue(t instanceof  ExecutionException);
460:                    assertTrue(t.getCause() instanceof  WebServiceException);
461:                    assertTrue(t.getCause().getCause() instanceof  UnknownHostException);
462:                    ttemp = t;
463:                }
464:                assertNotNull(ttemp);
465:            }
466:
467:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.