Source Code Cross Referenced for JAXBDispatch.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.util.concurrent.Future;
022:
023:        import javax.xml.bind.JAXBContext;
024:        import javax.xml.bind.JAXBElement;
025:        import javax.xml.ws.Dispatch;
026:        import javax.xml.ws.Service;
027:
028:        import org.xmlsoap.schemas.soap.envelope.Body;
029:        import org.xmlsoap.schemas.soap.envelope.Envelope;
030:        import org.apache.axis2.jaxws.TestLogger;
031:
032:        import junit.framework.TestCase;
033:        import test.EchoString;
034:        import test.EchoStringResponse;
035:        import test.ObjectFactory;
036:
037:        public class JAXBDispatch extends TestCase {
038:
039:            private Dispatch<Object> dispatchPayload;
040:            private Dispatch<Object> dispatchMessage;
041:            private JAXBContext jbc;
042:
043:            public JAXBDispatch(String name) {
044:                super (name);
045:            }
046:
047:            public void setUp() throws Exception {
048:                //Create the Service object
049:                Service svc = Service
050:                        .create(DispatchTestConstants.QNAME_SERVICE);
051:                svc.addPort(DispatchTestConstants.QNAME_PORT, null,
052:                        DispatchTestConstants.URL);
053:
054:                //Create the JAX-B Dispatch object to recognize the test and soap packages
055:                jbc = JAXBContext
056:                        .newInstance("test:org.xmlsoap.schemas.soap.envelope");
057:
058:                // Create Payload and Message Dispatch
059:                dispatchPayload = svc.createDispatch(
060:                        DispatchTestConstants.QNAME_PORT, jbc,
061:                        Service.Mode.PAYLOAD);
062:                dispatchMessage = svc.createDispatch(
063:                        DispatchTestConstants.QNAME_PORT, jbc,
064:                        Service.Mode.MESSAGE);
065:            }
066:
067:            public void testSyncPayload() throws Exception {
068:                TestLogger.logger
069:                        .debug("---------------------------------------");
070:                TestLogger.logger.debug("test: " + getName());
071:
072:                // Create the input param
073:                ObjectFactory factory = new ObjectFactory();
074:                EchoString request = factory.createEchoString();
075:                request.setInput("SYNC JAXB PAYLOAD TEST");
076:
077:                // Invoke the Dispatch<Object>
078:                TestLogger.logger
079:                        .debug(">> Invoking sync Dispatch with JAX-B Parameter");
080:                EchoStringResponse response = (EchoStringResponse) dispatchPayload
081:                        .invoke(request);
082:
083:                assertNotNull(response);
084:
085:                TestLogger.logger.debug(">> Response content: "
086:                        + response.getEchoStringReturn());
087:
088:                assertTrue("[ERROR] - Response object was null",
089:                        response != null);
090:                assertTrue("[ERROR] - No content in response object", response
091:                        .getEchoStringReturn() != null);
092:                assertTrue("[ERROR] - Zero length content in response",
093:                        response.getEchoStringReturn().length() > 0);
094:            }
095:
096:            public void testAysncPayload() throws Exception {
097:                TestLogger.logger
098:                        .debug("---------------------------------------");
099:                TestLogger.logger.debug("test: " + getName());
100:
101:                // Create the input param
102:                ObjectFactory factory = new ObjectFactory();
103:                EchoString request = factory.createEchoString();
104:                request.setInput("ASYNC(CALLBACK) JAXB PAYLOAD TEST");
105:
106:                // Create the callback for async responses
107:                JAXBCallbackHandler<Object> callback = new JAXBCallbackHandler<Object>();
108:
109:                // Invoke the Dispatch<Object> asynchronously
110:                TestLogger.logger
111:                        .debug(">> Invoking async(callback) Dispatch with JAX-B Parameter");
112:                Future<?> monitor = dispatchPayload.invokeAsync(request,
113:                        callback);
114:
115:                while (!monitor.isDone()) {
116:                    TestLogger.logger
117:                            .debug(">> Async invocation still not complete");
118:                    Thread.sleep(1000);
119:                }
120:
121:                EchoStringResponse response = (EchoStringResponse) callback
122:                        .getData();
123:                assertNotNull(response);
124:
125:                TestLogger.logger.debug(">> Response content: "
126:                        + response.getEchoStringReturn());
127:
128:                assertTrue("[ERROR] - Response object was null",
129:                        response != null);
130:                assertTrue("[ERROR] - No content in response object", response
131:                        .getEchoStringReturn() != null);
132:                assertTrue("[ERROR] - Zero length content in response",
133:                        response.getEchoStringReturn().length() > 0);
134:
135:            }
136:
137:            public void testOneWayPayload() throws Exception {
138:                TestLogger.logger
139:                        .debug("---------------------------------------");
140:                TestLogger.logger.debug("test: " + getName());
141:
142:                // Create the input param
143:                ObjectFactory factory = new ObjectFactory();
144:                EchoString request = factory.createEchoString();
145:                request.setInput("ONE-WAY JAXB PAYLOAD TEST");
146:
147:                // Invoke the Dispatch<Object> one-way
148:                TestLogger.logger
149:                        .debug(">> Invoking one-way Dispatch with JAX-B Parameter");
150:                dispatchPayload.invokeOneWay(request);
151:            }
152:
153:            public void testSyncMessage() throws Exception {
154:                TestLogger.logger
155:                        .debug("---------------------------------------");
156:                TestLogger.logger.debug("test: " + getName());
157:
158:                // Create the input param
159:                ObjectFactory factory = new ObjectFactory();
160:                EchoString echoString = factory.createEchoString();
161:                echoString.setInput("SYNC JAXB MESSAGETEST");
162:
163:                JAXBElement<Envelope> request = createJAXBEnvelope();
164:                request.getValue().getBody().getAny().add(echoString);
165:
166:                jbc.createMarshaller().marshal(request, System.out);
167:
168:                // Invoke the Dispatch<Object>
169:                TestLogger.logger
170:                        .debug(">> Invoking sync Dispatch with JAX-B Parameter");
171:                JAXBElement<Envelope> jaxbResponse = (JAXBElement<Envelope>) dispatchMessage
172:                        .invoke(request);
173:
174:                assertNotNull(jaxbResponse);
175:                Envelope response = jaxbResponse.getValue();
176:                assertNotNull(response);
177:                assertNotNull(response.getBody());
178:                EchoStringResponse echoStringResponse = (EchoStringResponse) response
179:                        .getBody().getAny().get(0);
180:
181:                TestLogger.logger.debug(">> Response content: "
182:                        + echoStringResponse.getEchoStringReturn());
183:                assertTrue("[ERROR] - No content in response object",
184:                        echoStringResponse.getEchoStringReturn() != null);
185:                assertTrue("[ERROR] - Zero length content in response",
186:                        echoStringResponse.getEchoStringReturn().length() > 0);
187:            }
188:
189:            public void testAysncMessage() throws Exception {
190:                TestLogger.logger
191:                        .debug("---------------------------------------");
192:                TestLogger.logger.debug("test: " + getName());
193:
194:                // Create the input param
195:                ObjectFactory factory = new ObjectFactory();
196:                EchoString echoString = factory.createEchoString();
197:                echoString.setInput("ASYNC(CALLBACK) JAXB MESSAGE TEST");
198:
199:                JAXBElement<Envelope> request = createJAXBEnvelope();
200:                request.getValue().getBody().getAny().add(echoString);
201:
202:                // Create the callback for async responses
203:                JAXBCallbackHandler<Object> callback = new JAXBCallbackHandler<Object>();
204:
205:                // Invoke the Dispatch<Object> asynchronously
206:                TestLogger.logger
207:                        .debug(">> Invoking async(callback) Dispatch with JAX-B Parameter");
208:                Future<?> monitor = dispatchMessage.invokeAsync(request,
209:                        callback);
210:
211:                while (!monitor.isDone()) {
212:                    TestLogger.logger
213:                            .debug(">> Async invocation still not complete");
214:                    Thread.sleep(1000);
215:                }
216:
217:                JAXBElement<Envelope> jaxbResponse = (JAXBElement<Envelope>) callback
218:                        .getData();
219:
220:                assertNotNull(jaxbResponse);
221:                Envelope response = jaxbResponse.getValue();
222:
223:                assertNotNull(response);
224:                assertNotNull(response.getBody());
225:                EchoStringResponse echoStringResponse = (EchoStringResponse) response
226:                        .getBody().getAny().get(0);
227:
228:                TestLogger.logger.debug(">> Response content: "
229:                        + echoStringResponse.getEchoStringReturn());
230:                assertTrue("[ERROR] - No content in response object",
231:                        echoStringResponse.getEchoStringReturn() != null);
232:                assertTrue("[ERROR] - Zero length content in response",
233:                        echoStringResponse.getEchoStringReturn().length() > 0);
234:
235:            }
236:
237:            public void testOneWayMessge() throws Exception {
238:                TestLogger.logger
239:                        .debug("---------------------------------------");
240:                TestLogger.logger.debug("test: " + getName());
241:
242:                // Create the input param
243:                ObjectFactory factory = new ObjectFactory();
244:                EchoString echoString = factory.createEchoString();
245:                echoString.setInput("ONE-WAY JAXB MESSAGE TEST");
246:
247:                JAXBElement<Envelope> request = createJAXBEnvelope();
248:                request.getValue().getBody().getAny().add(echoString);
249:
250:                // Invoke the Dispatch<Object> one-way
251:                TestLogger.logger
252:                        .debug(">> Invoking one-way Dispatch with JAX-B Parameter");
253:                dispatchMessage.invokeOneWay(request);
254:            }
255:
256:            private JAXBElement<Envelope> createJAXBEnvelope() {
257:                org.xmlsoap.schemas.soap.envelope.ObjectFactory factory = new org.xmlsoap.schemas.soap.envelope.ObjectFactory();
258:                Envelope env = new Envelope();
259:
260:                Body body = new Body();
261:                env.setBody(body);
262:
263:                JAXBElement<Envelope> jaxbEnv = factory.createEnvelope(env);
264:                return jaxbEnv;
265:            }
266:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.