Source Code Cross Referenced for StreamSourceDispatch.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.io.ByteArrayInputStream;
022:        import java.io.InputStream;
023:        import java.util.concurrent.Future;
024:
025:        import javax.xml.stream.XMLInputFactory;
026:        import javax.xml.stream.XMLStreamReader;
027:        import javax.xml.transform.Source;
028:        import javax.xml.transform.stream.StreamSource;
029:        import javax.xml.ws.Dispatch;
030:        import javax.xml.ws.Response;
031:        import javax.xml.ws.Service;
032:        import javax.xml.ws.Service.Mode;
033:
034:        import junit.framework.TestCase;
035:        import org.apache.axis2.jaxws.message.util.Reader2Writer;
036:        import org.apache.axis2.jaxws.TestLogger;
037:
038:        /**
039:         * This class tests the JAX-WS Dispatch<Source> functionality with various
040:         * forms of a StreamSource object. 
041:         *
042:         */
043:        public class StreamSourceDispatch extends TestCase {
044:
045:            private static XMLInputFactory inputFactory = XMLInputFactory
046:                    .newInstance();
047:
048:            /**
049:             * Invoke a Dispatch<Source> synchronously with the content in PAYLOAD mode.
050:             */
051:            public void testSyncPayloadMode() throws Exception {
052:                TestLogger.logger
053:                        .debug("---------------------------------------");
054:                TestLogger.logger.debug("test: " + getName());
055:
056:                // Initialize the JAX-WS client artifacts
057:                Service svc = Service
058:                        .create(DispatchTestConstants.QNAME_SERVICE);
059:                svc.addPort(DispatchTestConstants.QNAME_PORT, null,
060:                        DispatchTestConstants.URL);
061:                Dispatch<Source> dispatch = svc.createDispatch(
062:                        DispatchTestConstants.QNAME_PORT, Source.class,
063:                        Service.Mode.PAYLOAD);
064:
065:                // Create a StreamSource with the desired content
066:                byte[] bytes = DispatchTestConstants.sampleBodyContent
067:                        .getBytes();
068:                ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
069:                Source srcStream = new StreamSource((InputStream) stream);
070:
071:                // Invoke the Dispatch<Source>
072:                TestLogger.logger
073:                        .debug(">> Invoking sync Dispatch with PAYLOAD mode");
074:                Source response = dispatch.invoke(srcStream);
075:                assertNotNull(response);
076:
077:                // Prepare the response content for checking
078:                XMLStreamReader reader = inputFactory
079:                        .createXMLStreamReader(response);
080:                Reader2Writer r2w = new Reader2Writer(reader);
081:                String responseText = r2w.getAsString();
082:                TestLogger.logger.debug(responseText);
083:
084:                // Check to make sure the content is correct
085:                assertTrue(!responseText.contains("soap"));
086:                assertTrue(!responseText.contains("Envelope"));
087:                assertTrue(!responseText.contains("Body"));
088:                assertTrue(responseText.contains("echoStringResponse"));
089:            }
090:
091:            /**
092:             * Invoke a Dispatch<Source> synchronously with the content in MESSAGE mode.
093:             */
094:            public void testSyncMessageMode() throws Exception {
095:                TestLogger.logger
096:                        .debug("---------------------------------------");
097:                TestLogger.logger.debug("test: " + getName());
098:
099:                // Initialize the JAX-WS client artifacts
100:                Service svc = Service
101:                        .create(DispatchTestConstants.QNAME_SERVICE);
102:                svc.addPort(DispatchTestConstants.QNAME_PORT, null,
103:                        DispatchTestConstants.URL);
104:                Dispatch<Source> dispatch = svc.createDispatch(
105:                        DispatchTestConstants.QNAME_PORT, Source.class,
106:                        Mode.MESSAGE);
107:
108:                // Create a StreamSource with the desired content
109:                byte[] bytes = DispatchTestConstants.sampleSoapMessage
110:                        .getBytes();
111:                ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
112:                Source srcStream = new StreamSource((InputStream) stream);
113:
114:                TestLogger.logger
115:                        .debug(">> Invoking sync Dispatch with MESSAGE Mode");
116:                StreamSource response = (StreamSource) dispatch
117:                        .invoke(srcStream);
118:                assertNotNull(response);
119:
120:                // Prepare the response content for checking
121:                XMLStreamReader reader = inputFactory
122:                        .createXMLStreamReader(response);
123:                Reader2Writer r2w = new Reader2Writer(reader);
124:                String responseText = r2w.getAsString();
125:                TestLogger.logger.debug(responseText);
126:
127:                // Check to make sure the content is correct
128:                assertTrue(responseText.contains("soap"));
129:                assertTrue(responseText.contains("Envelope"));
130:                assertTrue(responseText.contains("Body"));
131:                assertTrue(responseText.contains("echoStringResponse"));
132:            }
133:
134:            /**
135:             * Invoke a Dispatch<Source> asynchronously with the content in PAYLOAD mode.
136:             */
137:            public void testAsyncCallbackPayloadMode() throws Exception {
138:                TestLogger.logger
139:                        .debug("---------------------------------------");
140:                TestLogger.logger.debug("test: " + getName());
141:
142:                // Initialize the JAX-WS client artifacts
143:                Service svc = Service
144:                        .create(DispatchTestConstants.QNAME_SERVICE);
145:                svc.addPort(DispatchTestConstants.QNAME_PORT, null,
146:                        DispatchTestConstants.URL);
147:                Dispatch<Source> dispatch = svc.createDispatch(
148:                        DispatchTestConstants.QNAME_PORT, Source.class,
149:                        Service.Mode.PAYLOAD);
150:
151:                // We'll need a callback instance to handle the async responses
152:                AsyncCallback<Source> callbackHandler = new AsyncCallback<Source>();
153:
154:                // Create a StreamSource with the desired content
155:                byte[] bytes = DispatchTestConstants.sampleBodyContent
156:                        .getBytes();
157:                ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
158:                Source srcStream = new StreamSource((InputStream) stream);
159:
160:                TestLogger.logger
161:                        .debug(">> Invoking async (callback) Dispatch with PAYLOAD mode");
162:                Future<?> monitor = dispatch.invokeAsync(srcStream,
163:                        callbackHandler);
164:
165:                // Wait for the async response to be returned
166:                while (!monitor.isDone()) {
167:                    TestLogger.logger
168:                            .debug(">> Async invocation still not complete");
169:                    Thread.sleep(1000);
170:                }
171:
172:                Source response = callbackHandler.getValue();
173:                assertNotNull(response);
174:
175:                // Prepare the response content for checking
176:                XMLStreamReader reader = inputFactory
177:                        .createXMLStreamReader(response);
178:                Reader2Writer r2w = new Reader2Writer(reader);
179:                String responseText = r2w.getAsString();
180:                TestLogger.logger.debug(responseText);
181:
182:                // Check to make sure the content is correct
183:                assertTrue(!responseText.contains("soap"));
184:                assertTrue(!responseText.contains("Envelope"));
185:                assertTrue(!responseText.contains("Body"));
186:                assertTrue(responseText.contains("echoStringResponse"));
187:            }
188:
189:            /**
190:             * Invoke a Dispatch<Source> asynchronously with the content in MESSAGE mode.
191:             */
192:            public void testAsyncCallbackMessageMode() throws Exception {
193:                TestLogger.logger
194:                        .debug("---------------------------------------");
195:                TestLogger.logger.debug("test: " + getName());
196:
197:                // Initialize the JAX-WS client artifacts 
198:                Service svc = Service
199:                        .create(DispatchTestConstants.QNAME_SERVICE);
200:                svc.addPort(DispatchTestConstants.QNAME_PORT, null,
201:                        DispatchTestConstants.URL);
202:                Dispatch<Source> dispatch = svc.createDispatch(
203:                        DispatchTestConstants.QNAME_PORT, Source.class,
204:                        Mode.MESSAGE);
205:
206:                // We'll need a callback instance to handle the async responses
207:                AsyncCallback<Source> callbackHandler = new AsyncCallback<Source>();
208:
209:                // Create a StreamSource with the desired content
210:                byte[] bytes = DispatchTestConstants.sampleSoapMessage
211:                        .getBytes();
212:                ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
213:                Source srcStream = new StreamSource((InputStream) stream);
214:
215:                TestLogger.logger
216:                        .debug(">> Invoking async (callback) Dispatch with MESSAGE mode");
217:                Future<?> monitor = dispatch.invokeAsync(srcStream,
218:                        callbackHandler);
219:
220:                // Wait for the async response to be returned
221:                while (!monitor.isDone()) {
222:                    TestLogger.logger
223:                            .debug(">> Async invocation still not complete");
224:                    Thread.sleep(1000);
225:                }
226:
227:                Source response = callbackHandler.getValue();
228:                assertNotNull(response);
229:
230:                // Prepare the response content for checking
231:                XMLStreamReader reader = inputFactory
232:                        .createXMLStreamReader(response);
233:                Reader2Writer r2w = new Reader2Writer(reader);
234:                String responseText = r2w.getAsString();
235:                TestLogger.logger.debug(responseText);
236:
237:                // Check to make sure the content is correct
238:                assertTrue(responseText.contains("soap"));
239:                assertTrue(responseText.contains("Envelope"));
240:                assertTrue(responseText.contains("Body"));
241:                assertTrue(responseText.contains("echoStringResponse"));
242:            }
243:
244:            /**
245:             * Invoke a Dispatch<Source> asynchronously with the content in PAYLOAD mode.
246:             */
247:            public void testAsyncPollingPayloadMode() throws Exception {
248:                TestLogger.logger
249:                        .debug("---------------------------------------");
250:                TestLogger.logger.debug("test: " + getName());
251:
252:                // Initialize the JAX-WS client artifacts
253:                Service svc = Service
254:                        .create(DispatchTestConstants.QNAME_SERVICE);
255:                svc.addPort(DispatchTestConstants.QNAME_PORT, null,
256:                        DispatchTestConstants.URL);
257:                Dispatch<Source> dispatch = svc.createDispatch(
258:                        DispatchTestConstants.QNAME_PORT, Source.class,
259:                        Service.Mode.PAYLOAD);
260:                // Create a StreamSource with the desired content
261:                byte[] bytes = DispatchTestConstants.sampleBodyContent
262:                        .getBytes();
263:                ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
264:                Source srcStream = new StreamSource((InputStream) stream);
265:
266:                TestLogger.logger
267:                        .debug(">> Invoking async (callback) Dispatch with PAYLOAD mode");
268:                Response<Source> asyncResponse = dispatch
269:                        .invokeAsync(srcStream);
270:
271:                // Wait for the async response to be returned
272:                while (!asyncResponse.isDone()) {
273:                    TestLogger.logger
274:                            .debug(">> Async invocation still not complete");
275:                    Thread.sleep(1000);
276:                }
277:
278:                Source response = asyncResponse.get();
279:                assertNotNull(response);
280:
281:                // Prepare the response content for checking
282:                XMLStreamReader reader = inputFactory
283:                        .createXMLStreamReader(response);
284:                Reader2Writer r2w = new Reader2Writer(reader);
285:                String responseText = r2w.getAsString();
286:                TestLogger.logger.debug(responseText);
287:
288:                // Check to make sure the content is correct
289:                assertTrue(!responseText.contains("soap"));
290:                assertTrue(!responseText.contains("Envelope"));
291:                assertTrue(!responseText.contains("Body"));
292:                assertTrue(responseText.contains("echoStringResponse"));
293:            }
294:
295:            /**
296:             * Invoke a Dispatch<Source> asynchronously with the content in MESSAGE mode.
297:             */
298:            public void testAsyncPollingMessageMode() throws Exception {
299:                TestLogger.logger
300:                        .debug("---------------------------------------");
301:                TestLogger.logger.debug("test: " + getName());
302:
303:                // Initialize the JAX-WS client artifacts 
304:                Service svc = Service
305:                        .create(DispatchTestConstants.QNAME_SERVICE);
306:                svc.addPort(DispatchTestConstants.QNAME_PORT, null,
307:                        DispatchTestConstants.URL);
308:                Dispatch<Source> dispatch = svc.createDispatch(
309:                        DispatchTestConstants.QNAME_PORT, Source.class,
310:                        Mode.MESSAGE);
311:
312:                // Create a StreamSource with the desired content
313:                byte[] bytes = DispatchTestConstants.sampleSoapMessage
314:                        .getBytes();
315:                ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
316:                Source srcStream = new StreamSource((InputStream) stream);
317:
318:                TestLogger.logger
319:                        .debug(">> Invoking async (callback) Dispatch with MESSAGE mode");
320:                Response<Source> asyncResponse = dispatch
321:                        .invokeAsync(srcStream);
322:
323:                // Wait for the async response to be returned
324:                while (!asyncResponse.isDone()) {
325:                    TestLogger.logger
326:                            .debug(">> Async invocation still not complete");
327:                    Thread.sleep(1000);
328:                }
329:
330:                Source response = asyncResponse.get();
331:                assertNotNull(response);
332:
333:                // Prepare the response content for checking
334:                XMLStreamReader reader = inputFactory
335:                        .createXMLStreamReader(response);
336:                Reader2Writer r2w = new Reader2Writer(reader);
337:                String responseText = r2w.getAsString();
338:                TestLogger.logger.debug(responseText);
339:
340:                // Check to make sure the content is correct
341:                assertTrue(responseText.contains("soap"));
342:                assertTrue(responseText.contains("Envelope"));
343:                assertTrue(responseText.contains("Body"));
344:                assertTrue(responseText.contains("echoStringResponse"));
345:            }
346:
347:            /**
348:             * Invoke a Dispatch<Source> one-way operation
349:             */
350:            public void testOneWayPayloadMode() throws Exception {
351:                TestLogger.logger
352:                        .debug("---------------------------------------");
353:                TestLogger.logger.debug("test: " + getName());
354:
355:                // Initialize the JAX-WS client artifacts
356:                Service svc = Service
357:                        .create(DispatchTestConstants.QNAME_SERVICE);
358:                svc.addPort(DispatchTestConstants.QNAME_PORT, null,
359:                        DispatchTestConstants.URL);
360:                Dispatch<Source> dispatch = svc.createDispatch(
361:                        DispatchTestConstants.QNAME_PORT, Source.class,
362:                        Service.Mode.PAYLOAD);
363:
364:                // Create a StreamSource with the desired content
365:                byte[] bytes = DispatchTestConstants.sampleBodyContent
366:                        .getBytes();
367:                ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
368:                Source srcStream = new StreamSource((InputStream) stream);
369:
370:                TestLogger.logger.debug(">> Invoking One Way Dispatch");
371:                dispatch.invokeOneWay(srcStream);
372:            }
373:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.