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


001:        package org.objectweb.celtix.bus.bindings.soap;
002:
003:        import java.io.ByteArrayInputStream;
004:        import java.io.IOException;
005:        import java.io.InputStream;
006:        import java.io.OutputStream;
007:        import java.lang.reflect.Method;
008:        import java.net.URL;
009:        import java.util.List;
010:        import java.util.Map;
011:        import java.util.concurrent.ConcurrentHashMap;
012:        import java.util.concurrent.Executor;
013:
014:        import javax.jws.WebMethod;
015:        import javax.jws.soap.SOAPBinding.Style;
016:        import javax.xml.namespace.QName;
017:
018:        import javax.xml.soap.Detail;
019:        import javax.xml.soap.MessageFactory;
020:        import javax.xml.soap.SOAPFault;
021:        import javax.xml.soap.SOAPMessage;
022:
023:        import javax.xml.transform.Source;
024:        import javax.xml.transform.dom.DOMSource;
025:        import javax.xml.ws.Binding;
026:        import javax.xml.ws.Endpoint;
027:        import javax.xml.ws.Provider;
028:        import javax.xml.ws.WebFault;
029:        import javax.xml.ws.WebServiceProvider;
030:        import javax.xml.ws.handler.Handler;
031:        import javax.xml.ws.handler.MessageContext;
032:
033:        import org.w3c.dom.Node;
034:        import org.w3c.dom.NodeList;
035:
036:        import junit.framework.TestCase;
037:
038:        import org.objectweb.celtix.Bus;
039:        import org.objectweb.celtix.bindings.DataBindingCallback;
040:        import org.objectweb.celtix.bindings.DataBindingCallback.Mode;
041:        import org.objectweb.celtix.bindings.ServerBindingEndpointCallback;
042:        import org.objectweb.celtix.bindings.ServerDataBindingCallback;
043:        import org.objectweb.celtix.bus.bindings.TestInputStreamContext;
044:        import org.objectweb.celtix.bus.bindings.TestOutputStreamContext;
045:        import org.objectweb.celtix.bus.jaxws.EndpointUtils;
046:        import org.objectweb.celtix.bus.jaxws.JAXBDataBindingCallback;
047:        import org.objectweb.celtix.bus.jaxws.ServerDynamicDataBindingCallback;
048:        import org.objectweb.celtix.context.InputStreamMessageContext;
049:        import org.objectweb.celtix.context.ObjectMessageContext;
050:        import org.objectweb.celtix.context.OutputStreamMessageContext;
051:        import org.objectweb.celtix.transports.ServerTransport;
052:        import org.objectweb.celtix.transports.ServerTransportCallback;
053:        import org.objectweb.celtix.ws.addressing.EndpointReferenceType;
054:        import org.objectweb.celtix.wsdl.EndpointReferenceUtils;
055:
056:        import org.objectweb.hello_world_soap_http.DocLitBareImpl;
057:        import org.objectweb.hello_world_soap_http.HWSoapMessageProvider;
058:        import org.objectweb.hello_world_soap_http.HWSourcePayloadProvider;
059:        import org.objectweb.hello_world_soap_http.HelloWorldServiceProvider;
060:        import org.objectweb.hello_world_soap_http.NoSuchCodeLitFault;
061:        import org.objectweb.hello_world_soap_http.NotAnnotatedGreeterImpl;
062:        import org.objectweb.hello_world_soap_http.NotAnnotatedGreeterImplRPCLit;
063:
064:        public class SOAPServerBindingTest extends TestCase {
065:            Bus bus;
066:            EndpointReferenceType epr;
067:
068:            public SOAPServerBindingTest(String arg0) {
069:                super (arg0);
070:            }
071:
072:            public static void main(String[] args) {
073:                junit.textui.TestRunner.run(SOAPServerBindingTest.class);
074:            }
075:
076:            protected void setUp() throws Exception {
077:                super .setUp();
078:                bus = Bus.init();
079:                epr = new EndpointReferenceType();
080:
081:                URL wsdlUrl = getClass().getResource("/wsdl/hello_world.wsdl");
082:                QName serviceName = new QName(
083:                        "http://objectweb.org/hello_world_soap_http",
084:                        "SOAPService");
085:                epr = EndpointReferenceUtils.getEndpointReference(wsdlUrl,
086:                        serviceName, "SoapPort");
087:            }
088:
089:            public void testGetBinding() throws Exception {
090:                SOAPServerBinding serverBinding = new SOAPServerBinding(bus,
091:                        epr, null);
092:                assertNotNull(serverBinding.getBinding());
093:            }
094:
095:            public void testProviderDispatchMessageModeSourceData()
096:                    throws Exception {
097:                HelloWorldServiceProvider provider = new HelloWorldServiceProvider();
098:                TestEndpointImpl testEndpoint = new TestEndpointImpl(
099:                        provider,
100:                        DataBindingCallback.Mode.MESSAGE,
101:                        DOMSource.class,
102:                        new QName[] { new QName(
103:                                "http://objectweb.org/hello_world_soap_http/types",
104:                                "sayHi") });
105:                TestServerBinding serverBinding = new TestServerBinding(bus,
106:                        epr, testEndpoint, testEndpoint);
107:                TestServerTransport serverTransport = new TestServerTransport(
108:                        bus, epr);
109:                TestInputStreamContext inCtx = new TestInputStreamContext(null);
110:
111:                InputStream is = getClass().getResourceAsStream(
112:                        "resources/sayHiDocLiteralReq.xml");
113:                inCtx.setInputStream(is);
114:
115:                serverBinding.testDispatch(inCtx, serverTransport);
116:
117:                assertEquals(1, provider.getInvokeCount());
118:                assertNotNull(serverTransport.getOutputStreamContext());
119:                assertFalse(serverTransport.getOutputStreamContext().isFault());
120:                OutputStream os = serverTransport.getOutputStreamContext()
121:                        .getOutputStream();
122:                assertNotNull(os);
123:            }
124:
125:            public void testProviderDispatchMessageModeSOAPMessageData()
126:                    throws Exception {
127:                HWSoapMessageProvider provider = new HWSoapMessageProvider();
128:                TestEndpointImpl testEndpoint = new TestEndpointImpl(
129:                        provider,
130:                        DataBindingCallback.Mode.MESSAGE,
131:                        SOAPMessage.class,
132:                        new QName[] { new QName(
133:                                "http://objectweb.org/hello_world_soap_http/types",
134:                                "sayHi") });
135:                TestServerBinding serverBinding = new TestServerBinding(bus,
136:                        epr, testEndpoint, testEndpoint);
137:                TestServerTransport serverTransport = new TestServerTransport(
138:                        bus, epr);
139:                TestInputStreamContext inCtx = new TestInputStreamContext(null);
140:
141:                InputStream is = getClass().getResourceAsStream(
142:                        "resources/sayHiDocLiteralReq.xml");
143:                inCtx.setInputStream(is);
144:
145:                serverBinding.testDispatch(inCtx, serverTransport);
146:
147:                assertEquals(1, provider.getInvokeCount());
148:                assertNotNull(serverTransport.getOutputStreamContext());
149:                assertFalse(serverTransport.getOutputStreamContext().isFault());
150:                OutputStream os = serverTransport.getOutputStreamContext()
151:                        .getOutputStream();
152:                assertNotNull(os);
153:            }
154:
155:            public void testProviderDispatchPayloadModeSourceData()
156:                    throws Exception {
157:                HWSourcePayloadProvider provider = new HWSourcePayloadProvider();
158:                TestEndpointImpl testEndpoint = new TestEndpointImpl(
159:                        provider,
160:                        DataBindingCallback.Mode.PAYLOAD,
161:                        DOMSource.class,
162:                        new QName[] { new QName(
163:                                "http://objectweb.org/hello_world_soap_http/types",
164:                                "sayHi") });
165:                TestServerBinding serverBinding = new TestServerBinding(bus,
166:                        epr, testEndpoint, testEndpoint);
167:                TestServerTransport serverTransport = new TestServerTransport(
168:                        bus, epr);
169:                TestInputStreamContext inCtx = new TestInputStreamContext(null);
170:
171:                InputStream is = getClass().getResourceAsStream(
172:                        "resources/sayHiDocLiteralReq.xml");
173:                inCtx.setInputStream(is);
174:
175:                serverBinding.testDispatch(inCtx, serverTransport);
176:
177:                assertEquals(1, provider.getInvokeCount());
178:                assertNotNull(serverTransport.getOutputStreamContext());
179:                assertFalse(serverTransport.getOutputStreamContext().isFault());
180:                OutputStream os = serverTransport.getOutputStreamContext()
181:                        .getOutputStream();
182:                assertNotNull(os);
183:            }
184:
185:            public void testDocLitDispatch() throws Exception {
186:                QName wrapName = new QName(
187:                        "http://objectweb.org/hello_world_soap_http/types",
188:                        "greetMe");
189:                QName wrapName2 = new QName(
190:                        "http://objectweb.org/hello_world_soap_http/types",
191:                        "sayHi");
192:
193:                TestEndpointImpl testEndpoint = new TestEndpointImpl(
194:                        new NotAnnotatedGreeterImpl(), new QName[] { wrapName,
195:                                wrapName2 });
196:                TestServerBinding serverBinding = new TestServerBinding(bus,
197:                        epr, testEndpoint, testEndpoint);
198:
199:                TestServerTransport serverTransport = new TestServerTransport(
200:                        bus, epr);
201:
202:                QName elName = new QName(
203:                        "http://objectweb.org/hello_world_soap_http/types",
204:                        "requestType");
205:                String data = new String("TestSOAPInputMessage");
206:
207:                byte[] bArray = SOAPMessageUtil.createWrapDocLitSOAPMessage(
208:                        wrapName, elName, data).getBytes();
209:                TestInputStreamContext inCtx = new TestInputStreamContext(
210:                        bArray);
211:
212:                serverBinding.testDispatch(inCtx, serverTransport);
213:
214:                assertNotNull(serverTransport.getOutputStreamContext());
215:                assertFalse(serverTransport.getOutputStreamContext().isFault());
216:                OutputStream os = serverTransport.getOutputStreamContext()
217:                        .getOutputStream();
218:                assertNotNull(os);
219:
220:                wrapName = new QName(
221:                        "http://objectweb.org/hello_world_soap_http/types",
222:                        "greetMeResponse");
223:                elName = new QName(
224:                        "http://objectweb.org/hello_world_soap_http/types",
225:                        "responseType");
226:
227:                String ref = SOAPMessageUtil.createWrapDocLitSOAPMessage(
228:                        wrapName, elName, data);
229:
230:                assertEquals(ref, os.toString());
231:
232:                //Doc Literal Case
233:                inCtx.clear();
234:                InputStream is = getClass().getResourceAsStream(
235:                        "resources/sayHiDocLiteralReq.xml");
236:                inCtx.setInputStream(is);
237:                serverBinding.testDispatch(inCtx, serverTransport);
238:                assertNotNull(serverTransport.getOutputStreamContext());
239:                assertFalse(serverTransport.getOutputStreamContext().isFault());
240:                is.close();
241:            }
242:
243:            public void testRPCLitDispatch() throws Exception {
244:                QName qn = new QName("http://objectweb.org/hello_world_rpclit",
245:                        "sayHi");
246:                TestEndpointImpl testEndpoint = new TestEndpointImpl(
247:                        new NotAnnotatedGreeterImplRPCLit(), new QName[] { qn });
248:                TestServerBinding serverBinding = new TestServerBinding(bus,
249:                        epr, testEndpoint, testEndpoint);
250:                TestServerTransport serverTransport = new TestServerTransport(
251:                        bus, epr);
252:                TestInputStreamContext inCtx = new TestInputStreamContext(null);
253:
254:                InputStream is = getClass().getResourceAsStream(
255:                        "resources/sayHiRpcLiteralReq.xml");
256:                inCtx.setInputStream(is);
257:                serverBinding.testDispatch(inCtx, serverTransport);
258:                is.close();
259:
260:                TestOutputStreamContext osc = (TestOutputStreamContext) serverTransport
261:                        .getOutputStreamContext();
262:                assertNotNull(osc);
263:                assertFalse(osc.isFault());
264:
265:                ByteArrayInputStream bais = new ByteArrayInputStream(osc
266:                        .getOutputStreamBytes());
267:
268:                //System.out.println(new String(osc.getOutputStreamBytes()));
269:
270:                SOAPMessage msg = MessageFactory.newInstance().createMessage(
271:                        null, bais);
272:                assertNotNull(msg);
273:                assertFalse(msg.getSOAPBody().hasFault());
274:                Node xmlNode = msg.getSOAPBody();
275:                assertNotNull(xmlNode);
276:                assertEquals(1, xmlNode.getChildNodes().getLength());
277:                //Check if the Response Node is "sayHiResponse"
278:                xmlNode = xmlNode.getFirstChild();
279:                assertEquals("sayHiResponse", xmlNode.getLocalName());
280:            }
281:
282:            public void testDispatchOneway() throws Exception {
283:                QName wrapName = new QName(
284:                        "http://objectweb.org/hello_world_soap_http/types",
285:                        "greetMeOneWay");
286:                TestEndpointImpl testEndpoint = new TestEndpointImpl(
287:                        new NotAnnotatedGreeterImpl(), new QName[] { wrapName });
288:                TestServerBinding serverBinding = new TestServerBinding(bus,
289:                        epr, testEndpoint, testEndpoint);
290:                TestServerTransport serverTransport = new TestServerTransport(
291:                        bus, epr);
292:
293:                QName elName = new QName(
294:                        "http://objectweb.org/hello_world_soap_http/types",
295:                        "requestType");
296:                String data = new String("TestSOAPInputMessage");
297:
298:                byte[] bArray = SOAPMessageUtil.createWrapDocLitSOAPMessage(
299:                        wrapName, elName, data).getBytes();
300:
301:                TestInputStreamContext inCtx = new TestInputStreamContext(
302:                        bArray);
303:                serverBinding.testDispatch(inCtx, serverTransport);
304:
305:                assertNotNull(serverTransport.getOutputStreamContext());
306:                OutputStream os = serverTransport.getOutputStreamContext()
307:                        .getOutputStream();
308:                assertNotNull(os);
309:
310:                assertEquals("", os.toString());
311:
312:            }
313:
314:            public void testDocLitBareDispatch() throws Exception {
315:                DocLitBareImpl dc = new DocLitBareImpl();
316:                TestEndpointImpl testEndpoint = new TestEndpointImpl(dc, null);
317:                TestServerBinding serverBinding = new TestServerBinding(bus,
318:                        epr, testEndpoint, testEndpoint);
319:                TestServerTransport serverTransport = new TestServerTransport(
320:                        bus, epr);
321:                TestInputStreamContext inCtx = new TestInputStreamContext(null);
322:
323:                InputStream is = getClass().getResourceAsStream(
324:                        "resources/sayHiDocLiteralBareReq.xml");
325:                inCtx.setInputStream(is);
326:                serverBinding.testDispatch(inCtx, serverTransport);
327:                is.close();
328:
329:                assertEquals(1, dc.getSayHiInvocationCount());
330:                assertNotNull(serverTransport.getOutputStreamContext());
331:                assertFalse("Should not have a SOAP Fault", serverTransport
332:                        .getOutputStreamContext().isFault());
333:            }
334:
335:            public void testDocLitBareNoParamDispatch() throws Exception {
336:                DocLitBareImpl dc = new DocLitBareImpl();
337:                TestEndpointImpl testEndpoint = new TestEndpointImpl(dc, null);
338:                TestServerBinding serverBinding = new TestServerBinding(bus,
339:                        epr, testEndpoint, testEndpoint);
340:                TestServerTransport serverTransport = new TestServerTransport(
341:                        bus, epr);
342:                TestInputStreamContext inCtx = new TestInputStreamContext(null);
343:
344:                InputStream is = getClass().getResourceAsStream(
345:                        "resources/EmptyBody.xml");
346:                inCtx.setInputStream(is);
347:                serverBinding.testDispatch(inCtx, serverTransport);
348:                is.close();
349:
350:                assertEquals(1, dc.getBareNoParamCount());
351:                assertNotNull(serverTransport.getOutputStreamContext());
352:                assertFalse("Should not have a SOAP Fault", serverTransport
353:                        .getOutputStreamContext().isFault());
354:            }
355:
356:            public void testUserFaultDispatch() throws Exception {
357:                QName qn = new QName(
358:                        "http://objectweb.org/hello_world_soap_http/types",
359:                        "testDocLitFault");
360:                TestEndpointImpl testEndpoint = new TestEndpointImpl(
361:                        new NotAnnotatedGreeterImpl(), new QName[] { qn });
362:                TestServerBinding serverBinding = new TestServerBinding(bus,
363:                        epr, testEndpoint, testEndpoint);
364:                TestServerTransport serverTransport = new TestServerTransport(
365:                        bus, epr);
366:                InputStream is = getClass().getResourceAsStream(
367:                        "resources/TestDocLitFaultReq.xml");
368:
369:                TestInputStreamContext inCtx = new TestInputStreamContext(null);
370:                inCtx.setInputStream(is);
371:                serverBinding.testDispatch(inCtx, serverTransport);
372:
373:                assertNotNull(serverTransport.getOutputStreamContext());
374:                assertTrue("Expecting a SOAP Fault", serverTransport
375:                        .getOutputStreamContext().isFault());
376:
377:                TestOutputStreamContext osc = (TestOutputStreamContext) serverTransport
378:                        .getOutputStreamContext();
379:                ByteArrayInputStream bais = new ByteArrayInputStream(osc
380:                        .getOutputStreamBytes());
381:                checkUserFaultMessage(bais, NoSuchCodeLitFault.class,
382:                        "TestException");
383:            }
384:
385:            public void testSystemFaultDispatch() throws Exception {
386:                TestEndpointImpl testEndpoint = new TestEndpointImpl(
387:                        new NotAnnotatedGreeterImpl(), new QName[] {});
388:                TestServerBinding serverBinding = new TestServerBinding(bus,
389:                        epr, testEndpoint, testEndpoint);
390:                TestServerTransport serverTransport = new TestServerTransport(
391:                        bus, epr);
392:                InputStream is = getClass().getResourceAsStream(
393:                        "resources/BadSoapMessage.xml");
394:
395:                TestInputStreamContext inCtx = new TestInputStreamContext(null);
396:                inCtx.setInputStream(is);
397:                serverBinding.testDispatch(inCtx, serverTransport);
398:
399:                assertNotNull(serverTransport.getOutputStreamContext());
400:                assertTrue("Expecting a SOAP Fault", serverTransport
401:                        .getOutputStreamContext().isFault());
402:
403:                TestOutputStreamContext osc = (TestOutputStreamContext) serverTransport
404:                        .getOutputStreamContext();
405:                ByteArrayInputStream bais = new ByteArrayInputStream(osc
406:                        .getOutputStreamBytes());
407:                checkSystemFaultMessage(bais);
408:            }
409:
410:            private void checkSystemFaultMessage(ByteArrayInputStream bais)
411:                    throws Exception {
412:                SOAPMessage msg = MessageFactory.newInstance().createMessage(
413:                        null, bais);
414:                assertNotNull(msg);
415:                Node xmlNode = msg.getSOAPBody();
416:                assertNotNull(xmlNode);
417:                assertEquals(1, xmlNode.getChildNodes().getLength());
418:
419:                assertTrue(msg.getSOAPBody().hasFault());
420:
421:                SOAPFault fault = msg.getSOAPBody().getFault();
422:                assertNotNull(fault);
423:                assertTrue(fault.hasChildNodes());
424:
425:                //For Celtix Runtime Exceptions - SOAPFault will not have a Detail Node
426:                Detail detail = fault.getDetail();
427:                if (detail != null) {
428:                    assertFalse("Detail should be non-existent or empty",
429:                            detail.hasChildNodes());
430:                }
431:            }
432:
433:            private void checkUserFaultMessage(ByteArrayInputStream bais,
434:                    Class<? extends Exception> clazz, String faultString)
435:                    throws Exception {
436:
437:                SOAPMessage msg = MessageFactory.newInstance().createMessage(
438:                        null, bais);
439:                assertNotNull(msg);
440:                assertTrue(msg.getSOAPBody().hasFault());
441:                SOAPFault fault = msg.getSOAPBody().getFault();
442:                assertNotNull(fault);
443:
444:                StringBuffer str = new StringBuffer(clazz.getName());
445:                str.append(": ");
446:                str.append(faultString);
447:                assertEquals(str.toString(), fault.getFaultString());
448:                assertTrue(fault.hasChildNodes());
449:                Detail detail = fault.getDetail();
450:                assertNotNull(detail);
451:
452:                NodeList list = detail.getChildNodes();
453:                assertEquals(1, list.getLength());
454:
455:                WebFault wfAnnotation = clazz.getAnnotation(WebFault.class);
456:                assertNotNull(wfAnnotation);
457:                assertEquals(wfAnnotation.targetNamespace(), list.item(0)
458:                        .getNamespaceURI());
459:                assertEquals(wfAnnotation.name(), list.item(0).getLocalName());
460:            }
461:
462:            class TestServerBinding extends SOAPServerBinding {
463:
464:                private QName qn;
465:
466:                public TestServerBinding(Bus b, EndpointReferenceType ref,
467:                        Endpoint ep, ServerBindingEndpointCallback cbFactory) {
468:                    super (b, ref, cbFactory);
469:                }
470:
471:                public ServerTransport getTransport(EndpointReferenceType ref)
472:                        throws Exception {
473:                    return createTransport(ref);
474:                }
475:
476:                public void testDispatch(InputStreamMessageContext inCtx,
477:                        ServerTransport t) {
478:                    super .dispatch(inCtx, t);
479:                }
480:
481:                public QName getOperationName(MessageContext ctx) {
482:                    qn = super .getOperationName(ctx);
483:                    return qn;
484:                }
485:
486:                public QName getInvokedMethod() {
487:                    return qn;
488:                }
489:            }
490:
491:            class TestServerTransport implements  ServerTransport {
492:                private OutputStreamMessageContext osmc;
493:
494:                public TestServerTransport(Bus b, EndpointReferenceType ref) {
495:                }
496:
497:                public void shutdown() {
498:                    //nothing to do
499:                }
500:
501:                public OutputStreamMessageContext rebase(
502:                        MessageContext context,
503:                        EndpointReferenceType decoupledResponseEndpoint)
504:                        throws IOException {
505:                    return null;
506:                }
507:
508:                public OutputStreamMessageContext createOutputStreamContext(
509:                        MessageContext context) throws IOException {
510:                    osmc = new TestOutputStreamContext(null, context);
511:                    return osmc;
512:                }
513:
514:                public void finalPrepareOutputStreamContext(
515:                        OutputStreamMessageContext context) throws IOException {
516:                }
517:
518:                public void postDispatch(MessageContext bindingContext,
519:                        OutputStreamMessageContext context) throws IOException {
520:                }
521:
522:                public void activate(ServerTransportCallback callback)
523:                        throws IOException {
524:                }
525:
526:                public void deactivate() throws IOException {
527:                }
528:
529:                public OutputStreamMessageContext getOutputStreamContext() {
530:                    return osmc;
531:                }
532:            }
533:
534:            final class TestEndpointImpl extends javax.xml.ws.Endpoint
535:                    implements  ServerBindingEndpointCallback {
536:
537:                private final Object implementor;
538:                private WebServiceProvider wsProvider;
539:                private DataBindingCallback.Mode mode;
540:                private Class<?> dataClazz;
541:                private Map<QName, ServerDataBindingCallback> callbackMap = new ConcurrentHashMap<QName, ServerDataBindingCallback>();
542:
543:                TestEndpointImpl(Object impl, QName ops[]) {
544:                    implementor = impl;
545:                    mode = DataBindingCallback.Mode.PARTS;
546:                    initOpMap(ops);
547:                }
548:
549:                TestEndpointImpl(Object impl,
550:                        DataBindingCallback.Mode dataMode, Class<?> clazz,
551:                        QName ops[]) {
552:                    implementor = impl;
553:                    mode = dataMode;
554:                    dataClazz = clazz;
555:                    initOpMap(ops);
556:                }
557:
558:                private void initOpMap(QName ops[]) {
559:                    if (ops != null) {
560:                        for (QName op : ops) {
561:                            callbackMap.put(op,
562:                                    getDataBindingCallback(op, mode));
563:                        }
564:                    } else {
565:                        addMethods(implementor.getClass());
566:                    }
567:                }
568:
569:                private void addMethods(Class<?> cls) {
570:                    if (cls == null) {
571:                        return;
572:                    }
573:                    for (Method meth : cls.getMethods()) {
574:                        WebMethod wm = meth.getAnnotation(WebMethod.class);
575:                        if (wm != null) {
576:                            QName op = new QName("", wm.operationName());
577:                            ServerDataBindingCallback cb = getDataBindingCallback(
578:                                    op, mode);
579:                            callbackMap.put(op, cb);
580:                        }
581:                    }
582:                    for (Class<?> cls2 : cls.getInterfaces()) {
583:                        addMethods(cls2);
584:                    }
585:                    addMethods(cls.getSuperclass());
586:                }
587:
588:                @SuppressWarnings("unchecked")
589:                private ServerDataBindingCallback getDataBindingCallback(
590:                        QName operationName, Mode dataMode) {
591:                    if (dataMode == DataBindingCallback.Mode.PARTS) {
592:                        return new JAXBDataBindingCallback(
593:                                getMethod(operationName), mode, null, null,
594:                                implementor);
595:                    }
596:
597:                    return new ServerDynamicDataBindingCallback(dataClazz,
598:                            mode, (Provider<?>) implementor);
599:                }
600:
601:                public ServerDataBindingCallback getDataBindingCallback(
602:                        QName operationName, ObjectMessageContext objContext,
603:                        Mode dataMode) {
604:                    if (operationName == null) {
605:                        return null;
606:                    }
607:                    return callbackMap.get(operationName);
608:                }
609:
610:                public Binding getBinding() {
611:                    return null;
612:                }
613:
614:                public List<Handler> getHandlerChain() {
615:                    return null;
616:                }
617:
618:                public Object getImplementor() {
619:                    return implementor;
620:                }
621:
622:                public List<Source> getMetadata() {
623:                    return null;
624:                }
625:
626:                public Executor getExecutor() {
627:                    return null;
628:                }
629:
630:                public boolean isPublished() {
631:                    return false;
632:                }
633:
634:                public void publish(Object serverContext) {
635:                }
636:
637:                public void publish(String address) {
638:                }
639:
640:                public void setHandlerChain(List<Handler> h) {
641:                }
642:
643:                public void setMetadata(List<Source> m) {
644:                }
645:
646:                public void setExecutor(Executor ex) {
647:                }
648:
649:                public void stop() {
650:                }
651:
652:                @Override
653:                public Map<String, Object> getProperties() {
654:                    // TODO Auto-generated method stub
655:                    return null;
656:                }
657:
658:                @Override
659:                public void setProperties(Map<String, Object> arg0) {
660:                    // TODO Auto-generated method stub
661:
662:                }
663:
664:                public Method getMethod(QName operationName) {
665:                    if (wsProvider != null) {
666:                        try {
667:                            return implementor.getClass().getDeclaredMethod(
668:                                    operationName.getLocalPart(), dataClazz);
669:                        } catch (Exception ex) {
670:                            //Ignore
671:                        }
672:                    }
673:                    return EndpointUtils.getMethod(implementor.getClass(),
674:                            operationName);
675:                }
676:
677:                public DataBindingCallback.Mode getServiceMode() {
678:                    return mode;
679:                }
680:
681:                public WebServiceProvider getWebServiceProvider() {
682:                    if (wsProvider == null) {
683:                        wsProvider = this .getImplementor().getClass()
684:                                .getAnnotation(WebServiceProvider.class);
685:                    }
686:                    return wsProvider;
687:                }
688:
689:                public Map<QName, ? extends DataBindingCallback> getOperations() {
690:                    return callbackMap;
691:                }
692:
693:                public Style getStyle() {
694:                    // TODO Auto-generated method stub
695:                    return Style.DOCUMENT;
696:                }
697:
698:                public DataBindingCallback getFaultDataBindingCallback(
699:                        ObjectMessageContext objContext) {
700:                    return new JAXBDataBindingCallback(null,
701:                            DataBindingCallback.Mode.PARTS, null);
702:                }
703:
704:            }
705:
706:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.