KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > ws > AbsWebServicesServiceImpl


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999-2005 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: AbsWebServicesServiceImpl.java,v 1.38 2005/07/28 09:52:22 sauthieg Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.ws;
27
28 import java.io.File JavaDoc;
29 import java.io.IOException JavaDoc;
30 import java.io.UnsupportedEncodingException JavaDoc;
31 import java.net.MalformedURLException JavaDoc;
32 import java.net.URL JavaDoc;
33 import java.net.URLClassLoader JavaDoc;
34 import java.net.URLEncoder JavaDoc;
35 import java.util.ArrayList JavaDoc;
36 import java.util.HashMap JavaDoc;
37 import java.util.Iterator JavaDoc;
38 import java.util.List JavaDoc;
39 import java.util.Map JavaDoc;
40 import java.util.Stack JavaDoc;
41 import java.util.StringTokenizer JavaDoc;
42
43 import javax.management.MBeanServer JavaDoc;
44 import javax.management.MalformedObjectNameException JavaDoc;
45 import javax.management.ObjectName JavaDoc;
46 import javax.naming.Context JavaDoc;
47 import javax.naming.InitialContext JavaDoc;
48 import javax.naming.NamingException JavaDoc;
49 import javax.naming.Reference JavaDoc;
50 import javax.naming.StringRefAddr JavaDoc;
51 import javax.xml.namespace.QName JavaDoc;
52
53 import org.objectweb.jonas_lib.I18n;
54 import org.objectweb.jonas_lib.deployment.api.HandlerDesc;
55 import org.objectweb.jonas_lib.loader.WebappClassLoader;
56 import org.objectweb.jonas_lib.naming.ContainerNaming;
57 import org.objectweb.jonas_lib.naming.factory.URLFactory;
58
59 import org.objectweb.jonas_web.deployment.api.WebContainerDeploymentDesc;
60 import org.objectweb.jonas_web.deployment.api.WebContainerDeploymentDescException;
61 import org.objectweb.jonas_web.deployment.lib.wrapper.WebManagerWrapper;
62
63 import org.objectweb.jonas_ws.deployment.api.JaxRpcPortComponentDesc;
64 import org.objectweb.jonas_ws.deployment.api.PortComponentDesc;
65 import org.objectweb.jonas_ws.deployment.api.SSBPortComponentDesc;
66 import org.objectweb.jonas_ws.deployment.api.ServiceDesc;
67 import org.objectweb.jonas_ws.deployment.api.WSDLFile;
68 import org.objectweb.jonas_ws.deployment.api.WSDeploymentDesc;
69 import org.objectweb.jonas_ws.deployment.api.WSDeploymentDescException;
70 import org.objectweb.jonas_ws.deployment.lib.wrapper.WSManagerWrapper;
71
72 import org.objectweb.jonas.common.JProp;
73 import org.objectweb.jonas.common.Log;
74 import org.objectweb.jonas.ear.EarServiceImpl;
75 import org.objectweb.jonas.jmx.J2eeObjectName;
76 import org.objectweb.jonas.jmx.JmxService;
77 import org.objectweb.jonas.naming.CompNamingContext;
78 import org.objectweb.jonas.naming.NamingManager;
79 import org.objectweb.jonas.service.AbsServiceImpl;
80 import org.objectweb.jonas.service.ServiceException;
81 import org.objectweb.jonas.service.ServiceManager;
82 import org.objectweb.jonas.web.JWebContainerService;
83 import org.objectweb.jonas.web.JWebContainerServiceException;
84 import org.objectweb.jonas.ws.handler.WSDLHandler;
85 import org.objectweb.jonas.ws.handler.WSDLHandlerFactory;
86 import org.objectweb.jonas.ws.mbean.Handler;
87 import org.objectweb.jonas.ws.mbean.PortComponent;
88 import org.objectweb.jonas.ws.mbean.Service;
89 import org.objectweb.jonas.ws.mbean.WebServicesObjectName;
90
91 import org.objectweb.util.monolog.api.BasicLevel;
92 import org.objectweb.util.monolog.api.Logger;
93
94 /**
95  * implements deployment process and declares commons abstract methods for all
96  * (used) Web services engine. Actually we consider Glue and AXIS.
97  * @author Guillaume Sauthier
98  * @author Xavier Delplanque
99  */

100 public abstract class AbsWebServicesServiceImpl extends AbsServiceImpl implements WebServicesService,
101         AbsWebServicesServiceImplMBean {
102
103     /**
104      * WebServices service configuration properties : Xml parsing with
105      * validation
106      */

107     public static final String JavaDoc PARSINGWITHVALIDATION = "jonas.service.ws.parsingwithvalidation";
108
109     /** WebServices service configuration properties : WSDL handlers */
110     public static final String JavaDoc WSDL_HANDLERS = "jonas.service.ws.wsdlhandlers";
111
112     /**
113      * WebServices service configuration properties : base for web services
114      * properties.
115      */

116     public static final String JavaDoc WS_BASE = "jonas.service.ws.";
117
118
119
120     /** Logger for this service. */
121     private static Logger logger = null;
122
123     /** Internationalization tool */
124     private static I18n i18n = I18n.getInstance(AbsWebServicesServiceImpl.class);
125
126     /** Manager for WSDL files publishing. */
127     private WSDLManager wsdlManager = null;
128
129     /** Reference to the web container service */
130     private JWebContainerService webService = null;
131
132     /** JMX Server */
133     private MBeanServer JavaDoc mbeanServer = null;
134
135     /**
136      * Map of deployments descriptor (ClassLoader -> Stack)
137      */

138     private Map JavaDoc deployments = null;
139
140     /**
141      * Map of warURL -> WebServices
142      */

143     private Map JavaDoc webservicesMBeans = null;
144
145     /**
146      * Initialize the service.
147      * @param ctx the configuration context of the service.
148      * @throws ServiceException if the initialization failed.
149      */

150     protected void doInit(Context JavaDoc ctx) throws ServiceException {
151         // Init the logger
152
logger = Log.getLogger(Log.JONAS_WS_PREFIX);
153
154
155         ServiceManager serviceManager = null;
156         try {
157             serviceManager = ServiceManager.getInstance();
158         } catch (Exception JavaDoc e) {
159             throw new ServiceException("Cannot initialize the WebServices Service", e);
160         }
161
162         // Init variables
163
deployments = new HashMap JavaDoc();
164         webservicesMBeans = new HashMap JavaDoc();
165
166         // Set the XML parsing mode to no validation
167
String JavaDoc parsingMode = "false";
168
169         try {
170             parsingMode = (String JavaDoc) ctx.lookup(PARSINGWITHVALIDATION);
171         } catch (NamingException JavaDoc e) {
172             // No problem if there is no value for 'parsingwithvalidation'
173
// (false by default)
174
parsingMode = "false";
175         }
176
177         WSManagerWrapper.setParsingWithValidation("true".equalsIgnoreCase(parsingMode));
178
179         if ("false".equalsIgnoreCase(parsingMode)) {
180             logger.log(BasicLevel.DEBUG, "WebServices XML parsing without validation");
181         } else {
182             logger.log(BasicLevel.DEBUG, "WebServices XML parsing with validation");
183         }
184
185         try {
186             // Get the JMX Server via JMX Service
187
JmxService jmxService = (JmxService) serviceManager.getJmxService();
188             mbeanServer = jmxService.getJmxServer();
189         } catch (ServiceException e) {
190             // the JMX service may not be started
191
mbeanServer = null;
192         }
193
194         // Init the wsdl Manager
195
wsdlManager = new WSDLManager();
196
197         // Get publishing parameters in jonas properties
198
JProp jp = null;
199
200         try {
201             jp = JProp.getInstance();
202         } catch (Exception JavaDoc e) {
203             String JavaDoc err = i18n.getMessage("AbsWebServicesServiceImpl.doInit.noJProp");
204             logger.log(BasicLevel.ERROR, err + " " + e.getMessage());
205             throw new WSServiceException(err, e);
206         }
207
208         String JavaDoc[] handlers = jp.getValueAsArray(WSDL_HANDLERS);
209
210         if (handlers == null) {
211             String JavaDoc err = i18n.getMessage("AbsWebServicesServiceImpl.doInit.noHandlers", WSDL_HANDLERS);
212             logger.log(BasicLevel.ERROR, err);
213             throw new WSServiceException(err);
214         }
215
216         // Build WSDLHandlers
217

218         WSDLHandlerFactory factory = WSDLHandlerFactory.newInstance();
219
220         // build each specified handlers and add it in the WSDLManager.
221
for (int i = 0; i < handlers.length; i++) {
222
223             // Create the handler
224
WSDLHandler handler = factory.newHandler(handlers[i]);
225
226             if (logger.isLoggable(BasicLevel.DEBUG)) {
227                 logger.log(BasicLevel.DEBUG, "Adding WSDLHandler '" + handlers[i] + "'");
228             }
229
230             // Add the created Handler
231
wsdlManager.addHandler(handler);
232         }
233     }
234
235     /**
236      * Get, update and publish WSDL documents contained in a set of jars and
237      * wars.
238      * @param ctx the context containing the configuration to deploy the wars.
239      * <BR>This context contains the following parameters :<BR>-
240      * jarUrls the list of the urls of the jars to deploy. <BR>- warUrls
241      * the list of the urls of the wars to deploy. <BR>- ejbClassLoader
242      * the classLoader of the ejbs(used for webapps too). <BR>-
243      * earClassLoader the ear classLoader of the j2ee app. <BR>-
244      * warCtxRootMapping the webapps contextRoots with associated war
245      * name. <BR>- unpackDir the directory where EAR has been unpacked
246      * (optionnal for pure webapp webservices).
247      * @throws WSServiceException if an error occurs during the deployment.
248      */

249     public void deployWebServices(Context JavaDoc ctx) throws WSServiceException {
250         /**
251          * For each Jar/WarUrls in the given ctx : - Get the jar/war deployment
252          * desc - Get the WSDL definition - Update the WSDL location - Publish
253          * the WSDL
254          */

255
256         // Cannot get webContainer at startup (cycles)
257
if (webService == null) {
258             try {
259                 webService = (JWebContainerService) ServiceManager.getInstance().getWebContainerService();
260             } catch (Exception JavaDoc e) {
261                 String JavaDoc err = i18n.getMessage("AbsWebServicesServiceImpl.deployWebServices.noWeb");
262                 logger.log(BasicLevel.ERROR, err);
263                 throw new WSServiceException(err, e);
264             }
265         }
266
267         // Get context parameters.
268
URL JavaDoc[] jarUrls = null;
269         URL JavaDoc[] warUrls = null;
270         URL JavaDoc earURL = null;
271         ClassLoader JavaDoc ejbClassLoader = null;
272         ClassLoader JavaDoc earClassLoader = null;
273         Map JavaDoc warCtxRootMapping = null;
274         String JavaDoc unpackDir = null;
275
276         // EAR & Webapp case common information
277
try {
278             jarUrls = (URL JavaDoc[]) ctx.lookup("jarUrls");
279             warUrls = (URL JavaDoc[]) ctx.lookup("warUrls");
280             unpackDir = (String JavaDoc) ctx.lookup("unpackDir");
281         } catch (NamingException JavaDoc e) {
282             String JavaDoc err = i18n.getMessage("AbsWebServicesServiceImpl.deployWebServices.ctxParamProblem");
283             logger.log(BasicLevel.ERROR, err + e.getMessage());
284             throw new WSServiceException(err, e);
285         }
286
287         // EAR case specific information
288
try {
289             earURL = (URL JavaDoc) ctx.lookup("earURL");
290             earClassLoader = (ClassLoader JavaDoc) ctx.lookup("earClassLoader");
291             warCtxRootMapping = (Map JavaDoc) ctx.lookup("warCtxRootMapping");
292             ejbClassLoader = (ClassLoader JavaDoc) ctx.lookup("ejbClassLoader");
293         } catch (NamingException JavaDoc ne) {
294             // WebApp case
295
earURL = null;
296             earClassLoader = null;
297             warCtxRootMapping = null;
298             ejbClassLoader = null;
299         }
300
301         // Deploy wars Web services.
302
URLClassLoader JavaDoc loaderForCls = null;
303         String JavaDoc earAppName = null;
304         if (earURL != null) {
305             earAppName = EarServiceImpl.buildJ2eeApplicationName(earURL);
306         }
307
308         String JavaDoc fileName = null;
309         WSDeploymentDesc wsDD = null;
310
311         for (int i = 0; i < warUrls.length; i++) {
312             // Get the name of a war to deploy.
313
fileName = warUrls[i].getFile();
314             logger.log(BasicLevel.DEBUG, "Analyzing war '" + fileName + "' for web services");
315
316             // Get the class loader for the current war.
317
loaderForCls = webService.getClassLoader(warUrls[i], earAppName, ejbClassLoader);
318
319             WebappClassLoader webLoader = (WebappClassLoader) loaderForCls;
320             URL JavaDoc url = webLoader.getBaseURL();
321
322             // Get the deployment descriptor from file.
323
try {
324                 wsDD = WSManagerWrapper.getDeploymentDesc(warUrls[i], url, loaderForCls, earClassLoader);
325             } catch (WSDeploymentDescException wsdde) {
326                 String JavaDoc err = i18n.getMessage("AbsWebServicesServiceImpl.deployWebServices.wsddEx", fileName);
327                 logger.log(BasicLevel.ERROR, err + ": " + wsdde);
328                 throw new WSServiceException(err, wsdde);
329             }
330
331             if (wsDD != null) {
332                 // The current War contains Webservices
333
try {
334                     Context JavaDoc compCtx = new CompNamingContext(fileName);
335                     compCtx.rebind("wsDD", wsDD);
336                     compCtx.rebind("cl", loaderForCls);
337
338                     if (earClassLoader != null) {
339                         compCtx.rebind("earCL", earClassLoader);
340                     }
341                     compCtx.rebind("warURL", warUrls[i]);
342
343                     // ear case
344
if (warCtxRootMapping != null) {
345                         compCtx.rebind("warContextRoot", warCtxRootMapping.get(warUrls[i]));
346
347                         // non-ear case
348
} else {
349                         compCtx.rebind("warContextRoot", "");
350                     }
351
352                     doDeployWebServices(compCtx);
353                 } catch (NamingException JavaDoc ne) {
354                     String JavaDoc err = i18n.getMessage("AbsWebServicesServiceImpl.deployWebServices.bindError", fileName);
355                     logger.log(BasicLevel.ERROR, err);
356                     throw new WSServiceException(err, ne);
357                 }
358             }
359         }
360         // End deploy wars Web services.
361

362         // Deploy jars Web services.
363
// Check warCtxRootMapping presence
364
if ((jarUrls.length != 0) && (warCtxRootMapping == null)) {
365             String JavaDoc err = i18n.getMessage("AbsWebServicesServiceImpl.deployWebServices.ctxRootMappingMissing");
366             logger.log(BasicLevel.ERROR, err);
367             throw new WSServiceException(err);
368         }
369
370         for (int i = 0; i < jarUrls.length; i++) {
371             // Get the name of a war to deploy.
372
fileName = jarUrls[i].getFile();
373             logger.log(BasicLevel.DEBUG, "Analyzing EjbJar '" + fileName + "' for web services");
374
375             URLClassLoader JavaDoc webClassLoader = null;
376
377             // Get the deployment descriptor from file.
378
try {
379                 wsDD = WSManagerWrapper.getDeploymentDesc(jarUrls[i], ejbClassLoader, earClassLoader);
380             } catch (WSDeploymentDescException wsdde) {
381                 String JavaDoc err = i18n.getMessage("AbsWebServicesServiceImpl.deployWebServices.wsddEx", fileName);
382                 logger.log(BasicLevel.ERROR, err + ": " + wsdde);
383                 throw new WSServiceException(err, wsdde);
384             }
385
386             if (wsDD != null) {
387                 // The current Jar contains Webservices
388
URL JavaDoc warURL = null;
389
390                 try {
391                     /**
392                      * Default Naming Convention for Webapp linked to Ejb
393                      * <ejb-name>.jar -> <ejb-name>.war
394                      */

395                     if (wsDD.getWarFile() != null) {
396                         // use getCanonicalFile to fix Bug #300658
397
//new File(new URL(dirName + File.separator + s).getFile()).getCanonicalFile().toURL();
398
warURL = new File JavaDoc(new URL JavaDoc(unpackDir + File.separator + wsDD.getWarFile()).getFile()).getCanonicalFile().toURL();
399                         //warURL = new URL(unpackDir + "/" + wsDD.getWarFile());
400
} else {
401                         String JavaDoc ejb = new File JavaDoc(jarUrls[i].getFile()).getName();
402                         String JavaDoc war = ejb.substring(0, ejb.length() - ".jar".length());
403                         //warURL = new URL(unpackDir + "/" + war + ".war");
404
warURL = new File JavaDoc(new URL JavaDoc(unpackDir + File.separator + war + ".war").getFile()).getCanonicalFile().toURL();
405                     }
406                     logger.log(BasicLevel.DEBUG, "Unpack Dir : " + unpackDir);
407                     logger.log(BasicLevel.DEBUG, "Computed URL : " + warURL);
408
409                     // check if webapp is present
410
boolean present = false;
411
412                     for (int w = 0; w < warUrls.length; w++) {
413                         if (warUrls[w].equals(warURL)) {
414                             present = true;
415                         }
416                         logger.log(BasicLevel.DEBUG, "warUrls[" + w + "]=" + warUrls[w]);
417                     }
418
419                     // get the linked web classloader
420
webClassLoader = webService.getClassLoader(warURL, earAppName, ejbClassLoader);
421
422                     if (!present) {
423                         String JavaDoc err = i18n.getMessage("AbsWebServicesServiceImpl.deployWebServices.webappNotFound",
424                                 warURL);
425                         logger.log(BasicLevel.ERROR, err);
426                         throw new WSServiceException(err);
427                     }
428                 } catch (MalformedURLException JavaDoc mue) {
429                     String JavaDoc err = i18n.getMessage("AbsWebServicesServiceImpl.deployWebServices.mue");
430                     logger.log(BasicLevel.ERROR, mue.getMessage());
431                     throw new WSServiceException(err, mue);
432                 } catch (IOException JavaDoc ioe) {
433                     // TODO add i18n
434
String JavaDoc err = "Cannot locate file : " + ioe.getMessage();
435                     logger.log(BasicLevel.ERROR, err);
436                     throw new WSServiceException(err, ioe);
437                 }
438
439                 try {
440                     Context JavaDoc compCtx = new CompNamingContext(fileName);
441                     compCtx.rebind("wsDD", wsDD);
442
443                     // Using WebClassLoader ()
444
compCtx.rebind("cl", webClassLoader);
445                     compCtx.rebind("earCL", earClassLoader);
446
447                     compCtx.rebind("warURL", warURL);
448
449                     // warContextRoot cannot be null in ejb case
450
// because an ejb needs a webapp for webservices
451
compCtx.rebind("warContextRoot", warCtxRootMapping.get(warURL));
452                     doDeployWebServices(compCtx);
453                 } catch (NamingException JavaDoc ne) {
454                     String JavaDoc err = i18n.getMessage("AbsWebServicesServiceImpl.deployWebServices.bindError", fileName);
455                     logger.log(BasicLevel.ERROR, err);
456                     throw new WSServiceException(err, ne);
457                 }
458             }
459         }
460
461         // End deploy jars Web services.
462
}
463
464     /**
465      * Deploy the given Web services.
466      * @param ctx Context used for parameter passing.
467      * @throws WSServiceException when error occurs.
468      */

469     protected void doDeployWebServices(Context JavaDoc ctx) throws WSServiceException {
470         /**
471          * Context structure : - wsDD Web Services deployment descriptor. - cl
472          * Module ClassLoader - earCL Application ClassLoader - warContextRoot
473          * the context-root of the war (null in ejb case) - warURL the url of
474          * war dispatching SOAP requests
475          */

476         WSDeploymentDesc wsDD = null;
477         ClassLoader JavaDoc cl = null;
478         ClassLoader JavaDoc earCL = null;
479         String JavaDoc warContextRoot = null;
480         URL JavaDoc warURL = null;
481
482         try {
483             wsDD = (WSDeploymentDesc) ctx.lookup("wsDD");
484             cl = (ClassLoader JavaDoc) ctx.lookup("cl");
485             warContextRoot = (String JavaDoc) ctx.lookup("warContextRoot");
486             warURL = (URL JavaDoc) ctx.lookup("warURL");
487         } catch (NamingException JavaDoc ne) {
488             String JavaDoc err = i18n.getMessage("AbsWebServicesServiceImpl.doDeployWebServices.namingError");
489             logger.log(BasicLevel.ERROR, err);
490             throw new WSServiceException(err, ne);
491         }
492
493         if (logger.isLoggable(BasicLevel.DEBUG)) {
494             logger.log(BasicLevel.DEBUG, "Deploying WebServices for '" + warURL + "'");
495         }
496
497         try {
498             earCL = (ClassLoader JavaDoc) ctx.lookup("earCL");
499         } catch (NamingException JavaDoc ne) {
500             // Nothing to do : non EAR case
501
earCL = null;
502         }
503
504         // store WSDeployInfo for later use (completeWSDeployment method)
505
ClassLoader JavaDoc key = cl;
506         if (earCL != null) {
507             key = earCL;
508         }
509         Stack JavaDoc s = (Stack JavaDoc) deployments.get(key);
510         if (s == null) {
511             s = new Stack JavaDoc();
512             deployments.put(key, s);
513         }
514         s.push(new WSDeployInfo(warURL, wsDD));
515
516
517         List JavaDoc sds = wsDD.getServiceDescs();
518
519         // for each WSDL contained in the component
520
for (Iterator JavaDoc i = sds.iterator(); i.hasNext();) {
521             ServiceDesc sd = (ServiceDesc) i.next();
522             WSDLFile wsdl = sd.getWSDL();
523
524             // get the endpoint URL for each port-component
525
// update the WSDL Definition
526
for (Iterator JavaDoc pc = sd.getPortComponents().iterator(); pc.hasNext();) {
527                 PortComponentDesc pcd = (PortComponentDesc) pc.next();
528                 QName JavaDoc portQName = pcd.getQName();
529                 URL JavaDoc endpoint = null;
530                 if (pcd.hasJaxRpcImpl()) {
531                     endpoint = getEndpointURL(wsDD, (JaxRpcPortComponentDesc) pcd, warURL, warContextRoot);
532                 } else {
533                     endpoint = getEndpointURL(wsDD, (SSBPortComponentDesc) pcd, warURL, cl, earCL, warContextRoot);
534                 }
535
536                 pcd.setEndpointURL(endpoint);
537                 wsdl.setLocation(portQName, endpoint);
538
539                 // add endpoint URL into JNDI namespace to allow application
540
// clients (that are not running in the same JVM) to use
541
// port-component-link
542
Context JavaDoc registry;
543                 try {
544                     registry = new InitialContext JavaDoc();
545                     Reference JavaDoc urlRef = new Reference JavaDoc(URL JavaDoc.class.getName(), URLFactory.class.getName(), null);
546                     urlRef.add(new StringRefAddr JavaDoc("url", endpoint.toString()));
547                     registry.rebind(pcd.getName(), urlRef);
548                     logger.log(BasicLevel.DEBUG, "Bind updated URL (" + endpoint + ") in " + pcd.getName());
549                 } catch (NamingException JavaDoc ne) {
550                     throw new WSServiceException("Cannot bind updated URL for port-component '" + pcd.getName()
551                             + "'", ne);
552                 }
553
554             }
555
556             // publish WSDL
557
wsdlManager.publish(sd);
558         }
559     }
560
561     /**
562      * Creates and adds all nested Handlers in the parent PortComponent.
563      * @param pcMBean parent PortComponent MBean
564      * @param pcd PortComponent Descriptor
565      */

566     private void addHandlerMBeansToPortComponent(PortComponent pcMBean, PortComponentDesc pcd) {
567
568         // iterates over the HandlerDesc list
569
for (Iterator JavaDoc i = pcd.getHandlers().iterator(); i.hasNext();) {
570             HandlerDesc hd = (HandlerDesc) i.next();
571
572             // creates the Handler MBean, and automatically
573
// add it to the PortComponent
574
Handler hMBean = createHandlerMBean(hd.getName(), pcMBean);
575
576             hMBean.setClassname(hd.getHandlerClassName());
577             hMBean.setName(hd.getName());
578             // soap-headers
579
List JavaDoc sh = hd.getSOAPHeaders();
580             // transform QName to String
581
String JavaDoc[] headers = new String JavaDoc[sh.size()];
582             int index = 0;
583             for (Iterator JavaDoc j = sh.iterator(); j.hasNext();) {
584                 // Stringify the QName
585
headers[index++] = ((QName JavaDoc) j.next()).toString();
586             }
587             hMBean.setSoapHeaders(headers);
588             // soap-roles
589
List JavaDoc sr = hd.getSOAPRoles();
590             hMBean.setSoapRoles((String JavaDoc[]) sr.toArray(new String JavaDoc[sr.size()]));
591
592             hMBean.setInitParams(hd.getInitParams());
593
594         }
595
596     }
597
598     /**
599      * @param name Handler name
600      * @param parent parent PortComponent
601      * @return Returns the creates Handler MBean
602      */

603     private static Handler createHandlerMBean(String JavaDoc name, PortComponent parent) {
604         Handler h = null;
605         try {
606             h = new Handler(WebServicesObjectName.handler(name, parent.getRealObjectName()).toString());
607         } catch (MalformedObjectNameException JavaDoc e) {
608             // should never happen
609
logger.log(BasicLevel.DEBUG, "Should never happen", e);
610         }
611         // add to the parent
612
parent.addHandlerMBean(h);
613         return h;
614     }
615
616     /**
617      * @param name PortComponent name
618      * @param parent parent Service
619      * @return Returns the created PortComponent MBean
620      */

621     private static PortComponent createPortComponentMBean(String JavaDoc name, Service parent) {
622         PortComponent pc = null;
623         try {
624             pc = new PortComponent(WebServicesObjectName.portComponent(name, parent.getRealObjectName()).toString());
625         } catch (MalformedObjectNameException JavaDoc e) {
626             // should never happen
627
logger.log(BasicLevel.DEBUG, "Should never happen", e);
628         }
629         // add to the parent
630
parent.addPortComponentMBean(pc);
631         return pc;
632     }
633
634     /**
635      * @param name Service name
636      * @param parent parent WebServices
637      * @return Returns the created Service MBean
638      */

639     private static Service createServiceMBean(String JavaDoc name, ObjectName JavaDoc parent) {
640         Service service = null;
641         try {
642             service = new Service(WebServicesObjectName.service(name, parent).toString());
643         } catch (MalformedObjectNameException JavaDoc e) {
644             // should never happen
645
logger.log(BasicLevel.DEBUG, "Should never happen", e);
646         }
647         return service;
648     }
649
650     /**
651      * Creates the endpointURL of a given PortComponentDesc.
652      * @param wsDD webservices.xml
653      * @param jpcd JaxRpcPortComponentDesc to analyze
654      * @param warURL URL of the war file containing the PortComponent
655      * @param contextRoot context-root of the webapp
656      * @return the endpointURL of a given PortComponentDesc.
657      * @throws WSServiceException When URL cannot be constructed.
658      */

659     private URL JavaDoc getEndpointURL(WSDeploymentDesc wsDD, JaxRpcPortComponentDesc jpcd, URL JavaDoc warURL, String JavaDoc contextRoot)
660             throws WSServiceException {
661
662         logger.log(BasicLevel.DEBUG, "get endpoint for JaxRpc Port Component");
663
664         return getEndpointURL(wsDD, jpcd.getWebDesc(), warURL, contextRoot, jpcd);
665
666     }
667
668     /**
669      * Creates the endpointURL of a given PortComponentDesc.
670      * @param wsDD webservices.xml
671      * @param spcd SSBPortComponentDesc to analyze
672      * @param warURL URL of the wabapp used to expose the Bean
673      * @param cl ejbjar classloader
674      * @param earCL application classloader
675      * @param contextRoot webapp context name
676      * @return the endpointURL of a given PortComponentDesc.
677      * @throws WSServiceException When URL cannot be created
678      */

679     private URL JavaDoc getEndpointURL(WSDeploymentDesc wsDD, SSBPortComponentDesc spcd, URL JavaDoc warURL, ClassLoader JavaDoc cl,
680             ClassLoader JavaDoc earCL, String JavaDoc contextRoot) throws WSServiceException {
681
682         logger.log(BasicLevel.DEBUG, "get endpoint for StatelessSessionBean Port Component");
683
684         WebContainerDeploymentDesc webDD = null;
685
686         try {
687             webDD = WebManagerWrapper.getDeploymentDesc(warURL, cl, earCL);
688         } catch (WebContainerDeploymentDescException e) {
689             String JavaDoc err = i18n.getMessage("AbsWebServicesServiceImpl.getEndpointURL.webDDException", warURL.getFile());
690             logger.log(BasicLevel.ERROR, err);
691             throw new WSServiceException(err, e);
692         }
693
694         return getEndpointURL(wsDD, webDD, warURL, contextRoot, spcd);