Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   /*
    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    *
    * Copyright (c) 1997-2013 Oracle and/or its affiliates. All rights reserved.
    *
    * The contents of this file are subject to the terms of either the GNU
    * General Public License Version 2 only ("GPL") or the Common Development
    * and Distribution License("CDDL") (collectively, the "License").  You
    * may not use this file except in compliance with the License.  You can
   * obtain a copy of the License at
   * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
   * or packager/legal/LICENSE.txt.  See the License for the specific
   * language governing permissions and limitations under the License.
   *
   * When distributing the software, include this License Header Notice in each
   * file and include the License file at packager/legal/LICENSE.txt.
   *
   * GPL Classpath Exception:
   * Oracle designates this particular file as subject to the "Classpath"
   * exception as provided by Oracle in the GPL Version 2 section of the License
   * file that accompanied this code.
   *
   * Modifications:
   * If applicable, add the following below the License Header, with the fields
   * enclosed by brackets [] replaced by your own identifying information:
   * "Portions Copyright [year] [name of copyright owner]"
   *
   * Contributor(s):
   * If you wish your version of this file to be governed by only the CDDL or
   * only the GPL Version 2, indicate your decision by adding "[Contributor]
   * elects to include this software in this distribution under the [CDDL or GPL
   * Version 2] license."  If you don't indicate a single choice of license, a
   * recipient has the option to distribute your version of this file under
   * either the CDDL, the GPL Version 2 or to extend the choice of license to
   * its licensees as provided above.  However, if you add GPL Version 2 code
   * and therefore, elected the GPL Version 2 license, then the option applies
   * only if the new code is made subject to such option by the copyright
   * holder.
   */
  
  package org.glassfish.webservices;
  
  
  
  
  import java.util.*;
  import java.net.*;
  import javax.xml.soap.*;
  
  import org.w3c.dom.*;
  import org.w3c.dom.Node;
  
 import java.io.*;
 
Web service related utilities.

Author(s):
Kenneth Saks
 
 public class WsUtil {
 
     // proprietary property for enabling logging of stub requests/responses
     public static final String CLIENT_TRANSPORT_LOG_PROPERTY =
       "com.sun.enterprise.webservice.client.transport.log";
 
     // xslt processing parameters for final wsdl transformation
     public static final String ENDPOINT_ADDRESS_PARAM_NAME =
         "endpointAddressParam";
 
     public final String WSDL_IMPORT_NAMESPACE_PARAM_NAME = 
         "wsdlImportNamespaceParam";
     public static final String WSDL_IMPORT_LOCATION_PARAM_NAME = 
         "wsdlImportLocationParam";
     public static final String WSDL_INCLUDE_LOCATION_PARAM_NAME = 
         "wsdlIncludeLocationParam";
 
     public final String SCHEMA_IMPORT_NAMESPACE_PARAM_NAME = 
         "schemaImportNamespaceParam";
     public static final String SCHEMA_IMPORT_LOCATION_PARAM_NAME = 
         "schemaImportLocationParam";    
     public static final String SCHEMA_INCLUDE_LOCATION_PARAM_NAME = 
         "schemaIncludeLocationParam";    
 
     private Config config = null;
     private List<NetworkListenernetworkListeners = null;
 
     public WsUtil() {
          = WebServiceContractImpl.getInstance().getConfig();
     }
 
     // @@@ These are jaxrpc-implementation specific MessageContextProperties
     // that should be added to jaxrpc spi
     private static final String ONE_WAY_OPERATION =
         "com.sun.xml.rpc.server.OneWayOperation";
     private static final String CLIENT_BAD_REQUEST =
         "com.sun.xml.rpc.server.http.ClientBadRequest";
     
     private static final String SECURITY_POLICY_NAMESPACE_URI = 
             "http://schemas.xmlsoap.org/ws/2005/07/securitypolicy";
 
     private static final Logger logger = LogUtils.getLogger();
 
     private JaxRpcObjectFactory rpcFactory;


    
Serve up the FINAL wsdl associated with this web service.

Returns:
true for success, false for failure
 
     public boolean handleGet(HttpServletRequest request
                              HttpServletResponse response
                              WebServiceEndpoint endpointthrows IOException {
 
         MimeHeaders headers = getHeaders(request);
         ifhasSomeTextXmlContent(headers) ) {
             String message = MessageFormat.format(.getResourceBundle().getString(.),
                     endpoint.getEndpointName(), endpoint.getEndpointAddressUri());
 
             writeInvalidMethodType(responsemessage);
             
             .info(message);
             
             return false;
         }
         
         URL wsdlUrl = null;
 
         String requestUriRaw = request.getRequestURI();
         String requestUri    = (requestUriRaw.charAt(0) == '/') ?
             requestUriRaw.substring(1) : requestUriRaw;
         String queryString = request.getQueryString();
 
         WebService webService = endpoint.getWebService();
 
         ifqueryString == null ) {
 
             // Get portion of request uri representing location within a module
             String wsdlPath = endpoint.getWsdlContentPath(requestUri);
 
             ifwsdlPath != null) {
                 ModuleDescriptor module =
                     webService.getBundleDescriptor().getModuleDescriptor();
 
                 ifwsdlPath.equals(webService.getWsdlFileUri())){
                     // If the request is for the main wsdl document, return
                     // the final wsdl instead of the wsdl from the module.
                     wsdlUrl = webService.getWsdlFileUrl();
                 } else ifisWsdlContent(wsdlPath
                                          webService.getBundleDescriptor()) ) {
                     // For relative document imports. These documents do not
                     // require modification during deployment, so serve them
                     // up directly from the packaged module.  isWsdlContent()
                     // check ensures we don't serve up arbitrary content from
                     // the module.
                     URL finalWsdlUrl = webService.getWsdlFileUrl();
                     String finalWsdlPath = finalWsdlUrl.getPath();
                     // remove the final wsdl uri from the above path
                     String wsdlDirPath = finalWsdlPath.substring(0, finalWsdlPath.length()-webService.getWsdlFileUri().length());
                     File wsdlDir = new File(wsdlDirPath);
                     File wsdlFile = new File(wsdlDirwsdlPath.replace('/'.));
                     try {
                         wsdlUrl = wsdlFile.toURL();
                     } catch(MalformedURLException mue) {
                         String msg = MessageFormat.format(
                                 .getResourceBundle().getString(.),
                                 webService.getName());
                         .log(.msgmue);
                     } 
                         
                 }
             }
 
         } else ifqueryString.equalsIgnoreCase("WSDL") ) {
             wsdlUrl = webService.getWsdlFileUrl();
         }
 
         boolean success = false;
         ifwsdlUrl != null ) {
             
             InputStream is = null;
             try {
                 response.setContentType("text/xml");
                 response.setStatus(.);
                 // if the requested file is the main wsdl document, we are going
                 // to reprocess it through the XML transformer to change the final
                 // endpoint URL correct for this particular web server instance.
                 // This is necessary in the case of SE/EE installations where
                 // the application can be running on different machines and ports
                 // than the one they were deployed on (DAS).
                 if (wsdlUrl.toURI().equals(webService.getWsdlFileUrl().toURI())) {
                     // get the application module ID
                     try {
                         
                         WebServerInfo wsi = getWebServerInfoForDAS();
                         URL url = webService.getWsdlFileUrl();
                         File originalWsdlFile = new File(url.getPath()+"__orig");
                         if(!originalWsdlFile.exists()) {
                             originalWsdlFile = new File(url.getPath());
                         }
                         generateFinalWsdl(originalWsdlFile.toURL(), webServicewsiresponse.getOutputStream());
                     } catch(Exception e) {
                         // if this fail, we revert to service the untouched 
                         // repository item.
                         URLConnection urlCon = wsdlUrl.openConnection();
                         urlCon.setUseCaches(false);
                         is = urlCon.getInputStream();                    
                         copyIsToOs(isresponse.getOutputStream());
                     }
                 } else {
                     // Copy bytes into output. Disable caches to avoid jar URL
                     // caching problem.
                     URLConnection urlCon = wsdlUrl.openConnection();
                     urlCon.setUseCaches(false);
                     is = urlCon.getInputStream();                    
                     copyIsToOs(isresponse.getOutputStream());
                 }
                 success = true;
                 if.isLoggable(.) ) {
                     .log(..,
                             new Object[] {wsdlUrlrequest.getRequestURL() + (queryString != null ? ("?"+queryString) : "")});
                 }
             } catch(Exception e) {
                 String msg = MessageFormat.format(
                                 .getResourceBundle().getString(.),
                                 webService.getName());
                 .log(.msge);
             } finally {
                 if(is != null) {
                     try {
                         is.close();
                     } catch(IOException ex) {}
                 }
             }
         }
 
         if( !success ) {
             String message = MessageFormat.format(
                     .getResourceBundle().getString(.),
                     request.getRequestURL() + (queryString != null ? ("?"+queryString) : ""),
                     webService.getName()
                     );
             .info(message);
 
             writeInvalidMethodType(responsemessage);
         }
         
         return success;
     }
 
     private void copyIsToOs(InputStream isOutputStream osthrows IOException {
         byte[] buf = new byte[4096];
         int len = 0;
         while (len != -1) {
             try {
                 len = is.read(buf, 0, buf.length);
             } catch (EOFException eof){
                 break;
             }
 
             if(len != -1) {
                 os.write(buf, 0, len);
             }
         }
         os.flush();
         is.close();
         os.close();
     }

    
All wsdl files and wsdl imported files live under a well-known wsdl directory.

Parameters:
uri module uri
 
     public boolean isWsdlContent(String uriBundleDescriptor bundle) {
         String wsdlDir = getWsdlDir(bundle);
         return (uri != null) && uri.startsWith(wsdlDir);
     }

    

Returns:
module-specific dedicated wsdl directory
 
     public String getWsdlDir(BundleDescriptor bundle) {
         boolean isWar = bundle.getModuleType().equals(DOLUtils.warType());
         return isWar ? "WEB-INF/wsdl" : "META-INF/wsdl";
     }

    

    
Collect all relative imports from a web service's main wsdl document.

Parameters:
wsdlRelativeImports outupt param in which wsdl relative imports will be added
schemaRelativeImports outupt param in which schema relative imports will be added
 
     private void parseRelativeImports(URL wsdlFileUrl
                                       Collection wsdlRelativeImports,
                                       Collection wsdlIncludes,
                                       Collection schemaRelativeImports,
                                        Collection schemaIncludes)
         throws Exception {
         
         // We will use our little parser rather than using JAXRPC's heavy weight WSDL parser
         DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
         factory.setNamespaceAware(true);
         //Validation is not needed as we don't want to be too strict in processing wsdls that could be generated by buggy tools.
         factory.setExpandEntityReferences(false);
         factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl"true);
         InputStream is = null;
         try {
             DocumentBuilder builder = factory.newDocumentBuilder();
             is = wsdlFileUrl.openStream();
             Document document = builder.parse(is);
             procesSchemaImports(documentschemaRelativeImports);
             procesWsdlImports(documentwsdlRelativeImports);
             procesSchemaIncludes(documentschemaIncludes);
             procesWsdlIncludes(documentwsdlIncludes);
         } catch (SAXParseException spe) {
             // Error generated by the parser
             .log(..,
                     new Object[] {spe.getLineNumber() ,spe.getSystemId()});
             // Use the contained exception, if any
             Exception x = spe;
             if (spe.getException() != null) {
                 x = spe.getException();
             }
             .log(..x);
         } catch (Exception sxe) {
             .log(..sxe.getMessage());
         } finally {
             try {
                 if(is != null) {
                     is.close();
                 }
             } catch (IOException io) {}
         }
     }
 
     private void addImportsAndIncludes(NodeList listCollection result,
                         String namespaceString locationthrows SAXException,
                         ParserConfigurationExceptionIOExceptionSAXParseException {
         for(int i=0; i<list.getLength(); i++) {
             String givenLocation = null;
             Node element = list.item(i);
             NamedNodeMap attrs = element.getAttributes();
             Node nattrs.getNamedItem(location);
             if(n != null) {
                 givenLocation = n.getNodeValue();
             }
             if((givenLocation == null) ||
                 (givenLocation.startsWith("http"))) {
                 continue;
             }
             Import imp = new Import();
             imp.setLocation(givenLocation);
             if(namespace != null) {
                 n = attrs.getNamedItem(namespace);
                 if(n != null) {
                     imp.setNamespace(n.getNodeValue());
                 }
             }
             result.add(imp);
         }        
         return;
     }
     
     private void procesSchemaImports(Document documentCollection schemaImportCollectionthrows SAXException,
                 ParserConfigurationExceptionIOException {
         NodeList schemaImports =
                          document.getElementsByTagNameNS("http://www.w3.org/2001/XMLSchema""import");
         addImportsAndIncludes(schemaImportsschemaImportCollection"namespace""schemaLocation");
     }
 
     private void procesWsdlImports(Document documentCollection wsdlImportCollectionthrows SAXException,
                 ParserConfigurationExceptionIOException {
         NodeList wsdlImports =
                          document.getElementsByTagNameNS("http://schemas.xmlsoap.org/wsdl/""import");
         addImportsAndIncludes(wsdlImportswsdlImportCollection"namespace""location");
     }        
 
     private void procesSchemaIncludes(Document documentCollection schemaIncludeCollectionthrows SAXException,
                 ParserConfigurationExceptionIOException{
         NodeList schemaIncludes = 
                          document.getElementsByTagNameNS("http://www.w3.org/2001/XMLSchema""include");
         addImportsAndIncludes(schemaIncludesschemaIncludeCollectionnull"schemaLocation");
     }
 
     private void procesWsdlIncludes(Document documentCollection wsdlIncludesCollectionthrows SAXException,
                 ParserConfigurationExceptionIOException{
         NodeList wsdlIncludes =
                          document.getElementsByTagNameNS("http://schemas.xmlsoap.org/wsdl/""include");
         addImportsAndIncludes(wsdlIncludeswsdlIncludesCollectionnull"location");
     }

    
Transform the deployed WSDL document for a given webservice by replacing the ENDPOINT ADDRESS for each port with the actual endpoint address on which it will be listening.
 
     public void generateFinalWsdl(URL wsdlFileUrlWebService webServiceWebServerInfo wsi,
                                   File finalWsdlFilethrows Exception {
        OutputStream outputStream =
             new BufferedOutputStream(new FileOutputStream(finalWsdlFile));
         generateFinalWsdl(wsdlFileUrlwebServicewsioutputStream);
                                       
     }
     
     public void generateFinalWsdl(URL wsdlFileUrlWebService webServiceWebServerInfo wsi,
                                   OutputStream outputStreamthrows Exception {
                                       
 
         Collection wsdlRelativeImports = new HashSet();
         Collection wsdlIncludes = new HashSet();
         Collection schemaRelativeImports = new HashSet();
         Collection schemaIncludes = new HashSet();
         ifwebService.hasUrlPublishing() ) {
             parseRelativeImports(wsdlFileUrlwsdlRelativeImports,
                          wsdlIncludesschemaRelativeImportsschemaIncludes);
         }
         
         Collection endpoints = webService.getEndpoints();
 
         // a WSDL file can contain several ports associated to a service.
         // however Deployment descriptors can be expressed in two ways 
         // to describe such a scenario in webservices.xml :
         //  - One webservice-description with 2 port-components
         //  - Two webservice-description with 1 port-component
         // The issue with #1, is that we need to configure the XSL with
         // the two ports so that the resulting unique WSDL has the correct
         // endpoint information and the JAXRPC stubs generated correctly.
         // So we need to check if this bundle is declaring more webservice
         // descriptor pointing to the same WSDL file...
         Collection endpointsCopy = new ArrayList();
         endpointsCopy.addAll(endpoints);
         
         BundleDescriptor bundle = webService.getBundleDescriptor();
         WebServicesDescriptor wsd = bundle.getWebServices();
         Collection webServices = wsd.getWebServices();
         if (webServices.size()>1) {
             for (Iterator wsIter = webServices.iterator();wsIter.hasNext();) {
                 WebService aWS = (WebServicewsIter.next();
                 if (webService.getName().equals(aWS.getName())) {
                     continue;
                 }
                 // this is another web service defined in the same bundle.
                 // let's check if it points to the same WSDL file
                 if ((webService.getWsdlFileUri() != null) &&
                      (aWS.getWsdlFileUri() != null) &&
                      (webService.getWsdlFileUri().equals(aWS.getWsdlFileUri()))) {
                     endpointsCopy.addAll(aWS.getEndpoints());
                 } else if ((webService.getWsdlFileUrl() != null) &&
                      (aWS.getWsdlFileUrl() != null) &&
                      ((webService.getWsdlFileUrl().toString())
                         .equals(aWS.getWsdlFileUrl().toString()))) {
                     endpointsCopy.addAll(aWS.getEndpoints());
                 }
             }
         }
 
         
         // Load the wsdl file bytes with caching turned off.  This is
         // to avoid a jar url consistency problem that can arise if we
         // overwrite the module file later on in deployment.
         InputStream wsdlInputStream = new BufferedInputStream(wsdlFileUrl.openStream());
         Source XsltWsdlDocument = new StreamSource(wsdlInputStream);
         Templates templates = createTemplatesFor
             (endpointsCopywsdlRelativeImportswsdlIncludes
                 schemaRelativeImportsschemaIncludes);
                                                  
         Transformer transformer = templates.newTransformer();
 
 
         // WSDL is associated with webservice, but url is endpoint-specific,
         // so let WebService choose which endpoint to use.
         WebServiceEndpoint endpointForImport = 
             webService.pickEndpointForRelativeImports();
         URL rootwsi.getWebServerRootURL(endpointForImport.isSecure());
         URL finalWsdlUrl = endpointForImport.composeFinalWsdlUrl(root);
         
         int wsdlImportNum = 0;
         for(Iterator iter = wsdlRelativeImports.iterator(); iter.hasNext();){
             Import next = (Importiter.next();
             transformer.setParameter
                 ( + wsdlImportNum
                  next.getNamespace());
             
             // Convert each relative import into an absolute import, using
             // the final wsdl's Url as the context
             URL relativeUrl  = new URL(finalWsdlUrlnext.getLocation());
             transformer.setParameter
                 ( + wsdlImportNumrelativeUrl);
             
             wsdlImportNum++;
         }
 
         int schemaImportNum = 0;
         for(Iterator iter = schemaRelativeImports.iterator(); iter.hasNext();){
             Import next = (Importiter.next();
             transformer.setParameter
                 ( + schemaImportNum
                  next.getNamespace());
             
             // Convert each relative import into an absolute import, using
             // the final wsdl's Url as the context
             URL relativeUrl  = new URL(finalWsdlUrlnext.getLocation());
             transformer.setParameter
                 ( + schemaImportNum
                  relativeUrl);
             
             schemaImportNum++;
         }        
 
         int wsdlIncludeNum = 0;
         for(Iterator iter = wsdlIncludes.iterator(); iter.hasNext();){
             Import next = (Importiter.next();
             URL relativeUrl  = new URL(finalWsdlUrlnext.getLocation());
             transformer.setParameter
                 ( + wsdlIncludeNumrelativeUrl);            
             wsdlIncludeNum++;
         }
 
         int schemaIncludeNum = 0;
         for(Iterator iter = schemaIncludes.iterator(); iter.hasNext();){
             Import next = (Importiter.next();
             URL relativeUrl  = new URL(finalWsdlUrlnext.getLocation());
             transformer.setParameter
                 ( + schemaIncludeNum
                  relativeUrl);            
             schemaIncludeNum++;
         }        
 
         int endpointNum = 0;
         for(Iterator iter = endpointsCopy.iterator(); iter.hasNext();) {
             WebServiceEndpoint next = (WebServiceEndpointiter.next();
 
             // Get a URL for the root of the webserver, where the host portion
             // is a canonical host name.  Since this will be used to compose the
             // endpoint address that is written into WSDL, it's better to use
             // hostname as opposed to IP address.
             // The protocol and port will be based on whether the endpoint 
             // has a transport guarantee of INTEGRAL or CONFIDENTIAL.
             // If yes, https will be used.  Otherwise, http will be used.
             URL rootURL = wsi.getWebServerRootURL(next.isSecure());
 
             URL actualAddress = next.composeEndpointAddress(rootURL);
 
             transformer.setParameter( + endpointNum
                                      actualAddress.toExternalForm());
 
             String endpointType = next.implementedByEjbComponent() ?
                 "EJB" : "Servlet";
             .log(..,
                     new Object[] {"[" + endpointType + "] " + next.getEndpointName(), actualAddress});
 
             endpointNum++;
         }
 
         transformer.transform(XsltWsdlDocumentnew StreamResult(outputStream));
         wsdlInputStream.close();
         outputStream.close();
 
         return;
     }
 
                                          ClassLoader loader
         throws Exception {
 
         QName[] headers = new QName[handler.getSoapHeaders().size()];
         int i = 0;
         for(Iterator iter = handler.getSoapHeaders().iterator();
             iter.hasNext();) {
             headers[i] = (QNameiter.next();
             i++;
         }
 
         Map properties = new HashMap();
         for(Iterator iter = handler.getInitParams().iterator(); 
             iter.hasNext();) {
             NameValuePairDescriptor next = (NameValuePairDescriptor
                 iter.next();
             properties.put(next.getName(), next.getValue());
         }
 
         Class handlerClass = loader.loadClass(handler.getHandlerClass());
         return new HandlerInfo(handlerClasspropertiesheaders);
     }

   
Accessing wsdl URL might involve file system access, so wrap operation in a doPrivileged block.
 
         (ServiceReferenceDescriptor descthrows Exception {
         URL wsdlFileURL;
         try {
             final ServiceReferenceDescriptor serviceRef = desc;
             wsdlFileURL = (URL) java.security.AccessController.doPrivileged
                 (new java.security.PrivilegedExceptionAction() {
                         public java.lang.Object run() throws Exception {
                             URL retVal;
                             if(serviceRef.hasWsdlOverride()) {
                                 retVal = serviceRef.getWsdlOverride();
                             } else {
                                 // Upon server restart, wsdlfileURL can be null
                                 // check that and return value from wsdlFileURI
                                 if(serviceRef.getWsdlFileUrl() != null) {
                                     retVal = serviceRef.getWsdlFileUrl();
                                 } else {
                                     if(serviceRef.getWsdlFileUri().startsWith("http")) {
                                         retVal = new URL(serviceRef.getWsdlFileUri());
                                     } else {
                                         if ((serviceRef.getWsdlFileUri().startsWith("WEB-INF")|| serviceRef.getWsdlFileUri().startsWith("META-INF"))) {
 
                                             //This can be the case when the toURL fails
                                             //because in its implementation it looks for user.dir
                                             // which sometimes can vary based on where vm is launched
                                             // so in this case
                                             //resolve from application path
                                             WebServiceContractImpl wscImpl  = WebServiceContractImpl.getInstance();
                                             ServerEnvironment se = wscImpl.getServerEnvironment();
 
                                             File appFile = new File(se.getApplicationRepositoryPath(),serviceRef.getBundleDescriptor().getApplication().getAppName());
                                             if (appFile.exists()) {
                                                retVal = new File(appFile,serviceRef.getWsdlFileUri()).toURL();
                                             } else {
                                                //Fix for 6853656 and 6868695
                                                //In case of appclients the wsdl will be in the classpath
                                                //This will work for launches using the appclient command and
                                                // for Java Web Start launches
                                                 
                                                retVal = Thread.currentThread().getContextClassLoader().getResource(serviceRef.getWsdlFileUri()) ;
                                             }
                                         }else {
                                             retVal = new File(serviceRef.getWsdlFileUri()).toURL();
                                         }
                                     }
                                 }
                             }
                             return retVal;
                         }
                     });
         } catch(PrivilegedActionException pae) {
             .log(..pae);
             Exception e = new Exception();
             e.initCause(pae.getCause());
             throw e;
         }
         return wsdlFileURL;
     }
 
     public boolean isJAXWSbasedService(WebService ws) {
 
         if(ws.isJaxWSBased() != null) {
             //already verified
             return ws.isJaxWSBased();
         }
 
         boolean jaxwsEndPtFound = false;
         boolean jaxrpcEndPtFound = false;
 
         String declaredType = ws.getType();
         if(declaredType != null) {
             if(declaredType.equals("JAXWS")) {
                 jaxwsEndPtFound = true;
             } else if(declaredType.equals("JAXRPC")) {
                 jaxrpcEndPtFound = true;
             } else {
                 .log(..new Object[] {ws.getDescription(), declaredType});
             }
         }
         //Verify that all the endpoints are of the same type 
         for (WebServiceEndpoint endpoint : ws.getEndpoints()) {
             if (endpoint.getLinkName() == null) {
                 String msg = MessageFormat.format(
                         .getResourceBundle().getString(.),
                         new Object[] {endpoint.getEndpointName(), endpoint.getLinkName()});
                     .log(.msg);
                     throw new RuntimeException(msg);
             }
             String implClassName = null;
             if (endpoint.implementedByEjbComponent()) {
                 if (endpoint.getEjbComponentImpl() != null) {
                     implClassName = endpoint.getEjbComponentImpl().getEjbClassName();
                 }
             } else {
                 if (endpoint.getWebComponentImpl() != null) {
                     implClassName = endpoint.getWebComponentImpl().getWebComponentImplementation();
                 }
             }
             if (implClassName == null || "".equals(implClassName.trim())) {
                 String msg = MessageFormat.format(
                         .getResourceBundle().getString(.),
                         endpoint.getEndpointName());
                 .log(.msg);
                 throw new RuntimeException(msg);
             }
             Class implClass;
             try {
                 implClass = Thread.currentThread().getContextClassLoader().loadClass(implClassName);
             } catch(Exception e) {
                 String msg = MessageFormat.format(
                         .getResourceBundle().getString(.),
                         implClassName);
                 .log(.msg);
                 throw new RuntimeException(msg);
             }
             if (implClass!=null) {
                 if(implClass.getAnnotation(javax.xml.ws.WebServiceProvider.class) != null) {
                     // if we already found a jaxrpcendpoint, flag error since we do not support jaxws+jaxrpc endpoint
                     // in the same service
                     if(jaxrpcEndPtFound) {
                         .log(..implClassName);
                         continue;
                     }
                     //This is a JAXWS endpoint with @WebServiceProvider
                     //Do not run wsgen for this endpoint
                     jaxwsEndPtFound = true;
                     continue;
                 }
                 if(implClass.getAnnotation(javax.jws.WebService.class) != null) {
                     // if we already found a jaxrpcendpoint, flag error since we do not support jaxws+jaxrpc endpoint
                     // in the same service
                     if(jaxrpcEndPtFound) {
                         .log(..implClassName);
                         continue;
                     }
                     // This is a JAXWS endpoint with @WebService;
                     jaxwsEndPtFound = true;
                     continue;
                 }
                 if (JAXWSServlet.class.isAssignableFrom(implClass)) {
                      // if we already found a jaxrpcendpoint, flag error since we do not support jaxws+jaxrpc endpoint
                     // in the same service
                     if(jaxrpcEndPtFound) {
                         .log(..implClassName);
                         continue;
                     }
                     // This is a JAXWS endpoint with @WebService;
                     jaxwsEndPtFound = true;
                     continue;
                 } else {
                     // this is a jaxrpc endpoint
                     // if we already found a jaxws endpoint, flag error since we do not support jaxws+jaxrpc endpoint
                     // in the same service
                     if(jaxwsEndPtFound) {
                         .log(..implClassName);
                         continue;
                     }
                     // Set spec version to 1.1 to indicate later the wscompile should be run
                     // We do this here so that jaxrpc endpoint having J2EE1.4 or JavaEE5
                     // descriptors will work properly
                     jaxrpcEndPtFound = true;
                     ws.getWebServicesDescriptor().setSpecVersion("1.1");
                 }
             }
         }
 
         if(jaxwsEndPtFound) {
             ws.setJaxWSBased(true);
             ws.setType("JAX-WS");
         } else {
             ws.setJaxWSBased(false);
             ws.setType("JAX-RPC");
         }
         return jaxwsEndPtFound;
     }
 
         (ServiceReferenceDescriptor descthrows Exception {
         
         final ServiceReferenceDescriptor serviceRef = desc;
         javax.xml.rpc.Service service = null;
         try {
 
             // Configured service can be created with any kind of URL.
             // Since resolving it might require file system access,
             // do operation in a doPrivivileged block.  JAXRPC RI should
             // probably have the doPrivileged as well.
 
             final URL wsdlFileURL = privilegedGetServiceRefWsdl(serviceRef);
             final QName serviceName = serviceRef.getServiceName();
             final ServiceFactory serviceFactory = ServiceFactory.newInstance();
 
             service = (javax.xml.rpc.Service
                 java.security.AccessController.doPrivileged
                 (new java.security.PrivilegedExceptionAction() {
                         public java.lang.Object run() throws Exception {
                             return serviceFactory.createService
                                 (wsdlFileURLserviceName);
                         }
                     });
 
         } catch(PrivilegedActionException pae) {
             .log(..pae);
             Exception e = new Exception();
             e.initCause(pae.getCause());
             throw e;
         }
 
         return service;
     }
 
     public void configureHandlerChain(ServiceReferenceDescriptor serviceRef,
                                       javax.xml.rpc.Service service
                                       Iterator portsClassLoader loader)
         throws Exception {
 
         if( !serviceRef.hasHandlers() ) {
             return;
         }
         
         HandlerRegistry registry = service.getHandlerRegistry();
         
         while(ports.hasNext()) {
             QName nextPort = (QNameports.next();
 
             List handlerChain = registry.getHandlerChain(nextPort);
             Collection soapRoles = new HashSet(); 
 
             for(Iterator iter = serviceRef.getHandlers().iterator();
                 iter.hasNext();) {
                 WebServiceHandler nextHandler = (WebServiceHandleriter.next();
                 Collection portNames = nextHandler.getPortNames();
                 ifportNames.isEmpty() || 
                     portNames.contains(nextPort.getLocalPart()) ) {
                     soapRoles.addAll(nextHandler.getSoapRoles());
                     HandlerInfo handlerInfo = 
                         createHandlerInfo(nextHandlerloader);
                     handlerChain.add(handlerInfo);
                 }
             }
         }
     }

    
Create an xslt template for transforming the packaged webservice WSDL to a final WSDL.
 
     private Templates createTemplatesFor(Collection endpoints,
                                          Collection wsdlRelativeImports,
                                          Collection wsdlIncludes,
                                          Collection schemaRelativeImports,
                                          Collection schemaIncludesthrows Exception {
 
         // create the stylesheet
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
         OutputStreamWriter writer = new OutputStreamWriter(bos"UTF-8");
 
         writer.write("<xsl:transform version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\" xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\" xmlns:soap12=\"http://schemas.xmlsoap.org/wsdl/soap12/\">\n");
 
         int wsdlImportNum = 0;
         for(Iterator iter = wsdlRelativeImports.iterator(); iter.hasNext();) {
 
             Import next = (Importiter.next();
             String importNamespaceParam =
                  + wsdlImportNum;
             String importLocationParam =
                  + wsdlImportNum;
             writer.write("<xsl:param name=\"" + importNamespaceParam + "\"/>\n");
             writer.write("<xsl:param name=\"" + importLocationParam + "\"/>\n");
 
             writer.write("<xsl:template match=\"/\"><xsl:apply-templates mode=\"copy\"/></xsl:template>\n");
             writer.write("<xsl:template match=\"wsdl:definitions/wsdl:import[@location='");
             writer.write(next.getLocation());
             writer.write("']\" mode=\"copy\">");
             writer.write("<wsdl:import>");
             writer.write("<xsl:attribute name=\"namespace\"><xsl:value-of select=\"$" + importNamespaceParam + "\"/>");
             writer.write("</xsl:attribute>");
             writer.write("<xsl:attribute name=\"location\"><xsl:value-of select=\"$" + importLocationParam + "\"/>");
             writer.write("</xsl:attribute>");
             writer.write("</wsdl:import></xsl:template>");
 
             wsdlImportNum++;
         }
 
         int wsdlIncludeNum = 0;
         for(Iterator iter = wsdlIncludes.iterator(); iter.hasNext();) {
 
             Import next = (Importiter.next();
             String importLocationParam =
                  + wsdlIncludeNum;
             writer.write("<xsl:param name=\"" + importLocationParam + "\"/>\n");
 
             writer.write("<xsl:template match=\"/\"><xsl:apply-templates mode=\"copy\"/></xsl:template>\n");
             writer.write("<xsl:template match=\"wsdl:definitions/wsdl:include[@location='");
             writer.write(next.getLocation());
             writer.write("']\" mode=\"copy\">");
             writer.write("<wsdl:include>");
             writer.write("<xsl:attribute name=\"location\"><xsl:value-of select=\"$" + importLocationParam + "\"/>");
             writer.write("</xsl:attribute>");
             writer.write("</wsdl:include></xsl:template>");
 
             wsdlIncludeNum++;
         }
 
         int schemaImportNum = 0;
         for(Iterator iter = schemaRelativeImports.iterator(); iter.hasNext();) {
 
             Import next = (Importiter.next();
             String importNamespaceParam =
                  + schemaImportNum;
             String importLocationParam =
                  + schemaImportNum;
             writer.write("<xsl:param name=\"" + importNamespaceParam + "\"/>\n");
             writer.write("<xsl:param name=\"" + importLocationParam + "\"/>\n");
 
             writer.write("<xsl:template match=\"/\"><xsl:apply-templates mode=\"copy\"/></xsl:template>\n");
             writer.write("<xsl:template match=\"wsdl:definitions/wsdl:types/xsd:schema/xsd:import[@schemaLocation='");
             writer.write(next.getLocation());
             writer.write("']\" mode=\"copy\">");
             writer.write("<xsd:import>");
             writer.write("<xsl:attribute name=\"namespace\"><xsl:value-of select=\"$" + importNamespaceParam + "\"/>");
             writer.write("</xsl:attribute>");
             writer.write("<xsl:attribute name=\"schemaLocation\"><xsl:value-of select=\"$" + importLocationParam + "\"/>");
             writer.write("</xsl:attribute>");
             writer.write("</xsd:import></xsl:template>");
 
             schemaImportNum++;
         }
 
         int schemaIncludeNum = 0;
         for(Iterator iter = schemaIncludes.iterator(); iter.hasNext();) {
 
             Import next = (Importiter.next();
             String importLocationParam =
                  + schemaIncludeNum;
             writer.write("<xsl:param name=\"" + importLocationParam + "\"/>\n");
 
             writer.write("<xsl:template match=\"/\"><xsl:apply-templates mode=\"copy\"/></xsl:template>\n");
             writer.write("<xsl:template match=\"wsdl:definitions/wsdl:types/xsd:schema/xsd:include[@schemaLocation='");
             writer.write(next.getLocation());
             writer.write("']\" mode=\"copy\">");
             writer.write("<xsd:include>");
             writer.write("<xsl:attribute name=\"schemaLocation\"><xsl:value-of select=\"$" + importLocationParam + "\"/>");
             writer.write("</xsl:attribute>");
             writer.write("</xsd:include></xsl:template>");
 
            schemaIncludeNum++;
        }
        int endpointNum = 0;
        for(Iterator iter = endpoints.iterator(); iter.hasNext();) {
            WebServiceEndpoint endpoint = (WebServiceEndpointiter.next();
            if( !endpoint.hasWsdlPort() ) {
                throw new Exception("No WSDL port specified for endpoint " +
                                    endpoint.getEndpointName());
            }
            if( !endpoint.hasServiceName() ) {
                throw new Exception("Runtime settings error.  Cannot find " +
                                    "service name for endpoint " +
                                    endpoint.getEndpointName());
            }
            String actualAddressParam =
                 + endpointNum;
            writer.write("<xsl:param name=\"" + actualAddressParam + "\"/>\n");
            writer.write("<xsl:template match=\"/\"><xsl:apply-templates mode=\"copy\"/></xsl:template>\n");
            writer.write("<xsl:template match=\"wsdl:definitions[@targetNamespace='");
            writer.write(endpoint.getServiceName().getNamespaceURI());
            writer.write("']/wsdl:service[@name='");
            writer.write(endpoint.getServiceName().getLocalPart());
            writer.write("']/wsdl:port[@name='");
            writer.write(endpoint.getWsdlPort().getLocalPart());
            writer.write("']/"+endpoint.getSoapAddressPrefix()+":address\" mode=\"copy\">");
            writer.write("<"+endpoint.getSoapAddressPrefix()+":address><xsl:attribute name=\"location\"><xsl:value-of select=\"$" + actualAddressParam + "\"/>");
            writer.write("</xsl:attribute></"+endpoint.getSoapAddressPrefix()+":address></xsl:template>");
            endpointNum++;
        }
        writer.write("<xsl:template match=\"@*|node()\" mode=\"copy\"><xsl:copy><xsl:apply-templates select=\"@*\" mode=\"copy\"/><xsl:apply-templates mode=\"copy\"/></xsl:copy></xsl:template>\n");
        writer.write("</xsl:transform>\n");
        writer.close();
        byte[] stylesheet = bos.toByteArray();
        if.isLoggable(.) ) {
            .fine(new String(