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