Source Code Cross Referenced for EndpointDescriptionImpl.java in  » Web-Services-AXIS2 » metadata » org » apache » axis2 » jaxws » description » impl » 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 » metadata » org.apache.axis2.jaxws.description.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * Licensed to the Apache Software Foundation (ASF) under one
0003:         * or more contributor license agreements. See the NOTICE file
0004:         * distributed with this work for additional information
0005:         * regarding copyright ownership. The ASF licenses this file
0006:         * to you under the Apache License, Version 2.0 (the
0007:         * "License"); you may not use this file except in compliance
0008:         * with the License. You may obtain a copy of the License at
0009:         *
0010:         * http://www.apache.org/licenses/LICENSE-2.0
0011:         *
0012:         * Unless required by applicable law or agreed to in writing,
0013:         * software distributed under the License is distributed on an
0014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
0015:         * KIND, either express or implied. See the License for the
0016:         * specific language governing permissions and limitations
0017:         * under the License.
0018:         */
0019:        package org.apache.axis2.jaxws.description.impl;
0020:
0021:        import java.io.InputStream;
0022:        import java.security.PrivilegedAction;
0023:        import java.util.Iterator;
0024:        import java.util.List;
0025:        import java.util.Map;
0026:        import java.util.TreeSet;
0027:
0028:        import javax.jws.HandlerChain;
0029:        import javax.jws.WebService;
0030:        import javax.wsdl.Binding;
0031:        import javax.wsdl.Definition;
0032:        import javax.wsdl.Port;
0033:        import javax.wsdl.extensions.ExtensibilityElement;
0034:        import javax.wsdl.extensions.http.HTTPBinding;
0035:        import javax.wsdl.extensions.soap.SOAPAddress;
0036:        import javax.wsdl.extensions.soap12.SOAP12Address;
0037:        import javax.wsdl.extensions.soap12.SOAP12Binding;
0038:        import javax.xml.namespace.QName;
0039:        import javax.xml.ws.BindingType;
0040:        import javax.xml.ws.Service;
0041:        import javax.xml.ws.ServiceMode;
0042:        import javax.xml.ws.WebServiceProvider;
0043:        import javax.xml.ws.handler.PortInfo;
0044:        import javax.xml.ws.soap.SOAPBinding;
0045:
0046:        import org.apache.axis2.AxisFault;
0047:        import org.apache.axis2.client.ServiceClient;
0048:        import org.apache.axis2.context.ConfigurationContext;
0049:        import org.apache.axis2.deployment.DeploymentException;
0050:        import org.apache.axis2.description.AxisService;
0051:        import org.apache.axis2.description.OutInAxisOperation;
0052:        import org.apache.axis2.description.OutOnlyAxisOperation;
0053:        import org.apache.axis2.description.Parameter;
0054:        import org.apache.axis2.description.WSDL11ToAllAxisServicesBuilder;
0055:        import org.apache.axis2.description.WSDL11ToAxisServiceBuilder;
0056:        import org.apache.axis2.engine.AxisConfiguration;
0057:        import org.apache.axis2.java.security.AccessController;
0058:        import org.apache.axis2.jaxws.ExceptionFactory;
0059:        import org.apache.axis2.jaxws.description.EndpointDescription;
0060:        import org.apache.axis2.jaxws.description.EndpointDescriptionJava;
0061:        import org.apache.axis2.jaxws.description.EndpointDescriptionWSDL;
0062:        import org.apache.axis2.jaxws.description.EndpointInterfaceDescription;
0063:        import org.apache.axis2.jaxws.description.ServiceDescription;
0064:        import org.apache.axis2.jaxws.description.ServiceDescriptionWSDL;
0065:        import org.apache.axis2.jaxws.description.builder.DescriptionBuilderComposite;
0066:        import org.apache.axis2.jaxws.description.builder.MDQConstants;
0067:        import org.apache.axis2.jaxws.description.builder.WsdlComposite;
0068:        import org.apache.axis2.jaxws.description.xml.handler.HandlerChainsType;
0069:        import org.apache.axis2.jaxws.i18n.Messages;
0070:        import org.apache.axis2.jaxws.util.ClassLoaderUtils;
0071:        import org.apache.axis2.jaxws.util.WSDL4JWrapper;
0072:        import org.apache.axis2.jaxws.util.WSDLWrapper;
0073:        import org.apache.commons.logging.Log;
0074:        import org.apache.commons.logging.LogFactory;
0075:
0076:        /** @see ../EndpointDescription */
0077:        /*
0078:         * TODO: EndpointDescription should be created via AxisService objects and not directly from WSDL
0079:         * IMPORTANT NOTE: Axis2 currently only supports 1 service and 1 port under that service.  When that is
0080:         * fixed, that will probably have an impact on this class.  In particular, I think this should be created 
0081:         * somehow from an AxisService/AxisPort combination, and not directly from the WSDL.
0082:         */
0083:        class EndpointDescriptionImpl implements  EndpointDescription,
0084:                EndpointDescriptionJava, EndpointDescriptionWSDL {
0085:
0086:            private ServiceDescriptionImpl parentServiceDescription;
0087:            private AxisService axisService;
0088:
0089:            private QName portQName;
0090:            private QName serviceQName;
0091:
0092:            // Corresponds to a port that was added dynamically via addPort and is not declared (either in WSDL or annotations)
0093:            private boolean isDynamicPort;
0094:
0095:            // If the WSDL is fully specified, we could build the AxisService from the WSDL
0096:            private boolean isAxisServiceBuiltFromWSDL;
0097:
0098:            private String serviceImplName; //class name of the service impl or SEI
0099:
0100:            // Note that an EndpointInterfaceDescription will ONLY be set for an Endpoint-based implementation;
0101:            // it will NOT be set for a Provider-based implementation
0102:            private EndpointInterfaceDescription endpointInterfaceDescription;
0103:
0104:            // This can be an SEI (on the client or server) or a Service implentation (server only)
0105:            // Note that for clients that are Dispatch, this will be null.  Also note that a client that was initially
0106:            // dispatch (sei = null) could later do a getPort(sei), at which time the original EndpointDescription will be
0107:            // updated with the SEI information.
0108:            private Class implOrSEIClass;
0109:
0110:            //On Client side, there should be One ServiceClient instance per AxisSerivce
0111:            private ServiceClient serviceClient = null;
0112:
0113:            //This is the base WebService or WebServiceProvider that we are processing
0114:            DescriptionBuilderComposite composite = null;
0115:
0116:            // Set of packages that are needed to marshal/unmashal data (used to set JAXBContext)
0117:            TreeSet<String> packages = null;
0118:
0119:            // The JAX-WS Handler port information corresponding to this endpoint
0120:            private PortInfo portInfo;
0121:
0122:            private String clientBindingID;
0123:            // The effective endpoint address.  It could be set by the client or come from the WSDL SOAP address
0124:            private String endpointAddress;
0125:            // The endpoint address from the WSDL soap:address extensibility element if present.
0126:            private String wsdlSOAPAddress;
0127:
0128:            private static final Log log = LogFactory
0129:                    .getLog(EndpointDescriptionImpl.class);
0130:
0131:            // ===========================================
0132:            // ANNOTATION related information
0133:            // ===========================================
0134:
0135:            // ANNOTATION: @WebService and @WebServiceProvider
0136:            // Only one of these two annotations will be set; they are mutually exclusive
0137:            private WebService webServiceAnnotation;
0138:            private WebServiceProvider webServiceProviderAnnotation;
0139:
0140:            //ANNOTATION: @HandlerChain
0141:            private HandlerChain handlerChainAnnotation;
0142:            private HandlerChainsType handlerChainsType;
0143:
0144:            // Information common to both WebService and WebServiceProvider annotations
0145:            private String annotation_WsdlLocation;
0146:            private String annotation_ServiceName;
0147:            private String annotation_PortName;
0148:            private String annotation_TargetNamespace;
0149:
0150:            // Information only set on WebService annotation
0151:            // ANNOTATION: @WebService
0152:            private String webService_EndpointInterface;
0153:            private String webService_Name;
0154:
0155:            // ANNOTATION: @ServiceMode
0156:            // Note this is only valid on a Provider-based endpoint
0157:            private ServiceMode serviceModeAnnotation;
0158:            private Service.Mode serviceModeValue;
0159:            // Default ServiceMode.value per JAXWS Spec 7.1 "javax.xml.ServiceMode" pg 79
0160:            public static final javax.xml.ws.Service.Mode ServiceMode_DEFAULT = javax.xml.ws.Service.Mode.PAYLOAD;
0161:
0162:            // ANNOTATION: @BindingType
0163:            private BindingType bindingTypeAnnotation;
0164:            private String bindingTypeValue;
0165:            // Default BindingType.value per JAXWS Spec Sec 7.8 "javax.xml.ws.BindingType" pg 83 
0166:            // and Sec 1.4 "SOAP Transport and Transfer Bindings" pg 119
0167:            public static final String BindingType_DEFAULT = javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_BINDING;
0168:
0169:            /**
0170:             * Create an EndpointDescription based on the WSDL port.  Note that per the JAX-WS Spec (Final
0171:             * Release, 4/19/2006 Section 4.2.3 Proxies, page 55)the "namespace component of the port is the
0172:             * target namespace of the WSDL definition document". Note this is currently only used on the
0173:             * client-side (this may change).
0174:             *
0175:             * @param theClass The SEI or Impl class.  This will be NULL for Dispatch clients since they
0176:             *                 don't use an SEI
0177:             */
0178:            EndpointDescriptionImpl(Class theClass, QName portName,
0179:                    ServiceDescriptionImpl parent) {
0180:                this (theClass, portName, false, parent);
0181:            }
0182:
0183:            EndpointDescriptionImpl(Class theClass, QName portName,
0184:                    boolean dynamicPort, ServiceDescriptionImpl parent) {
0185:                // TODO: This and the other constructor will (eventually) take the same args, so the logic needs to be combined
0186:                // TODO: If there is WSDL, could compare the namespace of the defn against the portQName.namespace
0187:                this .parentServiceDescription = parent;
0188:                this .implOrSEIClass = theClass;
0189:                // REVIEW: setting these should probably be done in the getters!  It needs to be done before we try to select a 
0190:                //         port to use if one wasn't specified because we'll try to get to the annotations to get the PortType
0191:                if (this .implOrSEIClass != null) {
0192:                    webServiceAnnotation = (WebService) implOrSEIClass
0193:                            .getAnnotation(WebService.class);
0194:                    webServiceProviderAnnotation = (WebServiceProvider) implOrSEIClass
0195:                            .getAnnotation(WebServiceProvider.class);
0196:                }
0197:                this .isDynamicPort = dynamicPort;
0198:                if (DescriptionUtils.isEmpty(portName)) {
0199:                    // If the port name is null, then per JAX-WS 2.0 spec p. 55, the runtime is responsible for selecting the port.
0200:                    this .portQName = selectPortToUse();
0201:                } else {
0202:                    this .portQName = portName;
0203:                }
0204:                // At this point, there must be a port QName set, either as passed in, or determined from the WSDL and/or annotations.
0205:                // If not, that is an error.
0206:                if (this .portQName == null) {
0207:                    if (log.isDebugEnabled()) {
0208:                        log
0209:                                .debug("PortQName was null and could not be determined by runtime.  Class: "
0210:                                        + theClass
0211:                                        + "; ServiceDescription: "
0212:                                        + parent);
0213:                    }
0214:                    throw ExceptionFactory
0215:                            .makeWebServiceException("EndpointDescription: portQName could not be determined for class "
0216:                                    + theClass);
0217:                }
0218:
0219:                // TODO: Refactor this with the consideration of no WSDL/Generic Service/Annotated SEI
0220:                setupAxisService();
0221:                addToAxisService();
0222:
0223:                buildDescriptionHierachy();
0224:                addAnonymousAxisOperations();
0225:
0226:                // This will set the serviceClient field after adding the AxisService to the AxisConfig
0227:                getServiceClient();
0228:                // Give the configuration builder a chance to finalize configuration for this service
0229:                try {
0230:                    getServiceDescriptionImpl().getClientConfigurationFactory()
0231:                            .completeAxis2Configuration(axisService);
0232:                } catch (DeploymentException e) {
0233:                    // TODO RAS & NLS
0234:                    if (log.isDebugEnabled()) {
0235:                        log
0236:                                .debug(
0237:                                        "Caught DeploymentException attempting to complete configuration on AxisService: "
0238:                                                + axisService
0239:                                                + " for ServiceDesription: "
0240:                                                + parent, e);
0241:                    }
0242:                    throw ExceptionFactory.makeWebServiceException(
0243:                            "Unable to complete configuration due to exception "
0244:                                    + e, e);
0245:                } catch (Exception e) {
0246:                    // TODO RAS & NLS
0247:                    if (log.isDebugEnabled()) {
0248:                        log.debug(
0249:                                "Caught Exception attempting to complete configuration on AxisService: "
0250:                                        + axisService
0251:                                        + " for ServiceDesription: " + parent,
0252:                                e);
0253:                    }
0254:                    throw ExceptionFactory.makeWebServiceException(
0255:                            "Unable to complete configuration due to exception "
0256:                                    + e, e);
0257:                }
0258:            }
0259:
0260:            /**
0261:             * Create an EndpointDescription based on the DescriptionBuilderComposite. Note that per the
0262:             * JAX-WS Spec (Final Release, 4/19/2006 Section 4.2.3 Proxies, page 55)the "namespace component
0263:             * of the port is the target namespace of the WSDL definition document".
0264:             *
0265:             * @param theClass The SEI or Impl class.  This will be NULL for Dispatch clients since they
0266:             *                 don't use an SEI
0267:             */
0268:            EndpointDescriptionImpl(ServiceDescriptionImpl parent,
0269:                    String serviceImplName) {
0270:
0271:                // TODO: This and the other constructor will (eventually) take the same args, so the logic needs to be combined
0272:                // TODO: If there is WSDL, could compare the namespace of the defn against the portQName.namespace
0273:                this .parentServiceDescription = parent;
0274:                this .serviceImplName = serviceImplName;
0275:                this .implOrSEIClass = null;
0276:
0277:                composite = getServiceDescriptionImpl()
0278:                        .getDescriptionBuilderComposite();
0279:                if (composite == null) {
0280:                    throw ExceptionFactory
0281:                            .makeWebServiceException("EndpointDescription.EndpointDescription: parents DBC is null");
0282:                }
0283:
0284:                //Set the base level of annotation that we are processing...currently
0285:                // a 'WebService' or a 'WebServiceProvider'
0286:                if (composite.getWebServiceAnnot() != null)
0287:                    webServiceAnnotation = composite.getWebServiceAnnot();
0288:                else
0289:                    webServiceProviderAnnotation = composite
0290:                            .getWebServiceProviderAnnot();
0291:
0292:                // REVIEW: Maybe this should be an error if the name has already been set and it doesn't match
0293:                // Note that on the client side, the service QN should be set; on the server side it will not be.
0294:                if (DescriptionUtils.isEmpty(getServiceDescription()
0295:                        .getServiceQName())) {
0296:                    getServiceDescriptionImpl().setServiceQName(
0297:                            getServiceQName());
0298:                }
0299:                //Call the getter to insure the qualified port name is set. 
0300:                getPortQName();
0301:
0302:                // TODO: Refactor this with the consideration of no WSDL/Generic Service/Annotated SEI
0303:                setupAxisServiceFromDBL();
0304:                addToAxisService(); //Add a reference to this EndpointDescription to the AxisService
0305:
0306:                //TODO: Need to remove operations from AxisService that have 'exclude = true
0307:                //      then call 'validateOperations' to verify that WSDL and AxisService match up,
0308:                //      Remember that this will only happen when we generate an AxisService from existing
0309:                //		WSDL and then need to perform further processing because we have annotations as well
0310:                //		If there is no WSDL, we would never process the Method to begin with.
0311:
0312:                buildDescriptionHierachy();
0313:
0314:                WsdlComposite wsdlComposite = null;
0315:
0316:                String bindingType = getBindingType();
0317:
0318:                boolean isSOAP11 = (bindingType
0319:                        .equals(javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_BINDING) || bindingType
0320:                        .equals(javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_MTOM_BINDING)) ? true
0321:                        : false;
0322:
0323:                // Determine if we need to generate WSDL
0324:                // First, make sure that this is only a SOAP 1.1 based binding, per JAXWS spec. we cannot 
0325:                // generate WSDL if the binding type is not SOAP 1.1 based.
0326:                // Then, assuming the composite does not contain a 
0327:                // Wsdl Definition, go ahead and generate it
0328:                // REVIEW: I think this should this be isSOAP11 so the generators are only called for 
0329:                //         SOAP11; i.e. NOT for SOAP12 or XML/HTTP bindings.
0330:                if (isSOAP11) {
0331:                    if ((isEndpointBased() && DescriptionUtils
0332:                            .isEmpty(getAnnoWebServiceEndpointInterface()))
0333:                            || (!isEndpointBased())) {
0334:                        //This is either an implicit SEI, or a WebService Provider
0335:
0336:                        wsdlComposite = generateWSDL(composite);
0337:
0338:                    } else if (isEndpointBased()) {
0339:                        //This impl class specifies an SEI...this is a special case. There is a bug
0340:                        //in the tooling that allows for the wsdllocation to be specifed on either the
0341:                        //impl. class, or the SEI, or both. So, we need to look for the wsdl as follows:
0342:                        //			1. If the Wsdl exists on the SEI, then check for it on the impl.
0343:                        //			2. If it is not found in either location, in that order, then generate
0344:
0345:                        DescriptionBuilderComposite seic = getServiceDescriptionImpl()
0346:                                .getDBCMap().get(
0347:                                        composite.getWebServiceAnnot()
0348:                                                .endpointInterface());
0349:
0350:                        //Only generate WSDL if a definition doesn't already exist
0351:                        if (seic.getWsdlDefinition() == null)
0352:                            wsdlComposite = generateWSDL(composite);
0353:                    }
0354:
0355:                } else if (composite.getWsdlDefinition() == null) {
0356:                    //This is a SOAP12 binding that does not contain a WSDL definition, log a WARNING
0357:                    log
0358:                            .warn("This implementation does not contain a WSDL definition and is not a SOAP 1.1 based binding. "
0359:                                    + "Per JAXWS spec. - a WSDL definition cannot be generated for this implementation. Name: "
0360:                                    + composite.getClassName());
0361:                }
0362:
0363:                if (isSOAP11) {
0364:
0365:                    //Save the WSDL Location and the WsdlDefinition, value depends on whether wsdl was generated
0366:                    Parameter wsdlLocationParameter = new Parameter();
0367:                    wsdlLocationParameter.setName(MDQConstants.WSDL_LOCATION);
0368:
0369:                    Parameter wsdlDefParameter = new Parameter();
0370:                    wsdlDefParameter.setName(MDQConstants.WSDL_DEFINITION);
0371:
0372:                    Parameter wsdlCompositeParameter = new Parameter();
0373:                    wsdlCompositeParameter.setName(MDQConstants.WSDL_COMPOSITE);
0374:
0375:                    if (wsdlComposite != null) {
0376:
0377:                        //We have a wsdl composite, so set these values for the generated wsdl
0378:                        wsdlCompositeParameter.setValue(wsdlComposite);
0379:                        wsdlLocationParameter.setValue(wsdlComposite
0380:                                .getWsdlFileName());
0381:                        wsdlDefParameter.setValue(getServiceDescriptionImpl()
0382:                                .getGeneratedWsdlWrapper().getDefinition());
0383:                    } else if (getServiceDescriptionImpl().getWSDLWrapper() != null) {
0384:                        //No wsdl composite because wsdl already exists
0385:                        wsdlLocationParameter
0386:                                .setValue(getAnnoWebServiceWSDLLocation());
0387:                        wsdlDefParameter.setValue(getServiceDescriptionImpl()
0388:                                .getWSDLWrapper().getDefinition());
0389:                    } else {
0390:                        //There is no wsdl composite and there is NOT a wsdl definition
0391:                        wsdlLocationParameter.setValue(null);
0392:                        wsdlDefParameter.setValue(null);
0393:
0394:                    }
0395:
0396:                    try {
0397:                        if (wsdlComposite != null) {
0398:                            axisService.addParameter(wsdlCompositeParameter);
0399:                        }
0400:                        axisService.addParameter(wsdlDefParameter);
0401:                        axisService.addParameter(wsdlLocationParameter);
0402:                    } catch (Exception e) {
0403:                        throw ExceptionFactory
0404:                                .makeWebServiceException("EndpointDescription: Unable to add parameters to AxisService");
0405:                    }
0406:                } else {
0407:                    // Need to account for SOAP 1.2 WSDL when supplied with application
0408:                    Parameter wsdlDefParameter = new Parameter();
0409:                    wsdlDefParameter.setName(MDQConstants.WSDL_DEFINITION);
0410:                    Parameter wsdlLocationParameter = new Parameter();
0411:                    wsdlLocationParameter.setName(MDQConstants.WSDL_LOCATION);
0412:                    if (getServiceDescriptionImpl().getWSDLWrapper() != null) {
0413:                        wsdlLocationParameter
0414:                                .setValue(getAnnoWebServiceWSDLLocation());
0415:                        wsdlDefParameter.setValue(getServiceDescriptionImpl()
0416:                                .getWSDLWrapper().getDefinition());
0417:                    }
0418:                    // No WSDL supplied and we do not generate for non-SOAP 1.1/HTTP
0419:                    // endpoints
0420:                    else {
0421:                        wsdlLocationParameter.setValue(null);
0422:                        wsdlDefParameter.setValue(null);
0423:                    }
0424:                    try {
0425:                        axisService.addParameter(wsdlDefParameter);
0426:                        axisService.addParameter(wsdlLocationParameter);
0427:
0428:                    } catch (Exception e) {
0429:                        throw ExceptionFactory
0430:                                .makeWebServiceException("EndpointDescription: Unable to add parameters to AxisService");
0431:                    }
0432:                }
0433:            }
0434:
0435:            /**
0436:             * Create from an annotated implementation or SEI class. Note this is
0437:             * currently used only on the server-side (this probably won't change).
0438:             * 
0439:             * @param theClass An implemntation or SEI class
0440:             * @param portName May be null; if so the annotation is used
0441:             * @param parent
0442:             */
0443:            EndpointDescriptionImpl(Class theClass, QName portName,
0444:                    AxisService axisService, ServiceDescriptionImpl parent) {
0445:                this .parentServiceDescription = parent;
0446:                this .portQName = portName;
0447:                this .implOrSEIClass = theClass;
0448:                this .axisService = axisService;
0449:
0450:                addToAxisService();
0451:
0452:                buildEndpointDescriptionFromAnnotations();
0453:
0454:                // The anonymous AxisOperations are currently NOT added here.  The reason 
0455:                // is that (for now) this is a SERVER-SIDE code path, and the anonymous operations
0456:                // are only needed on the client side.
0457:            }
0458:
0459:            private void addToAxisService() {
0460:                // Add a reference to this EndpointDescription object to the AxisService
0461:                if (axisService != null) {
0462:                    Parameter parameter = new Parameter();
0463:                    parameter
0464:                            .setName(EndpointDescription.AXIS_SERVICE_PARAMETER);
0465:                    parameter.setValue(this );
0466:                    // TODO: What to do if AxisFault
0467:                    try {
0468:                        axisService.addParameter(parameter);
0469:                    } catch (AxisFault e) {
0470:                        // TODO: Throwing wrong exception
0471:                        e.printStackTrace();
0472:                        throw new UnsupportedOperationException(
0473:                                "Can't add AxisService param: " + e);
0474:                    }
0475:                }
0476:            }
0477:
0478:            private void buildEndpointDescriptionFromAnnotations() {
0479:                // TODO: The comments below are not quite correct; this method is used on BOTH the 
0480:                //       client and server.  On the client the class is always an SEI.  On the server it 
0481:                //		 is always a service impl which may be a provider or endpoint based;
0482:                //		 endpoint based may reference an SEI class
0483:
0484:                // The Service Implementation class could be either Provider-based or Endpoint-based.  The 
0485:                // annotations that are present are similar but different.  Conformance requirements 
0486:                // per JAX-WS
0487:                // - A Provider based implementation MUST carry the @WebServiceProvider annotation
0488:                //   per section 5.1 javax.xml.ws.Provider on page 63
0489:                // - An Endpoint based implementation MUST carry the @WebService annotation per JSR-181 
0490:                //   (reference TBD) and JAX-WS (reference TBD)
0491:                // - An Endpoint based implementation @WebService annotation MAY reference an endpoint
0492:                //   interface 
0493:                // - The @WebService and @WebServiceProvider annotations can not appear in the same class per 
0494:                //   JAX-WS section 7.7 on page 82.
0495:
0496:                // Verify that one (and only one) of the required annotations is present.
0497:                // TODO: Add tests to verify this error checking
0498:
0499:                if (!getServiceDescriptionImpl().isDBCMap()) {
0500:
0501:                    webServiceAnnotation = (WebService) implOrSEIClass
0502:                            .getAnnotation(WebService.class);
0503:                    webServiceProviderAnnotation = (WebServiceProvider) implOrSEIClass
0504:                            .getAnnotation(WebServiceProvider.class);
0505:
0506:                    if (webServiceAnnotation == null
0507:                            && webServiceProviderAnnotation == null)
0508:                        // TODO: NLS
0509:                        throw ExceptionFactory
0510:                                .makeWebServiceException("Either WebService or WebServiceProvider annotation must be present on "
0511:                                        + implOrSEIClass);
0512:                    else if (webServiceAnnotation != null
0513:                            && webServiceProviderAnnotation != null)
0514:                        // TODO: NLS
0515:                        throw ExceptionFactory
0516:                                .makeWebServiceException("Both WebService or WebServiceProvider annotations cannot be presenton "
0517:                                        + implOrSEIClass);
0518:                }
0519:                // If portName was specified, set it.  Otherwise, we will get it from the appropriate
0520:                // annotation when the getter is called.
0521:                // TODO: If the portName is specified, should we verify it against the annotation?
0522:                // TODO: Add tests: null portName, !null portName, portName != annotation value
0523:                // TODO: Get portName from annotation if it is null.
0524:
0525:                // If this is an Endpoint-based service implementation (i.e. not a 
0526:                // Provider-based one), then create the EndpointInterfaceDescription to contain
0527:                // the operations on the endpoint.  Provider-based endpoints don't have operations
0528:                // associated with them, so they don't have an EndpointInterfaceDescription.
0529:                if (webServiceAnnotation != null) {
0530:                    // If this impl class references an SEI, then use that SEI to create the EndpointInterfaceDesc.
0531:                    // TODO: Add support for service impl endpoints that don't reference an SEI; remember
0532:                    //       that this is also called with just an SEI interface from svcDesc.updateWithSEI()
0533:                    String seiClassName = getAnnoWebServiceEndpointInterface();
0534:
0535:                    if (!getServiceDescriptionImpl().isDBCMap()) {
0536:                        Class seiClass = null;
0537:                        if (DescriptionUtils.isEmpty(seiClassName)) {
0538:                            // For now, just build the EndpointInterfaceDesc based on the class itself.
0539:                            // TODO: The EID ctor doesn't correctly handle anything but an SEI at this
0540:                            //       point; e.g. it doesn't publish the correct methods of just an impl.
0541:                            seiClass = implOrSEIClass;
0542:                        } else {
0543:                            try {
0544:                                // TODO: Using Class forName() is probably not the best long-term way to get the SEI class from the annotation
0545:                                seiClass = ClassLoaderUtils.forName(
0546:                                        seiClassName, false, ClassLoaderUtils
0547:                                                .getContextClassLoader());
0548:                                // Catch Throwable as ClassLoader can throw an NoClassDefFoundError that
0549:                                // does not extend Exception, so lets catch everything that extends Throwable
0550:                                // rather than just Exception.
0551:                            } catch (Throwable e) {
0552:                                // TODO: Throwing wrong exception
0553:                                e.printStackTrace();
0554:                                throw new UnsupportedOperationException(
0555:                                        "Can't create SEI class: " + e);
0556:                            }
0557:                        }
0558:                        endpointInterfaceDescription = new EndpointInterfaceDescriptionImpl(
0559:                                seiClass, this );
0560:                    } else {
0561:                        //TODO: Determine if we need logic here to determine implied SEI or not. This logic
0562:                        //		may be handled by EndpointInterfaceDescription
0563:
0564:                        if (DescriptionUtils
0565:                                .isEmpty(getAnnoWebServiceEndpointInterface())) {
0566:
0567:                            //TODO: Build the EndpointInterfaceDesc based on the class itself
0568:                            endpointInterfaceDescription = new EndpointInterfaceDescriptionImpl(
0569:                                    composite, true, this );
0570:
0571:                        } else {
0572:                            //Otherwise, build the EID based on the SEI composite
0573:                            endpointInterfaceDescription = new EndpointInterfaceDescriptionImpl(
0574:                                    getServiceDescriptionImpl().getDBCMap()
0575:                                            .get(seiClassName), false, this );
0576:                        }
0577:                    }
0578:                } else {
0579:                    if (log.isDebugEnabled()) {
0580:                        log
0581:                                .debug("WebServiceProvider without WSDL encountered");
0582:                    }
0583:                    // REVIEW: Currently this is only supported for HTTP Bindings; SOAPBindings
0584:                    //     for providers currently require that there be WSDL.
0585:                    String bindingType = getBindingType();
0586:                    if (javax.xml.ws.http.HTTPBinding.HTTP_BINDING
0587:                            .equals(bindingType)) {
0588:                        endpointInterfaceDescription = new EndpointInterfaceDescriptionImpl(
0589:                                composite, this );
0590:                    }
0591:                }
0592:            }
0593:
0594:            public QName getPortQName() {
0595:                // REVIEW: Implement WSDL/Annotation merge? May be OK as is; not sure how would know WHICH port Qname to get out of the WSDL if 
0596:                //       we didn't use annotations.
0597:                if (portQName == null) {
0598:                    // The name was not set by the constructors, so get it from the
0599:                    // appropriate annotation.
0600:                    String name = getAnnoWebServicePortName();
0601:                    String tns = getAnnoWebServiceTargetNamespace();
0602:
0603:                    // TODO: Check for name &/| tns null or empty string and add tests for same
0604:                    portQName = new QName(tns, name);
0605:                }
0606:                return portQName;
0607:            }
0608:
0609:            public QName getServiceQName() {
0610:                if (serviceQName == null) {
0611:                    // If the service name has been set on the Service, use that.  Otherwise
0612:                    // get the name off the annotations
0613:                    QName serviceDescQName = getServiceDescription()
0614:                            .getServiceQName();
0615:                    if (!DescriptionUtils.isEmpty(serviceDescQName)) {
0616:                        serviceQName = serviceDescQName;
0617:                    } else {
0618:                        String localPart = getAnnoWebServiceServiceName();
0619:                        String tns = getAnnoWebServiceTargetNamespace();
0620:                        serviceQName = new QName(tns, localPart);
0621:                    }
0622:                }
0623:                return serviceQName;
0624:            }
0625:
0626:            public ServiceDescription getServiceDescription() {
0627:                return parentServiceDescription;
0628:            }
0629:
0630:            ServiceDescriptionImpl getServiceDescriptionImpl() {
0631:                return (ServiceDescriptionImpl) parentServiceDescription;
0632:            }
0633:
0634:            public EndpointInterfaceDescription getEndpointInterfaceDescription() {
0635:                return endpointInterfaceDescription;
0636:            }
0637:
0638:            public AxisService getAxisService() {
0639:                return axisService;
0640:            }
0641:
0642:            boolean isDynamicPort() {
0643:                return isDynamicPort;
0644:            }
0645:
0646:            void updateWithSEI(Class sei) {
0647:                // Updating with an SEI is only valid for declared ports; it is not valid for dynamic ports.
0648:                if (isDynamicPort()) {
0649:                    // TODO: RAS and NLS
0650:                    throw ExceptionFactory
0651:                            .makeWebServiceException("Can not update an SEI on a dynamic port.  PortQName:"
0652:                                    + portQName);
0653:                }
0654:                if (sei == null) {
0655:                    // TODO: RAS and NLS
0656:                    throw ExceptionFactory
0657:                            .makeWebServiceException("EndpointDescription.updateWithSEI was passed a null SEI.  PortQName:"
0658:                                    + portQName);
0659:                }
0660:
0661:                if (endpointInterfaceDescription != null) {
0662:                    // The EndpointInterfaceDescription was created previously based on the port declaration (i.e. WSDL)
0663:                    // so update that with information from the SEI annotations
0664:                    ((EndpointInterfaceDescriptionImpl) endpointInterfaceDescription)
0665:                            .updateWithSEI(sei);
0666:                } else {
0667:                    // An EndpointInterfaceDescription does not exist yet.  This currently happens in the case where there is 
0668:                    // NO WSDL provided and a Dispatch client is created for prior to a getPort being done for that port.
0669:                    // There was no WSDL to create the EndpointInterfaceDescription from and there was no annotated SEI to
0670:                    // use at that time.  Now we have an annotated SEI, so create the EndpointInterfaceDescription now.
0671:                    endpointInterfaceDescription = new EndpointInterfaceDescriptionImpl(
0672:                            sei, this );
0673:                }
0674:                return;
0675:            }
0676:
0677:            private void setupAxisService() {
0678:                // TODO: Need to use MetaDataQuery validator to merge WSDL (if any) and annotations (if any)
0679:                // Build up the AxisService.  Note that if this is a dynamic port, then we don't use the
0680:                // WSDL to build up the AxisService since the port added to the Service by the client is not
0681:                // one that will be present in the WSDL.  A null class passed in as the SEI indicates this 
0682:                // is a dispatch client.
0683:                if (!isDynamicPort
0684:                        && getServiceDescriptionImpl().getWSDLWrapper() != null) {
0685:                    isAxisServiceBuiltFromWSDL = buildAxisServiceFromWSDL();
0686:                } else {
0687:                    buildAxisServiceFromAnnotations();
0688:                }
0689:
0690:                if (axisService == null) {
0691:                    // TODO: RAS & NLS
0692:                    throw ExceptionFactory
0693:                            .makeWebServiceException("Unable to create AxisService for "
0694:                                    + createAxisServiceName());
0695:                }
0696:
0697:                // Save the Service QName as a parameter.
0698:                Parameter serviceNameParameter = new Parameter();
0699:                serviceNameParameter
0700:                        .setName(WSDL11ToAllAxisServicesBuilder.WSDL_SERVICE_QNAME);
0701:                serviceNameParameter.setValue(getServiceDescription()
0702:                        .getServiceQName());
0703:
0704:                // Save the Port name.  Note: Axis does not expect a QName since the namespace for the port is the ns from the WSDL definition 
0705:                Parameter portParameter = new Parameter();
0706:                portParameter.setName(WSDL11ToAllAxisServicesBuilder.WSDL_PORT);
0707:                portParameter.setValue(portQName.getLocalPart());
0708:
0709:                try {
0710:                    axisService.addParameter(serviceNameParameter);
0711:                    axisService.addParameter(portParameter);
0712:                } catch (AxisFault e) {
0713:                    // TODO RAS
0714:                    e.printStackTrace();
0715:                }
0716:            }
0717:
0718:            /*
0719:             * This setups and builds the AxisService using only the DescriptionBuilderCompositeList
0720:             * 
0721:             */
0722:            private void setupAxisServiceFromDBL() {
0723:                // TODO: Need to use MetaDataQuery validator to merge WSDL (if any) and annotations (if any)
0724:                // Build up the AxisService.  Note that if this is a dispatch client, then we don't use the
0725:                // WSDL to build up the AxisService since the port added to the Service by the client is not
0726:                // one that will be present in the WSDL.  A null class passed in as the SEI indicates this 
0727:                // is a dispatch client.
0728:
0729:                // If WSDL is present, it may be full or only partial.  If we can create the AxisService from 
0730:                // the WSDL, that WSDL is fully specified.  Otherwise, it is "partial WSDL".  In that case
0731:                // we use annotaions to build the AxisService
0732:                isAxisServiceBuiltFromWSDL = false;
0733:                if (getServiceDescriptionImpl().getWSDLWrapper() != null) {
0734:                    isAxisServiceBuiltFromWSDL = buildAxisServiceFromWSDL();
0735:
0736:                }
0737:
0738:                if (!isAxisServiceBuiltFromWSDL) {
0739:                    //generateWSDL(composite);
0740:                    buildAxisServiceFromAnnotations();
0741:                }
0742:
0743:                if (axisService == null) {
0744:                    // TODO: RAS & NLS
0745:                    throw ExceptionFactory
0746:                            .makeWebServiceException("Unable to create AxisService for "
0747:                                    + createAxisServiceName());
0748:                }
0749:
0750:                //Save the Port Type name
0751:                Parameter portTypeNameParameter = new Parameter();
0752:                portTypeNameParameter.setName(MDQConstants.WSDL_PORTTYPE_NAME);
0753:                portTypeNameParameter.setValue(getName());
0754:
0755:                // Save the Service QName as a parameter.
0756:                Parameter serviceNameParameter = new Parameter();
0757:                serviceNameParameter.setName(MDQConstants.WSDL_SERVICE_QNAME);
0758:                serviceNameParameter.setValue(getServiceDescription()
0759:                        .getServiceQName());
0760:
0761:                // Save the Port name.  Note: Axis does not expect a QName since the namespace
0762:                //   for the port is the ns from the WSDL definition 
0763:                Parameter portParameter = new Parameter();
0764:                portParameter.setName(MDQConstants.WSDL_PORT);
0765:                portParameter.setValue(getPortQName().getLocalPart());
0766:
0767:                //Save the fully qualified class name for the serviceImpl
0768:                Parameter serviceClassNameParameter = new Parameter();
0769:                serviceClassNameParameter.setName(MDQConstants.SERVICE_CLASS);
0770:                serviceClassNameParameter.setValue(DescriptionUtils
0771:                        .javifyClassName(composite.getClassName()));
0772:
0773:                try {
0774:                    axisService.addParameter(portTypeNameParameter);
0775:                    axisService.addParameter(serviceNameParameter);
0776:                    axisService.addParameter(portParameter);
0777:                    axisService.addParameter(serviceClassNameParameter);
0778:                } catch (AxisFault e) {
0779:                    // TODO RAS
0780:                    e.printStackTrace();
0781:                }
0782:            }
0783:
0784:            private boolean buildAxisServiceFromWSDL() {
0785:                boolean isBuiltFromWSDL = false;
0786:                try {
0787:
0788:                    // TODO: Change this to use WSDLToAxisServiceBuilder superclass
0789:                    // Note that the axis service builder takes only the localpart of the port qname.
0790:                    // TODO:: This should check that the namespace of the definition matches the namespace of the portQName per JAXRPC spec
0791:
0792:                    WSDLWrapper wrapper = getServiceDescriptionImpl()
0793:                            .getWSDLWrapper();
0794:                    WSDL11ToAxisServiceBuilder serviceBuilder = new WSDL11ToAxisServiceBuilder(
0795:                            wrapper.getDefinition(), getServiceDescription()
0796:                                    .getServiceQName(), getPortQName()
0797:                                    .getLocalPart());
0798:
0799:                    //TODO: Temporary, please change the following log.info to log.debug
0800:                    log.info("Building AxisService from wsdl: "
0801:                            + wrapper.getWSDLLocation());
0802:
0803:                    if (getServiceDescriptionImpl().isDBCMap()) {
0804:                        //this.class.getClass().getClassLoader();
0805:                        URIResolverImpl uriResolver = new URIResolverImpl(
0806:                                composite.getClassLoader());
0807:                        serviceBuilder.setCustomResolver(uriResolver);
0808:                    } else {
0809:                        ClassLoader classLoader = (ClassLoader) AccessController
0810:                                .doPrivileged(new PrivilegedAction() {
0811:                                    public Object run() {
0812:                                        return Thread.currentThread()
0813:                                                .getContextClassLoader();
0814:                                    }
0815:                                });
0816:                        URIResolverImpl uriResolver = new URIResolverImpl(
0817:                                classLoader);
0818:                        serviceBuilder.setCustomResolver(uriResolver);
0819:                    }
0820:
0821:                    // TODO: Currently this only builds the client-side AxisService;
0822:                    // it needs to do client and server somehow.
0823:                    // Patterned after AxisService.createClientSideAxisService
0824:                    if (getServiceDescriptionImpl().isServerSide())
0825:                        serviceBuilder.setServerSide(true);
0826:                    else
0827:                        serviceBuilder.setServerSide(false);
0828:
0829:                    axisService = serviceBuilder.populateService();
0830:                    axisService.setName(createAxisServiceName());
0831:                    isBuiltFromWSDL = true;
0832:
0833:                } catch (AxisFault e) {
0834:                    // REVIEW: If we couldn't use the WSDL, should we fail instead of continuing to process using annotations?
0835:                    //         Note that if we choose to fail, we need to distinguish the partial WSDL case (which can not fail)
0836:                    // TODO: RAS/NLS  Need to update the message with the appropriate inserts
0837:                    //    		log.warn(Messages.getMessage("warnAxisFault", e.toString()), e);
0838:                    String wsdlLocation = (getServiceDescriptionImpl()
0839:                            .getWSDLLocation() != null) ? getServiceDescriptionImpl()
0840:                            .getWSDLLocation().toString()
0841:                            : null;
0842:                    String implClassName = null;
0843:                    if (getServiceDescriptionImpl().isDBCMap()) {
0844:                        implClassName = composite.getClassName();
0845:                    } else {
0846:                        implClassName = (implOrSEIClass != null) ? implOrSEIClass
0847:                                .getName()
0848:                                : null;
0849:                    }
0850:                    log
0851:                            .warn(
0852:                                    "The WSDL file could not be used due to an exception.  The WSDL will be ignored and annotations will be used.  Implementaiton class: "
0853:                                            + implClassName
0854:                                            + "; WSDL Location: "
0855:                                            + wsdlLocation
0856:                                            + "; Exception: "
0857:                                            + e.toString(), e);
0858:                    isBuiltFromWSDL = false;
0859:                    return isBuiltFromWSDL;
0860:                }
0861:                return isBuiltFromWSDL;
0862:            }
0863:
0864:            private void buildAxisServiceFromAnnotations() {
0865:                // TODO: Refactor this to create from annotations.
0866:                String serviceName = null;
0867:                if (portQName != null) {
0868:                    serviceName = createAxisServiceName();
0869:                } else {
0870:                    // REVIEW: Can the portQName ever be null?
0871:                    // Make this service name unique.  The Axis2 engine assumes that a service it can not find is a client-side service.
0872:                    serviceName = ServiceClient.ANON_SERVICE + this .hashCode()
0873:                            + System.currentTimeMillis();
0874:                }
0875:                axisService = new AxisService(serviceName);
0876:
0877:                //TODO: Set other things on AxisService here, this function may have to be
0878:                //      moved to after we create all the AxisOperations
0879:            }
0880:
0881:            private void buildDescriptionHierachy() {
0882:                // Build up the Description Hierachy.  Note that if this is a dynamic port, then we don't use the
0883:                // WSDL to build up the hierachy since the port added to the Service by the client is not
0884:                // one that will be present in the WSDL.
0885:
0886:                //First, check to see if we can build this with the DBC List
0887:                //TODO: When MDQ input is the only possible input, then we can remove the check for
0888:                //      the DBC list, until that time the code in here may appear somewhat redundant
0889:                if (getServiceDescriptionImpl().isDBCMap()) {
0890:                    if (!isDynamicPort && isWSDLFullySpecified())
0891:                        buildEndpointDescriptionFromWSDL();
0892:                    else
0893:                        buildEndpointDescriptionFromAnnotations();
0894:                } else {
0895:                    //Still processing annotations from the class
0896:                    // This path was not updated
0897:                    if (!isDynamicPort && isWSDLFullySpecified()) {
0898:                        buildEndpointDescriptionFromWSDL();
0899:                    } else if (implOrSEIClass != null) {
0900:                        // Create the rest of the description hierachy from annotations on the class.
0901:                        // If there is no SEI class, then this is a Distpach case, and we currently
0902:                        // don't create the rest of the description hierachy (since it is not an SEI and thus
0903:                        // not operation-based client.
0904:                        buildEndpointDescriptionFromAnnotations();
0905:                    }
0906:                }
0907:            }
0908:
0909:            private void buildEndpointDescriptionFromWSDL() {
0910:                Definition wsdlDefinition = getServiceDescriptionImpl()
0911:                        .getWSDLWrapper().getDefinition();
0912:                javax.wsdl.Service wsdlService = wsdlDefinition
0913:                        .getService(getServiceDescription().getServiceQName());
0914:                if (wsdlService == null) {
0915:                    throw ExceptionFactory.makeWebServiceException(Messages
0916:                            .getMessage("serviceDescErr2",
0917:                                    createAxisServiceName()));
0918:                }
0919:
0920:                Map wsdlPorts = wsdlService.getPorts();
0921:                boolean wsdlPortFound = false;
0922:                if (wsdlPorts != null && wsdlPorts.size() > 0) {
0923:                    Iterator wsdlPortIterator = wsdlPorts.values().iterator();
0924:
0925:                    while (wsdlPortIterator.hasNext() && !wsdlPortFound) {
0926:                        Port wsdlPort = (Port) wsdlPortIterator.next();
0927:                        // Note the namespace is not included on the WSDL Port.
0928:                        if (wsdlPort.getName().equals(portQName.getLocalPart())) {
0929:
0930:                            // Build the EndpointInterface based on the specified SEI if there is one
0931:                            // or on the service impl class (i.e. an implicit SEI).
0932:                            if (getServiceDescriptionImpl().isDBCMap()) {
0933:                                String seiClassName = getAnnoWebServiceEndpointInterface();
0934:                                if (DescriptionUtils.isEmpty(seiClassName)) {
0935:                                    // No SEI specified, so use the service impl as an implicit SEI
0936:                                    endpointInterfaceDescription = new EndpointInterfaceDescriptionImpl(
0937:                                            composite, true, this );
0938:                                } else {
0939:                                    // Otherwise, build the EID based on the SEI composite
0940:                                    endpointInterfaceDescription = new EndpointInterfaceDescriptionImpl(
0941:                                            getServiceDescriptionImpl()
0942:                                                    .getDBCMap().get(
0943:                                                            seiClassName),
0944:                                            false, this );
0945:                                }
0946:
0947:                            } else {
0948:                                // Create the Endpoint Interface Description based on the WSDL.
0949:                                endpointInterfaceDescription = new EndpointInterfaceDescriptionImpl(
0950:                                        this );
0951:
0952:                                // Update the EndpointInterfaceDescription created with WSDL with information from the
0953:                                // annotations in the SEI
0954:                                ((EndpointInterfaceDescriptionImpl) endpointInterfaceDescription)
0955:                                        .updateWithSEI(implOrSEIClass);
0956:                            }
0957:                            wsdlPortFound = true;
0958:                        }
0959:                    }
0960:                }
0961:
0962:                if (!wsdlPortFound) {
0963:                    // TODO: NLS and RAS
0964:                    throw ExceptionFactory
0965:                            .makeWebServiceException("WSDL Port not found for port "
0966:                                    + portQName.getLocalPart());
0967:                }
0968:            }
0969:
0970:            /**
0971:             * Adds the anonymous axis operations to the AxisService.  Note that this is only needed on the
0972:             * client side, and they are currently used in two cases (1) For Dispatch clients (which don't
0973:             * use SEIs and thus don't use operations) (2) TEMPORARLIY for Services created without WSDL
0974:             * (and thus which have no AxisOperations created) See the AxisInvocationController invoke
0975:             * methods for more details.
0976:             * <p/>
0977:             * Based on ServiceClient.createAnonymouService
0978:             */
0979:            private void addAnonymousAxisOperations() {
0980:                if (axisService != null) {
0981:                    OutOnlyAxisOperation outOnlyOperation = new OutOnlyAxisOperation(
0982:                            ServiceClient.ANON_OUT_ONLY_OP);
0983:                    axisService.addOperation(outOnlyOperation);
0984:
0985:                    OutInAxisOperation outInOperation = new OutInAxisOperation(
0986:                            ServiceClient.ANON_OUT_IN_OP);
0987:                    axisService.addOperation(outInOperation);
0988:                }
0989:            }
0990:
0991:            public ServiceClient getServiceClient() {
0992:                try {
0993:                    if (serviceClient == null) {
0994:                        ConfigurationContext configCtx = getServiceDescription()
0995:                                .getAxisConfigContext();
0996:                        AxisService axisSvc = getAxisService();
0997:                        AxisConfiguration axisCfg = configCtx
0998:                                .getAxisConfiguration();
0999:                        if (axisCfg.getService(axisSvc.getName()) != null) {
1000:                            axisSvc
1001:                                    .setName(axisSvc.getName()
1002:                                            + this .hashCode());
1003:                        }
1004:                        serviceClient = new ServiceClient(configCtx, axisSvc);
1005:                    }
1006:                } catch (AxisFault e) {
1007:                    throw ExceptionFactory.makeWebServiceException(Messages
1008:                            .getMessage("serviceClientCreateError"), e);
1009:                }
1010:                return serviceClient;
1011:            }
1012:
1013:            //This should eventually be deprecated in favor 'createAxisServiceNameFromDBL
1014:            private String createAxisServiceName() {
1015:                String portName = null;
1016:                if (portQName != null) {
1017:                    portName = portQName.getLocalPart();
1018:                } else {
1019:                    portName = "NoPortNameSpecified";
1020:
1021:                }
1022:                return getServiceDescription().getServiceQName().getLocalPart()
1023:                        + "." + portName;
1024:            }
1025:
1026:            public boolean isWSDLFullySpecified() {
1027:                return isAxisServiceBuiltFromWSDL;
1028:            }
1029:
1030:            public boolean isProviderBased() {
1031:                return webServiceProviderAnnotation != null;
1032:            }
1033:
1034:            public boolean isEndpointBased() {
1035:                return webServiceAnnotation != null;
1036:            }
1037:
1038:            // ===========================================
1039:            // ANNOTATION: WebService and WebServiceProvider
1040:            // ===========================================
1041:
1042:            public String getAnnoWebServiceWSDLLocation() {
1043:                if (annotation_WsdlLocation == null) {
1044:
1045:                    if (getAnnoWebService() != null) {
1046:                        annotation_WsdlLocation = getAnnoWebService()
1047:                                .wsdlLocation();
1048:
1049:                        //If this is not an implicit SEI, then make sure that its not on the SEI
1050:                        if (getServiceDescriptionImpl().isDBCMap()) {
1051:                            if (!DescriptionUtils
1052:                                    .isEmpty(getAnnoWebServiceEndpointInterface())) {
1053:
1054:                                DescriptionBuilderComposite seic = getServiceDescriptionImpl()
1055:                                        .getDBCMap().get(
1056:                                                composite.getWebServiceAnnot()
1057:                                                        .endpointInterface());
1058:                                if (!DescriptionUtils.isEmpty(seic
1059:                                        .getWebServiceAnnot().wsdlLocation())) {
1060:                                    annotation_WsdlLocation = seic
1061:                                            .getWebServiceAnnot()
1062:                                            .wsdlLocation();
1063:                                }
1064:                            }
1065:                        }
1066:                    } else if (getAnnoWebServiceProvider() != null
1067:                            && !DescriptionUtils
1068:                                    .isEmpty(getAnnoWebServiceProvider()
1069:                                            .wsdlLocation())) {
1070:                        annotation_WsdlLocation = getAnnoWebServiceProvider()
1071:                                .wsdlLocation();
1072:                    } else {
1073:                        // There is no default value per JSR-181 MR Sec 4.1 pg 16
1074:                        annotation_WsdlLocation = "";
1075:                    }
1076:                }
1077:                return annotation_WsdlLocation;
1078:            }
1079:
1080:            public String getAnnoWebServiceServiceName() {
1081:                if (annotation_ServiceName == null) {
1082:                    if (getAnnoWebService() != null
1083:                            && !DescriptionUtils.isEmpty(getAnnoWebService()
1084:                                    .serviceName())) {
1085:                        annotation_ServiceName = getAnnoWebService()
1086:                                .serviceName();
1087:                    } else if (getAnnoWebServiceProvider() != null
1088:                            && !DescriptionUtils
1089:                                    .isEmpty(getAnnoWebServiceProvider()
1090:                                            .serviceName())) {
1091:                        annotation_ServiceName = getAnnoWebServiceProvider()
1092:                                .serviceName();
1093:                    } else {
1094:                        // Default value is the "simple name" of the class or interface + "Service"
1095:                        // Per JSR-181 MR Sec 4.1, pg 15
1096:                        if (getServiceDescriptionImpl().isDBCMap()) {
1097:                            annotation_ServiceName = DescriptionUtils
1098:                                    .getSimpleJavaClassName(composite
1099:                                            .getClassName())
1100:                                    + "Service";
1101:                        } else {
1102:                            annotation_ServiceName = DescriptionUtils
1103:                                    .getSimpleJavaClassName(implOrSEIClass)
1104:                                    + "Service";
1105:                        }
1106:                    }
1107:                }
1108:                return annotation_ServiceName;
1109:            }
1110:
1111:            public String getAnnoWebServicePortName() {
1112:                if (annotation_PortName == null) {
1113:                    if (getAnnoWebService() != null
1114:                            && !DescriptionUtils.isEmpty(getAnnoWebService()
1115:                                    .portName())) {
1116:                        annotation_PortName = getAnnoWebService().portName();
1117:                    } else if (getAnnoWebServiceProvider() != null
1118:                            && !DescriptionUtils
1119:                                    .isEmpty(getAnnoWebServiceProvider()
1120:                                            .portName())) {
1121:                        annotation_PortName = getAnnoWebServiceProvider()
1122:                                .portName();
1123:                    } else {
1124:                        // Default the value
1125:                        if (isProviderBased()) {
1126:                            // This is the @WebServiceProvider annotation path
1127:                            // Default value is not specified in JSR-224, but we can assume it is 
1128:                            // similar to the default in the WebService case, however there is no
1129:                            // name attribute for a WebServiceProvider.  So in this case we use 
1130:                            // the default value for WebService.name per JSR-181 MR sec 4.1 pg 15.
1131:                            // Note that this is really the same thing as the call to getWebServiceName() 
1132:                            // in the WebService case; it is done sepertely just to be clear there is no 
1133:                            // name element on the WebServiceProvider annotation
1134:
1135:                            annotation_PortName = (getServiceDescriptionImpl()
1136:                                    .isDBCMap()) ? DescriptionUtils
1137:                                    .getSimpleJavaClassName(composite
1138:                                            .getClassName())
1139:                                    + "Port" : DescriptionUtils
1140:                                    .getSimpleJavaClassName(implOrSEIClass)
1141:                                    + "Port";
1142:                        } else {
1143:                            // This is the @WebService annotation path
1144:                            // Default value is the @WebService.name of the class or interface + "Port"
1145:                            // Per JSR-181 MR Sec 4.1, pg 15
1146:                            annotation_PortName = getAnnoWebServiceName()
1147:                                    + "Port";
1148:                        }
1149:                    }
1150:                }
1151:                return annotation_PortName;
1152:            }
1153:
1154:            public String getAnnoWebServiceTargetNamespace() {
1155:                if (annotation_TargetNamespace == null) {
1156:                    if (getAnnoWebService() != null
1157:                            && !DescriptionUtils.isEmpty(getAnnoWebService()
1158:                                    .targetNamespace())) {
1159:                        annotation_TargetNamespace = getAnnoWebService()
1160:                                .targetNamespace();
1161:                    } else if (getAnnoWebServiceProvider() != null
1162:                            && !DescriptionUtils
1163:                                    .isEmpty(getAnnoWebServiceProvider()
1164:                                            .targetNamespace())) {
1165:                        annotation_TargetNamespace = getAnnoWebServiceProvider()
1166:                                .targetNamespace();
1167:                    } else {
1168:                        // Default value per JSR-181 MR Sec 4.1 pg 15 defers to "Implementation defined, 
1169:                        // as described in JAX-WS 2.0, section 3.2" which is JAX-WS 2.0 Sec 3.2, pg 29.
1170:                        // FIXME: Hardcoded protocol for namespace
1171:                        if (getServiceDescriptionImpl().isDBCMap())
1172:                            annotation_TargetNamespace = DescriptionUtils
1173:                                    .makeNamespaceFromPackageName(
1174:                                            DescriptionUtils
1175:                                                    .getJavaPackageName(composite
1176:                                                            .getClassName()),
1177:                                            "http");
1178:                        else
1179:                            annotation_TargetNamespace = DescriptionUtils
1180:                                    .makeNamespaceFromPackageName(
1181:                                            DescriptionUtils
1182:                                                    .getJavaPackageName(implOrSEIClass),
1183:                                            "http");
1184:
1185:                    }
1186:                }
1187:                return annotation_TargetNamespace;
1188:            }
1189:
1190:            // ===========================================
1191:            // ANNOTATION: WebServiceProvider
1192:            // ===========================================
1193:
1194:            public WebServiceProvider getAnnoWebServiceProvider() {
1195:                return webServiceProviderAnnotation;
1196:            }
1197:
1198:            // ===========================================
1199:            // ANNOTATION: WebService
1200:            // ===========================================
1201:
1202:            public WebService getAnnoWebService() {
1203:                return webServiceAnnotation;
1204:            }
1205:
1206:            public String getAnnoWebServiceEndpointInterface() {
1207:                // TODO: Validation: Not allowed on WebServiceProvider
1208:                if (webService_EndpointInterface == null) {
1209:                    if (!isProviderBased()
1210:                            && getAnnoWebService() != null
1211:                            && !DescriptionUtils.isEmpty(getAnnoWebService()
1212:                                    .endpointInterface())) {
1213:                        webService_EndpointInterface = getAnnoWebService()
1214:                                .endpointInterface();
1215:                    } else {
1216:                        // This element is not valid on a WebServiceProvider annotation
1217:                        // REVIEW: Is this a correct thing to return if this is called against a WebServiceProvier
1218:                        //         which does not support this element?
1219:                        webService_EndpointInterface = "";
1220:                    }
1221:                }
1222:                return webService_EndpointInterface;
1223:            }
1224:
1225:            public String getAnnoWebServiceName() {
1226:                // TODO: Validation: Not allowed on WebServiceProvider
1227:
1228:                //TODO: Per JSR109 v1.2 Sec. 5.3.2.1
1229:                //      If not specified then we can use the default value as specified in JSR 181
1230:                //		(but only if it is unique within the module)...or If the name is
1231:                //		not specified in the Service Implementation Bean then fully
1232:                //		qualified name of the Bean class is used to guarantee uniqueness
1233:                //		If the above is not unique then fully qualified name of the
1234:                //		Bean class is used to guarantee uniqueness
1235:
1236:                if (webService_Name == null) {
1237:                    if (!isProviderBased()) {
1238:                        if (getAnnoWebService() != null
1239:                                && !DescriptionUtils
1240:                                        .isEmpty(getAnnoWebService().name())) {
1241:                            webService_Name = getAnnoWebService().name();
1242:                        } else {
1243:                            if (getServiceDescriptionImpl().isDBCMap()) {
1244:                                //The name is the simple name of the class or interface
1245:                                webService_Name = DescriptionUtils
1246:                                        .getSimpleJavaClassName(composite
1247:                                                .getClassName());
1248:                            } else {
1249:                                // Default per JSR-181 Sec 4.1, pg 15
1250:                                webService_Name = DescriptionUtils
1251:                                        .getSimpleJavaClassName(implOrSEIClass);
1252:                            }
1253:                        }
1254:                    } else {
1255:                        // This element is not valid on a WebServiceProvider annotation
1256:                        // REVIEW: Is this a correct thing to return if this is called against a WebServiceProvier
1257:                        //         which does not support this element?
1258:                        webService_Name = "";
1259:                    }
1260:                }
1261:                return webService_Name;
1262:            }
1263:
1264:            // ===========================================
1265:            // ANNOTATION: ServiceMode
1266:            // ===========================================
1267:            public ServiceMode getAnnoServiceMode() {
1268:
1269:                if (serviceModeAnnotation == null) {
1270:                    if (getServiceDescriptionImpl().isDBCMap()) {
1271:                        serviceModeAnnotation = composite.getServiceModeAnnot();
1272:                    } else {
1273:                        if (implOrSEIClass != null) {
1274:                            serviceModeAnnotation = (ServiceMode) implOrSEIClass
1275:                                    .getAnnotation(ServiceMode.class);
1276:                        }
1277:                    }
1278:                }
1279:                return serviceModeAnnotation;
1280:            }
1281:
1282:            public Service.Mode getServiceMode() {
1283:                // REVIEW: WSDL/Anno Merge
1284:                return getAnnoServiceModeValue();
1285:            }
1286:
1287:            public Service.Mode getAnnoServiceModeValue() {
1288:                // This annotation is only valid on Provider-based endpoints. 
1289:                if (isProviderBased() && serviceModeValue == null) {
1290:                    if (getAnnoServiceMode() != null) {
1291:                        serviceModeValue = getAnnoServiceMode().value();
1292:                    } else {
1293:                        serviceModeValue = ServiceMode_DEFAULT;
1294:                    }
1295:                }
1296:                return serviceModeValue;
1297:            }
1298:
1299:            // ===========================================
1300:            // ANNOTATION: BindingType
1301:            // ===========================================
1302:
1303:            public BindingType getAnnoBindingType() {
1304:                if (bindingTypeAnnotation == null) {
1305:                    if (getServiceDescriptionImpl().isDBCMap()) {
1306:                        bindingTypeAnnotation = composite.getBindingTypeAnnot();
1307:                    } else {
1308:                        if (implOrSEIClass != null) {
1309:                            bindingTypeAnnotation = (BindingType) implOrSEIClass
1310:                                    .getAnnotation(BindingType.class);
1311:                        }
1312:                    }
1313:                }
1314:                return bindingTypeAnnotation;
1315:            }
1316:
1317:            public String getBindingType() {
1318:                // REVIEW: Implement WSDL/Anno merge?
1319:                return getAnnoBindingTypeValue();
1320:            }
1321:
1322:            public String getAnnoBindingTypeValue() {
1323:                if (bindingTypeValue == null) {
1324:                    if (getAnnoBindingType() != null
1325:                            && !DescriptionUtils.isEmpty(getAnnoBindingType()
1326:                                    .value())) {
1327:                        bindingTypeValue = getAnnoBindingType().value();
1328:                    } else {
1329:                        // No BindingType annotation present or value was empty; use default value
1330:                        bindingTypeValue = BindingType_DEFAULT;
1331:                    }
1332:                }
1333:                return bindingTypeValue;
1334:            }
1335:
1336:            // ===========================================
1337:            // ANNOTATION: HandlerChain
1338:            // ===========================================
1339:
1340:            public void setHandlerChain(HandlerChainsType handlerChain) {
1341:                handlerChainsType = handlerChain;
1342:            }
1343:
1344:            /**
1345:             * Returns a schema derived java class containing the the handler configuration filel
1346:             *
1347:             * @return HandlerChainsType This is the top-level element for the Handler configuration file
1348:             */
1349:            public HandlerChainsType getHandlerChain() {
1350:
1351:                if (handlerChainsType == null) {
1352:                    getAnnoHandlerChainAnnotation();
1353:                    if (handlerChainAnnotation != null) {
1354:                        String handlerFileName = handlerChainAnnotation.file();
1355:
1356:                        // TODO RAS & NLS
1357:                        if (log.isDebugEnabled()) {
1358:                            log
1359:                                    .debug("EndpointDescriptionImpl.getHandlerChain: fileName: "
1360:                                            + handlerFileName
1361:                                            + " className: "
1362:                                            + composite.getClassName());
1363:                        }
1364:
1365:                        String className = getServiceDescriptionImpl()
1366:                                .isDBCMap() ? composite.getClassName()
1367:                                : implOrSEIClass.getName();
1368:
1369:                        ClassLoader classLoader = getServiceDescriptionImpl()
1370:                                .isDBCMap() ? composite.getClassLoader() : this 
1371:                                .getClass().getClassLoader();
1372:
1373:                        InputStream is = DescriptionUtils
1374:                                .openHandlerConfigStream(handlerFileName,
1375:                                        className, classLoader);
1376:
1377:                        if (is == null) {
1378:                            log.warn("Unable to load handlers from file: "
1379:                                    + handlerFileName);
1380:                        } else {
1381:                            handlerChainsType = DescriptionUtils
1382:                                    .loadHandlerChains(is);
1383:                        }
1384:                    }
1385:                }
1386:                return handlerChainsType;
1387:            }
1388:
1389:            public HandlerChain getAnnoHandlerChainAnnotation() {
1390:                if (this .handlerChainAnnotation == null) {
1391:                    if (getServiceDescriptionImpl().isDBCMap()) {
1392:                        /*
1393:                         * Per JSR-181 The @HandlerChain annotation MAY be present on
1394:                         * the endpoint interface and service implementation bean. The
1395:                         * service implementations bean's @HandlerChain is used if
1396:                         * @HandlerChain is present on both. So, if we do find the
1397:                         * annotation on this impl, then don't worry about else
1398:                         * Otherwise, check to see if the SEI might be annotated with
1399:                         * @HandlerChain
1400:                         */
1401:
1402:                        handlerChainAnnotation = composite
1403:                                .getHandlerChainAnnot();
1404:                        if (handlerChainAnnotation == null) {
1405:
1406:                            // If this is NOT an implicit SEI, then check for the
1407:                            // annotation on the SEI
1408:                            if (!DescriptionUtils
1409:                                    .isEmpty(getAnnoWebServiceEndpointInterface())) {
1410:
1411:                                DescriptionBuilderComposite seic = getServiceDescriptionImpl()
1412:                                        .getDBCMap().get(
1413:                                                composite.getWebServiceAnnot()
1414:                                                        .endpointInterface());
1415:                                if (seic != null) {
1416:                                    handlerChainAnnotation = seic
1417:                                            .getHandlerChainAnnot();
1418:                                }
1419:                                // TODO else clause for if to throw exception when seic == null
1420:                            }
1421:                        }
1422:                    } else {
1423:                        if (implOrSEIClass != null) {
1424:                            handlerChainAnnotation = (HandlerChain) implOrSEIClass
1425:                                    .getAnnotation(HandlerChain.class);
1426:                        }
1427:                    }
1428:                }
1429:
1430:                return handlerChainAnnotation;
1431:            }
1432:
1433:            private Definition getWSDLDefinition() {
1434:                return ((ServiceDescriptionWSDL) getServiceDescription())
1435:                        .getWSDLDefinition();
1436:            }
1437:
1438:            public javax.wsdl.Service getWSDLService() {
1439:                Definition defn = getWSDLDefinition();
1440:                if (defn != null) {
1441:                    return defn.getService(getServiceQName());
1442:                } else {
1443:                    return null;
1444:                }
1445:            }
1446:
1447:            public Port getWSDLPort() {
1448:                javax.wsdl.Service service = getWSDLService();
1449:                if (service != null) {
1450:                    return service.getPort(getPortQName().getLocalPart());
1451:                } else {
1452:                    return null;
1453:                }
1454:            }
1455:
1456:            public Binding getWSDLBinding() {
1457:                Binding wsdlBinding = null;
1458:                Port wsdlPort = getWSDLPort();
1459:                Definition wsdlDef = getWSDLDefinition();
1460:                if (wsdlPort != null && wsdlDef != null) {
1461:                    wsdlBinding = wsdlPort.getBinding();
1462:                }
1463:                return wsdlBinding;
1464:            }
1465:
1466:            public String getWSDLBindingType() {
1467:                String wsdlBindingType = null;
1468:                Binding wsdlBinding = getWSDLBinding();
1469:                if (wsdlBinding != null) {
1470:                    // If a WSDL binding was found, we need to find the proper extensibility
1471:                    // element and return the namespace.  The namespace will be different
1472:                    // for SOAP 1.1 vs. SOAP 1.2 bindings and HTTP.
1473:                    // TODO: What do we do if no extensibility element exists?
1474:                    List<ExtensibilityElement> elements = wsdlBinding
1475:                            .getExtensibilityElements();
1476:                    Iterator<ExtensibilityElement> itr = elements.iterator();
1477:                    while (itr.hasNext()) {
1478:                        ExtensibilityElement e = itr.next();
1479:                        if (javax.wsdl.extensions.soap.SOAPBinding.class
1480:                                .isAssignableFrom(e.getClass())) {
1481:                            javax.wsdl.extensions.soap.SOAPBinding soapBnd = (javax.wsdl.extensions.soap.SOAPBinding) e;
1482:                            wsdlBindingType = soapBnd.getElementType()
1483:                                    .getNamespaceURI();
1484:                            break;
1485:                        } else if (SOAP12Binding.class.isAssignableFrom(e
1486:                                .getClass())) {
1487:                            SOAP12Binding soapBnd = (SOAP12Binding) e;
1488:                            wsdlBindingType = soapBnd.getElementType()
1489:                                    .getNamespaceURI();
1490:                            break;
1491:                        } else if (HTTPBinding.class.isAssignableFrom(e
1492:                                .getClass())) {
1493:                            HTTPBinding httpBnd = (HTTPBinding) e;
1494:                            wsdlBindingType = httpBnd.getElementType()
1495:                                    .getNamespaceURI();
1496:                            break;
1497:                        }
1498:                    }
1499:                }
1500:                return wsdlBindingType;
1501:            }
1502:
1503:            public String getName() {
1504:                return getAnnoWebServiceName();
1505:            }
1506:
1507:            public String getTargetNamespace() {
1508:                return getAnnoWebServiceTargetNamespace();
1509:            }
1510:
1511:            public PortInfo getPortInfo() {
1512:                if (portInfo == null) {
1513:                    portInfo = new PortInfoImpl(getServiceQName(),
1514:                            getPortQName(), getBindingType());
1515:                }
1516:                return portInfo;
1517:            }
1518:
1519:            public void setClientBindingID(String clientBindingID) {
1520:
1521:                if (clientBindingID == null) {
1522:                    this .clientBindingID = DEFAULT_CLIENT_BINDING_ID;
1523:                } else if (validateClientBindingID(clientBindingID)) {
1524:                    this .clientBindingID = clientBindingID;
1525:                } else {
1526:                    throw ExceptionFactory.makeWebServiceException(Messages
1527:                            .getMessage("addPortErr0", getPortQName()
1528:                                    .toString()));
1529:                }
1530:            }
1531:
1532:            private boolean validateClientBindingID(String bindingId) {
1533:                boolean isValid = true;
1534:                if (bindingId != null
1535:                        && !(bindingId.equals(SOAPBinding.SOAP11HTTP_BINDING)
1536:                                || bindingId
1537:                                        .equals(javax.xml.ws.http.HTTPBinding.HTTP_BINDING)
1538:                                || bindingId
1539:                                        .equals(SOAPBinding.SOAP12HTTP_BINDING)
1540:                                || bindingId
1541:                                        .equals(SOAPBinding.SOAP11HTTP_MTOM_BINDING) || bindingId
1542:                                .equals(SOAPBinding.SOAP12HTTP_MTOM_BINDING))) {
1543:                    throw ExceptionFactory.makeWebServiceException(Messages
1544:                            .getMessage("addPortErr0", getPortQName()
1545:                                    .toString()));
1546:                }
1547:                return isValid;
1548:            }
1549:
1550:            public String getClientBindingID() {
1551:                if (clientBindingID == null) {
1552:                    if (getWSDLDefinition() != null) {
1553:                        clientBindingID = getWSDLBindingType();
1554:                    } else {
1555:                        clientBindingID = DEFAULT_CLIENT_BINDING_ID;
1556:                    }
1557:                }
1558:                return clientBindingID;
1559:            }
1560:
1561:            public void setEndpointAddress(String endpointAddress) {
1562:                // REVIEW: Should this be called whenever BindingProvider.ENDPOINT_ADDRESS_PROPERTY is set by the client?
1563:                if (!DescriptionUtils.isEmpty(endpointAddress)) {
1564:                    this .endpointAddress = endpointAddress;
1565:                } else {
1566:                    // Since a port can be added without setting an endpoint address, this is not an error.
1567:                    if (log.isDebugEnabled())
1568:                        log
1569:                                .debug(
1570:                                        "A null or empty endpoint address was attempted to be set",
1571:                                        new Throwable("Stack Traceback"));
1572:                }
1573:            }
1574:
1575:            public String getEndpointAddress() {
1576:                if (endpointAddress == null) {
1577:                    // If the endpointAddress has not been set explicitly by a call to setEndpointAddress()
1578:                    // then try to get it from the WSDL
1579:                    endpointAddress = getWSDLSOAPAddress();
1580:                }
1581:                return endpointAddress;
1582:            }
1583:
1584:            /**
1585:             * Return the SOAP Address from the WSDL for this port.
1586:             *
1587:             * @return The SOAP Address from the WSDL for this port or null.
1588:             */
1589:            public String getWSDLSOAPAddress() {
1590:                if (wsdlSOAPAddress == null) {
1591:                    Port wsdlPort = getWSDLPort();
1592:                    if (wsdlPort != null) {
1593:                        // The port is in the WSDL, so see if it has a SOAP address extensibility element specified.
1594:                        List extElementList = wsdlPort
1595:                                .getExtensibilityElements();
1596:                        for (Object listElement : extElementList) {
1597:                            ExtensibilityElement extElement = (ExtensibilityElement) listElement;
1598:                            if (isSOAPAddressElement(extElement)) {
1599:                                String soapAddress = getSOAPAddressFromElement(extElement);
1600:                                if (!DescriptionUtils.isEmpty(soapAddress)) {
1601:                                    wsdlSOAPAddress = soapAddress;
1602:                                }
1603:                            }
1604:                        }
1605:                    }
1606:                }
1607:                return wsdlSOAPAddress;
1608:            }
1609:
1610:            /**
1611:             * Determine if the WSDL Extensibility element corresponds to the SOAP Address element.
1612:             *
1613:             * @param exElement
1614:             * @return
1615:             */
1616:            static boolean isSOAPAddressElement(ExtensibilityElement exElement) {
1617:                boolean isAddress = false;
1618:                if (exElement != null) {
1619:                    isAddress = (SOAP_11_ADDRESS_ELEMENT.equals(exElement
1620:                            .getElementType()) || (SOAP_12_ADDRESS_ELEMENT
1621:                            .equals(exElement.getElementType())));
1622:                }
1623:                return isAddress;
1624:            }
1625:
1626:            static String getSOAPAddressFromElement(
1627:                    ExtensibilityElement extElement) {
1628:                String returnAddress = null;
1629:
1630:                if (extElement != null) {
1631:                    if (SOAP_11_ADDRESS_ELEMENT.equals(extElement
1632:                            .getElementType())) {
1633:                        returnAddress = ((SOAPAddress) extElement)
1634:                                .getLocationURI();
1635:                    } else if (SOAP_12_ADDRESS_ELEMENT.equals(extElement
1636:                            .getElementType())) {
1637:                        returnAddress = ((SOAP12Address) extElement)
1638:                                .getLocationURI();
1639:                    }
1640:                }
1641:
1642:                return returnAddress;
1643:            }
1644:
1645:            /**
1646:             * Selects a port to use in the case where a portQName was not specified by the client on the
1647:             * Service.getPort(Class) call.  If WSDL is present, then an appropriate port is looked for
1648:             * under the service element, and an exception is thrown if none can be found.  If WSDL is not
1649:             * present, then the selected port is simply the one determined by annotations.
1650:             *
1651:             * @return A QName representing the port that is to be used.
1652:             */
1653:            private QName selectPortToUse() {
1654:                QName portToUse = null;
1655:                // If WSDL Service for this port is present, then we'll find an appropriate port defined in there and set 
1656:                // the name accordingly.  If no WSDL is present, the the PortQName getter will use annotations to set the value.
1657:                if (getWSDLService() != null) {
1658:                    portToUse = selectWSDLPortToUse();
1659:                } else {
1660:                    // No WSDL, so the port to use is the one defined by the annotations.
1661:                    portToUse = getPortQName();
1662:                }
1663:                return portToUse;
1664:            }
1665:
1666:            /**
1667:             * Look through the WSDL Service for a port that should be used.  If none can be found, then
1668:             * throw an exception.
1669:             *
1670:             * @param wsdlService
1671:             * @return A QName representing the port from the WSDL that should be used.
1672:             */
1673:            private QName selectWSDLPortToUse() {
1674:                QName wsdlPortToUse = null;
1675:
1676:                // To select which WSDL Port to use, we do the following
1677:                // 1) Find the subset of all ports under the service that use the PortType represented by the SEI
1678:                // 2) From the subset in (1) find all those ports that specify a SOAP Address
1679:                // 3) Use the first port from (2)
1680:                // REVIEW: Should we be looking at the binding type or something else to determin which subset of ports to use;
1681:                //         i.e. instead of just finding ports that specify a SOAP Address?
1682:
1683:                // Per JSR-181, 
1684:                // - The portType name corresponds to the WebService.name annotation value, which is
1685:                //   returned by getName()
1686:                // - The portType namespace corresponds to the WebService.targetNamespace annotation, which
1687:                //   is returned by getTargetNamespace()
1688:                String portTypeLP = getName();
1689:                String portTypeTNS = getTargetNamespace();
1690:                QName portTypeQN = new QName(portTypeTNS, portTypeLP);
1691:
1692:                ServiceDescriptionWSDL serviceDescWSDL = (ServiceDescriptionWSDL) getServiceDescription();
1693:
1694:                List<Port> wsdlPortsUsingPortType = serviceDescWSDL
1695:                        .getWSDLPortsUsingPortType(portTypeQN);
1696:                List<Port> wsdlPortsUsingSOAPAddresses = serviceDescWSDL
1697:                        .getWSDLPortsUsingSOAPAddress(wsdlPortsUsingPortType);
1698:                if (wsdlPortsUsingSOAPAddresses != null
1699:                        && !wsdlPortsUsingSOAPAddresses.isEmpty()) {
1700:                    // We return the first port that uses the particluar PortType and has a SOAP address.
1701:                    // HOWEVER, that is not necessarily the first one in the WSDL that meets that criteria!  
1702:                    // The problem is that WSDL4J Service.getPorts(), which is used to get a Map of ports under the service 
1703:                    // DOES NOT return the ports in the order they are defined in the WSDL.  
1704:                    // Therefore, we can't necessarily predict which one we'll get back as the "first" one in the collection.
1705:                    // REVIEW: Note the above comment; is there anything more predictible and determinstic we can do?
1706:                    Port portToUse = (Port) wsdlPortsUsingSOAPAddresses
1707:                            .toArray()[0];
1708:                    String portLocalPart = portToUse.getName();
1709:                    String portNamespace = serviceDescWSDL.getWSDLService()
1710:                            .getQName().getNamespaceURI();
1711:                    wsdlPortToUse = new QName(portNamespace, portLocalPart);
1712:                }
1713:
1714:                return wsdlPortToUse;
1715:            }
1716:
1717:            private WsdlComposite generateWSDL(DescriptionBuilderComposite dbc) {
1718:
1719:                WsdlComposite wsdlComposite = null;
1720:                Definition defn = dbc.getWsdlDefinition();
1721:                if (defn == null || !isAxisServiceBuiltFromWSDL) {
1722:
1723:                    //Invoke the callback for generating the wsdl
1724:                    if (dbc.getCustomWsdlGenerator() != null) {
1725:                        String implName = null;
1726:                        if (axisService == null) {
1727:                            implName = DescriptionUtils
1728:                                    .javifyClassName(composite.getClassName());
1729:                        } else {
1730:                            implName = (String) axisService
1731:                                    .getParameterValue(MDQConstants.SERVICE_CLASS);
1732:                        }
1733:                        wsdlComposite = dbc.getCustomWsdlGenerator()
1734:                                .generateWsdl(implName, getBindingType());
1735:
1736:                        if (wsdlComposite != null) {
1737:                            wsdlComposite.setWsdlFileName((this 
1738:                                    .getAnnoWebServiceServiceName() + ".wsdl")
1739:                                    .toLowerCase());
1740:
1741:                            Definition wsdlDef = wsdlComposite
1742:                                    .getRootWsdlDefinition();
1743:
1744:                            try {
1745:                                WSDL4JWrapper wsdl4jWrapper = new WSDL4JWrapper(
1746:                                        dbc.getWsdlURL(), wsdlDef);
1747:                                getServiceDescriptionImpl()
1748:                                        .setGeneratedWsdlWrapper(wsdl4jWrapper);
1749:                            } catch (Exception e) {
1750:                                throw ExceptionFactory
1751:                                        .makeWebServiceException("EndpointDescriptionImpl: WSDLException thrown when attempting to instantiate WSDL4JWrapper ");
1752:                            }
1753:                        } else {
1754:                            // REVIEW:Determine if we should always throw an exception on this, or at this point
1755:                            //throw ExceptionFactory.makeWebServiceException("EndpointDescriptionImpl: Unable to find custom WSDL generator");
1756:                            if (log.isDebugEnabled()) {
1757:                                log
1758:                                        .debug("The custom WSDL generator returned null, so no generated WSDL is available");
1759:                            }
1760:
1761:                        }
1762:                    } else {
1763:                        // REVIEW: This used to throw an exception, but it seems we shouldn't require
1764:                        // a wsdl generator be provided.
1765:                        //                throw ExceptionFactory.makeWebServiceException("EndpointDescriptionImpl: Unable to find custom WSDL generator");
1766:                        if (log.isDebugEnabled()) {
1767:                            log
1768:                                    .debug("No custom WSDL generator was supplied, so WSDL can not be generated");
1769:                        }
1770:                    }
1771:                }
1772:                return wsdlComposite;
1773:            }
1774:
1775:            public String toString() {
1776:                final String newline = "\n";
1777:                final String sameline = "; ";
1778:                StringBuffer string = new StringBuffer();
1779:                try {
1780:                    string.append(super .toString());
1781:                    string.append(newline);
1782:                    string.append("Name: " + getName());
1783:                    string.append(sameline);
1784:                    string.append("Endpoint Address: " + getEndpointAddress());
1785:                    //
1786:                    string.append(newline);
1787:                    string.append("ServiceQName: " + getServiceQName());
1788:                    string.append(sameline);
1789:                    string.append("PortQName: " + getPortQName());
1790:                    string.append(sameline);
1791:                    string.append("TargetNamespace: " + getTargetNamespace());
1792:                    //
1793:                    string.append(newline);
1794:                    string.append("Service Mode: " + getServiceMode());
1795:                    string.append(sameline);
1796:                    string.append("Binding Type: " + getBindingType());
1797:                    string.append(sameline);
1798:                    string.append("Client Binding Type: "
1799:                            + getClientBindingID());
1800:                    //
1801:                    string.append(newline);
1802:                    string.append("Is provider-based: "
1803:                            + (isProviderBased() == true));
1804:                    string.append(sameline);
1805:                    string.append("Is proxy-based: "
1806:                            + (isEndpointBased() == true));
1807:                    string.append(sameline);
1808:                    string.append("Is WSDL fully specified: "
1809:                            + (isWSDLFullySpecified() == true));
1810:                    //
1811:                    string.append(newline);
1812:                    string.append("AxisService: " + getAxisService());
1813:                    //
1814:                    string.append(newline);
1815:                    EndpointInterfaceDescription endpointInterfaceDesc = getEndpointInterfaceDescription();
1816:                    if (endpointInterfaceDesc != null) {
1817:                        string.append("EndpointInterfaceDescription: "
1818:                                + endpointInterfaceDesc.toString());
1819:                    } else {
1820:                        string.append("EndpointInterfaceDescription is null.");
1821:                    }
1822:                } catch (Throwable t) {
1823:                    string.append(newline);
1824:                    string
1825:                            .append("Complete debug information not currently available for "
1826:                                    + "EndpointDescription");
1827:                    return string.toString();
1828:                }
1829:                return string.toString();
1830:            }
1831:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.