KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > webservice > WsUtil


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.webservice;
24
25 import com.sun.enterprise.webservice.spi.ServiceDelegateCreationListener;
26 import java.lang.reflect.Method JavaDoc;
27
28 import javax.xml.parsers.DocumentBuilder JavaDoc;
29 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
30 import javax.xml.parsers.FactoryConfigurationError JavaDoc;
31 import javax.xml.parsers.ParserConfigurationException JavaDoc;
32 import org.xml.sax.SAXException JavaDoc;
33 import org.xml.sax.SAXParseException JavaDoc;
34 import org.w3c.dom.*;
35 import javax.xml.xpath.XPathFactory JavaDoc;
36 import javax.xml.xpath.XPath JavaDoc;
37 import javax.xml.namespace.NamespaceContext JavaDoc;
38
39 import java.io.File JavaDoc;
40 import java.io.FileInputStream JavaDoc;
41 import java.io.ByteArrayOutputStream JavaDoc;
42 import java.io.InputStream JavaDoc;
43 import java.io.OutputStream JavaDoc;
44 import java.io.OutputStreamWriter JavaDoc;
45 import java.io.BufferedOutputStream JavaDoc;
46 import java.io.BufferedInputStream JavaDoc;
47 import java.io.ByteArrayInputStream JavaDoc;
48 import java.io.FileOutputStream JavaDoc;
49 import java.io.IOException JavaDoc;
50
51 import java.util.Iterator JavaDoc;
52 import java.util.Collection JavaDoc;
53 import java.util.HashSet JavaDoc;
54 import java.util.Set JavaDoc;
55 import java.util.Map JavaDoc;
56 import java.util.List JavaDoc;
57 import java.util.HashMap JavaDoc;
58 import java.util.Enumeration JavaDoc;
59 import java.util.ArrayList JavaDoc;
60 import java.util.StringTokenizer JavaDoc;
61 import java.util.LinkedList JavaDoc;
62
63 import java.util.jar.JarFile JavaDoc;
64 import java.util.jar.Manifest JavaDoc;
65 import java.util.jar.Attributes JavaDoc;
66 import java.util.zip.ZipEntry JavaDoc;
67
68 import javax.xml.transform.*;
69 import javax.xml.transform.stream.*;
70
71 import java.net.URL JavaDoc;
72 import java.net.URI JavaDoc;
73 import java.net.URLConnection JavaDoc;
74 import java.net.URLClassLoader JavaDoc;
75 import java.net.JarURLConnection JavaDoc;
76 import java.net.MalformedURLException JavaDoc;
77 import java.net.InetAddress JavaDoc;
78
79 import java.security.AccessController JavaDoc;
80 import java.security.PrivilegedExceptionAction JavaDoc;
81 import java.lang.reflect.InvocationTargetException JavaDoc;
82
83 import org.xml.sax.InputSource JavaDoc;
84 import javax.xml.namespace.QName JavaDoc;
85 import javax.xml.rpc.handler.MessageContext JavaDoc;
86 import javax.xml.rpc.Stub JavaDoc;
87 import javax.xml.rpc.ServiceFactory JavaDoc;
88 import javax.xml.rpc.handler.soap.SOAPMessageContext JavaDoc;
89 import javax.xml.rpc.soap.SOAPFaultException JavaDoc;
90 import javax.xml.rpc.handler.HandlerInfo JavaDoc;
91 import javax.xml.rpc.handler.HandlerRegistry JavaDoc;
92
93 import javax.xml.ws.soap.SOAPBinding;
94 import javax.xml.ws.http.HTTPBinding;
95
96 import javax.xml.soap.MimeHeaders JavaDoc;
97 import javax.xml.soap.MimeHeader JavaDoc;
98 import javax.xml.soap.MessageFactory JavaDoc;
99 import javax.xml.soap.SOAPMessage JavaDoc;
100 import javax.xml.soap.SOAPEnvelope JavaDoc;
101 import javax.xml.soap.SOAPBody JavaDoc;
102 import javax.xml.soap.SOAPBodyElement JavaDoc;
103 import javax.xml.soap.SOAPPart JavaDoc;
104 import javax.xml.soap.SOAPFault JavaDoc;
105 import javax.xml.soap.SOAPFactory JavaDoc;
106 import javax.xml.soap.SOAPException JavaDoc;
107 import javax.xml.soap.Detail JavaDoc;
108
109 import javax.servlet.http.HttpServletRequest JavaDoc;
110 import javax.servlet.http.HttpServletResponse JavaDoc;
111
112 import javax.enterprise.deploy.shared.ModuleType JavaDoc;
113
114 import com.sun.enterprise.Switch;
115 import com.sun.enterprise.InjectionException;
116
117 import com.sun.enterprise.admin.common.constant.DeploymentConstants;
118 import com.sun.enterprise.deployment.Application;
119 import com.sun.enterprise.deployment.deploy.shared.AbstractArchive;
120 import com.sun.enterprise.deployment.archivist.ApplicationArchivist;
121 import com.sun.enterprise.deployment.deploy.shared.InputJarArchive;
122 import com.sun.enterprise.deployment.backend.DeploymentRequest;
123 import com.sun.enterprise.deployment.BundleDescriptor;
124 import com.sun.enterprise.deployment.EjbBundleDescriptor;
125 import com.sun.enterprise.deployment.EjbDescriptor;
126 import com.sun.enterprise.deployment.NameValuePairDescriptor;
127 import com.sun.enterprise.deployment.ServiceReferenceDescriptor;
128 import com.sun.enterprise.deployment.util.DeploymentProperties;
129 import com.sun.enterprise.deployment.util.DescriptorVisitor;
130 import com.sun.enterprise.deployment.util.ModuleDescriptor;
131 import com.sun.enterprise.deployment.util.VirtualServerInfo;
132 import com.sun.enterprise.deployment.util.WebServerInfo;
133 import com.sun.enterprise.deployment.util.WsdlFileVisitor;
134 import com.sun.enterprise.deployment.WebBundleDescriptor;
135 import com.sun.enterprise.deployment.WebComponentDescriptor;
136 import com.sun.enterprise.deployment.web.SecurityConstraint;
137 import com.sun.enterprise.deployment.WebService;
138 import com.sun.enterprise.deployment.WebServiceEndpoint;
139 import com.sun.enterprise.deployment.WebServiceHandler;
140 import com.sun.enterprise.deployment.WebServicesDescriptor;
141 import com.sun.enterprise.deployment.WebServiceHandlerChain;
142 import com.sun.enterprise.deployment.web.UserDataConstraint;
143 import com.sun.enterprise.deployment.xml.WebServicesTagNames;
144 import com.sun.enterprise.util.shared.ArchivistUtils;
145 import com.sun.enterprise.util.InjectionManagerImpl;
146 import com.sun.enterprise.util.LocalStringManagerImpl;
147
148 import com.sun.enterprise.webservice.monitoring.WebServiceEngineImpl;
149
150 // jsr88 imports
151
import javax.enterprise.deploy.shared.ModuleType JavaDoc;
152
153 // admin stuff imports
154
import com.sun.enterprise.config.serverbeans.ServerBeansFactory;
155 import com.sun.enterprise.config.serverbeans.Domain;
156 import com.sun.enterprise.config.serverbeans.Server;
157 import com.sun.enterprise.config.serverbeans.Config;
158 import com.sun.enterprise.config.serverbeans.ApplicationRef;
159 import com.sun.enterprise.config.serverbeans.VirtualServer;
160 import com.sun.enterprise.config.serverbeans.HttpListener;
161 import com.sun.enterprise.config.serverbeans.HttpService;
162 import com.sun.enterprise.config.serverbeans.PropertyResolver;
163 import com.sun.enterprise.config.ConfigContext;
164 import com.sun.enterprise.config.ConfigException;
165 import com.sun.enterprise.server.ApplicationServer;
166 import com.sun.enterprise.config.serverbeans.ServerHelper;
167 import com.sun.enterprise.admin.server.core.AdminService;
168 import com.sun.enterprise.admin.AdminContext;
169
170 import com.sun.enterprise.admin.util.JMXConnectorConfig;
171
172 import org.w3c.dom.Element JavaDoc;
173
174 import java.util.logging.Logger JavaDoc;
175 import java.util.logging.Level JavaDoc;
176 import java.util.Properties JavaDoc;
177 import com.sun.logging.LogDomains;
178
179 import java.security.PrivilegedActionException JavaDoc;
180 import com.sun.enterprise.deployment.backend.IASDeploymentException;
181
182 import javax.xml.namespace.QName JavaDoc;
183 import java.io.PrintWriter JavaDoc;
184 import java.io.PrintStream JavaDoc;
185
186 //JAX-RPC SPI
187
import com.sun.xml.rpc.spi.JaxRpcObjectFactory;
188 import com.sun.xml.rpc.spi.model.Model;
189 import com.sun.xml.rpc.spi.model.ModelProperties;
190 import com.sun.xml.rpc.spi.model.Port;
191 import com.sun.xml.rpc.spi.model.Service;
192 import com.sun.xml.rpc.spi.runtime.ClientTransportFactory;
193 import com.sun.xml.rpc.spi.runtime.ClientTransportFactoryTypes;
194 import com.sun.xml.rpc.spi.runtime.SOAPConstants;
195 import com.sun.xml.rpc.spi.runtime.StreamingHandler;
196 import com.sun.xml.rpc.spi.runtime.StubBase;
197 import com.sun.xml.rpc.spi.runtime.Tie;
198 import com.sun.xml.rpc.spi.tools.WSDLUtil;
199 import com.sun.tools.ws.spi.WSToolsObjectFactory;
200 import com.sun.xml.ws.spi.runtime.WSRtObjectFactory;
201 import com.sun.xml.ws.spi.runtime.RuntimeEndpointInfo;
202 import com.sun.xml.messaging.saaj.soap.ExpressMessageFactoryImpl;
203 import com.sun.xml.bind.api.JAXBRIContext;
204 import javax.xml.ws.handler.Handler;
205 import javax.xml.ws.handler.HandlerResolver;
206 import javax.xml.ws.handler.PortInfo;
207
208 // Corba codegen
209
import com.sun.corba.ee.spi.codegen.Wrapper;
210 import com.sun.ejb.codegen.ClassGeneratorFactory;
211
212 // Imports for DOM processing of Handler file
213
import javax.xml.parsers.DocumentBuilder JavaDoc;
214 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
215 import javax.xml.parsers.FactoryConfigurationError JavaDoc;
216 import javax.xml.parsers.ParserConfigurationException JavaDoc;
217 import org.xml.sax.SAXException JavaDoc;
218 import org.xml.sax.SAXParseException JavaDoc;
219 import java.io.File JavaDoc;
220 import java.io.IOException JavaDoc;
221 import org.w3c.dom.Document JavaDoc;
222 import org.w3c.dom.Node JavaDoc;
223 import org.w3c.dom.NodeList JavaDoc;
224
225 /**
226  * Web service related utilities.
227  *
228  * @author Kenneth Saks
229  */

230 public class WsUtil {
231
232     // proprietary property for enabling logging of stub requests/responses
233
public static final String JavaDoc CLIENT_TRANSPORT_LOG_PROPERTY =
234       "com.sun.enterprise.webservice.client.transport.log";
235
236     // xslt processing parameters for final wsdl transformation
237
public static final String JavaDoc ENDPOINT_ADDRESS_PARAM_NAME =
238         "endpointAddressParam";
239
240     public final String JavaDoc WSDL_IMPORT_NAMESPACE_PARAM_NAME =
241         "wsdlImportNamespaceParam";
242     public static final String JavaDoc WSDL_IMPORT_LOCATION_PARAM_NAME =
243         "wsdlImportLocationParam";
244     public static final String JavaDoc WSDL_INCLUDE_LOCATION_PARAM_NAME =
245         "wsdlIncludeLocationParam";
246
247     public final String JavaDoc SCHEMA_IMPORT_NAMESPACE_PARAM_NAME =
248         "schemaImportNamespaceParam";
249     public static final String JavaDoc SCHEMA_IMPORT_LOCATION_PARAM_NAME =
250         "schemaImportLocationParam";
251     public static final String JavaDoc SCHEMA_INCLUDE_LOCATION_PARAM_NAME =
252         "schemaIncludeLocationParam";
253
254     public static final String JavaDoc SOAP11_TOKEN = "##SOAP11_HTTP";
255     public static final String JavaDoc SOAP12_TOKEN = "##SOAP12_HTTP";
256     public static final String JavaDoc SOAP11_MTOM_TOKEN = "##SOAP11_HTTP_MTOM";
257     public static final String JavaDoc SOAP12_MTOM_TOKEN = "##SOAP12_HTTP_MTOM";
258     public static final String JavaDoc XML_TOKEN = "##XML_HTTP";
259     
260     // @@@ These are jaxrpc-implementation specific MessageContextProperties
261
// that should be added to jaxrpc spi
262
private static final String JavaDoc ONE_WAY_OPERATION =
263         "com.sun.xml.rpc.server.OneWayOperation";
264     private static final String JavaDoc CLIENT_BAD_REQUEST =
265         "com.sun.xml.rpc.server.http.ClientBadRequest";
266
267     private static Logger JavaDoc logger =
268         LogDomains.getLogger(LogDomains.EJB_LOGGER);
269
270     private static Logger JavaDoc deploymentLogger =
271         LogDomains.getLogger(LogDomains.DPL_LOGGER);
272         
273     private JaxRpcObjectFactory rpcFactory;
274
275     public WsUtil() {
276         rpcFactory = JaxRpcObjectFactory.newInstance();
277     }
278
279     /**
280      * Notification of server startup, good place for services initialization
281      */

282     public static void start() {
283
284         // install our provider implementation
285
System.setProperty("javax.xml.ws.spi.Provider", "com.sun.enterprise.webservice.spi.ProviderImpl");
286         // force monitoring initialization
287
WebServiceEngineImpl.getInstance();
288         
289     }
290     /**
291      * Serve up the FINAL wsdl associated with this web service.
292      * @return true for success, false for failure
293      */

294     public boolean handleGet(HttpServletRequest JavaDoc request,
295                              HttpServletResponse JavaDoc response,
296                              WebServiceEndpoint endpoint) throws IOException JavaDoc {
297
298         MimeHeaders JavaDoc headers = getHeaders(request);
299         if( hasSomeTextXmlContent(headers) ) {
300             String JavaDoc message = "Received HTTP GET containing text/xml " +
301                 " content for endpoint " + endpoint.getEndpointName() +
302                 " at " + endpoint.getEndpointAddressUri() +
303                 " . HTTP POST should be used instead.";
304                         
305
306             writeInvalidMethodType(response, message);
307             
308             logger.info(message);
309             
310             return false;
311         }
312         
313         URL JavaDoc wsdlUrl = null;
314
315         String JavaDoc requestUriRaw = request.getRequestURI();
316         String JavaDoc requestUri = (requestUriRaw.charAt(0) == '/') ?
317             requestUriRaw.substring(1) : requestUriRaw;
318         String JavaDoc queryString = request.getQueryString();
319
320         WebService webService = endpoint.getWebService();
321
322         if( queryString == null ) {
323
324             // Get portion of request uri representing location within a module
325
String JavaDoc wsdlPath = endpoint.getWsdlContentPath(requestUri);
326
327             if( wsdlPath != null) {
328                 ModuleDescriptor module =
329                     webService.getBundleDescriptor().getModuleDescriptor();
330
331                 if( wsdlPath.equals(webService.getWsdlFileUri())){
332                     // If the request is for the main wsdl document, return
333
// the final wsdl instead of the wsdl from the module.
334
wsdlUrl = webService.getWsdlFileUrl();
335                 } else if( isWsdlContent(wsdlPath,
336                                          webService.getBundleDescriptor()) ) {
337                     // For relative document imports. These documents do not
338
// require modification during deployment, so serve them
339
// up directly from the packaged module. isWsdlContent()
340
// check ensures we don't serve up arbitrary content from
341
// the module.
342
URL JavaDoc finalWsdlUrl = webService.getWsdlFileUrl();
343                     String JavaDoc finalWsdlPath = finalWsdlUrl.getPath();
344                     // remove the final wsdl uri from the above path
345
String JavaDoc wsdlDirPath = finalWsdlPath.substring(0, finalWsdlPath.length()-webService.getWsdlFileUri().length());
346                     File JavaDoc wsdlDir = new File JavaDoc(wsdlDirPath);
347                     File JavaDoc wsdlFile = new File JavaDoc(wsdlDir, wsdlPath.replace('/', File.separatorChar));
348                     try {
349                         wsdlUrl = wsdlFile.toURL();
350                     } catch(MalformedURLException JavaDoc mue) {
351                         logger.log(Level.INFO, "Failure serving WSDL for " +
352                                    webService.getName(), mue);
353                     }
354                         
355                 }
356             }
357
358         } else if( queryString.equalsIgnoreCase("WSDL") ) {
359             wsdlUrl = webService.getWsdlFileUrl();
360         }
361
362         boolean success = false;
363         if( wsdlUrl != null ) {
364             
365             InputStream JavaDoc is = null;
366             try {
367                 response.setContentType("text/xml");
368                 response.setStatus(HttpServletResponse.SC_OK);
369                 // if the requested file is the main wsdl document, we are going
370
// to reprocess it through the XML transformer to change the final
371
// endpoint URL correct for this particular web server instance.
372
// This is necessary in the case of SE/EE installations where
373
// the application can be running on different machines and ports
374
// than the one they were deployed on (DAS).
375
if (wsdlUrl.equals(webService.getWsdlFileUrl())) {
376                     // get the application module ID
377
try {
378                         String JavaDoc moduleID = endpoint.getBundleDescriptor().getApplication().getRegistrationName();
379                         WebServerInfo wsi = getWebServerInfo(moduleID, request);
380                         URL JavaDoc url = webService.getWsdlFileUrl();
381                         File JavaDoc originalWsdlFile = new File JavaDoc(url.getPath()+"__orig");
382                         if(!originalWsdlFile.exists()) {
383                             originalWsdlFile = new File JavaDoc(url.getPath());
384                         }
385                         generateFinalWsdl(originalWsdlFile.toURL(), webService, wsi, response.getOutputStream());
386                     } catch(Exception JavaDoc e) {
387                         // if this fail, we revert to service the untouched
388
// repository item.
389
URLConnection JavaDoc urlCon = wsdlUrl.openConnection();
390                         urlCon.setUseCaches(false);
391                         is = urlCon.getInputStream();
392                         ArchivistUtils.copy(is, response.getOutputStream());
393                     }
394                 } else {
395                     // Copy bytes into output. Disable caches to avoid jar URL
396
// caching problem.
397
URLConnection JavaDoc urlCon = wsdlUrl.openConnection();
398                     urlCon.setUseCaches(false);
399                     is = urlCon.getInputStream();
400                     ArchivistUtils.copy(is, response.getOutputStream());
401                 }
402                 success = true;
403                 if( logger.isLoggable(Level.FINE) ) {
404                     logger.fine("Serving up final wsdl " + wsdlUrl + " for " +
405                                 request.getRequestURL() +
406                                 (queryString != null ? ("?"+queryString) : ""));
407                 }
408             } catch(Exception JavaDoc e) {
409                 logger.log(Level.INFO, "Failure serving WSDL for web service " +
410                            webService.getName(), e);
411             } finally {
412                 if(is != null) {
413                     try {
414                         is.close();
415                     } catch(IOException JavaDoc ex) {}
416                 }
417             }
418         }
419
420         if( !success ) {
421             String JavaDoc message =
422                 "Invalid wsdl request " + request.getRequestURL() +
423                 (queryString != null ? ("?"+queryString) : "") +
424                 " for web service "+ webService.getName();
425                 
426             logger.info(message);
427
428             writeInvalidMethodType(response, message);
429         }
430         
431         return success;
432     }
433
434     /**
435      * All wsdl files and wsdl imported files live under a well-known
436      * wsdl directory.
437      * @param uri module uri
438      */

439     public boolean isWsdlContent(String JavaDoc uri, BundleDescriptor bundle) {
440         String JavaDoc wsdlDir = getWsdlDir(bundle);
441         return (uri != null) && uri.startsWith(wsdlDir);
442     }
443
444     /**
445      * @return module-specific dedicated wsdl directory
446      */

447     public String JavaDoc getWsdlDir(BundleDescriptor bundle) {
448         boolean isWar = (bundle instanceof WebBundleDescriptor);
449         return isWar ? "WEB-INF/wsdl" : "META-INF/wsdl";
450     }
451
452     /**
453      * Set up a stub for request/response SOAP message logging.
454      */

455     public void setClientTransportLog(ServiceReferenceDescriptor serviceRef,
456                                       Stub JavaDoc stub, String JavaDoc transportLogUrlStr) {
457         try {
458             
459             final String JavaDoc logUrlString = transportLogUrlStr;
460
461             OutputStream JavaDoc os = (OutputStream JavaDoc)
462                 java.security.AccessController.doPrivileged
463                 (new java.security.PrivilegedExceptionAction JavaDoc() {
464                     public java.lang.Object JavaDoc run() throws Exception JavaDoc {
465                         URL JavaDoc transportLogUrl = new URL JavaDoc(logUrlString);
466                         File JavaDoc transportFile =new File JavaDoc(transportLogUrl.getFile());
467                         return new FileOutputStream JavaDoc(transportFile, true);
468                     }
469                 });
470
471             ClientTransportFactory transportFactory =
472                 rpcFactory.createClientTransportFactory(
473                         ClientTransportFactoryTypes.HTTP, os);
474
475             if( stub instanceof StubBase ) {
476                 ((StubBase)stub)._setTransportFactory(transportFactory);
477                 logger.info("Logging client transport for service-ref " +
478                             serviceRef.getName() + " to file " +
479                             transportLogUrlStr);
480             }
481
482         } catch(PrivilegedActionException JavaDoc pae) {
483             logger.log(Level.INFO, "", pae.getCause());
484         } catch(Throwable JavaDoc t) {
485             logger.log(Level.INFO, "", t);
486         }
487     }
488
489     /**
490      * Collect all relative imports from a web service's main wsdl document.
491      *
492      *@param wsdlRelativeImports outupt param in which wsdl relative imports
493      * will be added
494      *
495      *@param schemaRelativeImports outupt param in which schema relative
496      * imports will be added
497      */

498     private void parseRelativeImports(URL JavaDoc wsdlFileUrl,
499                                       Collection JavaDoc wsdlRelativeImports,
500                                       Collection JavaDoc wsdlIncludes,
501                                       Collection JavaDoc schemaRelativeImports,
502                                        Collection JavaDoc schemaIncludes)
503         throws Exception JavaDoc {
504         
505         // We will use our little parser rather than using JAXRPC's heavy weight WSDL parser
506
DocumentBuilderFactory JavaDoc factory = DocumentBuilderFactory.newInstance();
507         factory.setNamespaceAware(true);
508
509         InputStream JavaDoc is = null;
510         try {
511             DocumentBuilder JavaDoc builder = factory.newDocumentBuilder();
512             is = wsdlFileUrl.openStream();
513             Document JavaDoc document = builder.parse(is);
514             procesSchemaImports(document, schemaRelativeImports);
515             procesWsdlImports(document, wsdlRelativeImports);
516             procesSchemaIncludes(document, schemaIncludes);
517             procesWsdlIncludes(document, wsdlIncludes);
518         } catch (SAXParseException JavaDoc spe) {
519             // Error generated by the parser
520
logger.log(Level.SEVERE,"\n** Parsing error" + ", line " +
521                 spe.getLineNumber() + ", uri " + spe.getSystemId());
522             // Use the contained exception, if any
523
Exception JavaDoc x = spe;
524             if (spe.getException() != null) {
525                 x = spe.getException();
526             }
527             x.printStackTrace();
528         } catch (Exception JavaDoc sxe) {
529             logger.log(Level.SEVERE, "Error parsing WSDL" + sxe.getMessage());
530         } finally {
531             try {
532                 if(is != null) {
533                     is.close();
534                 }
535             } catch (IOException JavaDoc io) {}
536         }
537     }
538
539     private void addImportsAndIncludes(NodeList JavaDoc list, Collection JavaDoc result,
540                         String JavaDoc namespace, String JavaDoc location) throws SAXException JavaDoc,
541                         ParserConfigurationException JavaDoc, IOException JavaDoc, SAXParseException JavaDoc {
542         for(int i=0; i<list.getLength(); i++) {
543             Import imp = new Import();
544             Node JavaDoc element = list.item(i);
545             NamedNodeMap attrs = element.getAttributes();
546             Node JavaDoc n;
547             if(namespace != null) {
548                 n = attrs.getNamedItem(namespace);
549                 if(n != null) {
550                     imp.setNamespace(n.getNodeValue());
551                 }
552             }
553             n = attrs.getNamedItem(location);
554             if(n != null) {
555                 imp.setLocation(n.getNodeValue());
556                 result.add(imp);
557             }
558         }
559         return;
560     }
561     
562     private void procesSchemaImports(Document JavaDoc document, Collection JavaDoc schemaImportCollection) throws SAXException JavaDoc,
563                 ParserConfigurationException JavaDoc, IOException JavaDoc, SAXParseException JavaDoc {
564         NodeList JavaDoc schemaImports =
565                          document.getElementsByTagNameNS("http://www.w3.org/2001/XMLSchema", "import");
566         addImportsAndIncludes(schemaImports, schemaImportCollection, "namespace", "schemaLocation");
567     }
568
569     private void procesWsdlImports(Document JavaDoc document, Collection JavaDoc wsdlImportCollection) throws SAXException JavaDoc,
570                 ParserConfigurationException JavaDoc, IOException JavaDoc, SAXParseException JavaDoc {
571         NodeList JavaDoc wsdlImports =
572                          document.getElementsByTagNameNS("http://schemas.xmlsoap.org/wsdl/", "import");
573         addImportsAndIncludes(wsdlImports, wsdlImportCollection, "namespace", "location");
574     }
575
576     private void procesSchemaIncludes(Document JavaDoc document, Collection JavaDoc schemaIncludeCollection) throws SAXException JavaDoc,
577                 ParserConfigurationException JavaDoc, IOException JavaDoc, SAXParseException JavaDoc {
578         NodeList JavaDoc schemaIncludes =
579                          document.getElementsByTagNameNS("http://www.w3.org/2001/XMLSchema", "include");
580         addImportsAndIncludes(schemaIncludes, schemaIncludeCollection, null, "schemaLocation");
581     }
582
583     private void procesWsdlIncludes(Document JavaDoc document, Collection JavaDoc wsdlIncludesCollection) throws SAXException JavaDoc,
584                 ParserConfigurationException JavaDoc, IOException JavaDoc, SAXParseException JavaDoc {
585         NodeList JavaDoc wsdlIncludes =
586                          document.getElementsByTagNameNS("http://schemas.xmlsoap.org/wsdl/", "import");
587         addImportsAndIncludes(wsdlIncludes, wsdlIncludesCollection, null, "location");
588     }
589
590
591     /**
592      * Transform the deployed WSDL document for a given webservice by
593      * replacing the ENDPOINT ADDRESS for each port with the actual
594      * endpoint address on which it will be listening.
595      *
596      */

597     public void generateFinalWsdl(URL JavaDoc wsdlFileUrl, WebService webService, WebServerInfo wsi,
598                                   File JavaDoc finalWsdlFile) throws Exception JavaDoc {
599
600 /**
601         // Before generating final WSDL, ensure that the @WebService svcName/portName
602         // attributes (if any) match with those in wsdl - lets do this only for jaxws ervices
603         if(webService.getMappingFileUri() == null) {
604             for(WebServiceEndpoint endpoint : webService.getEndpoints()) {
605                 DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance();
606                 InputSource inputSource =
607                         new InputSource(new BufferedInputStream(new FileInputStream(wsdlFileUrl.getPath())));
608                 Document wsdlDoc =
609                         dFactory.newDocumentBuilder().parse(new BufferedInputStream(new FileInputStream(wsdlFileUrl.getPath())));
610
611
612                 XPathFactory xPathFactory = XPathFactory.newInstance();
613                 XPath xPath = xPathFactory.newXPath();
614                 NamespaceContext context =
615                         new com.sun.enterprise.webservice.monitoring.NamespaceContextImpl(wsdlDoc);
616                 xPath.setNamespaceContext(context);
617
618                 String xpathExpression = "/:definitions/:service/@name";
619                 String expStr = xPath.evaluate(xpathExpression, inputSource);
620                 if (!endpoint.getWsdlService().getLocalPart().equals(expStr)) {
621                     throw new Exception(localStrings.getLocalString(
622                             "enterprise.webservice.serviceNameMismatch",
623                             "There is a mismatch in the serviceName specified with @WebService annotation in the endpoint implementation and the serviceName found in the WSDL; ServiceName in WSDL={0}; ServiceName in endpoint={1}",
624                             new Object[] {expStr,endpoint.getWsdlService().getLocalPart()}));
625                 }
626                 
627                 inputSource =
628                         new InputSource(new BufferedInputStream(new FileInputStream(wsdlFileUrl.getPath())));
629                 xpathExpression = "/:definitions/:service/:port/@name";
630                 expStr = xPath.evaluate(xpathExpression, inputSource);
631                 if (!endpoint.getWsdlPort().getLocalPart().equals(expStr)) {
632                     throw new Exception(localStrings.getLocalString(
633                             "enterprise.webservice.portNameMismatch",
634                             "There is a mismatch in the portName specified with @WebService annotation in the endpoint implementation and the portName found in the WSDL; PortName in WSDL={0}; PortName in endpoint={1}",
635                             new Object[] {expStr,endpoint.getWsdlPort().getLocalPart()}));
636                 }
637             }
638         }
639 */

640         
641         OutputStream JavaDoc outputStream =
642             new BufferedOutputStream JavaDoc(new FileOutputStream JavaDoc(finalWsdlFile));
643         generateFinalWsdl(wsdlFileUrl, webService, wsi, outputStream);
644                                       
645     }
646     
647     public void generateFinalWsdl(URL JavaDoc wsdlFileUrl, WebService webService, WebServerInfo wsi,
648                                   OutputStream JavaDoc outputStream) throws Exception JavaDoc {
649                                       
650         Switch theSwitch = Switch.getSwitch();
651
652         String JavaDoc webServiceName = webService.getName();
653
654         Collection JavaDoc wsdlRelativeImports = new HashSet JavaDoc();
655         Collection JavaDoc wsdlIncludes = new HashSet JavaDoc();
656         Collection JavaDoc schemaRelativeImports = new HashSet JavaDoc();
657         Collection JavaDoc schemaIncludes = new HashSet JavaDoc();
658         if( webService.hasUrlPublishing() ) {
659             parseRelativeImports(wsdlFileUrl, wsdlRelativeImports,
660                          wsdlIncludes, schemaRelativeImports, schemaIncludes);
661         }
662         
663         Collection JavaDoc endpoints = webService.getEndpoints();
664
665         // a WSDL file can contain several ports associated to a service.
666
// however Deployment descriptors can be expressed in two ways
667
// to describe such a scenario in webservices.xml :
668
// - One webservice-description with 2 port-components
669
// - Two webservice-description with 1 port-component
670
// The issue with #1, is that we need to configure the XSL with
671
// the two ports so that the resulting unique WSDL has the correct
672
// endpoint information and the JAXRPC stubs generated correctly.
673
// So we need to check if this bundle is declaring more webservice
674
// descriptor pointing to the same WSDL file...
675
Collection JavaDoc endpointsCopy = new ArrayList JavaDoc();
676         endpointsCopy.addAll(endpoints);
677         
678         BundleDescriptor bundle = webService.getBundleDescriptor();
679         WebServicesDescriptor wsd = bundle.getWebServices();
680         Collection JavaDoc webServices = wsd.getWebServices();
681         if (webServices.size()>1) {
682             for (Iterator JavaDoc wsIter = webServices.iterator();wsIter.hasNext();) {
683                 WebService aWS = (WebService) wsIter.next();
684                 if (webService.getName().equals(aWS.getName())) {
685                     continue;
686                 }
687                 // this is another web service defined in the same bundle.
688
// let's check if it points to the same WSDL file
689
if (webService.getWsdlFileUri().equals(aWS.getWsdlFileUri())) {
690                     endpointsCopy.addAll(aWS.getEndpoints());
691                 }
692             }
693         }
694
695         
696         // Load the wsdl file bytes with caching turned off. This is
697
// to avoid a jar url consistency problem that can arise if we
698
// overwrite the module file later on in deployment.
699
InputStream JavaDoc wsdlInputStream = new BufferedInputStream JavaDoc(wsdlFileUrl.openStream());
700         Source JavaDoc XsltWsdlDocument = new StreamSource(wsdlInputStream);
701         Templates templates = createTemplatesFor
702             (endpointsCopy, wsdlRelativeImports, wsdlIncludes,
703                 schemaRelativeImports, schemaIncludes);
704                                                  
705         Transformer transformer = templates.newTransformer();
706
707
708         // WSDL is associated with webservice, but url is endpoint-specific,
709
// so let WebService choose which endpoint to use.
710
WebServiceEndpoint endpointForImport =
711             webService.pickEndpointForRelativeImports();
712         URL JavaDoc root= wsi.getWebServerRootURL(endpointForImport.isSecure());
713         URL JavaDoc finalWsdlUrl = endpointForImport.composeFinalWsdlUrl(root);
714         
715         int wsdlImportNum = 0;
716         for(Iterator JavaDoc iter = wsdlRelativeImports.iterator(); iter.hasNext();){
717             Import next = (Import) iter.next();
718             transformer.setParameter
719                 (WSDL_IMPORT_NAMESPACE_PARAM_NAME + wsdlImportNum,
720                  next.getNamespace());
721             
722             // Convert each relative import into an absolute import, using
723
// the final wsdl's Url as the context
724
URL JavaDoc relativeUrl = new URL JavaDoc(finalWsdlUrl, next.getLocation());
725             transformer.setParameter
726                 (WSDL_IMPORT_LOCATION_PARAM_NAME + wsdlImportNum, relativeUrl);
727             
728             wsdlImportNum++;
729         }
730
731         int schemaImportNum = 0;
732         for(Iterator JavaDoc iter = schemaRelativeImports.iterator(); iter.hasNext();){
733             Import next = (Import) iter.next();
734             transformer.setParameter
735                 (SCHEMA_IMPORT_NAMESPACE_PARAM_NAME + schemaImportNum,
736                  next.getNamespace());
737             
738             // Convert each relative import into an absolute import, using
739
// the final wsdl's Url as the context
740
URL JavaDoc relativeUrl = new URL JavaDoc(finalWsdlUrl, next.getLocation());
741             transformer.setParameter
742                 (SCHEMA_IMPORT_LOCATION_PARAM_NAME + schemaImportNum,
743                  relativeUrl);
744             
745             schemaImportNum++;
746         }
747
748                 int wsdlIncludeNum = 0;
749         for(Iterator JavaDoc iter = wsdlIncludes.iterator(); iter.hasNext();){
750             Import next = (Import) iter.next();
751             URL JavaDoc relativeUrl = new URL JavaDoc(finalWsdlUrl, next.getLocation());
752             transformer.setParameter
753                 (WSDL_INCLUDE_LOCATION_PARAM_NAME + wsdlIncludeNum, relativeUrl);
754             wsdlIncludeNum++;
755         }
756
757         int schemaIncludeNum = 0;
758         for(Iterator JavaDoc iter = schemaIncludes.iterator(); iter.hasNext();){
759             Import next = (Import) iter.next();
760             URL JavaDoc relativeUrl = new URL JavaDoc(finalWsdlUrl, next.getLocation());
761             transformer.setParameter
762                 (SCHEMA_INCLUDE_LOCATION_PARAM_NAME + schemaIncludeNum,
763                  relativeUrl);
764             schemaIncludeNum++;
765         }
766         
767         int endpointNum = 0;
768         for(Iterator JavaDoc iter = endpointsCopy.iterator(); iter.hasNext();) {
769             WebServiceEndpoint next = (WebServiceEndpoint) iter.next();
770
771             // Get a URL for the root of the webserver, where the host portion
772
// is a canonical host name. Since this will be used to compose the
773
// endpoint address that is written into WSDL, it's better to use
774
// hostname as opposed to IP address.
775
// The protocol and port will be based on whether the endpoint
776
// has a transport guarantee of INTEGRAL or CONFIDENTIAL.
777
// If yes, https will be used. Otherwise, http will be used.
778
URL JavaDoc rootURL = wsi.getWebServerRootURL(next.isSecure());
779
780             URL JavaDoc actualAddress = next.composeEndpointAddress(rootURL);
781
782             transformer.setParameter(ENDPOINT_ADDRESS_PARAM_NAME + endpointNum,
783                                      actualAddress.toExternalForm());
784
785             String JavaDoc endpointType = next.implementedByEjbComponent() ?
786                 "EJB" : "Servlet";
787
788             deploymentLogger.log(Level.INFO,
789                                  "enterprise.deployment.endpoint.registration",
790                        new Object JavaDoc[] { endpointType,
791                                       next.getEndpointName(), actualAddress });
792             
793             endpointNum++;
794         }
795
796         transformer.transform(XsltWsdlDocument, new StreamResult(outputStream));
797         wsdlInputStream.close();
798         outputStream.close();
799
800         return;
801     }
802
803     public HandlerInfo JavaDoc createHandlerInfo(WebServiceHandler handler,
804                                          ClassLoader JavaDoc loader)
805         throws Exception JavaDoc {
806
807         QName JavaDoc[] headers = new QName JavaDoc[handler.getSoapHeaders().size()];
808         int i = 0;
809         for(Iterator JavaDoc iter = handler.getSoapHeaders().iterator();
810             iter.hasNext();) {
811             headers[i] = (QName JavaDoc) iter.next();
812             i++;
813         }
814
815         Map JavaDoc properties = new HashMap JavaDoc();
816         for(Iterator JavaDoc iter = handler.getInitParams().iterator();
817             iter.hasNext();) {
818             NameValuePairDescriptor next = (NameValuePairDescriptor)
819                 iter.next();
820             properties.put(next.getName(), next.getValue());
821         }
822
823         Class JavaDoc handlerClass = loader.loadClass(handler.getHandlerClass());
824         return new HandlerInfo JavaDoc(handlerClass, properties, headers);
825     }
826
827     /**
828      * Accessing wsdl URL might involve file system access, so wrap
829      * operation in a doPrivileged block.
830      */

831     public URL JavaDoc privilegedGetServiceRefWsdl
832         (ServiceReferenceDescriptor desc) throws Exception JavaDoc {
833         URL JavaDoc wsdlFileURL;
834         try {
835             final ServiceReferenceDescriptor serviceRef = desc;
836             wsdlFileURL = (URL JavaDoc) java.security.AccessController.doPrivileged
837                 (new java.security.PrivilegedExceptionAction JavaDoc() {
838                         public java.lang.Object JavaDoc run() throws Exception JavaDoc {
839                             URL JavaDoc retVal;
840                             if(serviceRef.hasWsdlOverride()) {
841                                 retVal = serviceRef.getWsdlOverride();
842                             } else {
843                                 // Upon server restart, wsdlfileURL can be null
844
// check that and return value from wsdlFileURI
845
if(serviceRef.getWsdlFileUrl() != null) {
846                                     retVal = serviceRef.getWsdlFileUrl();
847                                 } else {
848                                     if(serviceRef.getWsdlFileUri().startsWith("http")) {
849                                         retVal = new URL JavaDoc(serviceRef.getWsdlFileUri());
850                                     } else {
851                                         retVal = (new File JavaDoc(serviceRef.getWsdlFileUri())).toURL();
852                                     }
853                                 }
854                             }
855                             return retVal;
856                         }
857                     });
858         } catch(PrivilegedActionException JavaDoc pae) {
859             logger.log(Level.WARNING, "", pae);
860             Exception JavaDoc e = new Exception JavaDoc();
861             e.initCause(pae.getCause());
862             throw e;
863         }
864         return wsdlFileURL;
865     }
866
867     public javax.xml.rpc.Service JavaDoc createConfiguredService
868         (ServiceReferenceDescriptor desc) throws Exception JavaDoc {
869         
870         final ServiceReferenceDescriptor serviceRef = desc;
871         javax.xml.rpc.Service JavaDoc service = null;
872         try {
873
874             // Configured service can be created with any kind of URL.
875
// Since resolving it might require file system access,
876
// do operation in a doPrivivileged block. JAXRPC RI should
877
// probably have the doPrivileged as well.
878

879             final URL JavaDoc wsdlFileURL = privilegedGetServiceRefWsdl(serviceRef);
880             final QName JavaDoc serviceName = serviceRef.getServiceName();
881             final ServiceFactory JavaDoc serviceFactory = ServiceFactory.newInstance();
882
883             service = (javax.xml.rpc.Service JavaDoc)
884                 java.security.AccessController.doPrivileged
885                 (new java.security.PrivilegedExceptionAction JavaDoc() {
886                         public java.lang.Object JavaDoc run() throws Exception JavaDoc {
887                             return serviceFactory.createService
888                                 (wsdlFileURL, serviceName);
889                         }
890                     });
891
892         } catch(PrivilegedActionException JavaDoc pae) {
893             logger.log(Level.WARNING, "", pae);
894             Exception JavaDoc e = new Exception JavaDoc();
895             e.initCause(pae.getCause());
896             throw e;
897         }
898
899         return service;
900     }
901
902     public void configureHandlerChain(ServiceReferenceDescriptor serviceRef,
903                                       javax.xml.rpc.Service JavaDoc service,
904                                       Iterator JavaDoc ports, ClassLoader JavaDoc loader)
905         throws Exception JavaDoc {
906
907         if( !serviceRef.hasHandlers() ) {
908             return;
909         }
910         
911         HandlerRegistry JavaDoc registry = service.getHandlerRegistry();
912         
913         while(ports.hasNext()) {
914             QName JavaDoc nextPort = (QName JavaDoc) ports.next();
915
916             List JavaDoc handlerChain = registry.getHandlerChain(nextPort);
917             Collection JavaDoc soapRoles = new HashSet JavaDoc();
918
919             for(Iterator JavaDoc iter = serviceRef.getHandlers().iterator();
920                 iter.hasNext();) {
921                 WebServiceHandler nextHandler = (WebServiceHandler) iter.next();
922                 Collection JavaDoc portNames = nextHandler.getPortNames();
923                 if( portNames.isEmpty() ||
924                     portNames.contains(nextPort.getLocalPart()) ) {
925                     soapRoles.addAll(nextHandler.getSoapRoles());
926                     HandlerInfo JavaDoc handlerInfo =
927                         createHandlerInfo(nextHandler, loader);
928                     handlerChain.add(handlerInfo);
929                 }
930             }
931         }
932     }
933
934     /**
935      * Create an xslt template for transforming the packaged webservice
936      * WSDL to a final WSDL.
937      */

938     private Templates createTemplatesFor(Collection JavaDoc endpoints,
939                                          Collection JavaDoc wsdlRelativeImports,
940                                          Collection JavaDoc wsdlIncludes,
941                                          Collection JavaDoc schemaRelativeImports,
942                                          Collection JavaDoc schemaIncludes) throws Exception JavaDoc {
943
944         // create the stylesheet
945
ByteArrayOutputStream JavaDoc bos = new ByteArrayOutputStream JavaDoc();
946         OutputStreamWriter JavaDoc writer = new OutputStreamWriter JavaDoc(bos, "UTF-8");
947         
948         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");
949
950         int wsdlImportNum = 0;
951         for(Iterator JavaDoc iter = wsdlRelativeImports.iterator(); iter.hasNext();) {
952
953             Import next = (Import) iter.next();
954             String JavaDoc importNamespaceParam =
955                 WSDL_IMPORT_NAMESPACE_PARAM_NAME + wsdlImportNum;
956             String JavaDoc importLocationParam =
957                 WSDL_IMPORT_LOCATION_PARAM_NAME + wsdlImportNum;
958             writer.write("<xsl:param name=\"" + importNamespaceParam + "\"/>\n");
959             writer.write("<xsl:param name=\"" + importLocationParam + "\"/>\n");
960             
961             writer.write("<xsl:template match=\"/\"><xsl:apply-templates mode=\"copy\"/></xsl:template>\n");
962             writer.write("<xsl:template match=\"wsdl:definitions/wsdl:import[@location='");
963             writer.write(next.getLocation());
964             writer.write("']\" mode=\"copy\">");
965             writer.write("<wsdl:import>");
966             writer.write("<xsl:attribute name=\"namespace\"><xsl:value-of select=\"$" + importNamespaceParam + "\"/>");
967             writer.write("</xsl:attribute>");
968             writer.write("<xsl:attribute name=\"location\"><xsl:value-of select=\"$" + importLocationParam + "\"/>");
969             writer.write("</xsl:attribute>");
970             writer.write("</wsdl:import></xsl:template>");
971
972             wsdlImportNum++;
973         }
974
975                 int wsdlIncludeNum = 0;
976         for(Iterator JavaDoc iter = wsdlIncludes.iterator(); iter.hasNext();) {
977
978             Import next = (Import) iter.next();
979             String JavaDoc importLocationParam =
980                 WSDL_INCLUDE_LOCATION_PARAM_NAME + wsdlIncludeNum;
981             writer.write("<xsl:param name=\"" + importLocationParam + "\"/>\n");
982             
983             writer.write("<xsl:template match=\"/\"><xsl:apply-templates mode=\"copy\"/></xsl:template>\n");
984             writer.write("<xsl:template match=\"wsdl:definitions/wsdl:include[@location='");
985             writer.write(next.getLocation());
986             writer.write("']\" mode=\"copy\">");
987             writer.write("<wsdl:include>");
988             writer.write("<xsl:attribute name=\"location\"><xsl:value-of select=\"$" + importLocationParam + "\"/>");
989             writer.write("</xsl:attribute>");
990             writer.write("</wsdl:include></xsl:template>");
991
992             wsdlIncludeNum++;
993         }
994                 
995         int schemaImportNum = 0;
996         for(Iterator JavaDoc iter = schemaRelativeImports.iterator(); iter.hasNext();) {
997
998             Import next = (Import) iter.next();
999             String JavaDoc importNamespaceParam =
1000                SCHEMA_IMPORT_NAMESPACE_PARAM_NAME + schemaImportNum;
1001            String JavaDoc importLocationParam =
1002                SCHEMA_IMPORT_LOCATION_PARAM_NAME + schemaImportNum;
1003            writer.write("<xsl:param name=\"" + importNamespaceParam + "\"/>\n");
1004            writer.write("<xsl:param name=\"" + importLocationParam + "\"/>\n");
1005            
1006            writer.write("<xsl:template match=\"/\"><xsl:apply-templates mode=\"copy\"/></xsl:template>\n");
1007            writer.write("<xsl:template match=\"wsdl:definitions/wsdl:types/xsd:schema/xsd:import[@schemaLocation='");
1008            writer.write(next.getLocation());
1009            writer.write("']\" mode=\"copy\">");
1010            writer.write("<xsd:import>");
1011            writer.write("<xsl:attribute name=\"namespace\"><xsl:value-of select=\"$" + importNamespaceParam + "\"/>");
1012            writer.write("</xsl:attribute>");
1013            writer.write("<xsl:attribute name=\"schemaLocation\"><xsl:value-of select=\"$" + importLocationParam + "\"/>");
1014            writer.write("</xsl:attribute>");
1015            writer.write("</xsd:import></xsl:template>");
1016
1017            schemaImportNum++;
1018        }
1019
1020        int schemaIncludeNum = 0;
1021        for(Iterator JavaDoc iter = schemaIncludes.iterator(); iter.hasNext();) {
1022
1023            Import next = (Import) iter.next();
1024            String JavaDoc importLocationParam =
1025                SCHEMA_INCLUDE_LOCATION_PARAM_NAME + schemaIncludeNum;
1026            writer.write("<xsl:param name=\"" + importLocationParam + "\"/>\n");
1027            
1028            writer.write("<xsl:template match=\"/\"><xsl:apply-templates mode=\"copy\"/></xsl:template>\n");
1029            writer.write("<xsl:template match=\"wsdl:definitions/wsdl:types/xsd:schema/xsd:include[@schemaLocation='");
1030            writer.write(next.getLocation());
1031            writer.write("']\" mode=\"copy\">");
1032            writer.write("<xsd:include>");
1033            writer.write("<xsl:attribute name=\"schemaLocation\"><xsl:value-of select=\"$" + importLocationParam + "\"/>");
1034            writer.write("</xsl:attribute>");
1035            writer.write("</xsd:include></xsl:template>");
1036
1037            schemaIncludeNum++;
1038        }
1039
1040        int endpointNum = 0;
1041        for(Iterator JavaDoc iter = endpoints.iterator(); iter.hasNext();) {
1042            WebServiceEndpoint endpoint = (WebServiceEndpoint) iter.next();
1043
1044            if( !endpoint.hasWsdlPort() ) {
1045                throw new Exception JavaDoc("No WSDL port specified for endpoint " +
1046                                    endpoint.getEndpointName());
1047            }
1048            if( !endpoint.hasServiceName() ) {
1049                throw new Exception JavaDoc("Runtime settings error. Cannot find " +
1050                                    "service name for endpoint " +
1051                                    endpoint.getEndpointName());
1052            }
1053            
1054            String JavaDoc actualAddressParam =
1055                ENDPOINT_ADDRESS_PARAM_NAME + endpointNum;
1056
1057            writer.write("<xsl:param name=\"" + actualAddressParam + "\"/>\n");
1058        
1059            writer.write("<xsl:template match=\"/\"><xsl:apply-templates mode=\"copy\"/></xsl:template>\n");
1060        
1061            writer.write("<xsl:template match=\"wsdl:definitions[@targetNamespace='");
1062            writer.write(endpoint.getServiceName().getNamespaceURI());
1063            writer.write("']/wsdl:service[@name='");
1064            writer.write(endpoint.getServiceName().getLocalPart());
1065            writer.write("']/wsdl:port[@name='");
1066            writer.write(endpoint.getWsdlPort().getLocalPart());
1067            writer.write("']/"+endpoint.getSoapAddressPrefix()+":address\" mode=\"copy\">");
1068            writer.write("<"+endpoint.getSoapAddressPrefix()+":address><xsl:attribute name=\"location\"><xsl:value-of select=\"$" + actualAddressParam + "\"/>");
1069            writer.write("</xsl:attribute></"+endpoint.getSoapAddressPrefix()+":address></xsl:template>");
1070            endpointNum++;
1071        }
1072
1073        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");
1074        writer.write("</xsl:transform>\n");
1075        writer.close();
1076        byte[] stylesheet = bos.toByteArray();
1077
1078        if( logger.isLoggable(Level.FINE) ) {
1079            logger.fine(new String JavaDoc(stylesheet));
1080        }
1081        
1082        Source JavaDoc stylesheetSource =
1083            new StreamSource(new ByteArrayInputStream JavaDoc(stylesheet));
1084        TransformerFactory transformerFactory=TransformerFactory.newInstance();
1085        Templates templates = transformerFactory.newTemplates(stylesheetSource);
1086
1087        return templates;
1088    }
1089
1090    /**
1091     * @return Set of service endpoint interface class names supported by
1092     * a generated service interface.
1093     *
1094     * @return Collection of String class names
1095     */

1096    public Collection JavaDoc getSEIsFromGeneratedService
1097        (Class JavaDoc generatedServiceInterface) throws Exception JavaDoc {
1098        
1099        Collection JavaDoc seis = new HashSet JavaDoc();
1100
1101        Method JavaDoc[] declaredMethods =
1102            generatedServiceInterface.getDeclaredMethods();
1103
1104        // Use naming convention from jaxrpc spec to derive SEI class name.
1105
for(int i = 0; i < declaredMethods.length; i++) {
1106            Method JavaDoc next = declaredMethods[i];
1107            Class JavaDoc returnType = next.getReturnType();
1108            if( next.getName().startsWith("get") &&
1109                (next.getDeclaringClass() != javax.xml.rpc.Service JavaDoc.class) &&
1110                java.rmi.Remote JavaDoc.class.isAssignableFrom(returnType) ) {
1111                seis.add(returnType.getName());
1112            }
1113        }
1114
1115        return seis;
1116    }
1117
1118    /**
1119     * Called from client side deployment object on receipt of final
1120     * wsdl from server.
1121     *
1122     *@param clientPublishUrl Url of directory on local file system to which
1123     * wsdl is published
1124     *
1125     *@param finalWsdlUri location relative to publish directory where final
1126     * wsdl should be written, in uri form.
1127     *
1128     *@return file to which final wsdl was written
1129     */

1130    public File JavaDoc publishFinalWsdl(URL JavaDoc clientPublishUrl, String JavaDoc finalWsdlUri,
1131                                 byte[] finalWsdlBytes)
1132        throws Exception JavaDoc
1133    {
1134        File JavaDoc finalWsdlFile = null;
1135        FileOutputStream JavaDoc fos = null;
1136        try {
1137            finalWsdlFile = new File JavaDoc
1138                (clientPublishUrl.getFile(),
1139                 finalWsdlUri.replace('/', File.separatorChar));
1140            File JavaDoc parent = finalWsdlFile.getParentFile();
1141            if( !parent.exists() ) {
1142                boolean madeDirs = parent.mkdirs();
1143                if( !madeDirs ) {
1144                    throw new IOException JavaDoc("Error creating " + parent);
1145                }
1146            }
1147            fos = new FileOutputStream JavaDoc(finalWsdlFile);
1148            fos.write(finalWsdlBytes, 0, finalWsdlBytes.length);
1149        } finally {
1150            if( fos != null ) {
1151                try {
1152                    fos.close();
1153                } catch(IOException JavaDoc ioe) {
1154                    logger.log(Level.INFO, "", ioe);
1155                }
1156            }
1157        }
1158        return finalWsdlFile;
1159    }
1160
1161    /**
1162     * Find a Port object within the JAXRPC Model.
1163     */

1164    public Port getPortFromModel(Model model, QName JavaDoc portName) {
1165        
1166        for(Iterator JavaDoc serviceIter = model.getServices(); serviceIter.hasNext();){
1167            Service next = (Service) serviceIter.next();
1168            for(Iterator JavaDoc portIter = next.getPorts(); portIter.hasNext();) {
1169                Port nextPort = (Port) portIter.next();
1170                if( portsEqual(nextPort, portName) ) {
1171                    return nextPort;
1172                }
1173            }
1174        }
1175        return null;
1176    }
1177
1178    /**
1179     * Find a Service in which a particular port is defined. Assumes port
1180     * QName is unique within a WSDL.
1181     */

1182    public Service getServiceForPort(Model model, QName JavaDoc thePortName) {
1183
1184        for(Iterator JavaDoc serviceIter = model.getServices();
1185            serviceIter.hasNext();) {
1186            Service nextService = (Service) serviceIter.next();
1187            for(Iterator JavaDoc portIter = nextService.getPorts();
1188                portIter.hasNext();) {
1189                
1190                Port nextPort = (Port) portIter.next();
1191                if( portsEqual(nextPort, thePortName) ) {
1192                    return nextService;
1193                }
1194            }
1195        }
1196
1197        return null;
1198    }
1199
1200    /**
1201     * Logic for matching a port qname with a Port object from
1202     * the JAXRPC-RI Model.
1203     */

1204    public boolean portsEqual(Port port, QName JavaDoc candidatePortName) {
1205
1206        boolean equal = false;
1207
1208        // Better to use Port object's WSDL_PORT property for port
1209
// QName than Port.getName(). If that returns null, use
1210
// Port.getName().
1211
QName JavaDoc portPropertyName = (QName JavaDoc) port.getProperty
1212            (ModelProperties.PROPERTY_WSDL_PORT_NAME);
1213
1214        if( portPropertyName != null ) {
1215            equal = candidatePortName.equals(portPropertyName);
1216        } else {
1217            equal = candidatePortName.equals(port.getName());
1218        }
1219
1220        return equal;
1221    }
1222
1223    // Return collection of Port objects
1224
public Collection JavaDoc getAllPorts(Model model) {
1225        Collection JavaDoc ports = new HashSet JavaDoc();
1226        for(Iterator JavaDoc serviceIter = model.getServices();
1227            serviceIter.hasNext();) {
1228            Service next = (Service) serviceIter.next();
1229            ports.addAll(next.getPortsList());
1230        }
1231        return ports;
1232    }
1233
1234    /**
1235     *@return a method object representing the target of a web service
1236     * invocation
1237     */

1238    public Method JavaDoc getInvMethod(Tie webServiceTie, MessageContext JavaDoc context)
1239        throws Exception JavaDoc {
1240
1241        // Use tie to get Method from SOAP message inv.webServiceTie
1242

1243        SOAPMessageContext JavaDoc soapMsgContext = (SOAPMessageContext JavaDoc) context;
1244        SOAPMessage JavaDoc message = soapMsgContext.getMessage();
1245        StreamingHandler streamingHandler = (StreamingHandler) webServiceTie;
1246        int opcode = streamingHandler.getOpcodeForRequestMessage(message);
1247        return streamingHandler.getMethodForOpcode(opcode);
1248    }
1249
1250    /**
1251     * Convenience method for throwing a SOAP fault exception.
1252     */

1253    public void throwSOAPFaultException(String JavaDoc faultString, com.sun.xml.ws.spi.runtime.MessageContext msgContext) {
1254        
1255        SOAPMessage JavaDoc soapMessage =
1256                ((com.sun.xml.ws.spi.runtime.SOAPMessageContext)msgContext).getMessage();
1257        throwSOAPFaultException(faultString, soapMessage);
1258        
1259    }
1260    
1261    public void throwSOAPFaultException(String JavaDoc faultString, MessageContext JavaDoc msgContext) {
1262        
1263        SOAPMessage JavaDoc soapMessage =
1264                ((SOAPMessageContext JavaDoc)msgContext).getMessage();
1265        throwSOAPFaultException(faultString, soapMessage);
1266        
1267    }
1268    
1269    public void throwSOAPFaultException(String JavaDoc faultString,
1270                                        SOAPMessage JavaDoc soapMessage)
1271        throws SOAPFaultException JavaDoc {
1272
1273        SOAPFaultException JavaDoc sfe = null;
1274
1275        try {
1276
1277            SOAPPart JavaDoc sp = soapMessage.getSOAPPart();
1278            SOAPEnvelope JavaDoc se = sp.getEnvelope();
1279
1280            // Consume the request
1281
SOAPBody JavaDoc sb = se.getBody();
1282
1283            // Access the child elements of body
1284
Iterator JavaDoc iter = sb.getChildElements();
1285
1286            // Response should only include the fault, so remove
1287
// any request body nodes.
1288
if (iter.hasNext()) {
1289                SOAPBodyElement JavaDoc requestBody = (SOAPBodyElement JavaDoc)iter.next();
1290                // detach this node from the tree
1291
requestBody.detachNode();
1292            }
1293
1294
1295            SOAPFault JavaDoc soapFault = sb.addFault();
1296
1297            se.setEncodingStyle(SOAPConstants.URI_ENCODING);
1298
1299            String JavaDoc faultActor = "http://schemas.xmlsoap.org/soap/actor/next";
1300            QName JavaDoc faultCode = SOAPConstants.FAULT_CODE_SERVER;
1301
1302            soapFault.setFaultCode("env:" + faultCode.getLocalPart());
1303            soapFault.setFaultString(faultString);
1304            soapFault.setFaultActor(faultActor);
1305
1306            sfe = new SOAPFaultException JavaDoc(faultCode, faultActor, faultString,
1307                                         null);
1308        } catch(SOAPException JavaDoc se) {
1309            logger.log(Level.FINE, "", se);
1310        }
1311
1312        if( sfe != null ) {
1313            throw sfe;
1314        }
1315    }
1316
1317
1318    void writeReply(HttpServletResponse JavaDoc response,
1319       com.sun.xml.rpc.spi.runtime.SOAPMessageContext messageContext)
1320        throws IOException JavaDoc, SOAPException JavaDoc
1321    {
1322
1323        // In case of a one-way operation, send no reply or fault.
1324
if (isMessageContextPropertySet(messageContext, ONE_WAY_OPERATION)) {
1325            return;
1326        }
1327          
1328        SOAPMessage JavaDoc reply = messageContext.getMessage();
1329        int statusCode = 0;
1330        if (messageContext.isFailure()) {
1331            
1332            if (isMessageContextPropertySet(messageContext,
1333                                            CLIENT_BAD_REQUEST)) {
1334                response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
1335                setContentTypeAndFlush(response);
1336                return;
1337                
1338            } else {
1339              response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
1340            }
1341            
1342        } else {
1343            response.setStatus(HttpServletResponse.SC_OK);
1344        }
1345        
1346        OutputStream JavaDoc os = response.getOutputStream();
1347        String JavaDoc[] headers = reply.getMimeHeaders().getHeader("Content-Type");
1348        if (headers != null && headers.length > 0) {
1349            response.setContentType(headers[0]);
1350        } else {
1351            response.setContentType("text/xml");
1352        }
1353
1354        putHeaders(reply.getMimeHeaders(), response);
1355        
1356        reply.writeTo(os);
1357        os.flush();
1358              
1359    }
1360
1361    private static void putHeaders(MimeHeaders JavaDoc headers,
1362                                   HttpServletResponse JavaDoc response) {
1363        headers.removeHeader("Content-Type");
1364        headers.removeHeader("Content-Length");
1365        Iterator JavaDoc it = headers.getAllHeaders();
1366        while (it.hasNext()) {
1367            MimeHeader JavaDoc header = (MimeHeader JavaDoc)it.next();
1368            response.setHeader(header.getName(), header.getValue());
1369        }
1370    }
1371    
1372    public static void raiseException(HttpServletResponse JavaDoc resp, String JavaDoc binding, String JavaDoc faultString) {
1373        
1374        resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
1375        
1376        if (HTTPBinding.HTTP_BINDING.equals(binding)) {
1377            resp.setContentType("text/xml");
1378            try {
1379                PrintWriter JavaDoc writer = new PrintWriter JavaDoc(resp.getOutputStream());
1380                writer.println("<error>" + faultString + "</error>");
1381            } catch(IOException JavaDoc ioe) {
1382                logger.log(Level.WARNING, "Cannot write out a HTTP XML exception : " + ioe.getMessage());
1383            }
1384        } else {
1385            String JavaDoc protocol;
1386            if (SOAPBinding.SOAP12HTTP_BINDING.equals(binding)) {
1387                protocol = javax.xml.soap.SOAPConstants.SOAP_1_2_PROTOCOL;
1388            } else {
1389                protocol = javax.xml.soap.SOAPConstants.SOAP_1_1_PROTOCOL;
1390            }
1391            SOAPMessage JavaDoc fault = WsUtil.getSOAPFault(protocol, faultString);
1392            
1393            if (fault!=null) {
1394                resp.setContentType("text/xml");
1395                try {
1396                    fault.writeTo(resp.getOutputStream());
1397                } catch(Exception JavaDoc ex) {
1398                    logger.log(Level.WARNING, "cannot write SOAPFault to the HTTP response", ex);
1399                }
1400            }
1401        }
1402    }
1403    
1404    public static SOAPMessage JavaDoc getSOAPFault(String JavaDoc protocol, String JavaDoc faultString) {
1405
1406        if (protocol==null) {
1407            protocol = javax.xml.soap.SOAPConstants.SOAP_1_1_PROTOCOL;
1408        }
1409        try {
1410            MessageFactory JavaDoc factory = MessageFactory.newInstance(protocol);
1411            if (factory==null) {
1412                factory = MessageFactory.newInstance();
1413            }
1414            SOAPMessage JavaDoc message = factory.createMessage();
1415            SOAPBody JavaDoc body = message.getSOAPBody();
1416            SOAPFault JavaDoc fault = body.addFault();
1417            fault.setFaultString(faultString);
1418            SOAPEnvelope JavaDoc envelope = message.getSOAPPart().getEnvelope();
1419            String JavaDoc envelopeNamespace = envelope.getNamespaceURI();
1420            QName JavaDoc faultCode = new QName JavaDoc(envelopeNamespace, "Server", "env");
1421            fault.setFaultCode(faultCode);
1422            return message;
1423        } catch(SOAPException JavaDoc e) {
1424            logger.log(Level.WARNING, "Cannot create soap fault for " + faultString);
1425        }
1426        return null;
1427    }
1428
1429    void writeInvalidContentType(HttpServletResponse JavaDoc response)
1430        throws SOAPException JavaDoc, IOException JavaDoc {
1431        //bad client content-type
1432
response.setStatus(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
1433        
1434        setContentTypeAndFlush(response);
1435    }
1436
1437    void writeInvalidMethodType(HttpServletResponse JavaDoc response,
1438                                String JavaDoc message) throws IOException JavaDoc {
1439        response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
1440        response.setContentType("text/html");
1441        PrintWriter JavaDoc out = response.getWriter();
1442        out.println("<html>");
1443        out.println("<head><title>");
1444        
1445        out.println("Invalid Method Type");
1446        out.println("</title></head>");
1447        out.println("<body>");
1448        out.println(message);
1449        out.println("</body>");
1450        out.println("</html>");
1451        
1452    }
1453
1454    private void writeNotFoundErrorPage(HttpServletResponse JavaDoc response,
1455                                        String JavaDoc message) throws IOException JavaDoc {
1456
1457        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
1458        response.setContentType("text/html");
1459        PrintWriter JavaDoc out = response.getWriter();
1460        out.println("<html>");
1461        out.println("<head><title>");
1462        out.println("J2EE Web Services");
1463        out.println("</title></head>");
1464        out.println("<body>");
1465        out.println("<h1>404 Not Found: " + message + "</h1>");
1466        out.println("</body>");
1467        out.println("</html>");
1468
1469    }
1470
1471    /*
1472     * Used to send back the message after a 4XX response code has been set
1473     */

1474    private void setContentTypeAndFlush(HttpServletResponse JavaDoc response)
1475        throws IOException JavaDoc {
1476        response.setContentType("text/xml");
1477        response.flushBuffer(); // prevent html message in response
1478
response.getWriter().close();
1479    }
1480    
1481    boolean hasSomeTextXmlContent(MimeHeaders JavaDoc headers) {
1482        return ( hasTextXmlContentType(headers) &&
1483                 (getContentLength(headers) > 0) );
1484    }
1485    
1486    private int getContentLength(MimeHeaders JavaDoc headers) {
1487        String JavaDoc[] contentLength = headers.getHeader("Content-Length");
1488
1489        int length = 0;
1490
1491        if ((contentLength != null) && (contentLength.length > 0)) {
1492            length = new Integer JavaDoc(contentLength[0]).intValue();
1493        }
1494
1495        return length;
1496    }
1497
1498    boolean hasTextXmlContentType(MimeHeaders JavaDoc headers) {
1499        
1500        String JavaDoc[] contentTypes = headers.getHeader("Content-Type");
1501        if ((contentTypes != null) && (contentTypes.length >= 1)){
1502            if (contentTypes[0].indexOf("text/xml") != -1){
1503                return true;
1504            }
1505        }
1506        return false;
1507    }
1508
1509    boolean isMessageContextPropertySet
1510        (com.sun.xml.rpc.spi.runtime.SOAPMessageContext messageContext,
1511         String JavaDoc property){
1512        
1513        Object JavaDoc prop = messageContext.getProperty(property);
1514        if (prop != null) {
1515            if ( (prop instanceof String JavaDoc) &&
1516                 ((String JavaDoc)prop).equalsIgnoreCase("true") ) {
1517                return true;
1518            }
1519        }
1520
1521        return false;
1522    }
1523
1524    MimeHeaders JavaDoc getHeaders(HttpServletRequest JavaDoc request) {
1525        Enumeration JavaDoc e = request.getHeaderNames();
1526        MimeHeaders JavaDoc headers = new MimeHeaders JavaDoc();
1527
1528        while (e.hasMoreElements()) {
1529            String JavaDoc headerName = (String JavaDoc)e.nextElement();
1530            String JavaDoc headerValue = request.getHeader(headerName);
1531            headers.addHeader(headerName, headerValue);
1532        }
1533
1534        return headers;
1535    }
1536    
1537    /**
1538     * @return the web server information based on a deployment request.
1539     */

1540    public WebServerInfo getWebServerInfo(DeploymentRequest request) throws ConfigException {
1541
1542        /**
1543         * If there is only one target and that target is a stand alone server, WSDL_TARGET_HINT in options would have been set
1544         * by the client. Use this hint to enable WSDL generation with the specific target's host and port.
1545         * Refer to bug 6157923 for more info
1546         */

1547        
1548        String JavaDoc serverTarget = (String JavaDoc) request.getOptionalArguments().get(DeploymentProperties.WSDL_TARGET_HINT);
1549        if(serverTarget == null) {
1550            return(getWebServerInfoForDAS(request));
1551        }
1552        ConfigContext cc = AdminService.getAdminService().getAdminContext().getAdminConfigContext();
1553        if(cc==null) {
1554            return(getWebServerInfoForDAS(request));
1555        }
1556        Config config = ServerHelper.getConfigForServer(cc, serverTarget);
1557        JMXConnectorConfig info = ServerHelper.getJMXConnectorInfo(cc, serverTarget);
1558        if((config==null) || (info==null) ) {
1559            return(getWebServerInfoForDAS(request));
1560        }
1561        String JavaDoc host = info.getHost();
1562        return(getWebServerInfo(cc, config, null, serverTarget, host));
1563    }
1564    
1565    private WebServerInfo getWebServerInfoForDAS(DeploymentRequest request) {
1566        WebServerInfo wsi = new WebServerInfo();
1567        wsi.setHttpVS(new VirtualServerInfo("http", request.getHttpHostName(), request.getHttpPort()));
1568        wsi.setHttpsVS(new VirtualServerInfo("https", request.getHttpsHostName(), request.getHttpsPort()));
1569        return wsi;
1570    }
1571
1572    /**
1573     * @return the web server information based on a http request
1574     */

1575    public WebServerInfo getWebServerInfo(String JavaDoc moduleID, HttpServletRequest JavaDoc request) throws ConfigException {
1576
1577    
1578        // let's get our admin context
1579
ConfigContext cc = ApplicationServer.getServerContext().getConfigContext();
1580        Server server = ServerBeansFactory.getServerBean(cc);
1581        Config config = ServerBeansFactory.getConfigBean(cc);
1582        ApplicationRef ref = server.getApplicationRefByRef(moduleID);
1583        return(getWebServerInfo(cc, config, ref.getVirtualServers(), null, null));
1584    }
1585    
1586    private WebServerInfo getWebServerInfo(ConfigContext cc, Config config,
1587                            String JavaDoc virtualServers, String JavaDoc targetName, String JavaDoc targetHostName) throws ConfigException {
1588        HttpService httpService = config.getHttpService();
1589        VirtualServer[] vServers = null;
1590        List JavaDoc httpListeners = new ArrayList JavaDoc();
1591        if (virtualServers==null) {
1592            vServers = httpService.getVirtualServer();
1593            if (vServers!=null) {
1594                for (int i=0;i<vServers.length;i++) {
1595                    VirtualServer vs = vServers[i];
1596                    // admin virtual server does not count
1597
if (vs.getId().equals("__asadmin"))
1598                        continue;
1599                    
1600                    String JavaDoc httpListenersString = vs.getHttpListeners();
1601                    if (httpListenersString!=null) {
1602                        String JavaDoc[] httpListenerIDs = httpListenersString.split(",");
1603                        if (httpListenerIDs!=null) {
1604                            for (int j=0;j<httpListenerIDs.length;j++) {
1605                                httpListeners.add(httpService.getHttpListenerById(httpListenerIDs[j]));
1606                            }
1607                        }
1608                    }
1609                }
1610            }
1611        } else {
1612            String JavaDoc virtualServerNames[] = virtualServers.split(",");
1613            if (virtualServerNames!=null) {
1614                for (int i=0;i<virtualServerNames.length;i++) {
1615                    VirtualServer vs = httpService.getVirtualServerById(virtualServerNames[i]);
1616                    String JavaDoc httpListenersString = vs.getHttpListeners();
1617                    if (httpListenersString!=null) {
1618                        String JavaDoc[] httpListenerIDs = httpListenersString.split(",");
1619                        if (httpListenerIDs!=null) {
1620                            for (int j=0;j<httpListenerIDs.length;j++) {
1621                                httpListeners.add(httpService.getHttpListenerById(httpListenerIDs[i]));
1622                            }
1623                        }
1624                    }
1625                }
1626            }
1627        }
1628    
1629        WebServerInfo wsi = new WebServerInfo();
1630        for (int i=0;i<httpListeners.size();i++) {
1631            HttpListener hl = (HttpListener) httpListeners.get(i);
1632            if (!hl.isEnabled())
1633                continue;
1634            
1635            if(targetHostName == null) {
1636                targetHostName = hl.getServerName();
1637                if (targetHostName==null || targetHostName.length()==0) {
1638                    targetHostName = getDefaultHostName();
1639                }
1640            }
1641            try {
1642                targetHostName = InetAddress.getByName(targetHostName).getCanonicalHostName();
1643            } catch (java.net.UnknownHostException JavaDoc unex) {
1644                throw new ConfigException(unex.getMessage(), unex);
1645            }
1646            String JavaDoc redirectPortNb = hl.getRedirectPort();
1647            String JavaDoc portNb;
1648            if (redirectPortNb!=null) {
1649                portNb = redirectPortNb;
1650            } else {
1651                portNb = hl.getPort();
1652            }
1653            if(targetName == null) {
1654                targetName = ApplicationServer.getServerContext().getInstanceName();
1655            }
1656            PropertyResolver pr = new PropertyResolver(cc, targetName);
1657            String JavaDoc resolvedPort = pr.resolve(portNb);
1658            
1659            int port = Integer.parseInt(resolvedPort);
1660            if (hl.isSecurityEnabled()) {
1661                wsi.setHttpsVS(new VirtualServerInfo("https", targetHostName, port));
1662            } else {
1663                wsi.setHttpVS(new VirtualServerInfo("http", targetHostName, port));
1664            }
1665
1666            if (wsi.getHttpVS()!=null && wsi.getHttpsVS()!=null)
1667                break;
1668        }
1669        return wsi;
1670    }
1671    
1672    private String JavaDoc getDefaultHostName() {
1673        String JavaDoc defaultHostName = "localhost";
1674        try {
1675            InetAddress JavaDoc host = InetAddress.getLocalHost();
1676            defaultHostName = host.getCanonicalHostName();
1677        } catch(java.net.UnknownHostException JavaDoc uhe) {
1678            deploymentLogger.log(Level.FINEST, "mbean.get_local_host_error", uhe);
1679            deploymentLogger.log(Level.INFO, "mbean.use_default_host");
1680        }
1681        return defaultHostName;
1682    }
1683
1684    private static Logger JavaDoc _logger = null;
1685    
1686    /**
1687     * @return the default Logger implementation for this package
1688     */

1689    public static Logger JavaDoc getDefaultLogger() {
1690        return logger;
1691    }
1692
1693    // resources...
1694
static LocalStringManagerImpl localStrings =
1695        new LocalStringManagerImpl(WsUtil.class);
1696    
1697    public static LocalStringManagerImpl getDefaultStringManager() {
1698        return localStrings;
1699    }
1700    
1701    public void validateEjbEndpoint(WebServiceEndpoint ejbEndpoint) {
1702        EjbDescriptor ejbDescriptor = ejbEndpoint.getEjbComponentImpl();
1703        EjbBundleDescriptor bundle = ejbDescriptor.getEjbBundleDescriptor();
1704        WebServicesDescriptor webServices = bundle.getWebServices();
1705        Collection JavaDoc endpoints =
1706            webServices.getEndpointsImplementedBy(ejbDescriptor);
1707        if( endpoints.size() == 1 ) {
1708            if( ejbDescriptor.hasWebServiceEndpointInterface() ) {
1709                if(!ejbEndpoint.getServiceEndpointInterface().equals
1710                   (ejbDescriptor.getWebServiceEndpointInterfaceName())) {
1711                    String JavaDoc msg = "Ejb " + ejbDescriptor.getName() +
1712                        " service endpoint interface does not match " +
1713                        " port component " + ejbEndpoint.getEndpointName();
1714                    throw new IllegalStateException JavaDoc(msg);
1715                }
1716            } else {
1717                String JavaDoc msg = "Ejb " + ejbDescriptor.getName() +
1718                    " must declare <service-endpoint> interface";
1719                throw new IllegalStateException JavaDoc(msg);
1720            }
1721        } else if( endpoints.size() > 1 ) {
1722            String JavaDoc msg = "Ejb " + ejbDescriptor.getName() +
1723                " implements " + endpoints.size() + " web service endpoints " +
1724                " but must only implement 1";
1725            throw new IllegalStateException JavaDoc(msg);
1726        }
1727    }
1728
1729    public void updateServletEndpointRuntime(WebServiceEndpoint endpoint) {
1730
1731        // Copy the value of the servlet impl bean class into
1732
// the runtime information. This way, we'll still
1733
// remember it after the servlet-class element has been
1734
// replaced with the name of the container's servlet class.
1735
endpoint.saveServletImplClass();
1736
1737        WebComponentDescriptor webComp =
1738            (WebComponentDescriptor) endpoint.getWebComponentImpl();
1739
1740        WebBundleDescriptor bundle = webComp.getWebBundleDescriptor();
1741        WebServicesDescriptor webServices = bundle.getWebServices();
1742        Collection JavaDoc endpoints =
1743            webServices.getEndpointsImplementedBy(webComp);
1744
1745        if( endpoints.size() > 1 ) {
1746            String JavaDoc msg = "Servlet " + endpoint.getWebComponentLink() +
1747                " implements " + endpoints.size() + " web service endpoints " +
1748                " but must only implement 1";
1749            throw new IllegalStateException JavaDoc(msg);
1750        }
1751
1752        if( endpoint.getEndpointAddressUri() == null ) {
1753            Set JavaDoc urlPatterns = webComp.getUrlPatternsSet();
1754            if( urlPatterns.size() == 1 ) {
1755
1756                // Set endpoint-address-uri runtime info to uri.
1757
// Final endpoint address will still be relative to context root
1758
String JavaDoc uri = (String JavaDoc) urlPatterns.iterator().next();
1759                endpoint.setEndpointAddressUri(uri);
1760
1761                // Set transport guarantee in runtime info if transport
1762
// guarantee is INTEGRAL or CONDIFIDENTIAL for any
1763
// security constraint with this url-pattern.
1764
Collection JavaDoc constraints =
1765                    bundle.getSecurityConstraintsForUrlPattern(uri);
1766                for(Iterator JavaDoc i = constraints.iterator(); i.hasNext();) {
1767                    SecurityConstraint next = (SecurityConstraint) i.next();
1768                        
1769                    UserDataConstraint dataConstraint =
1770                        next.getUserDataConstraint();
1771                    String JavaDoc guarantee = (dataConstraint != null) ?
1772                        dataConstraint.getTransportGuarantee() : null;
1773
1774                    if( (guarantee != null) &&
1775                        ( guarantee.equals
1776                          (UserDataConstraint.INTEGRAL_TRANSPORT) ||
1777                          guarantee.equals
1778                          (UserDataConstraint.CONFIDENTIAL_TRANSPORT) ) ) {
1779                        endpoint.setTransportGuarantee(guarantee);
1780                        break;
1781                    }
1782                }
1783            } else {
1784                String JavaDoc msg = "Endpoint " + endpoint.getEndpointName() +
1785                    " has not been assigned an endpoint address " +
1786                    " and is associated with servlet " +
1787                    webComp.getCanonicalName() + " , which has " +
1788                    urlPatterns.size() + " url patterns";
1789                throw new IllegalStateException JavaDoc(msg);
1790            }
1791        }
1792    }
1793
1794    private boolean runWsGen(String JavaDoc implClass, boolean skipGenWsdl, String JavaDoc classPath, File JavaDoc stubsDir,
1795            File JavaDoc wsdlDir, QName JavaDoc sQname, QName JavaDoc port) {
1796        int numArgs;
1797        if(skipGenWsdl) {
1798            numArgs = 6;
1799        } else {
1800            numArgs = 13;
1801        }
1802        String JavaDoc[] wsgenArgs = new String JavaDoc[numArgs];
1803        int argIndex= 0 ;
1804        wsgenArgs[argIndex++] = "-cp";
1805        wsgenArgs[argIndex++] = classPath;
1806        wsgenArgs[argIndex++] = "-keep";
1807        if(!skipGenWsdl) {
1808            wsgenArgs[argIndex++] = "-wsdl";
1809            wsgenArgs[argIndex++] = "-r";
1810            wsgenArgs[argIndex++] = wsdlDir.getAbsolutePath();
1811            wsgenArgs[argIndex++] = "-servicename";
1812            wsgenArgs[argIndex++] = sQname.toString();
1813            wsgenArgs[argIndex++] = "-portname";
1814            wsgenArgs[argIndex++] = port.toString();
1815        }
1816        wsgenArgs[argIndex++] = "-d";
1817        wsgenArgs[argIndex++] = stubsDir.getAbsolutePath();
1818        wsgenArgs[argIndex++] = implClass;
1819        WSToolsObjectFactory wsTools = WSToolsObjectFactory.newInstance();
1820        return(wsTools.wsgen(System.out, wsgenArgs));
1821    }
1822
1823    private void downloadFile(URL JavaDoc httpUrl, File JavaDoc toFile) throws Exception JavaDoc {
1824        InputStream JavaDoc is = null;
1825        FileOutputStream JavaDoc os = null;
1826        try {
1827            if(!toFile.createNewFile()) {
1828                throw new Exception JavaDoc("Unable to create new File " + toFile.getAbsolutePath());
1829            }
1830            is = httpUrl.openStream();
1831            os = new FileOutputStream JavaDoc(toFile);
1832            int readCount;
1833            int offset = 0;
1834            byte[] buffer = new byte[10240]; // Read 10KB at a time
1835
do {
1836                readCount = is.read(buffer, 0, 10240);
1837                os.write(buffer, offset, readCount);
1838                offset+=readCount;
1839            } while(readCount == 10240);
1840        } finally {
1841            if(is != null) {
1842            is.close();
1843            }
1844            if(os != null) {
1845            os.flush();
1846            os.close();
1847            }
1848        }
1849    }
1850
1851    private void downloadWsdlsAndSchemas(WebService ws, URL JavaDoc httpUrl, File JavaDoc wsdlDir) throws Exception JavaDoc {
1852        // First make required directories and download this wsdl file
1853
wsdlDir.mkdirs();
1854        String JavaDoc fileName = httpUrl.toString().substring(httpUrl.toString().lastIndexOf("/")+1);
1855        File JavaDoc toFile = new File JavaDoc(wsdlDir.getAbsolutePath()+File.separator+fileName);
1856        downloadFile(httpUrl, toFile);
1857
1858        // Get a list of wsdl and schema relative imports in this wsdl
1859
Collection JavaDoc<Import> wsdlRelativeImports = new HashSet JavaDoc();
1860        Collection JavaDoc<Import> schemaRelativeImports = new HashSet JavaDoc();
1861        Collection JavaDoc<Import> wsdlIncludes = new HashSet JavaDoc();
1862        Collection JavaDoc<Import> schemaIncludes = new HashSet JavaDoc();
1863        parseRelativeImports(httpUrl, wsdlRelativeImports, wsdlIncludes,
1864                schemaRelativeImports, schemaIncludes);
1865        wsdlRelativeImports.addAll(wsdlIncludes);
1866        schemaRelativeImports.addAll(schemaIncludes);
1867        
1868        // Download all schema relative imports
1869
String JavaDoc urlWithoutFileName = httpUrl.toString().substring(0, httpUrl.toString().lastIndexOf("/"));
1870        for(Import next : schemaRelativeImports) {
1871            String JavaDoc location = next.getLocation();
1872            location.replaceAll("/", "\\"+File.separator);
1873            if(location.lastIndexOf(File.separator) != -1) {
1874                File JavaDoc newDir = new File JavaDoc(wsdlDir.getAbsolutePath()+File.separator+
1875                location.substring(0, location.lastIndexOf(File.separator)));
1876                newDir.mkdirs();
1877            }
1878            downloadFile(new URL JavaDoc(urlWithoutFileName+"/"+next.getLocation()),
1879                        new File JavaDoc(wsdlDir.getAbsolutePath()+File.separator+location));
1880        }
1881
1882        // Download all wsdl relative imports
1883
for(Import next : wsdlRelativeImports) {
1884            String JavaDoc newWsdlLocation = next.getLocation();
1885            newWsdlLocation.replaceAll("/", "\\"+File.separator);
1886            File JavaDoc newWsdlDir;
1887            if(newWsdlLocation.lastIndexOf(File.separator) != -1) {
1888                newWsdlDir = new File JavaDoc(wsdlDir.getAbsolutePath() + File.separator +
1889                newWsdlLocation.substring(0, newWsdlLocation.lastIndexOf(File.separator)));
1890            } else {
1891                newWsdlDir = wsdlDir;
1892            }
1893            downloadWsdlsAndSchemas(ws, new URL JavaDoc(urlWithoutFileName+"/"+next.getLocation()), newWsdlDir);
1894        }
1895        return;
1896    }
1897
1898    private String JavaDoc addJarsToClassPath(String JavaDoc cp, String JavaDoc dirName) throws IASDeploymentException {
1899        try {
1900           File JavaDoc dir = new File JavaDoc(dirName);
1901           if(dir.exists()) {
1902               Iterator JavaDoc fileSetIter = com.sun.enterprise.util.FileUtil.getAllFilesUnder(dir, null, false).iterator();
1903               while(fileSetIter.hasNext()) {
1904                   cp+=(File.pathSeparator+((File JavaDoc)fileSetIter.next()).getAbsolutePath());
1905               }
1906           }
1907        } catch (IOException JavaDoc ioex) {
1908            throw new IASDeploymentException("IOException : " + ioex.getMessage() +
1909                    " when trying to get list of files under " + dirName);
1910        }
1911        return cp;
1912    }
1913    
1914    private String JavaDoc getWsgenClassPath(File JavaDoc classesDir, String JavaDoc webinfLibDir,
1915            String JavaDoc appLibDirPath, String JavaDoc moduleDir) throws IASDeploymentException {
1916        // First thing in the classpath is modules' classes directory
1917
String JavaDoc classpath = classesDir.getAbsolutePath();
1918        
1919        // Next add the Jar files in WEB-INF/lib, if any
1920
if(webinfLibDir != null) {
1921            classpath = addJarsToClassPath(classpath, webinfLibDir);
1922        }
1923        
1924        // Next add the jar files in the EAR level lib directory
1925
if(appLibDirPath != null) {
1926            classpath = addJarsToClassPath(classpath, appLibDirPath);
1927        }
1928        
1929        // Now add the classpath elements in the modules Manifest entries
1930
FileInputStream JavaDoc is = null;
1931        try {
1932            File JavaDoc mfFile = new File JavaDoc(moduleDir+File.separator+"META-INF"+
1933                    File.separator+"MANIFEST.MF");
1934            if(mfFile.exists()) {
1935                is = new FileInputStream JavaDoc(mfFile);
1936                Manifest JavaDoc ms = new Manifest JavaDoc(is);
1937                Attributes JavaDoc attrMap = ms.getMainAttributes();
1938                String JavaDoc mfCp = attrMap.getValue(Attributes.Name.CLASS_PATH);
1939                if(mfCp != null && mfCp.length() != 0) {
1940                    StringTokenizer JavaDoc strTok = new StringTokenizer JavaDoc(mfCp, " \t");
1941                    while(strTok.hasMoreTokens()) {
1942                        String JavaDoc givenCP = strTok.nextToken();
1943                        // Append moduleDir to all relative classPaths
1944
if(!givenCP.startsWith(File.separator)) {
1945                            givenCP = moduleDir+File.separator+givenCP;
1946                        }
1947                        classpath+=(File.pathSeparator+givenCP);
1948                    }
1949                }
1950            }
1951        } catch (Exception JavaDoc e) {
1952            throw new IASDeploymentException("Exception : " + e.getMessage() +
1953                    " when trying to process MANIFEST file under " + moduleDir);
1954        } finally {
1955            if(is != null) {
1956                try {
1957                    is.close();
1958                } catch(IOException JavaDoc t) {}
1959            }
1960        }
1961        return classpath;
1962    }
1963    
1964    /**
1965     * Creates missing wsdl from SEI/SIB declared in the deployment descriptors or
1966     * through the @WebService annotation
1967     */

1968    public void genWSInfo(Application app, DeploymentRequest request) throws IASDeploymentException {
1969
1970        Set JavaDoc<BundleDescriptor> bundles = (Set JavaDoc<BundleDescriptor>) app.getBundleDescriptors();
1971        for(BundleDescriptor bundle : bundles) {
1972            WebServicesDescriptor wsDesc = bundle.getWebServices();
1973            for (WebService ws : wsDesc.getWebServices()) {
1974
1975                // for modules this is domains/<domain-name>/j2ee-modules/<module-name>
1976
// for apps this is domains/<domain-name>/j2ee-apps/<app-name>/<foo_war> (in case of embedded wars)
1977
// or domains/<domain-name>/j2ee-apps/<app-name>/<foo_jar> (in case of embedded jars)
1978
File JavaDoc moduleDir = request.getDeployedDirectory();
1979                File JavaDoc wsdlDir = request.getGeneratedXMLDirectory();
1980                File JavaDoc stubsDir = request.getStubsDirectory();
1981                
1982                if(request.isApplication()) {
1983                    String JavaDoc subDirName = bundle.getModuleDescriptor().getArchiveUri();
1984                    moduleDir = new File JavaDoc(moduleDir, subDirName.replaceAll("\\.", "_"));
1985                    wsdlDir = new File JavaDoc(wsdlDir, subDirName.replaceAll("\\.", "_"));
1986                }
1987                File JavaDoc classesDir;
1988                String JavaDoc webinfLibDir = null;
1989                if (ModuleType.WAR.equals(bundle.getModuleType())) {
1990                    classesDir = new File JavaDoc(moduleDir, "WEB-INF"+File.separator+"classes");
1991                    webinfLibDir = moduleDir.getAbsolutePath() + File.separator + "WEB-INF"+File.separator+"lib";
1992                } else if (ModuleType.EJB.equals(bundle.getModuleType())) {
1993                    classesDir = moduleDir;
1994                } else {
1995                    // unknown module type with @WebService, just ignore...
1996
continue;
1997                }
1998                wsdlDir = new File JavaDoc(wsdlDir, bundle.getWsdlDir().replaceAll("/", "\\"+File.separator));
1999
2000                // Check if catalog file is present, if so get mapped WSDLs
2001
String JavaDoc wsdlFileUri;
2002                File JavaDoc wsdlFile;
2003                checkCatalog(bundle, ws, moduleDir);
2004                if (ws.hasWsdlFile()) {
2005                // If wsdl file is an http URL, download that WSDL and all embedded relative wsdls, schemas
2006
if (ws.getWsdlFileUri().startsWith("http")) {
2007                        try {
2008                            downloadWsdlsAndSchemas(ws, new URL JavaDoc(ws.getWsdlFileUri()), wsdlDir);
2009                        } catch(Exception JavaDoc e) {
2010                            throw new IASDeploymentException(e.toString(), e);
2011                        }
2012                        wsdlFileUri = ws.getWsdlFileUri().substring(ws.getWsdlFileUri().lastIndexOf("/")+1);
2013                        wsdlFile = new File JavaDoc(wsdlDir, wsdlFileUri);
2014                        
2015                        // at this point, we don't care we got it from and it simplifies
2016
// the rest of the deployment process to just think that is was
2017
// generated during deployment
2018
ws.setWsdlFileUri(null);
2019                    
2020                    } else {
2021                        wsdlFileUri = ws.getWsdlFileUri();
2022                        if(wsdlFileUri.startsWith("/")) {
2023                            wsdlFile = new File JavaDoc(wsdlFileUri);
2024                        } else {
2025                            wsdlFile = new File JavaDoc(moduleDir, wsdlFileUri);
2026                        }
2027                        if (!wsdlFile.exists()) {
2028                            throw new IASDeploymentException("WebService " + ws.getName() + " wsdl file "
2029                                    + ws.getWsdlFileUri() + " not found in archive "
2030                                    + bundle.getModuleDescriptor().getArchiveUri());
2031                        }
2032                    }
2033
2034                } else {
2035                    //make required dirs in case they are not present
2036
wsdlFileUri = JAXBRIContext.mangleNameToClassName(ws.getName()) + ".wsdl";
2037                    wsdlDir.mkdirs();
2038                    wsdlFile = new File JavaDoc(wsdlDir, wsdlFileUri);
2039                }
2040                
2041
2042                for (WebServiceEndpoint endpoint : ws.getEndpoints()) {
2043
2044                    String JavaDoc implClassName;
2045                    boolean jaxwsEndPtFound = false;
2046                    boolean jaxrpcEndPtFound = false;
2047                    if (endpoint.implementedByEjbComponent()) {
2048                        implClassName = endpoint.getEjbComponentImpl().getEjbClassName();
2049                    } else {
2050                        implClassName = endpoint.getWebComponentImpl().getWebComponentImplementation();
2051                    }
2052                    
2053                    // check this is NOT a provider interface
2054
Class JavaDoc implClass;
2055                    try {
2056                        implClass = app.getClassLoader().loadClass(implClassName);
2057                    } catch(Exception JavaDoc e) {
2058                            throw new IASDeploymentException("WebService " + ws.getName() + "implementation "
2059                                    + implClassName + " not found in archive "
2060                                    + bundle.getModuleDescriptor().getArchiveUri());
2061                    }
2062                    
2063                    if (implClass!=null) {
2064                        if(implClass.getAnnotation(javax.xml.ws.WebServiceProvider.class) != null) {
2065                            // if we already found a jaxrpcendpoint, flag error since we do not support jaxws+jaxrpc endpoint
2066
// in the same service
2067
if(jaxrpcEndPtFound) {
2068                                throw new IASDeploymentException("WebService " + ws.getName() +
2069                                        "has a JAXWS and a JAXRPC endpoint; this is not supported now");
2070                            }
2071                            //This is a JAXWS endpoint with @WebServiceProvider
2072
//Do not run wsgen for this endpoint
2073
jaxwsEndPtFound = true;
2074                            continue;
2075                        }
2076                        if(implClass.getAnnotation(javax.jws.WebService.class) != null) {
2077                    
2078                            // if we already found a jaxrpcendpoint, flag error since we do not support jaxws+jaxrpc endpoint
2079
// in the same service
2080
if(jaxrpcEndPtFound) {
2081                                throw new IASDeploymentException("WebService " + ws.getName() +
2082                                        "has a JAXWS and a JAXRPC endpoint; this is not supported now");
2083                            }
2084                            // This is a JAXWS endpoint with @WebService; Invoke wsgen
2085
jaxwsEndPtFound = true;
2086                            String JavaDoc wsgenClassPath = getWsgenClassPath(classesDir, webinfLibDir,
2087                                request.getDeployedDirectory().getAbsolutePath()+File.separator+app.getLibraryDirectory(),
2088                                moduleDir.getAbsolutePath());
2089                            boolean wsgenDone =
2090                                runWsGen(implClassName, wsdlFile.exists(), wsgenClassPath,
2091                                    stubsDir, wsdlDir, endpoint.getServiceName(), endpoint.getWsdlPort());
2092                            if(!wsgenDone) {
2093                                throw new IASDeploymentException("WSGEN FAILED");
2094                            }
2095                            try {
2096                                endpoint.getWebService().setWsdlFileUrl(wsdlFile.toURI().toURL());
2097                            } catch(java.net.MalformedURLException JavaDoc mue) {
2098                                throw new IASDeploymentException("WSGEN Failed");
2099                            }
2100                            logger.log(Level.INFO, "wsgen successful");
2101                        } else {
2102                            // this is a jaxrpc endpoint
2103
// if we already found a jaxws endpoint, flag error since we do not support jaxws+jaxrpc endpoint
2104
// in the same service
2105
if(jaxwsEndPtFound) {
2106                                throw new IASDeploymentException("WebService " + ws.getName() +
2107                                        "has a JAXWS and a JAXRPC endpoint; this is not supported now");
2108                            }
2109                            // Set spec version to 1.1 to indicate later the wscompile should be run
2110
// We do this here so that jaxrpc endpoint having J2EE1.4 or JavaEE5
2111
// descriptors will work properly
2112
jaxrpcEndPtFound = true;
2113                            ws.getWebServicesDescriptor().setSpecVersion("1.1");
2114                        }
2115                    }
2116                }
2117            }
2118        }
2119    }
2120
2121    public URL JavaDoc resolveCatalog(File JavaDoc catalogFile, String JavaDoc wsdlFile, WebService ws) throws IASDeploymentException {
2122        try {
2123            URL JavaDoc retVal = null;
2124            // Get an entity resolver
2125
org.xml.sax.EntityResolver JavaDoc resolver =
2126                    WSRtObjectFactory.newInstance().createEntityResolver(catalogFile.toURL());
2127            org.xml.sax.InputSource JavaDoc source = resolver.resolveEntity(null, wsdlFile);
2128            if(source != null) {
2129                String JavaDoc mappedEntry = source.getSystemId();
2130                // For entries with relative paths, Entity resolver always
2131
// return file://<absolute path
2132
if(mappedEntry.startsWith("file:")) {
2133                    File JavaDoc f = new File JavaDoc(mappedEntry.substring(mappedEntry.indexOf(":")+1));
2134                    if(!f.exists()) {
2135                        throw new IASDeploymentException("File " + mappedEntry + " not found");
2136                    }
2137                    retVal = f.toURI().toURL();
2138                    if(ws != null) {
2139                        ws.setWsdlFileUri(f.getAbsolutePath());
2140                        ws.setWsdlFileUrl(retVal);
2141                    }
2142                } else if(mappedEntry.startsWith("http")) {
2143                    retVal = new URL JavaDoc(mappedEntry);
2144                    if(ws != null) {
2145                        ws.setWsdlFileUrl(retVal);
2146                    }
2147                }
2148            }
2149            return retVal;
2150        } catch (Throwable JavaDoc t) {
2151            throw new IASDeploymentException("Exception while processing catalog "
2152                    + catalogFile.getAbsolutePath() + "; Reason " + t.getMessage());
2153        }
2154    }
2155    
2156    // If catalog file is present, get the mapped WSDL for given WSDL and replace the value in
2157
// the given WebService object
2158
private void checkCatalog(BundleDescriptor bundle, WebService ws, File JavaDoc moduleDir)
2159                            throws IASDeploymentException {
2160        // If no catalog file is present, return
2161
File JavaDoc catalogFile = new File JavaDoc(moduleDir,
2162                bundle.getDeploymentDescriptorDir() +
2163                File.separator + "jax-ws-catalog.xml");
2164        if(!catalogFile.exists()) {
2165            return;
2166        }
2167        resolveCatalog(catalogFile, ws.getWsdlFileUri(), ws);
2168    }
2169    
2170    public static Class JavaDoc generateAndLoad(ClassGeneratorFactory cgf,
2171                                         ClassLoader JavaDoc loader) {
2172
2173        cgf.evaluate();
2174
2175        Properties props = new Properties();
2176        if( logger.isLoggable(Level.FINE) ) {
2177
2178            props.put(Wrapper.DUMP_AFTER_SETUP_VISITOR, "true");
2179            props.put(Wrapper.TRACE_BYTE_CODE_GENERATION, "true");
2180            props.put(Wrapper.USE_ASM_VERIFIER, "true");
2181
2182            try {
2183
2184                ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
2185                PrintStream JavaDoc ps = new PrintStream JavaDoc(baos);
2186
2187                Wrapper._sourceCode(ps, props);
2188                logger.log(Level.FINE,baos.toString());
2189
2190            } catch(Exception JavaDoc e) {
2191                logger.log(Level.FINE, "exception generating src", e);
2192            }
2193
2194        }
2195
2196        return Wrapper._generate(loader, null, props);
2197
2198    }
2199
2200    /*
2201     * Calls @PostConstruct method in the implementor
2202     */

2203    public void doPostConstruct(Class JavaDoc impl, Object JavaDoc implObj) {
2204        invokeServiceMethod(javax.annotation.PostConstruct.class, impl,
2205                implObj);
2206    }
2207    
2208    /*
2209     * Calls @PreDestroy method in the implementor
2210     */

2211    public void doPreDestroy(WebServiceEndpoint ep, ClassLoader JavaDoc loader) {
2212        // Call @PreDestroy in endpoint, if any
2213
try {
2214            Class JavaDoc impl = Class.forName(ep.getServletImplClass(),
2215                                true, loader);
2216            invokeServiceMethod(javax.annotation.PreDestroy.class, impl,
2217                    impl.newInstance());
2218        } catch (Throwable JavaDoc ex) {
2219            logger.log(Level.SEVERE, "Class " + ep.getServletImplClass() +
2220                            "not found during PreDestroy processing", ex);
2221        }
2222                                                                                
2223        // Call @PreDestroy in the handlers if any
2224
if(!ep.hasHandlerChain()) {
2225            return;
2226        }
2227        for(Iterator JavaDoc<WebServiceHandlerChain> hc = ep.getHandlerChain().iterator();
2228                                hc.hasNext();) {
2229            WebServiceHandlerChain thisHc = hc.next();
2230            for(Iterator JavaDoc<WebServiceHandler> h = thisHc.getHandlers().iterator();
2231                                    h.hasNext();) {
2232                WebServiceHandler thisHandler = h.next();
2233                try {
2234                    Class JavaDoc handlerClass = Class.forName(thisHandler.getHandlerClass(),
2235                                            true, loader);
2236                    invokeServiceMethod(javax.annotation.PreDestroy.class, handlerClass,
2237                            handlerClass.newInstance());
2238                } catch (Throwable JavaDoc ex) {
2239                    logger.log(Level.SEVERE, "Handler class " + thisHandler.getHandlerClass() +
2240                                    "not found during PreDestroy processing", ex);
2241                }
2242            }
2243        }
2244    }
2245
2246    /*
2247     * Calls the PostConstruct / PreDestroy method
2248     */

2249    private void invokeServiceMethod(Class JavaDoc annType, Class JavaDoc impl, final Object JavaDoc implObj) {
2250        Method JavaDoc[] methods = impl.getDeclaredMethods();
2251        // Only one method can have @PostConstruct / @PreDestroy
2252
// Call the first method with this annotation and return
2253
for(final Method JavaDoc method : methods) {
2254            if (method.getAnnotation(annType) != null) {
2255                try {
2256                    AccessController.doPrivileged(new PrivilegedExceptionAction JavaDoc() {
2257                        public Object JavaDoc run() throws IllegalAccessException JavaDoc,
2258                        InvocationTargetException JavaDoc {
2259                            if (!method.isAccessible()) {
2260                                method.setAccessible(true);
2261                            }
2262                            method.invoke(implObj, new Object JavaDoc[]{});
2263                            return null;
2264                        }
2265                    });
2266                } catch(Throwable JavaDoc e) {
2267                    // Should we log or throw an exception
2268
logger.log(Level.SEVERE,
2269                            "Failure while calling PostConstruct/PreDestroy method", e);
2270                }
2271                break;
2272            }
2273        }
2274    }
2275    
2276    private boolean matchQNamePatterns(QName JavaDoc cfgQName, QName JavaDoc givenPattern) {
2277        if (givenPattern.getNamespaceURI().equals(cfgQName.getNamespaceURI())) {
2278            String JavaDoc expr = givenPattern.getLocalPart().replaceAll("\\*", ".*");
2279            return java.util.regex.Pattern.matches(expr, cfgQName.getLocalPart());
2280        }
2281        return false;
2282    }
2283
2284    private boolean patternsMatch(WebServiceHandlerChain hc, QName JavaDoc svcName,
2285                                    QName JavaDoc portName, String JavaDoc bindingId) {
2286        // If service name pattern in handler chain does not match the service name
2287
// for this endpoint, skip handler processing
2288
if(hc.getServiceNamePattern() != null && svcName != null) {
2289            QName JavaDoc svcPattern = QName.valueOf(hc.getServiceNamePattern());
2290            if(!matchQNamePatterns(svcName, svcPattern)) {
2291                return false;
2292            }
2293        }
2294
2295        // If port name pattern in handler chain does not match the port name
2296
// for this endpoint, skip handler processing
2297
if(hc.getPortNamePattern() != null && portName != null) {
2298            QName JavaDoc portPattern = QName.valueOf(hc.getPortNamePattern());
2299            if(!matchQNamePatterns(portName, portPattern)) {
2300                return false;
2301            }
2302        }
2303
2304        // Check if the binding protocol for this endpoint is present
2305
// as part of the protocol-bindings list
2306
if(hc.getProtocolBindings() != null && bindingId != null) {
2307            String JavaDoc givenBindings = hc.getProtocolBindings();
2308            if( (bindingId.equals(HTTPBinding.HTTP_BINDING)) &&
2309                ((givenBindings.indexOf(HTTPBinding.HTTP_BINDING) != -1) ||
2310                 (givenBindings.indexOf(XML_TOKEN) != -1))) {
2311                return true;
2312            }
2313            if( (bindingId.equals(SOAPBinding.SOAP11HTTP_BINDING)) &&
2314                ((givenBindings.indexOf(SOAPBinding.SOAP11HTTP_BINDING) != -1) ||
2315                 (givenBindings.indexOf(SOAP11_TOKEN) != -1))) {
2316                return true;
2317            }
2318            if( (bindingId.equals(SOAPBinding.SOAP12HTTP_BINDING)) &&
2319                ((givenBindings.indexOf(SOAPBinding.SOAP12HTTP_BINDING) != -1) ||
2320                 (givenBindings.indexOf(SOAP12_TOKEN) != -1))) {
2321                return true;
2322            }
2323            if( (bindingId.equals(SOAPBinding.SOAP11HTTP_MTOM_BINDING)) &&
2324                ((givenBindings.indexOf(SOAPBinding.SOAP11HTTP_MTOM_BINDING) != -1) ||
2325                 (givenBindings.indexOf(SOAP11_MTOM_TOKEN) != -1))) {
2326                return true;
2327            }
2328            if( (bindingId.equals(SOAPBinding.SOAP12HTTP_MTOM_BINDING)) &&
2329                ((givenBindings.indexOf(SOAPBinding.SOAP12HTTP_MTOM_BINDING) != -1) ||
2330                 (givenBindings.indexOf(SOAP12_MTOM_TOKEN) != -1))) {
2331                return true;
2332            }
2333        }
2334        return true;
2335    }
2336
2337    private List JavaDoc<Handler> processConfiguredHandlers(List JavaDoc<WebServiceHandler> handlersList, Set JavaDoc<String JavaDoc> roles) {
2338        List JavaDoc<Handler> handlerChain = new ArrayList JavaDoc<Handler>();
2339        for(WebServiceHandler h : handlersList) {
2340            Handler handler = null;
2341            Map JavaDoc<String JavaDoc, Object JavaDoc> params = new HashMap JavaDoc<String JavaDoc, Object JavaDoc>();
2342            ClassLoader JavaDoc loader = Thread.currentThread().getContextClassLoader();
2343            // Get Handler Class instance
2344
Class JavaDoc handlerClass;
2345            try {
2346                handlerClass = Class.forName(h.getHandlerClass(), true, loader);
2347                handler = (Handler)handlerClass.newInstance();
2348            } catch (Throwable JavaDoc t) {
2349                logger.log(Level.SEVERE, "Unable to load handler class " +
2350                        h.getHandlerClass());
2351                t.printStackTrace();
2352                continue;
2353            }
2354            
2355            // perform injection
2356
try {
2357                new InjectionManagerImpl().injectInstance(handler);
2358            } catch(InjectionException e) {
2359                logger.severe("Handler " + h.getHandlerClass() +
2360                            " instance injection failed : " + e.getMessage());
2361                continue;
2362            }
2363            
2364            // Call @PostConstruct if any
2365
doPostConstruct(handlerClass, handler);
2366            
2367            // Add soap-roles
2368
Collection JavaDoc<String JavaDoc> rolesColl = h.getSoapRoles();
2369            roles.addAll(rolesColl);
2370            
2371            // Add this handler to the mail list
2372
handlerChain.add(handler);
2373        }
2374        return handlerChain;
2375    }
2376    
2377    public void configureJAXWSServiceHandlers(WebServiceEndpoint ep, RuntimeEndpointInfo jaxwsInfo) {
2378        // No handler chains; do nothing
2379
if(!ep.hasHandlerChain()) {
2380            return;
2381        }
2382        LinkedList JavaDoc handlerChainList = ep.getHandlerChain();
2383        List JavaDoc<Handler> finalHandlerList = new ArrayList JavaDoc<Handler>();
2384        Set JavaDoc<String JavaDoc> roles = new HashSet JavaDoc();
2385        String JavaDoc bindingId =
2386                ((com.sun.xml.ws.binding.BindingImpl)jaxwsInfo.getBinding()).getBindingId();
2387        for(Iterator JavaDoc<WebServiceHandlerChain> i = handlerChainList.iterator(); i.hasNext();) {
2388            WebServiceHandlerChain hc = i.next();
2389            
2390            // Apply the serviceName / portName / bindings filter to ensure
2391
// that the handlers are for this endpoint
2392
if(!patternsMatch(hc, ep.getServiceName(), ep.getWsdlPort(), bindingId)) {
2393                continue;
2394            }
2395
2396            // OK - this handler has to be configured for this endpoint
2397
// Iterate through all handlers that have been configured
2398
List JavaDoc<Handler> handlerInfo = processConfiguredHandlers(hc.getHandlers(), roles);
2399            finalHandlerList.addAll(handlerInfo);
2400        }
2401        // Processing of all handlers over;
2402
// set final list of handler in RuntimeEndpointInfo
2403
jaxwsInfo.getBinding().setHandlerChain(finalHandlerList);
2404        // Set soap roles for soap bindings only
2405
if(jaxwsInfo.getBinding() instanceof javax.xml.ws.soap.SOAPBinding) {
2406            ((javax.xml.ws.soap.SOAPBinding)jaxwsInfo.getBinding()).setRoles(roles);
2407        }
2408    }
2409    
2410    public void configureJAXWSClientHandlers(javax.xml.ws.Service svcClass, ServiceReferenceDescriptor desc) {
2411
2412        // Create a resolver and get all ports for the Service
2413

2414    // configure client-side message layer security.
2415
// if a resolver is returned, security will be injected via a
2416
// jaxrpc handler
2417
HandlerResolverImpl resolver =
2418        JAXWSSystemHandlerDelegateFactory.getHandlerResolverImpl(svcClass,desc);
2419    
2420    if (resolver == null) {
2421        // otherwise, a SystemHandlerDelegate willbe used;
2422
// in which case, no need to construct a resolver if
2423
// f no handlers are configured
2424
if (desc.hasHandlerChain()) {
2425        resolver = new HandlerResolverImpl();
2426        } else {
2427        return;
2428        }
2429    }
2430
2431        Set JavaDoc<String JavaDoc> roles = new HashSet JavaDoc();
2432        
2433        Iterator JavaDoc<QName JavaDoc> ports = svcClass.getPorts();
2434
2435        // Set handler chain for each port of this service
2436
while(ports.hasNext()) {
2437            QName JavaDoc nextPort = ports.next();
2438            LinkedList JavaDoc handlerChainList = desc.getHandlerChain();
2439            for(Iterator JavaDoc<WebServiceHandlerChain> i = handlerChainList.iterator(); i.hasNext();) {
2440                WebServiceHandlerChain hc = i.next();
2441                // Apply the serviceName / portName filter to ensure
2442
// that the handlers are for this service and this port
2443
if(!patternsMatch(hc, desc.getServiceName(), nextPort, null)) {
2444                    continue;
2445                }
2446                // Decide for what all protocols this handler should be applied
2447
ArrayList JavaDoc<String JavaDoc> protocols = new ArrayList JavaDoc<String JavaDoc>();
2448                if(hc.getProtocolBindings() == null) {
2449                    // No protocol bindings given in descriptor; apply this handler
2450
// for all protocols
2451
protocols.add(SOAP11_TOKEN);
2452                    protocols.add(SOAP12_TOKEN);
2453                    protocols.add(SOAP11_MTOM_TOKEN);
2454                    protocols.add(SOAP12_MTOM_TOKEN);
2455                    protocols.add(XML_TOKEN);
2456                    protocols.add(HTTPBinding.HTTP_BINDING);
2457                    protocols.add(SOAPBinding.SOAP11HTTP_BINDING);
2458                    protocols.add(SOAPBinding.SOAP12HTTP_BINDING);
2459                    protocols.add(SOAPBinding.SOAP11HTTP_MTOM_BINDING);
2460                    protocols.add(SOAPBinding.SOAP12HTTP_MTOM_BINDING);
2461                } else {
2462                    // protocols specified; handlers are for only these protocols
2463
String JavaDoc specifiedProtocols = hc.getProtocolBindings();
2464                    if((specifiedProtocols.indexOf(HTTPBinding.HTTP_BINDING) != -1) ||
2465                         (specifiedProtocols.indexOf(XML_TOKEN) != -1)) {
2466                        protocols.add(XML_TOKEN);
2467                        protocols.add(HTTPBinding.HTTP_BINDING);
2468                    }
2469                    if((specifiedProtocols.indexOf(SOAPBinding.SOAP11HTTP_BINDING) != -1) ||
2470                         (specifiedProtocols.indexOf(SOAP11_TOKEN) != -1)) {
2471                        protocols.add(SOAP11_TOKEN);
2472                        protocols.add(SOAPBinding.SOAP11HTTP_BINDING);
2473                    }
2474                    if((specifiedProtocols.indexOf(SOAPBinding.SOAP12HTTP_BINDING) != -1) ||
2475                         (specifiedProtocols.indexOf(SOAP12_TOKEN) != -1)) {
2476                        protocols.add(SOAP12_TOKEN);
2477                        protocols.add(SOAPBinding.SOAP12HTTP_BINDING);
2478                    }
2479                    if((specifiedProtocols.indexOf(SOAPBinding.SOAP11HTTP_MTOM_BINDING) != -1) ||
2480                         (specifiedProtocols.indexOf(SOAP11_MTOM_TOKEN) != -1)) {
2481                        protocols.add(SOAP11_MTOM_TOKEN);
2482                        protocols.add(SOAPBinding.SOAP11HTTP_MTOM_BINDING);
2483                    }
2484                    if((specifiedProtocols.indexOf(SOAPBinding.SOAP12HTTP_MTOM_BINDING) != -1) ||
2485                         (specifiedProtocols.indexOf(SOAP12_MTOM_TOKEN) != -1)) {
2486                        protocols.add(SOAP12_MTOM_TOKEN);
2487                        protocols.add(SOAPBinding.SOAP12HTTP_MTOM_BINDING);
2488                    }
2489                }
2490                // Iterate through all handlers that have been configured
2491
List JavaDoc<WebServiceHandler> handlersList = hc.getHandlers();
2492                // From this list, remove those handlers that have port-name that is different
2493
// than the current port
2494
for(WebServiceHandler thisOne : handlersList) {
2495                    Collection JavaDoc portNames = thisOne.getPortNames();
2496                    if(!portNames.isEmpty() &&
2497                        !portNames.contains(nextPort.getLocalPart())) {
2498                        handlersList.remove(thisOne);
2499                    }
2500                }
2501                // Now you have the handlers that need to be added; process them
2502
List JavaDoc<Handler> handlerInfo = processConfiguredHandlers(handlersList, roles);
2503                // Now you have the handler list; Set it in resolver;
2504
// one set for each protocol
2505
for(Iterator JavaDoc<String JavaDoc> s = protocols.iterator(); s.hasNext();) {
2506                    javax.xml.ws.handler.PortInfo portInfo =
2507                            new PortInfoImpl(s.next(), nextPort, desc.getServiceName());
2508                    resolver.setHandlerChain(portInfo, handlerInfo);
2509                }
2510            }
2511        }
2512        // Now that processing of all handlers is over, set HandlerResolver for
2513
// the service
2514

2515    // SecurityHandlers will be lazily bound within the resolver -
2516
// when a handler chain for a port is requested; thus we must
2517
// set the resolver, even if no handlers are defined by the
2518
// application.
2519

2520        svcClass.setHandlerResolver(resolver);
2521        
2522        //XXX TODO : What to do with soap roles on client side ?
2523
}
2524
2525    /* This util is to implement the jaxws table that defines how MTOM is set
2526    *
2527    * BindingType - enable-mtom in DD - final MTOM value
2528    *
2529    * SOAPXX_BINDING none false
2530    * SOAPXX_BINDING false false
2531    * SOAPXX_BINDING true true
2532    * SOAPXX_MTOM_BINDING none true
2533    * SOAPXX_MTOM_BINDING false false
2534    * SOAPXX_MTOM_BINDING true true
2535    */

2536    public void setMtom(javax.xml.ws.Binding bnd, WebServiceEndpoint ep) {
2537        String JavaDoc currentBinding = ep.getProtocolBinding();
2538        if((ep.getMtomEnabled() == null) &&
2539            (SOAPBinding.SOAP11HTTP_MTOM_BINDING.equals(currentBinding) ||
2540             SOAPBinding.SOAP12HTTP_MTOM_BINDING.equals(currentBinding) ||
2541             SOAP11_MTOM_TOKEN.equals(currentBinding) ||
2542             SOAP12_MTOM_TOKEN.equals(currentBinding))) {
2543            ((SOAPBinding)bnd).setMTOMEnabled(true);
2544        }
2545        if((new Boolean JavaDoc(ep.getMtomEnabled())).booleanValue() &&
2546            (SOAPBinding.SOAP11HTTP_BINDING.equals(currentBinding) ||
2547             SOAPBinding.SOAP12HTTP_BINDING.equals(currentBinding) ||
2548             SOAP11_TOKEN.equals(currentBinding) ||
2549             SOAP12_TOKEN.equals(currentBinding) ||
2550             SOAPBinding.SOAP11HTTP_MTOM_BINDING.equals(currentBinding) ||
2551             SOAPBinding.SOAP12HTTP_MTOM_BINDING.equals(currentBinding) ||
2552             SOAP11_MTOM_TOKEN.equals(currentBinding) ||
2553             SOAP12_MTOM_TOKEN.equals(currentBinding))) {
2554            ((SOAPBinding)bnd).setMTOMEnabled(true);
2555        }
2556    }
2557    
2558    // Used by the message layer security subsystem to get an efficient
2559
// representation of the contained message from the SOAPMessageContext.
2560
// when called by jaxrpc Hander or SystemHandlerDelegate
2561
public static SOAPMessage JavaDoc getMessage
2562    (javax.xml.rpc.handler.soap.SOAPMessageContext JavaDoc c) {
2563    // TODO
2564
return c.getMessage();
2565    }
2566
2567    private static boolean readProperty = true;
2568    private static ExpressMessageFactoryImpl soapMsgFactory = null;
2569    private static final String JavaDoc EXPRESS_MSG_FACTORY =
2570        "com.sun.enterprise.webservice.expressMsgFactory";
2571
2572    private static SOAPMessage JavaDoc getFactoryMessage
2573    (com.sun.xml.ws.spi.runtime.SOAPMessageContext c, boolean nameKnown) {
2574
2575    synchronized (WsUtil.class) {
2576        if (readProperty) {
2577        try {
2578            soapMsgFactory = (ExpressMessageFactoryImpl)
2579            java.security.AccessController.doPrivileged
2580            (new java.security.PrivilegedExceptionAction JavaDoc() {
2581                public Object JavaDoc run() throws Exception JavaDoc {
2582                ExpressMessageFactoryImpl emfi = null;
2583                if (System.getProperty
2584                    (EXPRESS_MSG_FACTORY) != null) {
2585                    emfi = new ExpressMessageFactoryImpl();
2586                }
2587                return emfi;
2588                }
2589            });
2590        } catch (Exception JavaDoc e) {
2591            // exception thrown while reading property or
2592
// creating factory; disable factory
2593
soapMsgFactory = null;
2594        }
2595        readProperty = false;
2596        }
2597    }
2598     
2599    SOAPMessage JavaDoc message = null;
2600
2601    if (soapMsgFactory != null) {
2602        try {
2603        message = soapMsgFactory.createMessage(c,nameKnown);
2604        } catch (Exception JavaDoc e) {
2605        // exception thrown by factory
2606
message = null;
2607        }
2608    }
2609
2610    // returns null if factory was not enabled
2611
// or problem occurs when trying to get a
2612
// message from it
2613

2614    return message;
2615    }
2616
2617    // when called by jaxws Hander or SystemHandlerDelegate
2618
// 2nd parameter should be true if you don't need to
2619
// peek into the message for operationName
2620
private static synchronized SOAPMessage JavaDoc getMessage
2621    (javax.xml.ws.handler.soap.SOAPMessageContext c, boolean nameKnown) {
2622
2623    SOAPMessage JavaDoc message = null;
2624    
2625    if (c instanceof com.sun.xml.ws.spi.runtime.SOAPMessageContext) {
2626
2627        com.sun.xml.ws.spi.runtime.SOAPMessageContext spiC =
2628        (com.sun.xml.ws.spi.runtime.SOAPMessageContext) c;
2629
2630        if (spiC.isAlreadySoap()) {
2631        message = spiC.getMessage();
2632        } else {
2633        message = getFactoryMessage(spiC,nameKnown);
2634        }
2635    }
2636    // handle else case, and try to avoid returning null message
2637
if (message == null) {
2638        message = c.getMessage();
2639    }
2640    
2641    return message;
2642    }
2643    
2644    // when called by jaxws Hander or SystemHandlerDelegate
2645
public static synchronized SOAPMessage JavaDoc getMessage
2646    (javax.xml.ws.handler.soap.SOAPMessageContext c) {
2647    return getMessage(c,true);
2648    }
2649
2650    // when called by jaxws Hander or SystemHandlerDelegate and when
2651
// the operation name must be available from the message
2652
public static synchronized SOAPMessage JavaDoc getMessageWithName
2653    (javax.xml.ws.handler.soap.SOAPMessageContext c) {
2654    return getMessage(c,false);
2655    }
2656}
2657
2658
2659
2660
2661
2662
2663
Popular Tags