Source Code Cross Referenced for WebServiceDescriptorFactory.java in  » Portal » Open-Portal » com » sun » portal » providers » simplewebservice » 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 » Portal » Open Portal » com.sun.portal.providers.simplewebservice 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * $Id: WebServiceDescriptorFactory.java,v 1.9 2003/12/01 10:47:36 vv138407 Exp $
003:         * Copyright 2002-2003 Sun Microsystems, Inc. All
004:         * rights reserved. Use of this product is subject
005:         * to license terms. Federal Acquisitions:
006:         * Commercial Software -- Government Users
007:         * Subject to Standard License Terms and
008:         * Conditions.
009:         *
010:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011:         * are trademarks or registered trademarks of Sun Microsystems,
012:         * Inc. in the United States and other countries.
013:         */package com.sun.portal.providers.simplewebservice;
014:
015:        import java.util.Map;
016:        import java.util.Iterator;
017:        import java.util.List;
018:        import java.util.ArrayList;
019:
020:        import com.sun.portal.providers.simplewebservice.util.TimeBoundHashMap;
021:        import com.sun.portal.providers.simplewebservice.wsdl.DefinitionDescriptor;
022:        import com.sun.portal.providers.simplewebservice.wsdl.MessageDescriptor;
023:        import com.sun.portal.providers.simplewebservice.wsdl.PortTypeDescriptor;
024:        import com.sun.portal.providers.simplewebservice.wsdl.BindingDescriptor;
025:        import com.sun.portal.providers.simplewebservice.wsdl.ServiceDescriptor;
026:        import com.sun.portal.providers.simplewebservice.wsdl.PartDescriptor;
027:        import com.sun.portal.providers.simplewebservice.wsdl.PortDescriptor;
028:        import com.sun.portal.providers.simplewebservice.wsdl.OperationDescriptor;
029:        import com.sun.portal.providers.simplewebservice.wsdl.BindingOperationDescriptor;
030:        import com.sun.portal.providers.simplewebservice.wsdl.BindingOperationInputDescriptor;
031:        import com.sun.portal.providers.simplewebservice.wsdl.BindingOperationOutputDescriptor;
032:        import com.sun.portal.providers.simplewebservice.wsdl.TypeDescriptor;
033:        import com.sun.portal.providers.simplewebservice.wsdl.TypeElementDescriptor;
034:
035:        import com.sun.portal.providers.simplewebservice.wsdl.impl.WSDLReader;
036:        import com.sun.portal.providers.simplewebservice.wsdl.impl.WSDLException;
037:        import com.sun.portal.providers.simplewebservice.util.XList;
038:        import com.sun.portal.providers.simplewebservice.util.SimpleWebServiceUtilImpl;
039:        import com.sun.xml.rpc.processor.model.Model;
040:        import com.sun.xml.rpc.wsdl.document.soap.SOAPStyle;
041:        import com.sun.xml.rpc.wsdl.document.soap.SOAPUse;
042:        import com.sun.xml.rpc.encoding.soap.SOAPConstants;
043:
044:        /**
045:         * Singleton class that locally caches the WebServiceDescriptors
046:         * that contain the information obtained from the web service WSDL
047:         * required to invoke the web service.
048:         * <P>
049:         *
050:         */
051:        public class WebServiceDescriptorFactory {
052:
053:            // ab jan24 -- set the cache timeout to a suitable value
054:            // 10 minutes
055:            private static final int CACHE_TIME_OUT = 600;
056:
057:            //  private TimeBoundHashMap webServiceDescriptors = (TimeBoundHashMap)
058:            //	Collections.synchronizedMap(new TimeBoundHashMap(CACHE_TIME_OUT));
059:
060:            private static TimeBoundHashMap webServiceDescriptors;
061:
062:            private static WebServiceDescriptorFactory factory = new WebServiceDescriptorFactory();
063:
064:            // Private Constructor to avoid extra instances.
065:            private WebServiceDescriptorFactory() {
066:                synchronized (this ) {
067:                    if (webServiceDescriptors == null) {
068:                        webServiceDescriptors = new TimeBoundHashMap(
069:                                CACHE_TIME_OUT);
070:                    }
071:                }
072:            }
073:
074:            /**
075:             * Returns the WebServiceDescriptorFactory singleton.
076:             * <P>
077:             *
078:             * @return the WebServiceDescriptorFactory singleton.
079:             */
080:            public static WebServiceDescriptorFactory getFactory() {
081:                return factory;
082:            }
083:
084:            /**
085:             * Get the WebServiceDescriptor based on the WSDL URL and the
086:             * name of the web service.
087:             *
088:             * @param wsdlURL the WSDL URL.
089:             * @param methodName the name of the method to invoke on the web service.
090:             * @param cacheTimeOut the timeout value for the web service descriptor cache(in secs).
091:             *
092:             * @return the WebServiceDescriptor containing information about the
093:             *         specified web service and its associated method.
094:             */
095:            public WebServiceDescriptor getWebServiceDescriptor(String wsdlURL,
096:                    String methodName, int cacheTimeOut)
097:                    throws WebServiceDescriptorException {
098:
099:                WebServiceDescriptor descriptor = null;
100:                if (wsdlURL != null && methodName != null) {
101:                    if (cacheTimeOut != SimpleWebServiceProviderAdapter.NO_CACHE_TIME_OUT_SPECIFIED
102:                            && cacheTimeOut != webServiceDescriptors
103:                                    .getTimeOut()) {
104:                        synchronized (this ) {
105:                            webServiceDescriptors.setTimeOut(cacheTimeOut);
106:                        }
107:
108:                        descriptor = (WebServiceDescriptor) webServiceDescriptors
109:                                .get(wsdlURL + methodName);
110:
111:                        if (descriptor == null) {
112:                            synchronized (this ) {
113:                                descriptor = (WebServiceDescriptor) webServiceDescriptors
114:                                        .get(wsdlURL + methodName);
115:                                if (descriptor == null) {
116:                                    descriptor = createWebServiceDescriptor(
117:                                            wsdlURL, methodName);
118:                                    webServiceDescriptors.put(wsdlURL
119:                                            + methodName, descriptor);
120:                                }
121:                            }
122:                        }
123:                    }
124:                } else {
125:                    throw new WebServiceDescriptorException(
126:                            WebServiceDescriptorException.INVALID_WSDL,
127:                            "Both wsdl url and methodname should be non-empty");
128:                }
129:
130:                return descriptor;
131:            }
132:
133:            /**
134:             * Create the WebServiceDescriptor based on the WSDL URL and the
135:             * name of the web service.
136:             *
137:             * @param wsdlURL the WSDL URL.
138:             * @param methodName the name of the method to invoke on the web service.
139:             *
140:             * @return the WebServiceDescriptor containing information about the
141:             *         specified web service.
142:             */
143:            private WebServiceDescriptor createWebServiceDescriptor(
144:                    String wsdlURL, String methodName)
145:                    throws WebServiceDescriptorException {
146:
147:                WebServiceDescriptor webServiceDescriptor = null;
148:                boolean isOneWayOperation = false;
149:
150:                try {
151:                    WSDLReader reader = WSDLReader.getWSDLReader();
152:                    DefinitionDescriptor definition = reader
153:                            .getWSDLDefinitionDescriptor(wsdlURL);
154:
155:                    // service name
156:                    Map servicesList = definition.getServiceDescriptors();
157:
158:                    if (servicesList == null) {
159:                        throw new WebServiceDescriptorException(
160:                                WebServiceDescriptorException.INVALID_WSDL,
161:                                "Service definition not found in WSDL");
162:                    }
163:
164:                    Iterator serviceIterator = servicesList.values().iterator();
165:
166:                    ServiceDescriptor serviceDescriptor = null;
167:
168:                    while (serviceIterator.hasNext()) {
169:                        serviceDescriptor = (ServiceDescriptor) serviceIterator
170:                                .next();
171:                        if (serviceDescriptor != null)
172:                            break;
173:                    }
174:
175:                    if (serviceDescriptor == null) {
176:                        throw new WebServiceDescriptorException(
177:                                WebServiceDescriptorException.INVALID_WSDL,
178:                                "Service definition not found in WSDL");
179:                    }
180:
181:                    String serviceName = serviceDescriptor.getName();
182:
183:                    // portTypes
184:                    Map portTypes = definition.getPortTypeDescriptors();
185:
186:                    Iterator portTypesIterator = portTypes.values().iterator();
187:
188:                    PortTypeDescriptor portTypeDescriptor = null;
189:                    OperationDescriptor operation = null;
190:
191:                    while (portTypesIterator.hasNext()) {
192:                        portTypeDescriptor = (PortTypeDescriptor) portTypesIterator
193:                                .next();
194:                        operation = portTypeDescriptor.getOperationDescriptor(
195:                                methodName, null, null);
196:                        if (operation != null) {
197:                            break;
198:                        }
199:                    }
200:
201:                    if (operation == null) {
202:                        throw new WebServiceDescriptorException(
203:                                WebServiceDescriptorException.INVALID_WSDL,
204:                                "method:"
205:                                        + methodName
206:                                        + " not found in WSDL <portType> <operation>");
207:                    }
208:
209:                    //String portName = portTypeDescriptor.getName();
210:
211:                    String inputMessageName = removeNS(operation
212:                            .getInputMessageDescriptorName());
213:                    String outputMessageName = removeNS(operation
214:                            .getOutputMessageDescriptorName());
215:
216:                    if (inputMessageName == null) {
217:                        throw new WebServiceDescriptorException(
218:                                WebServiceDescriptorException.INVALID_WSDL,
219:                                "no input <message> found in WSDL <portType> <operation> name:"
220:                                        + operation.getName());
221:                    }
222:
223:                    if (outputMessageName == null) {
224:                        throw new WebServiceDescriptorException(
225:                                WebServiceDescriptorException.INVALID_WSDL,
226:                                "no output <message> found in WSDL <portType> <operation> name:"
227:                                        + operation.getName());
228:                    }
229:
230:                    //-------------------------------------
231:                    // Input parameter
232:
233:                    // messages
234:                    MessageDescriptor inputMessage = definition
235:                            .getMessageDescriptor(inputMessageName);
236:
237:                    if (inputMessage == null) {
238:                        throw new WebServiceDescriptorException(
239:                                WebServiceDescriptorException.INVALID_WSDL,
240:                                "no input <message> name:" + inputMessageName
241:                                        + " found in WSDL <definitions> ");
242:                    }
243:                    /*
244:                    List orderedInputPartNames = inputMessage.getOrderedPartDescriptors();
245:
246:                    Iterator partNameIterator = orderedInputPartNames.iterator();
247:                     */
248:                    Map inputPartNames = inputMessage.getPartDescriptors();
249:
250:                    //Iterator partNameIterator = inputPartNames.values().iterator();
251:                    Iterator partNameIterator = inputMessage
252:                            .getOrderedPartDescriptors().iterator();
253:
254:                    List inputParamsList = new ArrayList();
255:
256:                    while (partNameIterator.hasNext()) {
257:
258:                        //PartDescriptor inputParamPart = (PartDescriptor)partNameIterator.next();
259:
260:                        PartDescriptor inputParamPart = (PartDescriptor) inputPartNames
261:                                .get(partNameIterator.next());
262:
263:                        ParameterDescriptor inputParamDescriptor = createParameterDescriptor(
264:                                definition, inputParamPart.getName(),
265:                                inputParamPart.getType());
266:
267:                        if (inputParamDescriptor != null) {
268:                            inputParamsList.add(inputParamDescriptor);
269:                        } else {
270:                            throw new WebServiceDescriptorException(
271:                                    WebServiceDescriptorException.INVALID_WSDL,
272:                                    "Failed to determine type of Param "
273:                                            + inputParamPart.getName());
274:                        }
275:
276:                    }
277:
278:                    // InputParmeters are zero. So it is a one-way operation.
279:                    // Currently we do not support one-way operations
280:                    if (0 == inputParamsList.size()) {
281:
282:                        /*    throw new WebServiceDescriptorException(WebServiceDescriptorException.UNSUPPORTED_WSDL,
283:
284:                                    "One-way operations are currently not supported.");*/
285:                    }
286:
287:                    ParameterDescriptor[] inputParams = new ParameterDescriptor[inputParamsList
288:                            .size()];
289:
290:                    inputParams = (ParameterDescriptor[]) inputParamsList
291:                            .toArray(inputParams);
292:
293:                    //-------------------------------------
294:                    // Output parameter
295:
296:                    MessageDescriptor outputMessage = definition
297:                            .getMessageDescriptor(outputMessageName);
298:
299:                    if (outputMessage == null) {
300:                        throw new WebServiceDescriptorException(
301:                                WebServiceDescriptorException.INVALID_WSDL,
302:                                "no output <message> name:" + outputMessageName
303:                                        + " found in WSDL <definitions> ");
304:                    }
305:
306:                    Map outputParts = outputMessage.getPartDescriptors();
307:
308:                    Iterator outputPartNameIterator = outputParts.values()
309:                            .iterator();
310:
311:                    List outputParamsList = new ArrayList();
312:
313:                    while (outputPartNameIterator.hasNext()) {
314:
315:                        PartDescriptor outputPart = (PartDescriptor) outputPartNameIterator
316:                                .next();
317:
318:                        ParameterDescriptor outputParam = createParameterDescriptor(
319:                                definition, outputPart.getName(), outputPart
320:                                        .getType());
321:
322:                        if (outputParam != null) {
323:                            outputParamsList.add(outputParam);
324:                        } else {
325:                            throw new WebServiceDescriptorException(
326:                                    WebServiceDescriptorException.INVALID_WSDL,
327:                                    "Failed to determine type of outputParam ");
328:                        }
329:                    }
330:
331:                    // OutputParmeters are zero. So it is a one-way operation.
332:                    // Currently we do not support one-way operations
333:                    if (0 == outputParamsList.size()) {
334:                        /*throw new WebServiceDescriptorException(WebServiceDescriptorException.UNSUPPORTED_WSDL,
335:                                            "One-way operations are currently not supported");*/
336:                        isOneWayOperation = true;
337:                    }
338:
339:                    ParameterDescriptor[] outputParams = new ParameterDescriptor[outputParamsList
340:                            .size()];
341:
342:                    outputParams = (ParameterDescriptor[]) outputParamsList
343:                            .toArray(outputParams);
344:
345:                    //-------------------------------------
346:                    // bindings
347:                    Map bindings = definition.getBindingDescriptors();
348:
349:                    BindingDescriptor binding = (BindingDescriptor) bindings
350:                            .values().iterator().next();
351:
352:                    //RK: Note : The binding correponding to the portType in which
353:                    //the intended operation is found should be chosen.It is not necessary
354:                    //that the first of the bindings is the desired binding.
355:                    // the code can be as follows
356:
357:                    Iterator bindingsIterator = definition
358:                            .getBindingDescriptors().values().iterator();
359:                    while (bindingsIterator.hasNext()) {
360:                        binding = (BindingDescriptor) bindingsIterator.next();
361:                        if (binding.getPortTypeDescriptorName() == portTypeDescriptor
362:                                .getName())
363:                            break;
364:                        else
365:                            binding = null;
366:                    }
367:
368:                    if (binding == null) {
369:                        throw new WebServiceDescriptorException(
370:                                WebServiceDescriptorException.INVALID_WSDL,
371:                                "No binding found corresponding to"
372:                                        + "portType Name "
373:                                        + portTypeDescriptor.getName());
374:                    }
375:
376:                    // RK Note : End
377:                    String soapBindingStyle = binding.getSOAPBindingStyle();
378:                    String soapBindingTransport = binding
379:                            .getSOAPBindingTransport();
380:
381:                    List bindingOperations = binding
382:                            .getBindingOperationDescriptors();
383:
384:                    // jun 12 fix
385:                    Iterator bindingOperationIterator = bindingOperations
386:                            .iterator();
387:
388:                    BindingOperationDescriptor bindingOperation = null;
389:                    while (bindingOperationIterator != null
390:                            && bindingOperationIterator.hasNext()) {
391:                        BindingOperationDescriptor bod = (BindingOperationDescriptor) bindingOperationIterator
392:                                .next();
393:                        if (bod != null && bod.getName().equals(methodName)) {
394:                            bindingOperation = bod;
395:                            break;
396:                        }
397:                    }
398:
399:                    if (bindingOperation == null) {
400:                        throw new WebServiceDescriptorException(
401:                                WebServiceDescriptorException.INVALID_WSDL,
402:                                "Binding Operation missing, name: "
403:                                        + methodName);
404:                    }
405:
406:                    String soapAction = bindingOperation.getSOAPAction();
407:
408:                    BindingOperationInputDescriptor bindingOperationInput = bindingOperation
409:                            .getBindingOperationInputDescriptor();
410:
411:                    BindingOperationOutputDescriptor bindingOperationOutput = bindingOperation
412:                            .getBindingOperationOutputDescriptor();
413:
414:                    String inputNamespace = bindingOperationInput
415:                            .getNamespace();
416:                    String inputEncodingStyle = bindingOperationInput.getUse();
417:                    String inputEncodingStyleURI = bindingOperationInput
418:                            .getEncodingStyle();
419:
420:                    String outputNamespace = bindingOperationOutput
421:                            .getNamespace();
422:                    String outputEncodingStyle = bindingOperationOutput
423:                            .getUse();
424:                    String outputEncodingStyleURI = bindingOperationOutput
425:                            .getEncodingStyle();
426:
427:                    // verifyValidBindingParams("input",inputNamespace,
428:                    //                         inputEncodingStyle,inputEncodingStyleURI);
429:                    // verifyValidBindingParams("output",outputNamespace,
430:                    //                         outputEncodingStyle,outputEncodingStyleURI);
431:
432:                    // services
433:                    Map services = definition.getServiceDescriptors();
434:
435:                    ServiceDescriptor service = (ServiceDescriptor) services
436:                            .values().iterator().next();
437:
438:                    Map ports = service.getPortDescriptors();
439:                    String documentation = service.getDocumentation();
440:
441:                    PortDescriptor port = (PortDescriptor) ports.values()
442:                            .iterator().next();
443:                    //RK Note: We cannot assume that the first of the ports in the
444:                    //service corresponds to the binding -> portType-> operation
445:                    // selected .So we should find the port Which correponds to the
446:                    //binding
447:                    Iterator portsIterator = ports.values().iterator();
448:                    while (portsIterator.hasNext()) {
449:                        port = (PortDescriptor) port;
450:                        if (port.getBindingDescriptorName() == binding
451:                                .getName())
452:                            break;
453:                        else
454:                            port = null;
455:                    }
456:
457:                    if (port == null) {
458:                        throw new WebServiceDescriptorException(
459:                                WebServiceDescriptorException.INVALID_WSDL,
460:                                "No Port Corresponding to Binding "
461:                                        + binding.getName() + "was found ");
462:                    }
463:                    //RK Note End
464:                    String endPointURL = port.getSOAPAddressLocation();
465:                    String portName = port.getName();
466:
467:                    if (endPointURL == null) {
468:                        throw new WebServiceDescriptorException(
469:                                WebServiceDescriptorException.INVALID_WSDL,
470:                                "\"endPointURL\" attribute not specified in "
471:                                        + "WSDL <service> <port> name:"
472:                                        + port.getName());
473:                    }
474:
475:                    webServiceDescriptor = new WebServiceDescriptor(wsdlURL,
476:                            serviceName, portName, methodName, endPointURL,
477:                            inputNamespace, outputNamespace,
478:                            inputEncodingStyle, outputEncodingStyle,
479:                            inputEncodingStyleURI, outputEncodingStyleURI,
480:                            inputParams, outputParams, soapBindingStyle,
481:                            soapBindingTransport, soapAction, documentation);
482:                    webServiceDescriptor.setOneWayOperation(isOneWayOperation);
483:                } catch (WebServiceDescriptorException wsdex) {
484:
485:                    throw wsdex;
486:                } catch (WSDLException wsdlex) {
487:
488:                    throw new WebServiceDescriptorException(
489:                            WebServiceDescriptorException.INVALID_WSDL, null,
490:                            wsdlex);
491:                } catch (Throwable throwable) {
492:
493:                    throw new WebServiceDescriptorException(
494:                            WebServiceDescriptorException.OTHER_ERROR, null,
495:                            throwable);
496:                }
497:
498:                return webServiceDescriptor;
499:            }
500:
501:            private ParameterDescriptor createParameterDescriptor(
502:                    DefinitionDescriptor definition, String partName,
503:                    String partType) {
504:
505:                ParameterDescriptor inputParam = null;
506:                SimpleWebServiceUtilImpl swsRPCUtil = new SimpleWebServiceUtilImpl();
507:
508:                Class primitiveClassType = swsRPCUtil
509:                        .getSimpleClassType(removeNS(partType));
510:
511:                if (primitiveClassType != null) {
512:                    inputParam = new ParameterDescriptor(partName,
513:                            primitiveClassType, null, null);
514:                } else {
515:                    TypeDescriptor typeDescriptor = definition
516:                            .getTypeDescriptor(partType);
517:
518:                    if (typeDescriptor == null)
519:                        typeDescriptor = definition
520:                                .getTypeDescriptor(removeNS(partType));
521:
522:                    if (typeDescriptor != null) {
523:                        XList xlist = new XList(typeDescriptor.getName(),
524:                                typeDescriptor.getSchemaTargetNamespace());
525:                        // fix jun 12
526:                        // inputParam = new ParameterDescriptor(inputPart.getName(),
527:                        inputParam = new ParameterDescriptor(partName,
528:                                XList.class, xlist, null);
529:
530:                        if (typeDescriptor.isArrayType()) {
531:
532:                            inputParam.setArrayType(typeDescriptor
533:                                    .isArrayType());
534:                            String arrayTypeName = removeNS(typeDescriptor
535:                                    .getArrayTypeName());
536:                            inputParam.setArrayTypeName(arrayTypeName);
537:
538:                            // Is it complexType array
539:                            if (swsRPCUtil.getSimpleClassType(arrayTypeName) == null) {
540:
541:                                // Construct the parameter for the type pointed to by the 'arrayType' of
542:                                // <attribute> of <restriction>.
543:                                ParameterDescriptor arrayTypeParam = null;
544:                                //19/11/03
545:                                Iterator it = typeDescriptor
546:                                        .getOrderedTypeElementDescriptors()
547:                                        .iterator();
548:
549:                                TypeElementDescriptor tld = typeDescriptor
550:                                        .getTypeElementDescriptor((String) it
551:                                                .next());
552:                                //end of change 19//11/03 also see the commented parameter "arrayTypeName" on the line below
553:                                arrayTypeParam = createParameterDescriptor(
554:                                        definition,
555:                                        tld.getName()/* arrayTypeName*/,
556:                                        arrayTypeName);
557:                                arrayTypeParam.setRepeated(tld.isRepeated());
558:                                xlist.add(arrayTypeParam);
559:                            } else {
560:                                //vv138407
561:                                //19/11/03
562:                                ParameterDescriptor arrayTypeParam = null;
563:
564:                                Iterator it = typeDescriptor
565:                                        .getOrderedTypeElementDescriptors()
566:                                        .iterator();
567:
568:                                TypeElementDescriptor tld = typeDescriptor
569:                                        .getTypeElementDescriptor((String) it
570:                                                .next());
571:                                //end of change 19//11/03 also see the commented parameter "item" on the line below
572:
573:                                arrayTypeParam = new ParameterDescriptor(tld
574:                                        .getName()/*"item"*/, swsRPCUtil
575:                                        .getSimpleClassType(arrayTypeName),
576:                                        null, null);
577:                                arrayTypeParam.setRepeated(tld.isRepeated());
578:                                xlist.add(arrayTypeParam);
579:                            }
580:                        } else {
581:                            Iterator typeElementDescriptorIterator = typeDescriptor
582:                                    .getOrderedTypeElementDescriptors()
583:                                    .iterator();
584:
585:                            // For each type element get the
586:                            while (typeElementDescriptorIterator.hasNext()) {
587:                                TypeElementDescriptor childDesc = (TypeElementDescriptor) typeDescriptor
588:                                        .getTypeElementDescriptor((String) typeElementDescriptorIterator
589:                                                .next());
590:
591:                                Class classType = swsRPCUtil
592:                                        .getSimpleClassType(removeNS(childDesc
593:                                                .getType()));
594:                                ParameterDescriptor childParam = null;
595:
596:                                if (classType != null) { // Primitive type element
597:                                    childParam = new ParameterDescriptor(
598:                                            childDesc.getName(), classType,
599:                                            null, inputParam);
600:
601:                                } else { // ComplexType element
602:                                    childParam = createParameterDescriptor(
603:                                            definition, childDesc.getName(),
604:                                            childDesc.getType());
605:                                }
606:                                childParam.setRepeated(childDesc.isRepeated());
607:                                xlist.add(childParam);
608:                            }
609:                        }
610:                    }
611:                }
612:
613:                return inputParam;
614:            }
615:
616:            /**
617:             * Remove any Namespace prefix associated with the web service.
618:             *
619:             * @param inputStr the string containing the namespace the prefix.
620:             *
621:             * @return the string without any Namespace prefix.
622:             */
623:            private String removeNS(String inputStr) {
624:                if (inputStr != null) {
625:                    int delimPosition = inputStr.lastIndexOf(':');
626:                    return inputStr.substring(delimPosition + 1);
627:                }
628:                return null;
629:            }
630:
631:            private void verifyValidBindingParams(String type,
632:                    String namespace, String encodingStyle,
633:                    String encodingStyleURI)
634:                    throws WebServiceDescriptorException {
635:
636:                if (namespace == null) {
637:                    throw new WebServiceDescriptorException(
638:                            WebServiceDescriptorException.INVALID_WSDL,
639:                            "urn \"namespace\" attribute not specified in "
640:                                    + "WSDL <binding> <operation> <" + type
641:                                    + ">");
642:                }
643:
644:                if (encodingStyle == null) {
645:                    throw new WebServiceDescriptorException(
646:                            WebServiceDescriptorException.INVALID_WSDL,
647:                            "encoding sytle \"use\" attribute not specified in "
648:                                    + "WSDL <binding> <operation> <" + type
649:                                    + ">");
650:                }
651:
652:                if (encodingStyleURI == null) {
653:                    throw new WebServiceDescriptorException(
654:                            WebServiceDescriptorException.INVALID_WSDL,
655:                            "\"encodingStyleURI\" attribute not specified in "
656:                                    + "WSDL <binding> <operation> <" + type
657:                                    + ">");
658:                }
659:            }
660:
661:            /** for testing purposes only
662:             */
663:            public static void main(String[] argv) {
664:
665:                try {
666:                    WebServiceDescriptorFactory factory = WebServiceDescriptorFactory
667:                            .getFactory();
668:                    Integer timeOut = new Integer(argv[2]);
669:                    WebServiceDescriptor w = factory.getWebServiceDescriptor(
670:                            argv[0], argv[1], timeOut.intValue());
671:                    System.out.println(w);
672:                } catch (Exception e) {
673:                    e.printStackTrace();
674:                }
675:            }
676:
677:            /**
678:             * Note: Delete this method if not used
679:             * @param wsdlURL
680:             * @param methodName
681:             * @return
682:             * @throws WebServiceDescriptorException
683:             */
684:
685:            private WebServiceDescriptor createWebServiceDescriptorFromModel(
686:                    String wsdlURL, String methodName)
687:                    throws WebServiceDescriptorException {
688:
689:                WebServiceDescriptor descriptor = null;
690:                WSDLReader reader = null;
691:                Model model = null;
692:                try {
693:                    reader = WSDLReader.getWSDLReader();
694:                    model = reader.getWSDLModel(wsdlURL);
695:                    Iterator servicesIterator = null;
696:                    com.sun.xml.rpc.processor.model.Service service = null;
697:                    servicesIterator = model.getServices();
698:
699:                    while (servicesIterator.hasNext()) {
700:                        service = (com.sun.xml.rpc.processor.model.Service) servicesIterator
701:                                .next();
702:                        if (service != null)
703:                            break;
704:                    }
705:                    if (service == null)
706:                        throw new WebServiceDescriptorException(
707:                                WebServiceDescriptorException.INVALID_WSDL,
708:                                "Service definition not found in WSDL");
709:                    String serviceName = service.getName().getLocalPart();
710:
711:                    Iterator portsIterator = service.getPorts();
712:                    com.sun.xml.rpc.processor.model.Port port = null;
713:                    com.sun.xml.rpc.processor.model.Operation operation = null;
714:                    while (portsIterator.hasNext()) {
715:                        port = (com.sun.xml.rpc.processor.model.Port) portsIterator
716:                                .next();
717:                        //Note: The current implementation of WSDLModeler ignores ports corresponding to
718:                        //non-soap bindings such as Http and Mime Bindings.However future releases may not
719:                        //filter non-soap bindings
720:                        Iterator opsIterator = port.getOperations();
721:                        while (opsIterator.hasNext()) {
722:                            operation = (com.sun.xml.rpc.processor.model.Operation) opsIterator
723:                                    .next();
724:                            if (operation.getName().getLocalPart() == methodName) {
725:                                break;
726:                            }
727:                            operation = null;
728:                        }
729:                        if (operation != null) {
730:                            break;
731:                        }
732:
733:                        port = null;
734:                    }
735:                    if (port == null || operation == null) {
736:                        throw new WebServiceDescriptorException(
737:                                WebServiceDescriptorException.INVALID_WSDL,
738:                                "method:"
739:                                        + methodName
740:                                        + " not found in WSDL <portType> <operation>");
741:                    }
742:
743:                    String endPointURL = port.getAddress(); //End point URL for SOAP Operation
744:
745:                    String soapStyle = "";
746:                    if (operation.getSOAPAction().equals(SOAPStyle.RPC)) {
747:                        soapStyle = "rpc";
748:                    }
749:                    if (operation.getStyle().equals(SOAPStyle.DOCUMENT)) {
750:                        soapStyle = "document";
751:
752:                    }
753:                    if (soapStyle == "") //SOAP Style can be "rpc" or "document"
754:                        throw new WebServiceDescriptorException(
755:                                WebServiceDescriptorException.INVALID_WSDL,
756:                                "Invalid SOAPStyle "
757:                                        + operation.getStyle().toString()
758:                                        + "Found in the WSDL");
759:                    String soapAction = operation.getSOAPAction(); //SOAP Action
760:
761:                    String soapUse = "";
762:                    if (operation.getUse().equals(SOAPUse.ENCODED)) {
763:                        soapUse = "encoded";
764:                    }
765:                    if (operation.getUse().equals(SOAPUse.LITERAL)) {
766:                        soapUse = "literal";
767:                    }
768:                    if (soapUse == "") {
769:                        throw new WebServiceDescriptorException(
770:                                WebServiceDescriptorException.INVALID_WSDL,
771:                                "Invalid Encoding "
772:                                        + operation.getUse().toString()
773:                                        + "Found in the WSDL");
774:                    }
775:                    String inputEncodingStyle = "";
776:                    String inputEncodingStyleURI = "";
777:                    String outputEncodingStyle = "";
778:                    String outputEncodingStyleURI = "";
779:                    if (soapUse == "encoded") {
780:                        inputEncodingStyleURI = SOAPConstants.URI_ENCODING;
781:                        outputEncodingStyleURI = SOAPConstants.URI_ENCODING;
782:                        inputEncodingStyle = "encoded";
783:                        outputEncodingStyle = "encoded";
784:
785:                    }
786:                    if (soapUse == "literal") {
787:                        inputEncodingStyleURI = "";
788:                        inputEncodingStyle = "";
789:                        outputEncodingStyle = "";
790:                        outputEncodingStyleURI = "";
791:                    }
792:                    String soapTransport = SOAPConstants.URI_HTTP;
793:                    com.sun.xml.rpc.processor.model.Request request = operation
794:                            .getRequest();
795:                    com.sun.xml.rpc.processor.model.Response response = operation
796:                            .getResponse();
797:
798:                    if (request == null || response == null) {
799:                        throw new WebServiceDescriptorException(
800:                                WebServiceDescriptorException.UNSUPPORTED_WSDL,
801:                                "One Way operations are currently not supported");
802:
803:                    }
804:
805:                    List inputParameterList = new ArrayList();
806:                    List outputParameterList = new ArrayList();
807:                    String inputNamespace = "";
808:                    String outputNamespace = "";
809:                    Iterator inParamsIterator = request.getParameters();
810:                    com.sun.xml.rpc.processor.model.Parameter parameter = null;
811:
812:                    while (inParamsIterator.hasNext()) {
813:                        parameter = (com.sun.xml.rpc.processor.model.Parameter) inParamsIterator
814:                                .next();
815:                        inputNamespace = parameter.getBlock().getName()
816:                                .getNamespaceURI();
817:                        //Note: We expect all the input Parameters to be in the same namespace
818:
819:                    }
820:
821:                } catch (WebServiceDescriptorException wsdex) {
822:
823:                    throw wsdex;
824:                } catch (WSDLException wsdlex) {
825:
826:                    throw new WebServiceDescriptorException(
827:                            WebServiceDescriptorException.INVALID_WSDL, null,
828:                            wsdlex);
829:                } catch (Throwable throwable) {
830:
831:                    throw new WebServiceDescriptorException(
832:                            WebServiceDescriptorException.OTHER_ERROR, null,
833:                            throwable);
834:                }
835:
836:                return descriptor;
837:
838:            }
839:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.