KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > web > AbsJWebContainerServiceImpl


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: AbsJWebContainerServiceImpl.java,v 1.65 2005/06/09 09:55:22 sauthieg Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.web;
27
28 import java.io.File JavaDoc;
29 import java.io.IOException JavaDoc;
30 import java.net.MalformedURLException JavaDoc;
31 import java.net.URL JavaDoc;
32 import java.net.URLClassLoader JavaDoc;
33 import java.rmi.RemoteException JavaDoc;
34 import java.util.ArrayList JavaDoc;
35 import java.util.Enumeration JavaDoc;
36 import java.util.HashSet JavaDoc;
37 import java.util.Hashtable JavaDoc;
38 import java.util.Iterator JavaDoc;
39 import java.util.List JavaDoc;
40 import java.util.Set JavaDoc;
41 import java.util.StringTokenizer JavaDoc;
42 import java.util.Vector JavaDoc;
43
44 import javax.management.InstanceAlreadyExistsException JavaDoc;
45 import javax.management.MBeanRegistrationException JavaDoc;
46 import javax.management.MBeanServer JavaDoc;
47 import javax.management.NotCompliantMBeanException JavaDoc;
48 import javax.naming.Context JavaDoc;
49 import javax.naming.LinkRef JavaDoc;
50 import javax.naming.NamingException JavaDoc;
51 import javax.naming.Reference JavaDoc;
52 import javax.naming.StringRefAddr JavaDoc;
53
54 import org.objectweb.jonas_lib.deployment.api.EjbLocalRefDesc;
55 import org.objectweb.jonas_lib.deployment.api.EjbRefDesc;
56 import org.objectweb.jonas_lib.deployment.api.EnvEntryDesc;
57 import org.objectweb.jonas_lib.deployment.api.MessageDestinationRefDesc;
58 import org.objectweb.jonas_lib.deployment.api.ResourceEnvRefDesc;
59 import org.objectweb.jonas_lib.deployment.api.ResourceRefDesc;
60 import org.objectweb.jonas_lib.loader.SimpleWebappClassLoader;
61 import org.objectweb.jonas_lib.loader.WebappClassLoader;
62 import org.objectweb.jonas_lib.naming.ContainerNaming;
63 import org.objectweb.jonas_lib.security.PermissionManagerException;
64
65 import org.objectweb.jonas_web.deployment.api.WebContainerDeploymentDesc;
66 import org.objectweb.jonas_web.deployment.api.WebContainerDeploymentDescException;
67 import org.objectweb.jonas_web.deployment.lib.wrapper.WebManagerWrapper;
68
69 import org.objectweb.jonas_ws.deployment.api.ServiceRefDesc;
70
71 import org.objectweb.jonas.common.JModule;
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.JmxService;
76 import org.objectweb.jonas.jmx.JonasObjectName;
77 import org.objectweb.jonas.naming.CompNamingContext;
78 import org.objectweb.jonas.naming.NamingManager;
79 import org.objectweb.jonas.server.LoaderManager;
80 import org.objectweb.jonas.service.AbsServiceImpl;
81 import org.objectweb.jonas.service.ServiceException;
82 import org.objectweb.jonas.service.ServiceManager;
83 import org.objectweb.jonas.web.lib.JarTools;
84 import org.objectweb.jonas.web.lib.PermissionManager;
85 import org.objectweb.jonas.ws.JServiceFactory;
86 import org.objectweb.jonas.ws.JServiceFactoryFinder;
87 import org.objectweb.jonas.ws.WebServicesService;
88
89 import org.objectweb.util.monolog.api.BasicLevel;
90 import org.objectweb.util.monolog.api.Logger;
91
92 /**
93  * This abstract class provides an implementation for a dynamic
94  * JWebContainerService service.
95  * @author Florent Benoit
96  * @author Ludovic Bert (J2EE 1.3)
97  * @author Nicolas Van Caneghem (exploded ear)
98  * @author Michel-Ange Anton (contributor)
99  */

100 public abstract class AbsJWebContainerServiceImpl extends AbsServiceImpl implements JWebContainerService,
101         AbsJWebContainerServiceImplMBean {
102
103     /**
104      * The name of the JONAS_BASE directory.
105      */

106     protected static final String JavaDoc JONAS_BASE = JProp.getJonasBase();
107
108     /**
109      * The name of the webapps directory.
110      */

111     protected static final String JavaDoc WEBAPPS_DIR = JONAS_BASE + File.separator + "webapps";
112
113     /**
114      * The name of the working directory.
115      */

116     protected static final String JavaDoc WORK_DIR = JProp.getWorkDir();
117
118     /**
119      * The name of the working apps directory.
120      */

121     protected static final String JavaDoc WORK_WEBAPPS_DIR = WORK_DIR + File.separator + "webapps";
122
123     /**
124      * Web service configuration properties : Files deployed
125      */

126     public static final String JavaDoc DESCRIPTORS = "jonas.service.web.descriptors";
127
128     /**
129      * Web service configuration properties : Autdeployed the files in these
130      * directories
131      */

132     public static final String JavaDoc AUTOLOADDIR = "jonas.service.web.autoloaddir";
133
134     /**
135      * Web service configuration properties : Xml parsing with validation
136      */

137     public static final String JavaDoc PARSINGWITHVALIDATION = "jonas.service.web.parsingwithvalidation";
138
139     /**
140      * Length of the extension .war
141      */

142     private static final int WAR_EXTENSION_LENGTH = 4;
143
144     /**
145      * Web service configuration properties : Implementation of the web
146      * container
147      */

148     public static final String JavaDoc CLASS = "jonas.service.web.class";
149
150     /**
151      * Logger for this service.
152      */

153     private static Logger logger = null;
154
155     /**
156      * The name of the current jonas server
157      */

158     private static String JavaDoc nameOfServer = null;
159
160     /**
161      * Reference on the NamingManager.
162      */

163     private ContainerNaming naming;
164
165     /**
166      * Associates an URL of an unpacked WAR file to its classloader.
167      */

168     private Hashtable JavaDoc warLoaders = new Hashtable JavaDoc();
169
170     /**
171      * Associates an URL of a deployed WAR file to its classloader.
172      */

173     private Hashtable JavaDoc warBindings = new Hashtable JavaDoc();
174
175     /**
176      * Reference to a MBean server.
177      */

178     private MBeanServer JavaDoc mbeanServer = null; // Bug Tomcat 5 doesn't remove MBean
179
// WebModule, normally the type is
180
// "private"
181

182     /**
183      * List of the war names to load when starting the Web container Service.
184      */

185     private Vector JavaDoc warNames = new Vector JavaDoc();
186
187     /**
188      * List of the war deployed by the Web container Service.
189      */

190     private Vector JavaDoc warDeployed = new Vector JavaDoc();
191
192     /**
193      * List of autoloaded directories.
194      */

195     private List JavaDoc autoloadDirectories = new ArrayList JavaDoc();
196
197     /**
198      * Name of the server
199      */

200     private String JavaDoc serverName = null;
201
202     /**
203      * Version of the server
204      */

205     private String JavaDoc serverVersion = null;
206
207     /**
208      * Reference to the WebServices service
209      */

210     private WebServicesService wsService = null;
211
212     /**
213      * Application Classloader
214      */

215     private ClassLoader JavaDoc appsClassLoader;
216
217     /**
218      * Initialize the service.
219      * @param ctx the configuration context of the service.
220      * @throws ServiceException if the initialization failed.
221      */

222     protected void doInit(Context JavaDoc ctx) throws ServiceException {
223
224         // Init the logger
225
logger = Log.getLogger(Log.JONAS_WEB_PREFIX);
226
227         // get apps ClassLoader
228
try {
229             LoaderManager lm = LoaderManager.getInstance();
230             appsClassLoader = lm.getAppsLoader();
231         } catch (Exception JavaDoc e) {
232             logger.log(BasicLevel.ERROR, "Cannot get the Applications ClassLoader from Web Container Service: " + e);
233             throw new ServiceException("Cannot get the Applications ClassLoader from Web Container Service", e);
234         }
235
236         ServiceManager sm = null;
237         try {
238             sm = ServiceManager.getInstance();
239         } catch (Exception JavaDoc e) {
240             String JavaDoc err = "Cannot get ServiceManager instance.";
241             logger.log(BasicLevel.ERROR, err);
242             throw new ServiceException(err, e);
243         }
244
245         // Get the JMX Server via JMX Service
246
try {
247             mbeanServer = ((JmxService) sm.getJmxService()).getJmxServer();
248         } catch (ServiceException e) {
249             // the JMX service may not be started
250
mbeanServer = null;
251         }
252
253         // Get the WebServices service
254
try {
255             wsService = (WebServicesService) sm.getWebServicesService();
256         } catch (ServiceException e) {
257             if (logger.isLoggable(BasicLevel.DEBUG)) {
258                 logger.log(BasicLevel.DEBUG, "WebServices service not started");
259             }
260             //not started
261
wsService = null;
262         }
263
264         // Set the XML parsing mode to no validation
265
String JavaDoc parsingMode = "false";
266         try {
267             parsingMode = (String JavaDoc) ctx.lookup(PARSINGWITHVALIDATION);
268         } catch (NamingException JavaDoc e) {
269             if (logger.isLoggable(BasicLevel.DEBUG)) {
270                 logger.log(BasicLevel.DEBUG, "No value for parsingWithValidation");
271             }
272             // No problem if there is no value for 'parsingwithvalidation'
273
// (false by default)
274
}
275
276         WebManagerWrapper.setParsingWithValidation("true".equalsIgnoreCase(parsingMode));
277         if (logger.isLoggable(BasicLevel.DEBUG)) {
278             if ("false".equalsIgnoreCase(parsingMode)) {
279                 logger.log(BasicLevel.DEBUG, "Web XML parsing without validation");
280             } else {
281                 logger.log(BasicLevel.DEBUG, "Web XML parsing with validation");
282             }
283         }
284
285         // Init the war names to be loaded when starting
286
String JavaDoc descsValue = null;
287         try {
288             descsValue = (String JavaDoc) ctx.lookup(DESCRIPTORS);
289         } catch (NamingException JavaDoc e) {
290             if (logger.isLoggable(BasicLevel.DEBUG)) {
291                 logger.log(BasicLevel.DEBUG, "No " + DESCRIPTORS);
292             }
293         }
294         if (descsValue != null) {
295             StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(descsValue, ",");
296             while (st.hasMoreTokens()) {
297                 String JavaDoc fileName = st.nextToken().trim();
298                 warNames.add(fileName);
299             }
300         }
301         // Add the wars of the jonas.service.web.autoloaddir property
302
String JavaDoc dirValue = null;
303         ArrayList JavaDoc autoDirs = new ArrayList JavaDoc();
304         try {
305             dirValue = (String JavaDoc) ctx.lookup(AUTOLOADDIR);
306         } catch (NamingException JavaDoc e) {
307             if (logger.isLoggable(BasicLevel.DEBUG)) {
308                 logger.log(BasicLevel.DEBUG, "No " + AUTOLOADDIR);
309             }
310         }
311         if (dirValue != null) {
312             StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(dirValue, ",");
313             while (st.hasMoreTokens()) {
314                 String JavaDoc dirName = st.nextToken().trim();
315                 addWars(dirName);
316                 autoDirs.add(dirName);
317             }
318         }
319         // Build autoload directories
320
File JavaDoc oFile;
321         Iterator JavaDoc it = autoDirs.iterator();
322         while (it.hasNext()) {
323             String JavaDoc dirName = (String JavaDoc) it.next();
324             try {
325                 oFile = new File JavaDoc(WEBAPPS_DIR, dirName);
326                 if (!oFile.exists()) {
327                     oFile = new File JavaDoc(dirName);
328                 }
329                 if (oFile.exists()) {
330                     autoloadDirectories.add(oFile.getCanonicalPath());
331                 }
332             } catch (Exception JavaDoc e) {
333                 String JavaDoc err = "Error when trying to verify Webapps autoload directory : " + dirName;
334                 logger.log(BasicLevel.ERROR, err + " " + e.getMessage());
335             }
336         }
337
338         //Init the naming manager
339
try {
340             naming = NamingManager.getInstance();
341         } catch (NamingException JavaDoc e) {
342             throw new ServiceException("Error when getting the reference to the Naming manager");
343         }
344
345         JProp jp = null;
346         try {
347             jp = JProp.getInstance();
348         } catch (Exception JavaDoc e) {
349             String JavaDoc err = "Error when trying to get jonas name ";
350             logger.log(BasicLevel.ERROR, err + " " + e.getMessage());
351             throw new ServiceException(err, e);
352         }
353         AbsJWebContainerServiceImpl.nameOfServer = jp.getValue("jonas.name", "jonas");
354
355     }
356
357     /**
358      * Start the service.
359      * @throws ServiceException if the startup failed.
360      */

361     protected void doStart() throws ServiceException {
362         // Deploy all wars which are in descriptors section
363
for (Enumeration JavaDoc e = warNames.elements(); e.hasMoreElements();) {
364             String JavaDoc fileName = (String JavaDoc) e.nextElement();
365
366             URL JavaDoc warURL = checkWarFile(fileName);
367
368             Context JavaDoc contctx = null;
369             try {
370                 contctx = new CompNamingContext(fileName);
371                 contctx.rebind("warURL", warURL);
372                 // No context root to rebind because not in ear case.
373
// => no rebind("contextRoot", ...)
374
} catch (NamingException JavaDoc ne) {
375                 String JavaDoc err = "Cannot start the WebContainerService";
376                 throw new ServiceException(err, ne);
377             }
378             try {
379                 registerWar(contctx);
380             } catch (JWebContainerServiceException jwcse) {
381                 String JavaDoc err = "Cannot deploy the file '" + warURL + "' : " + jwcse.getMessage();
382                 logger.log(BasicLevel.WARN, err);
383             }
384         }
385
386         try {
387             // Register JWebContainerService MBean :
388
// JWebContainerServiceImplMBean
389
if (mbeanServer != null) {
390                 mbeanServer.registerMBean(this, JonasObjectName.webContainerService());
391             }
392         } catch (InstanceAlreadyExistsException JavaDoc iae) {
393             String JavaDoc err = "Cannot start the WebContainerService Already Exists";
394             throw new ServiceException(err, iae);
395         } catch (MBeanRegistrationException JavaDoc mbre) {
396             throw new ServiceException("Cannot start the WebContainerService (MBean registration error)", mbre);
397         } catch (NotCompliantMBeanException JavaDoc ncmbe) {
398             throw new ServiceException("Cannot start the WebContainerService (MBean Not compliant error)", ncmbe);
399         }
400     }
401
402     /**
403      * Stop the service.
404      * @throws ServiceException if the stop failed.
405      */

406     protected void doStop() throws ServiceException {
407
408         // Get all the deployed war which are not in an ear application file
409
// and undeploy them.
410
for (int i = warDeployed.size() - 1; i >= 0; i--) {
411             War war = (War) warDeployed.elementAt(i);
412             URL JavaDoc warURL = war.getWarURL();
413             String JavaDoc fileName = warURL.getFile();
414             try {
415                 // Test if the war is in an ear application.
416
if (!war.isInEarCase()) {
417                     Context JavaDoc ctx = new CompNamingContext(fileName);
418                     ctx.rebind("warURL", warURL);
419                     ctx.rebind("isEarCase", new Boolean JavaDoc(false));
420                     unRegisterWar(ctx);
421                 }
422             } catch (Exception JavaDoc e) {
423                 //We don't stop the process of undeploying the wars.
424
//We only display an error in the logger.
425
String JavaDoc err = "Error when undeploying the war :" + fileName;
426                 logger.log(BasicLevel.ERROR, err + e.getMessage());
427             }
428         }
429
430         if (mbeanServer != null) {
431             try {
432                 // unregister AbsJWebContainerServiceImpl MBean
433
mbeanServer.unregisterMBean(JonasObjectName.webContainerService());
434             } catch (Exception JavaDoc e) {
435                 logger.log(BasicLevel.ERROR, "Cannot stop the WebContainerService: " + e);
436             }
437         }
438         if (logger.isLoggable(BasicLevel.DEBUG)) {
439             logger.log(BasicLevel.DEBUG, "WebContainerService stopped");
440         }
441     }
442
443     /**
444      * Create the environment and delegate the operation to the implementation
445      * of the web container.
446      * @param ctx the context which contains the configuration in order to
447      * deploy a WAR.
448      * @throws JWebContainerServiceException if the registration of the WAR
449      * failed.
450      */

451     protected abstract void doRegisterWar(Context JavaDoc ctx) throws JWebContainerServiceException;
452
453     /**
454      * Delegate the unregistration to the implementation of the web container.
455      * @param ctx the context which contains the configuration in order to
456      * undeploy a WAR.
457      * @throws JWebContainerServiceException if the unregistration failed.
458      */

459     protected abstract void doUnRegisterWar(Context JavaDoc ctx) throws JWebContainerServiceException;
460
461     /**
462      * Return the URL where warURL has been unpacked.
463      * @param warURL the URL of the war
464      * @param earAppName EAR Application name (can be null if not in EAR case)
465      * @return the URL where warURL has been unpacked.
466      * @throws JWebContainerServiceException when it is impossible to retrieve
467      * the unpacked URL.
468      */

469     protected URL JavaDoc getUnpackDir(URL JavaDoc warURL, String JavaDoc earAppName) throws JWebContainerServiceException {
470
471         String JavaDoc destDir = WORK_WEBAPPS_DIR + File.separator + nameOfServer + File.separator;
472
473         // Two cases :
474
// war is alone --> unpack it in :
475
// WEBAPPS_DIR/servername/filename_without_extension_dir/
476
// war come from an ear --> unpack it in :
477
// WEBAPPS_DIR/servername/ear_AppName/filename_without_extension_dir/
478

479         // location of unpacked War
480
URL JavaDoc unpackedWarURL = null;
481
482         String JavaDoc fileName = warURL.getFile();
483
484         // War file
485
if (new File JavaDoc(fileName).isFile()) {
486             // Note : if the war is alone, earAppName is null.
487
// ear case
488
if (earAppName != null) {
489                 destDir += earAppName + File.separator;
490             }
491
492             String JavaDoc fTemp = new File JavaDoc(fileName).getName();
493             destDir += fTemp.substring(0, fTemp.length() - WAR_EXTENSION_LENGTH);
494
495             // Unpack the war into a directory
496
JarTools.unpack(fileName, destDir);
497         } else {
498             // Directory (No unpack)
499
destDir = fileName;
500         }
501
502         try {
503             unpackedWarURL = new File JavaDoc(destDir).toURL();
504         } catch (MalformedURLException JavaDoc mue) {
505             throw new JWebContainerServiceException("Error", mue);
506         }
507
508         return unpackedWarURL;
509
510     }
511
512     /**
513      * Return the class loader of the given warURL. Unpack the associated war
514      * and build the loader if it's not in the cache.
515      * @param warURL the url of the war we want to get the loader
516      * @param earAppName the name of the ear application containing the war. May
517      * be null in non ear case.
518      * @param parentLoader the ejb class loader of the ear. May be null in non
519      * ear case.
520      * @return the class loader of the given warURL.
521      * @throws JWebContainerServiceException if the process failed.
522      */

523     public URLClassLoader JavaDoc getClassLoader(URL JavaDoc warURL, String JavaDoc earAppName, ClassLoader JavaDoc parentLoader)
524             throws JWebContainerServiceException {
525
526         URLClassLoader JavaDoc loaderForCls = null;
527         try {
528             WebLoaderHolder holder = (WebLoaderHolder) warLoaders.get(warURL);
529             if (holder != null) {
530                 loaderForCls = holder.getJonasWebLoader();
531             }
532         } catch (Exception JavaDoc e) {
533             throw new JWebContainerServiceException("Error when getting '" + warURL + "' in cache", e);
534         }
535
536         if (loaderForCls == null) {
537             // the war is not already used
538

539             // Use the unpacked directory
540
URL JavaDoc unpackedWarURL = getUnpackDir(warURL, earAppName);
541
542             try {
543                 if (parentLoader != null) {
544                     // ear case.
545
loaderForCls = new WebappClassLoader(unpackedWarURL, parentLoader);
546                 } else {
547                     //Case of non-ear application : only a single war
548
loaderForCls = new WebappClassLoader(unpackedWarURL, appsClassLoader);
549                 }
550             } catch (IOException JavaDoc ioe) {
551                 throw new JWebContainerServiceException(
552                         "Cannot create WebAppClassLoader from '" + unpackedWarURL + "'", ioe);
553             }
554
555             // add the class loader in cache.
556
try {
557                 WebLoaderHolder holder = new WebLoaderHolder(loaderForCls, null);
558                 warLoaders.put(warURL, holder);
559             } catch (Exception JavaDoc e) {
560                 throw new JWebContainerServiceException("Error when adding '" + warURL + "' in cache", e);
561             }
562         }
563
564         return loaderForCls;
565
566     }
567
568     /**
569      * @param warURL the URL of the webapp
570      * @return Returns the ClassLoader used to link a JNDI environnment to a webapp
571      */

572     public ClassLoader JavaDoc getContextLinkedClassLoader(URL JavaDoc warURL) {
573         WebLoaderHolder holder = (WebLoaderHolder) warLoaders.get(warURL);
574         if (holder != null) {
575             return holder.getEnvWebLoader();
576         }
577         return null;
578     }
579
580     /**
581      * Create the environment and delegate the operation to the implementation
582      * of the web container.
583      * @param ctx the context which contains the configuration in order to
584      * deploy a WAR.
585      * @throws JWebContainerServiceException if the registration of the WAR
586      * failed.
587      */

588     private void registerWar(Context JavaDoc ctx) throws JWebContainerServiceException {
589         // There are 6 possible parameters :
590
// - warURL is the URL of the war to deploy (required param).
591
// - parentClassLoader is the parent classloader of
592
// the web classloader (optional param).
593
// - earClassLoader is the ear classloader (optional param).
594
// - earURL is the URL of the ear (optional parameter :
595
// if earURL is set it means that we are in the ear case, else it
596
// means that we are in the non ear case).
597
// - altDD is the optional deployment descriptor (optional param).
598
// - contextRoot is the context root for the Web application
599
// (optional param).
600

601         // Get the URL of the ear application file in the case of an
602
// ear application, null otherwise.
603
URL JavaDoc earURL = null;
604         String JavaDoc contextRoot = null;
605         String JavaDoc earAppName = null;
606         try {
607             earURL = (URL JavaDoc) ctx.lookup("earURL");
608             contextRoot = (String JavaDoc) ctx.lookup("contextRoot");
609             earAppName = EarServiceImpl.buildJ2eeApplicationName(earURL);
610         } catch (NamingException JavaDoc e) {
611             if (earURL != null || contextRoot != null) {
612                 String JavaDoc err = "Error while getting parameter from context param :" + e.getMessage();
613                 logger.log(BasicLevel.ERROR, err);
614                 throw new JWebContainerServiceException(err, e);
615             } // else nothing to do : non-ear case.
616
}
617
618         // Get the URL of the war to deploy ...
619
URL JavaDoc warURL = null;
620         try {
621             warURL = (URL JavaDoc) ctx.lookup("warURL");
622         } catch (NamingException JavaDoc e) {
623             String JavaDoc err = "Error while getting parameter from context param :" + e.getMessage();
624             logger.log(BasicLevel.ERROR, err);
625             throw new JWebContainerServiceException(err, e);
626         }
627
628         // ... and check if the war to deploy exists.
629
File JavaDoc warFile = new File JavaDoc(warURL.getFile());
630         if (!warFile.exists()) {
631             String JavaDoc err = "registerWar: '" + warFile.getPath() + "' not found";
632             logger.log(BasicLevel.ERROR, err);
633             throw new JWebContainerServiceException(err);
634         }
635
636         // Check if the war to deploy is not already deployed.
637
War war = getWar(warURL);
638         if (war != null) {
639             // The war is already deployed.
640
String JavaDoc err = "Cannot deploy war '" + warURL.getFile() + "' is already deployed."
641                     + " You must undeploy the war before a new deployment.";
642             throw new JWebContainerServiceException(err);
643         }
644
645         URLClassLoader JavaDoc parentLoader = null;
646         URLClassLoader JavaDoc earClassLoader = null;
647         try {
648             parentLoader = (URLClassLoader JavaDoc) ctx.lookup("parentClassLoader");
649             earClassLoader = (URLClassLoader JavaDoc) ctx.lookup("earClassLoader");
650         } catch (NamingException JavaDoc ne) {
651             if (logger.isLoggable(BasicLevel.DEBUG)) {
652                 logger.log(BasicLevel.DEBUG, "Not an ear case");
653             }
654             // exception occurs when the earClassLoader is not found.
655
}
656
657         // get the war class loader.
658
URLClassLoader JavaDoc loaderForCls = getClassLoader(warURL, earAppName, parentLoader);
659
660         // get the directory where the war have been unpacked
661
URL JavaDoc unpackedWarURL = getUnpackDir(warURL, earAppName);
662
663         // Only if the WebServicesService is started
664
// And in non EAR case
665
if (wsService != null && earClassLoader == null) {
666             try {
667                 CompNamingContext contctx = null;
668                 try {
669                     contctx = new CompNamingContext(unpackedWarURL.getFile());
670                     contctx.rebind("unpackDir", unpackedWarURL.toExternalForm());
671                     contctx.rebind("jarUrls", new URL JavaDoc[0]);
672                     contctx.rebind("warUrls", new URL JavaDoc[] {warURL});
673                     if (parentLoader != null) {
674                         contctx.rebind("ejbClassLoader", parentLoader);
675                     }
676                 } catch (NamingException JavaDoc e) {
677                     String JavaDoc err = "Can not bind params for the WebServices service, "
678                             + "Can't deploy Web Services Endpoint";
679                     throw new JWebContainerServiceException(err, e);
680                 }
681                 wsService.deployWebServices(contctx);
682             } catch (ServiceException se) {
683                 String JavaDoc err = "Error during the deployment of the WebServices of the War file '" + warURL + "'";
684                 logger.log(BasicLevel.ERROR, err + " : " + se.getMessage());
685                 throw new JWebContainerServiceException(err, se);
686             }
687         }
688
689         // Get the deployment descriptor from file
690
WebContainerDeploymentDesc webDD = null;
691         try {
692             webDD = WebManagerWrapper.getDeploymentDesc(warURL, loaderForCls, earClassLoader);
693         } catch (WebContainerDeploymentDescException e) {
694             String JavaDoc err = "Cannot read the deployment descriptors '" + warURL.getFile() + "'";
695             logger.log(BasicLevel.ERROR, err + ": " + e);
696             e.printStackTrace(System.err);
697             throw new JWebContainerServiceException(err, e);
698         }
699
700         // Populate the java:comp/env (ENC) environment.
701
URLClassLoader JavaDoc webClassLoader = null;
702         try {
703             if (logger.isLoggable(BasicLevel.DEBUG)) {
704                 logger.log(BasicLevel.DEBUG, "Populating environment of the file " + warURL.getFile());
705             }
706             Context JavaDoc ctxParam = new CompNamingContext(unpackedWarURL.getFile());
707             ctxParam.rebind("DeploymentDesc", webDD);
708             ctxParam.rebind("warName", unpackedWarURL.getFile());
709             if (parentLoader == null) {
710                 webClassLoader = new SimpleWebappClassLoader(unpackedWarURL, appsClassLoader);
711             } else {
712   &nbs