Source Code Cross Referenced for DispatchClientServerTest.java in  » ESB » celtix-1.0 » org » objectweb » celtix » systest » 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 » ESB » celtix 1.0 » org.objectweb.celtix.systest.dispatch 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.objectweb.celtix.systest.dispatch;
002:
003:        import java.io.IOException;
004:        import java.io.InputStream;
005:        import java.net.URL;
006:        import java.util.concurrent.Future;
007:
008:        import javax.xml.bind.JAXBContext;
009:        import javax.xml.namespace.QName;
010:        import javax.xml.soap.MessageFactory;
011:        import javax.xml.soap.SOAPMessage;
012:        import javax.xml.transform.dom.DOMSource;
013:        import javax.xml.transform.sax.SAXSource;
014:        import javax.xml.transform.stream.StreamSource;
015:        import javax.xml.ws.AsyncHandler;
016:        import javax.xml.ws.Dispatch;
017:        import javax.xml.ws.Response;
018:        import javax.xml.ws.Service;
019:
020:        import org.xml.sax.InputSource;
021:
022:        import junit.framework.Test;
023:        import junit.framework.TestSuite;
024:
025:        import org.objectweb.celtix.systest.basic.Server;
026:        import org.objectweb.celtix.systest.common.ClientServerSetupBase;
027:        import org.objectweb.celtix.systest.common.ClientServerTestBase;
028:        import org.objectweb.hello_world_soap_http.SOAPService;
029:        import org.objectweb.hello_world_soap_http.types.GreetMe;
030:        import org.objectweb.hello_world_soap_http.types.GreetMeResponse;
031:
032:        public class DispatchClientServerTest extends ClientServerTestBase {
033:
034:            private final QName serviceName = new QName(
035:                    "http://objectweb.org/hello_world_soap_http", "SOAPService");
036:            private final QName portName = new QName(
037:                    "http://objectweb.org/hello_world_soap_http", "SoapPort");
038:
039:            public static Test suite() throws Exception {
040:                TestSuite suite = new TestSuite(DispatchClientServerTest.class);
041:                return new ClientServerSetupBase(suite) {
042:                    public void startServers() throws Exception {
043:                        assertTrue("server did not launch correctly",
044:                                launchServer(Server.class));
045:                    }
046:                };
047:            }
048:
049:            public void testSOAPMessage() throws Exception {
050:
051:                URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
052:                assertNotNull(wsdl);
053:
054:                SOAPService service = new SOAPService(wsdl, serviceName);
055:                assertNotNull(service);
056:
057:                InputStream is = getClass().getResourceAsStream(
058:                        "resources/GreetMeDocLiteralReq.xml");
059:                SOAPMessage soapReqMsg = MessageFactory.newInstance()
060:                        .createMessage(null, is);
061:                assertNotNull(soapReqMsg);
062:
063:                InputStream is1 = getClass().getResourceAsStream(
064:                        "resources/GreetMeDocLiteralReq1.xml");
065:                SOAPMessage soapReqMsg1 = MessageFactory.newInstance()
066:                        .createMessage(null, is1);
067:                assertNotNull(soapReqMsg1);
068:
069:                InputStream is2 = getClass().getResourceAsStream(
070:                        "resources/GreetMeDocLiteralReq2.xml");
071:                SOAPMessage soapReqMsg2 = MessageFactory.newInstance()
072:                        .createMessage(null, is2);
073:                assertNotNull(soapReqMsg2);
074:
075:                InputStream is3 = getClass().getResourceAsStream(
076:                        "resources/GreetMeDocLiteralReq3.xml");
077:                SOAPMessage soapReqMsg3 = MessageFactory.newInstance()
078:                        .createMessage(null, is3);
079:                assertNotNull(soapReqMsg3);
080:
081:                Dispatch<SOAPMessage> disp = service.createDispatch(portName,
082:                        SOAPMessage.class, Service.Mode.MESSAGE);
083:                SOAPMessage soapResMsg = disp.invoke(soapReqMsg);
084:                assertNotNull(soapResMsg);
085:                String expected = "Hello TestSOAPInputMessage";
086:                assertEquals("Response should be : Hello TestSOAPInputMessage",
087:                        expected, soapResMsg.getSOAPBody().getTextContent());
088:
089:                disp.invokeOneWay(soapReqMsg1);
090:
091:                Response response = disp.invokeAsync(soapReqMsg2);
092:                SOAPMessage soapResMsg2 = (SOAPMessage) response.get();
093:                assertNotNull(soapResMsg2);
094:                String expected2 = "Hello TestSOAPInputMessage2";
095:                assertEquals(
096:                        "Response should be : Hello TestSOAPInputMessage2",
097:                        expected2, soapResMsg2.getSOAPBody().getTextContent());
098:
099:                TestSOAPMessageHandler tsmh = new TestSOAPMessageHandler();
100:                Future f = disp.invokeAsync(soapReqMsg3, tsmh);
101:                assertNotNull(f);
102:                while (!f.isDone()) {
103:                    //wait
104:                }
105:                String expected3 = "Hello TestSOAPInputMessage3";
106:                assertEquals(
107:                        "Response should be : Hello TestSOAPInputMessage3",
108:                        expected3, tsmh.getReplyBuffer());
109:            }
110:
111:            public void testDOMSourceMESSAGE() throws Exception {
112:
113:                URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
114:                assertNotNull(wsdl);
115:
116:                SOAPService service = new SOAPService(wsdl, serviceName);
117:                assertNotNull(service);
118:
119:                InputStream is = getClass().getResourceAsStream(
120:                        "resources/GreetMeDocLiteralReq.xml");
121:                SOAPMessage soapReqMsg = MessageFactory.newInstance()
122:                        .createMessage(null, is);
123:                DOMSource domReqMsg = new DOMSource(soapReqMsg.getSOAPPart());
124:                assertNotNull(domReqMsg);
125:
126:                InputStream is1 = getClass().getResourceAsStream(
127:                        "resources/GreetMeDocLiteralReq1.xml");
128:                SOAPMessage soapReqMsg1 = MessageFactory.newInstance()
129:                        .createMessage(null, is1);
130:                DOMSource domReqMsg1 = new DOMSource(soapReqMsg1.getSOAPPart());
131:                assertNotNull(domReqMsg1);
132:
133:                InputStream is2 = getClass().getResourceAsStream(
134:                        "resources/GreetMeDocLiteralReq2.xml");
135:                SOAPMessage soapReqMsg2 = MessageFactory.newInstance()
136:                        .createMessage(null, is2);
137:                DOMSource domReqMsg2 = new DOMSource(soapReqMsg2.getSOAPPart());
138:                assertNotNull(domReqMsg2);
139:
140:                InputStream is3 = getClass().getResourceAsStream(
141:                        "resources/GreetMeDocLiteralReq3.xml");
142:                SOAPMessage soapReqMsg3 = MessageFactory.newInstance()
143:                        .createMessage(null, is3);
144:                DOMSource domReqMsg3 = new DOMSource(soapReqMsg3.getSOAPPart());
145:                assertNotNull(domReqMsg3);
146:
147:                Dispatch<DOMSource> disp = service.createDispatch(portName,
148:                        DOMSource.class, Service.Mode.MESSAGE);
149:                DOMSource domResMsg = disp.invoke(domReqMsg);
150:                assertNotNull(domResMsg);
151:                String expected = "Hello TestSOAPInputMessage";
152:                assertEquals("Response should be : Hello TestSOAPInputMessage",
153:                        expected, domResMsg.getNode().getFirstChild()
154:                                .getTextContent());
155:
156:                disp.invokeOneWay(domReqMsg1);
157:
158:                Response response = disp.invokeAsync(domReqMsg2);
159:                DOMSource domRespMsg2 = (DOMSource) response.get();
160:                assertNotNull(domReqMsg2);
161:                String expected2 = "Hello TestSOAPInputMessage2";
162:                assertEquals(
163:                        "Response should be : Hello TestSOAPInputMessage2",
164:                        expected2, domRespMsg2.getNode().getFirstChild()
165:                                .getTextContent());
166:
167:                TestDOMSourceHandler tdsh = new TestDOMSourceHandler();
168:                Future fd = disp.invokeAsync(domReqMsg3, tdsh);
169:                assertNotNull(fd);
170:                while (!fd.isDone()) {
171:                    //wait
172:                }
173:                String expected3 = "Hello TestSOAPInputMessage3";
174:                assertEquals(
175:                        "Response should be : Hello TestSOAPInputMessage3",
176:                        expected3, tdsh.getReplyBuffer());
177:            }
178:
179:            public void testDOMSourcePAYLOAD() throws Exception {
180:
181:                URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
182:                assertNotNull(wsdl);
183:
184:                SOAPService service = new SOAPService(wsdl, serviceName);
185:                assertNotNull(service);
186:
187:                InputStream is = getClass().getResourceAsStream(
188:                        "resources/GreetMeDocLiteralReq.xml");
189:                SOAPMessage soapReqMsg = MessageFactory.newInstance()
190:                        .createMessage(null, is);
191:                DOMSource domReqMsg = new DOMSource(soapReqMsg.getSOAPBody()
192:                        .extractContentAsDocument());
193:                assertNotNull(domReqMsg);
194:
195:                InputStream is1 = getClass().getResourceAsStream(
196:                        "resources/GreetMeDocLiteralReq1.xml");
197:                SOAPMessage soapReqMsg1 = MessageFactory.newInstance()
198:                        .createMessage(null, is1);
199:                DOMSource domReqMsg1 = new DOMSource(soapReqMsg1.getSOAPBody()
200:                        .extractContentAsDocument());
201:                assertNotNull(domReqMsg1);
202:
203:                InputStream is2 = getClass().getResourceAsStream(
204:                        "resources/GreetMeDocLiteralReq2.xml");
205:                SOAPMessage soapReqMsg2 = MessageFactory.newInstance()
206:                        .createMessage(null, is2);
207:                DOMSource domReqMsg2 = new DOMSource(soapReqMsg2.getSOAPBody()
208:                        .extractContentAsDocument());
209:                assertNotNull(domReqMsg2);
210:
211:                InputStream is3 = getClass().getResourceAsStream(
212:                        "resources/GreetMeDocLiteralReq3.xml");
213:                SOAPMessage soapReqMsg3 = MessageFactory.newInstance()
214:                        .createMessage(null, is3);
215:                DOMSource domReqMsg3 = new DOMSource(soapReqMsg3.getSOAPBody()
216:                        .extractContentAsDocument());
217:                assertNotNull(domReqMsg3);
218:
219:                Dispatch<DOMSource> disp = service.createDispatch(portName,
220:                        DOMSource.class, Service.Mode.PAYLOAD);
221:
222:                //invoke
223:                DOMSource domResMsg = disp.invoke(domReqMsg);
224:                assertNotNull(domResMsg);
225:                String expected = "Hello TestSOAPInputMessage";
226:                assertEquals("Response should be : Hello TestSOAPInputMessage",
227:                        expected, domResMsg.getNode().getFirstChild()
228:                                .getTextContent());
229:
230:                //invokeOneWay
231:                disp.invokeOneWay(domReqMsg1);
232:
233:                //invokeAsync
234:                Response response = disp.invokeAsync(domReqMsg2);
235:                DOMSource domRespMsg2 = (DOMSource) response.get();
236:                assertNotNull(domRespMsg2);
237:                String expected2 = "Hello TestSOAPInputMessage2";
238:                assertEquals(
239:                        "Response should be : Hello TestSOAPInputMessage2",
240:                        expected2, domRespMsg2.getNode().getFirstChild()
241:                                .getTextContent());
242:
243:                //invokeAsync with AsyncHandler
244:                TestDOMSourceHandler tdsh = new TestDOMSourceHandler();
245:                Future fd = disp.invokeAsync(domReqMsg3, tdsh);
246:                assertNotNull(fd);
247:                while (!fd.isDone()) {
248:                    //wait
249:                }
250:                String expected3 = "Hello TestSOAPInputMessage3";
251:                assertEquals(
252:                        "Response should be : Hello TestSOAPInputMessage3",
253:                        expected3, tdsh.getReplyBuffer());
254:
255:            }
256:
257:            public void testSAXSourceMESSAGE() throws Exception {
258:
259:                URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
260:                assertNotNull(wsdl);
261:
262:                SOAPService service = new SOAPService(wsdl, serviceName);
263:                assertNotNull(service);
264:
265:                InputStream is = getClass().getResourceAsStream(
266:                        "resources/GreetMeDocLiteralReq.xml");
267:                InputSource inputSource = new InputSource(is);
268:                SAXSource saxSourceReq = new SAXSource(inputSource);
269:                assertNotNull(saxSourceReq);
270:
271:                InputStream is1 = getClass().getResourceAsStream(
272:                        "resources/GreetMeDocLiteralReq1.xml");
273:                InputSource inputSource1 = new InputSource(is1);
274:                SAXSource saxSourceReq1 = new SAXSource(inputSource1);
275:                assertNotNull(saxSourceReq1);
276:
277:                InputStream is2 = getClass().getResourceAsStream(
278:                        "resources/GreetMeDocLiteralReq2.xml");
279:                InputSource inputSource2 = new InputSource(is2);
280:                SAXSource saxSourceReq2 = new SAXSource(inputSource2);
281:                assertNotNull(saxSourceReq2);
282:
283:                InputStream is3 = getClass().getResourceAsStream(
284:                        "resources/GreetMeDocLiteralReq3.xml");
285:                InputSource inputSource3 = new InputSource(is3);
286:                SAXSource saxSourceReq3 = new SAXSource(inputSource3);
287:                assertNotNull(saxSourceReq3);
288:
289:                Dispatch<SAXSource> disp = service.createDispatch(portName,
290:                        SAXSource.class, Service.Mode.MESSAGE);
291:                SAXSource saxSourceResp = disp.invoke(saxSourceReq);
292:                assertNotNull(saxSourceResp);
293:                String expected = "Hello TestSOAPInputMessage";
294:                checkSAXSource(expected, saxSourceResp);
295:
296:                disp.invokeOneWay(saxSourceReq1);
297:
298:                Response response = disp.invokeAsync(saxSourceReq2);
299:                SAXSource saxSourceResp2 = (SAXSource) response.get();
300:                assertNotNull(saxSourceResp2);
301:                String expected2 = "Hello TestSOAPInputMessage2";
302:                checkSAXSource(expected2, saxSourceResp2);
303:
304:                TestSAXSourceHandler tssh = new TestSAXSourceHandler();
305:                Future fd = disp.invokeAsync(saxSourceReq3, tssh);
306:                assertNotNull(fd);
307:                while (!fd.isDone()) {
308:                    //wait
309:                }
310:                String expected3 = "Hello TestSOAPInputMessage3";
311:                SAXSource saxSourceResp3 = tssh.getSAXSource();
312:                assertNotNull(saxSourceResp3);
313:                checkSAXSource(expected3, saxSourceResp3);
314:
315:            }
316:
317:            public void testSAXSourcePAYLOAD() throws Exception {
318:
319:                URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
320:                assertNotNull(wsdl);
321:
322:                SOAPService service = new SOAPService(wsdl, serviceName);
323:                assertNotNull(service);
324:
325:                InputStream is = getClass().getResourceAsStream(
326:                        "resources/GreetMeDocLiteralSOAPBodyReq.xml");
327:                InputSource inputSource = new InputSource(is);
328:                SAXSource saxSourceReq = new SAXSource(inputSource);
329:                assertNotNull(saxSourceReq);
330:
331:                InputStream is1 = getClass().getResourceAsStream(
332:                        "resources/GreetMeDocLiteralSOAPBodyReq1.xml");
333:                InputSource inputSource1 = new InputSource(is1);
334:                SAXSource saxSourceReq1 = new SAXSource(inputSource1);
335:                assertNotNull(saxSourceReq1);
336:
337:                InputStream is2 = getClass().getResourceAsStream(
338:                        "resources/GreetMeDocLiteralSOAPBodyReq2.xml");
339:                InputSource inputSource2 = new InputSource(is2);
340:                SAXSource saxSourceReq2 = new SAXSource(inputSource2);
341:                assertNotNull(saxSourceReq2);
342:
343:                InputStream is3 = getClass().getResourceAsStream(
344:                        "resources/GreetMeDocLiteralSOAPBodyReq3.xml");
345:                InputSource inputSource3 = new InputSource(is3);
346:                SAXSource saxSourceReq3 = new SAXSource(inputSource3);
347:                assertNotNull(saxSourceReq3);
348:
349:                Dispatch<SAXSource> disp = service.createDispatch(portName,
350:                        SAXSource.class, Service.Mode.PAYLOAD);
351:                SAXSource saxSourceResp = disp.invoke(saxSourceReq);
352:                assertNotNull(saxSourceResp);
353:                String expected = "Hello TestSOAPInputMessage";
354:                checkSAXSource(expected, saxSourceResp);
355:
356:                disp.invokeOneWay(saxSourceReq1);
357:
358:                Response response = disp.invokeAsync(saxSourceReq2);
359:                SAXSource saxSourceResp2 = (SAXSource) response.get();
360:                assertNotNull(saxSourceResp2);
361:                String expected2 = "Hello TestSOAPInputMessage2";
362:                checkSAXSource(expected2, saxSourceResp2);
363:
364:                TestSAXSourceHandler tssh = new TestSAXSourceHandler();
365:                Future fd = disp.invokeAsync(saxSourceReq3, tssh);
366:                assertNotNull(fd);
367:                while (!fd.isDone()) {
368:                    //wait
369:                }
370:                String expected3 = "Hello TestSOAPInputMessage3";
371:                SAXSource saxSourceResp3 = tssh.getSAXSource();
372:                assertNotNull(saxSourceResp3);
373:                checkSAXSource(expected3, saxSourceResp3);
374:
375:            }
376:
377:            public void testStreamSourceMESSAGE() throws Exception {
378:
379:                URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
380:                assertNotNull(wsdl);
381:
382:                SOAPService service = new SOAPService(wsdl, serviceName);
383:                assertNotNull(service);
384:
385:                InputStream is = getClass().getResourceAsStream(
386:                        "resources/GreetMeDocLiteralReq.xml");
387:                StreamSource streamSourceReq = new StreamSource(is);
388:                assertNotNull(streamSourceReq);
389:
390:                InputStream is1 = getClass().getResourceAsStream(
391:                        "resources/GreetMeDocLiteralReq1.xml");
392:                StreamSource streamSourceReq1 = new StreamSource(is1);
393:                assertNotNull(streamSourceReq1);
394:
395:                InputStream is2 = getClass().getResourceAsStream(
396:                        "resources/GreetMeDocLiteralReq2.xml");
397:                StreamSource streamSourceReq2 = new StreamSource(is2);
398:                assertNotNull(streamSourceReq2);
399:
400:                InputStream is3 = getClass().getResourceAsStream(
401:                        "resources/GreetMeDocLiteralReq3.xml");
402:                StreamSource streamSourceReq3 = new StreamSource(is3);
403:                assertNotNull(streamSourceReq3);
404:
405:                Dispatch<StreamSource> disp = service.createDispatch(portName,
406:                        StreamSource.class, Service.Mode.MESSAGE);
407:                StreamSource streamSourceResp = disp.invoke(streamSourceReq);
408:                assertNotNull(streamSourceResp);
409:                String expected = "Hello TestSOAPInputMessage";
410:                checkStreamSource(expected, streamSourceResp);
411:
412:                disp.invokeOneWay(streamSourceReq1);
413:
414:                Response response = disp.invokeAsync(streamSourceReq2);
415:                StreamSource streamSourceResp2 = (StreamSource) response.get();
416:                assertNotNull(streamSourceResp2);
417:                String expected2 = "Hello TestSOAPInputMessage2";
418:                checkStreamSource(expected2, streamSourceResp2);
419:
420:                TestStreamSourceHandler tssh = new TestStreamSourceHandler();
421:                Future fd = disp.invokeAsync(streamSourceReq3, tssh);
422:                assertNotNull(fd);
423:                while (!fd.isDone()) {
424:                    //wait
425:                }
426:                String expected3 = "Hello TestSOAPInputMessage3";
427:                StreamSource streamSourceResp3 = tssh.getStreamSource();
428:                assertNotNull(streamSourceResp3);
429:                checkStreamSource(expected3, streamSourceResp3);
430:
431:            }
432:
433:            public void testStreamSourcePAYLOAD() throws Exception {
434:
435:                URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
436:                assertNotNull(wsdl);
437:
438:                SOAPService service = new SOAPService(wsdl, serviceName);
439:                assertNotNull(service);
440:
441:                InputStream is = getClass().getResourceAsStream(
442:                        "resources/GreetMeDocLiteralSOAPBodyReq.xml");
443:                StreamSource streamSourceReq = new StreamSource(is);
444:                assertNotNull(streamSourceReq);
445:
446:                InputStream is1 = getClass().getResourceAsStream(
447:                        "resources/GreetMeDocLiteralSOAPBodyReq1.xml");
448:                StreamSource streamSourceReq1 = new StreamSource(is1);
449:                assertNotNull(streamSourceReq1);
450:
451:                InputStream is2 = getClass().getResourceAsStream(
452:                        "resources/GreetMeDocLiteralSOAPBodyReq2.xml");
453:                StreamSource streamSourceReq2 = new StreamSource(is2);
454:                assertNotNull(streamSourceReq2);
455:
456:                InputStream is3 = getClass().getResourceAsStream(
457:                        "resources/GreetMeDocLiteralSOAPBodyReq3.xml");
458:                StreamSource streamSourceReq3 = new StreamSource(is3);
459:                assertNotNull(streamSourceReq3);
460:
461:                Dispatch<StreamSource> disp = service.createDispatch(portName,
462:                        StreamSource.class, Service.Mode.PAYLOAD);
463:                StreamSource streamSourceResp = disp.invoke(streamSourceReq);
464:                assertNotNull(streamSourceResp);
465:                String expected = "Hello TestSOAPInputMessage";
466:                checkStreamSource(expected, streamSourceResp);
467:
468:                disp.invokeOneWay(streamSourceReq1);
469:
470:                Response response = disp.invokeAsync(streamSourceReq2);
471:                StreamSource streamSourceResp2 = (StreamSource) response.get();
472:                assertNotNull(streamSourceResp2);
473:                String expected2 = "Hello TestSOAPInputMessage2";
474:                checkStreamSource(expected2, streamSourceResp2);
475:
476:                TestStreamSourceHandler tssh = new TestStreamSourceHandler();
477:                Future fd = disp.invokeAsync(streamSourceReq3, tssh);
478:                assertNotNull(fd);
479:                while (!fd.isDone()) {
480:                    //wait
481:                }
482:                String expected3 = "Hello TestSOAPInputMessage3";
483:                StreamSource streamSourceResp3 = tssh.getStreamSource();
484:                assertNotNull(streamSourceResp3);
485:                checkStreamSource(expected3, streamSourceResp3);
486:
487:            }
488:
489:            public void testJAXBObjectPAYLOAD() throws Exception {
490:
491:                URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
492:                assertNotNull(wsdl);
493:
494:                SOAPService service = new SOAPService(wsdl, serviceName);
495:                assertNotNull(service);
496:
497:                JAXBContext jc = JAXBContext
498:                        .newInstance("org.objectweb.hello_world_soap_http.types");
499:                Dispatch<Object> disp = service.createDispatch(portName, jc,
500:                        Service.Mode.PAYLOAD);
501:
502:                String expected = "Hello Jeeves";
503:                GreetMe greetMe = new GreetMe();
504:                greetMe.setRequestType("Jeeves");
505:
506:                Object response = disp.invoke(greetMe);
507:                assertNotNull(response);
508:                String responseValue = ((GreetMeResponse) response)
509:                        .getResponseType();
510:                assertTrue("Expected string, " + expected, expected
511:                        .equals(responseValue));
512:
513:                disp.invokeOneWay(greetMe);
514:
515:                Response response2 = disp.invokeAsync(greetMe);
516:                assertNotNull(response2);
517:                GreetMeResponse greetMeResponse = (GreetMeResponse) response2
518:                        .get();
519:                String responseValue2 = greetMeResponse.getResponseType();
520:                assertTrue("Expected string, " + expected, expected
521:                        .equals(responseValue2));
522:
523:                TestJAXBHandler tjbh = new TestJAXBHandler();
524:                Future fd = disp.invokeAsync(greetMe, tjbh);
525:                assertNotNull(fd);
526:                while (!fd.isDone()) {
527:                    //wait
528:                }
529:                String responseValue3 = ((GreetMeResponse) tjbh.getResponse())
530:                        .getResponseType();
531:                assertTrue("Expected string, " + expected, expected
532:                        .equals(responseValue3));
533:
534:            }
535:
536:            private void checkSAXSource(String expected, SAXSource source) {
537:
538:                InputSource inputSource = source.getInputSource();
539:                InputStream is = inputSource.getByteStream();
540:
541:                int i = 0;
542:                StringBuilder sb = new StringBuilder();
543:                try {
544:                    while (i != -1) {
545:                        i = is.read();
546:                        sb.append((char) i);
547:                    }
548:                } catch (IOException e) {
549:                    // TODO Auto-generated catch block
550:                    e.printStackTrace();
551:                }
552:                String received = sb.toString();
553:                assertTrue("Expected: " + expected, received.contains(expected));
554:
555:            }
556:
557:            private void checkStreamSource(String expected, StreamSource source) {
558:
559:                InputStream is = source.getInputStream();
560:
561:                int i = 0;
562:                StringBuilder sb = new StringBuilder();
563:                try {
564:                    while (i != -1) {
565:                        i = is.read();
566:                        sb.append((char) i);
567:                    }
568:                } catch (IOException e) {
569:                    // TODO Auto-generated catch block
570:                    e.printStackTrace();
571:                }
572:                String received = sb.toString();
573:                assertTrue("Expected: " + expected, received.contains(expected));
574:
575:            }
576:
577:            class TestSOAPMessageHandler implements  AsyncHandler<SOAPMessage> {
578:
579:                String replyBuffer;
580:
581:                public void handleResponse(Response<SOAPMessage> response) {
582:                    try {
583:                        SOAPMessage reply = response.get();
584:                        replyBuffer = reply.getSOAPBody().getTextContent();
585:                    } catch (Exception e) {
586:                        e.printStackTrace();
587:                    }
588:                }
589:
590:                public String getReplyBuffer() {
591:                    return replyBuffer;
592:                }
593:            }
594:
595:            class TestDOMSourceHandler implements  AsyncHandler<DOMSource> {
596:
597:                String replyBuffer;
598:
599:                public void handleResponse(Response<DOMSource> response) {
600:                    try {
601:                        DOMSource reply = response.get();
602:                        replyBuffer = reply.getNode().getFirstChild()
603:                                .getTextContent();
604:                    } catch (Exception e) {
605:                        e.printStackTrace();
606:                    }
607:                }
608:
609:                public String getReplyBuffer() {
610:                    return replyBuffer;
611:                }
612:            }
613:
614:            class TestSAXSourceHandler implements  AsyncHandler<SAXSource> {
615:
616:                SAXSource reply;
617:
618:                public void handleResponse(Response<SAXSource> response) {
619:                    try {
620:                        reply = response.get();
621:
622:                    } catch (Exception e) {
623:                        e.printStackTrace();
624:                    }
625:                }
626:
627:                public SAXSource getSAXSource() {
628:                    return reply;
629:                }
630:            }
631:
632:            class TestStreamSourceHandler implements  AsyncHandler<StreamSource> {
633:
634:                StreamSource reply;
635:
636:                public void handleResponse(Response<StreamSource> response) {
637:                    try {
638:                        reply = response.get();
639:
640:                    } catch (Exception e) {
641:                        e.printStackTrace();
642:                    }
643:                }
644:
645:                public StreamSource getStreamSource() {
646:                    return reply;
647:                }
648:            }
649:
650:            class TestJAXBHandler implements  AsyncHandler<Object> {
651:
652:                Object reply;
653:
654:                public void handleResponse(Response<Object> response) {
655:                    try {
656:                        reply = response.get();
657:                    } catch (Exception e) {
658:                        e.printStackTrace();
659:                    }
660:                }
661:
662:                public Object getResponse() {
663:                    return reply;
664:                }
665:            }
666:
667:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.