KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > web > tomcat > tc6 > deployers > TomcatDeployment


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2005, JBoss Inc., and individual contributors as indicated
4  * by the @authors tag. See the copyright.txt in the distribution for a
5  * full listing of individual contributors.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this software; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21  */

22 package org.jboss.web.tomcat.tc6.deployers;
23
24 import java.io.File JavaDoc;
25 import java.io.FileOutputStream JavaDoc;
26 import java.io.IOException JavaDoc;
27 import java.io.InputStream JavaDoc;
28 import java.net.MalformedURLException JavaDoc;
29 import java.net.URL JavaDoc;
30 import java.net.URLDecoder JavaDoc;
31 import java.security.CodeSource JavaDoc;
32 import java.security.cert.Certificate JavaDoc;
33 import java.util.ArrayList JavaDoc;
34 import java.util.HashMap JavaDoc;
35 import java.util.HashSet JavaDoc;
36 import java.util.Iterator JavaDoc;
37 import java.util.List JavaDoc;
38 import java.util.Set JavaDoc;
39 import java.util.zip.ZipEntry JavaDoc;
40 import java.util.zip.ZipFile JavaDoc;
41
42 import javax.management.Attribute JavaDoc;
43 import javax.management.MBeanServer JavaDoc;
44 import javax.management.ObjectName JavaDoc;
45 import javax.naming.Context JavaDoc;
46 import javax.naming.InitialContext JavaDoc;
47
48 import org.apache.catalina.Loader;
49 import org.apache.tomcat.util.modeler.Registry;
50 import org.jboss.deployers.spi.deployer.DeploymentUnit;
51 import org.jboss.logging.Logger;
52 import org.jboss.metadata.WebMetaData;
53 import org.jboss.mx.util.MBeanServerLocator;
54 import org.jboss.security.AuthorizationManager;
55 import org.jboss.security.authorization.PolicyRegistration;
56 import org.jboss.virtual.VirtualFile;
57 import org.jboss.web.WebApplication;
58 import org.jboss.web.deployers.AbstractWarDeployment;
59 import org.jboss.web.tomcat.security.JaccContextValve;
60 import org.jboss.web.tomcat.security.RunAsListener;
61 import org.jboss.web.tomcat.security.SecurityAssociationValve;
62 import org.jboss.web.tomcat.tc6.TomcatInjectionContainer;
63 import org.jboss.web.tomcat.tc6.WebAppLoader;
64 import org.jboss.web.tomcat.tc6.WebCtxLoader;
65 import org.jboss.web.tomcat.tc6.session.AbstractJBossManager;
66 import org.jboss.web.tomcat.tc6.session.ClusteringNotSupportedException;
67 import org.jboss.web.tomcat.tc6.session.JBossCacheManager;
68 import org.omg.CORBA.ORB JavaDoc;
69
70 /**
71  * A tomcat web application deployment.
72  *
73  * @author Scott.Stark@jboss.org
74  * @author Costin Manolache
75  * @version $Revision: 56605 $
76  */

77 public class TomcatDeployment extends AbstractWarDeployment
78 {
79    private static final Logger log = Logger.getLogger(TomcatDeployment.class);
80
81    /**
82     * The name of the war level context configuration descriptor
83     */

84    private static final String JavaDoc CONTEXT_CONFIG_FILE = "WEB-INF/context.xml";
85
86    private DeployerConfig config;
87    private String JavaDoc[] javaVMs = { " jboss.management.local:J2EEServer=Local,j2eeType=JVM,name=localhost" };
88    private String JavaDoc serverName = "jboss";
89    private HashMap JavaDoc vhostToHostNames = new HashMap JavaDoc();
90    private ORB JavaDoc orb = null;
91    private TomcatInjectionContainer injectionContainer;
92
93    public ORB JavaDoc getORB()
94    {
95       return orb;
96    }
97    public void setORB(ORB JavaDoc orb)
98    {
99       this.orb = orb;
100    }
101
102    @Override JavaDoc
103    public void init(Object JavaDoc containerConfig) throws Exception JavaDoc
104    {
105       this.config = (DeployerConfig)containerConfig;
106       super.setJava2ClassLoadingCompliance(config.isJava2ClassLoadingCompliance());
107       super.setUnpackWars(config.isUnpackWars());
108       super.setLenientEjbLink(config.isLenientEjbLink());
109       super.setDefaultSecurityDomain(config.getDefaultSecurityDomain());
110    }
111
112    @Override JavaDoc
113    protected void performDeploy(WebApplication webApp, String JavaDoc warUrl)
114          throws Exception JavaDoc
115    {
116       // Decode the URL as tomcat can't deal with paths with escape chars
117
warUrl = URLDecoder.decode(warUrl, "UTF-8");
118       webApp.setDomain(config.getCatalinaDomain());
119       WebMetaData metaData = webApp.getMetaData();
120       String JavaDoc hostName = null;
121       // Get any jboss-web/virtual-hosts
122
Iterator JavaDoc vhostNames = metaData.getVirtualHosts();
123       // Map the virtual hosts onto the configured hosts
124
Iterator JavaDoc hostNames = mapVirtualHosts(vhostNames);
125       if (hostNames.hasNext())
126       {
127          hostName = hostNames.next().toString();
128       }
129       performDeployInternal(hostName, webApp, warUrl);
130       while (hostNames.hasNext())
131       {
132          String JavaDoc additionalHostName = hostNames.next().toString();
133          performDeployInternal(additionalHostName, webApp, warUrl);
134       }
135    }
136
137    protected void performDeployInternal(String JavaDoc hostName,
138          WebApplication webApp, String JavaDoc warUrl) throws Exception JavaDoc
139    {
140
141       WebMetaData metaData = webApp.getMetaData();
142       String JavaDoc ctxPath = metaData.getContextRoot();
143       if (ctxPath.equals("/") || ctxPath.equals("/ROOT") || ctxPath.equals(""))
144       {
145          log.debug("deploy root context=" + ctxPath);
146          ctxPath = "/";
147          metaData.setContextRoot(ctxPath);
148       }
149
150       log.info("deploy, ctxPath=" + ctxPath + ", warUrl="
151             + shortWarUrlFromServerHome(warUrl));
152
153       URL JavaDoc url = new URL JavaDoc(warUrl);
154
155       ClassLoader JavaDoc loader = Thread.currentThread().getContextClassLoader();
156       metaData.setContextLoader(loader);
157       
158       injectionContainer = new TomcatInjectionContainer(webApp, webApp.getDeploymentUnit());
159
160       Loader webLoader = webApp.getDeploymentUnit().getAttachment(Loader.class);
161       if( webLoader == null )
162          webLoader = getWebLoader(webApp.getDeploymentUnit(), loader, url);
163
164       webApp.setName(url.getPath());
165       webApp.setClassLoader(loader);
166       webApp.setURL(url);
167
168       String JavaDoc objectNameS = config.getCatalinaDomain() + ":j2eeType=WebModule,name=//"
169             + ((hostName == null) ? "localhost" : hostName) + ctxPath
170             + ",J2EEApplication=none,J2EEServer=none";
171
172       ObjectName JavaDoc objectName = new ObjectName JavaDoc(objectNameS);
173
174       String JavaDoc contextClassName = config.getContextClassName();
175       Registry.getRegistry().registerComponent(
176             Class.forName(contextClassName).newInstance(), objectName,
177             contextClassName);
178
179       // Find and set warInfo file on the context
180
// If WAR is packed, expand warInfo file to temp folder
181
String JavaDoc ctxConfig = null;
182       try
183       {
184          // TODO: this should be input metadata
185
ctxConfig = findConfig(url);
186       } catch (IOException JavaDoc e)
187       {
188          log.debug("No " + CONTEXT_CONFIG_FILE + " in " + url, e);
189       }
190
191       if (injectionContainer != null)
192       {
193          server.setAttribute(objectName, new Attribute JavaDoc("annotationProcessor", injectionContainer));
194       }
195
196       server.setAttribute(objectName, new Attribute JavaDoc("docBase", url.getFile()));
197
198       server.setAttribute(objectName, new Attribute JavaDoc("configFile", ctxConfig));
199
200       server.setAttribute(objectName, new Attribute JavaDoc("defaultContextXml",
201             "context.xml"));
202       server.setAttribute(objectName, new Attribute JavaDoc("defaultWebXml",
203             "conf/web.xml"));
204       // If there is an alt-dd set it
205
if( metaData.getAltDDPath() != null )
206       {
207          String JavaDoc altPath = metaData.getAltDDPath();
208          log.debug("Setting altDDName to: "+altPath);
209          server.setAttribute(objectName, new Attribute JavaDoc("altDDName", altPath));
210       }
211
212       server.setAttribute(objectName, new Attribute JavaDoc("javaVMs", javaVMs));
213
214       server.setAttribute(objectName, new Attribute JavaDoc("server", serverName));
215
216       server.setAttribute(objectName,
217             new Attribute JavaDoc("saveConfig", Boolean.FALSE));
218
219       if (webLoader != null)
220       {
221          server.setAttribute(objectName, new Attribute JavaDoc("loader", webLoader));
222       } else
223       {
224          server.setAttribute(objectName, new Attribute JavaDoc("parentClassLoader",
225                loader));
226       }
227
228       server.setAttribute(objectName, new Attribute JavaDoc("delegate", new Boolean JavaDoc(
229             webApp.getJava2ClassLoadingCompliance())));
230
231       String JavaDoc[] jspCP = getCompileClasspath(loader);
232       StringBuffer JavaDoc classpath = new StringBuffer JavaDoc();
233       for (int u = 0; u < jspCP.length; u++)
234       {
235          String JavaDoc repository = jspCP[u];
236          if (repository == null)
237             continue;
238          if (repository.startsWith("file://"))
239             repository = repository.substring(7);
240          else if (repository.startsWith("file:"))
241             repository = repository.substring(5);
242          else
243             continue;
244          if (repository == null)
245             continue;
246          // ok it is a file. Make sure that is is a directory or jar file
247
File JavaDoc fp = new File JavaDoc(repository);
248          if (!fp.isDirectory())
249          {
250             // if it is not a directory, try to open it as a zipfile.
251
try
252             {
253                // avoid opening .xml files
254
if (fp.getName().toLowerCase().endsWith(".xml"))
255                   continue;
256
257                ZipFile JavaDoc zip = new ZipFile JavaDoc(fp);
258                zip.close();
259             } catch (IOException JavaDoc e)
260             {
261                continue;
262             }
263
264          }
265          if (u > 0)
266             classpath.append(File.pathSeparator);
267          classpath.append(repository);
268       }
269
270       server.setAttribute(objectName, new Attribute JavaDoc("compilerClasspath",
271             classpath.toString()));
272
273       // Set the session cookies flag according to metadata
274
switch (metaData.getSessionCookies())
275       {
276       case WebMetaData.SESSION_COOKIES_ENABLED:
277          server.setAttribute(objectName, new Attribute JavaDoc("cookies", new Boolean JavaDoc(
278                true)));
279          log.debug("Enabling session cookies");
280          break;
281       case WebMetaData.SESSION_COOKIES_DISABLED:
282          server.setAttribute(objectName, new Attribute JavaDoc("cookies", new Boolean JavaDoc(
283                false)));
284          log.debug("Disabling session cookies");
285          break;
286       default:
287          log.debug("Using session cookies default setting");
288       }
289
290       // Add a valve to estalish the JACC context before authorization valves
291
Certificate JavaDoc[] certs = null;
292       CodeSource JavaDoc cs = new CodeSource JavaDoc(url, certs);
293       JaccContextValve jaccValve = new JaccContextValve(metaData, cs);
294       server.invoke(objectName, "addValve", new Object JavaDoc[] { jaccValve },
295             new String JavaDoc[] { "org.apache.catalina.Valve" });
296
297       // Pass the metadata to the RunAsListener via a thread local
298
RunAsListener.metaDataLocal.set(metaData);
299       try
300       {
301          // Init the container; this will also start it
302
server.invoke(objectName, "init", new Object JavaDoc[] {}, new String JavaDoc[] {});
303       }
304       finally
305       {
306          RunAsListener.metaDataLocal.set(null);
307       }
308
309       // make the context class loader known to the WebMetaData, ws4ee needs it
310
// to instanciate service endpoint pojos that live in this webapp
311
Loader ctxLoader = (Loader) server.getAttribute(objectName, "loader");
312       metaData.setContextLoader(ctxLoader.getClassLoader());
313
314       // Start it
315
server.invoke(objectName, "start", new Object JavaDoc[]{},
316             new String JavaDoc[]{});
317       // Build the ENC
318

319       if (injectionContainer == null)
320          super.processEnc(webLoader.getClassLoader(), webApp);
321       else
322       {
323          Thread JavaDoc currentThread = Thread.currentThread();
324          ClassLoader JavaDoc currentLoader = loader;
325          try
326          {
327             // Create a java:comp/env environment unique for the web application
328
log.debug("Creating ENC using ClassLoader: " + loader);
329             ClassLoader JavaDoc parent = loader.getParent();
330             while (parent != null)
331             {
332                log.debug(".." + parent);
333                parent = parent.getParent();
334             }
335             // TODO: The enc should be an input?
336
currentThread.setContextClassLoader(webLoader.getClassLoader());
337             metaData.setENCLoader(webLoader.getClassLoader());
338             InitialContext JavaDoc iniCtx = new InitialContext JavaDoc();
339             Context JavaDoc envCtx = (Context JavaDoc) iniCtx.lookup("java:comp");
340             envCtx = envCtx.createSubcontext("env");
341             injectionContainer.populateEnc(webLoader.getClassLoader());
342             // TODO: this should be bindings in the metadata
343
currentThread.setContextClassLoader(webLoader.getClassLoader());
344             String JavaDoc securityDomain = metaData.getSecurityDomain();
345             log.debug("linkSecurityDomain");
346             linkSecurityDomain(securityDomain, envCtx);
347          }
348          finally
349          {
350             currentThread.setContextClassLoader(currentLoader);
351          }
352       }
353
354       // Clustering
355
if (metaData.getDistributable())
356       {
357          // Try to initate clustering, fallback to standard if no clustering is
358
// available
359
try
360          {
361             AbstractJBossManager manager = null;
362             String JavaDoc managerClassName = config.getManagerClass();
363             Class JavaDoc managerClass = Thread.currentThread().getContextClassLoader()
364                   .loadClass(managerClassName);
365             manager = (AbstractJBossManager) managerClass.newInstance();
366             String JavaDoc name = "//" + ((hostName == null) ? "localhost" : hostName)
367                   + ctxPath;
368             manager.init(name, metaData, config.isUseJK(), config
369                   .isUseLocalCache());
370
371             if (manager instanceof JBossCacheManager)
372             {
373                String JavaDoc snapshotMode = config.getSnapshotMode();
374                int snapshotInterval = config.getSnapshotInterval();
375                JBossCacheManager jbcm = (JBossCacheManager) manager;
376                jbcm.setSnapshotMode(snapshotMode);
377                jbcm.setSnapshotInterval(snapshotInterval);
378             }
379
380             server.setAttribute(objectName, new Attribute JavaDoc("manager", manager));
381
382             log.debug("Enabled clustering support for ctxPath=" + ctxPath);
383          }
384          catch (ClusteringNotSupportedException e)
385          {
386             // JBAS-3513 Just log a WARN, not an ERROR
387
log.warn("Failed to setup clustering, clustering disabled. ClusteringNotSupportedException: "
388                         + e.getMessage());
389          }
390          catch (NoClassDefFoundError JavaDoc ncdf)
391          {
392             // JBAS-3513 Just log a WARN, not an ERROR
393
log.debug("Classes needed for clustered webapp unavailable", ncdf);
394             log.warn("Failed to setup clustering, clustering disabled. NoClassDefFoundError: "
395                         + ncdf.getMessage());
396          }
397          catch (Throwable JavaDoc t)
398          {
399             // TODO consider letting this through and fail the deployment
400
log.error("Failed to setup clustering, clustering disabled. Exception: ", t);
401          }
402       }
403
404       /*
405        * Add security association valve after the authorization valves so that
406        * the authenticated user may be associated with the request
407        * thread/session.
408        */

409       SecurityAssociationValve valve = new SecurityAssociationValve(metaData,
410             config.getSecurityManagerService());
411       valve.setSubjectAttributeName(config.getSubjectAttributeName());
412       server.invoke(objectName, "addValve", new Object JavaDoc[] { valve },
413             new String JavaDoc[] { "org.apache.catalina.Valve" });
414
415       /* TODO: Retrieve the state, and throw an exception in case of a failure
416       Integer state = (Integer) server.getAttribute(objectName, "state");
417       if (state.intValue() != 1)
418       {
419          throw new DeploymentException("URL " + warUrl + " deployment failed");
420       }
421       */

422
423       webApp.setAppData(objectName);
424
425       /*
426        * TODO: Create mbeans for the servlets ObjectName servletQuery = new
427        * ObjectName (config.getCatalinaDomain() + ":j2eeType=Servlet,WebModule=" +
428        * objectName.getKeyProperty("name") + ",*"); Iterator iterator =
429        * server.queryMBeans(servletQuery, null).iterator(); while
430        * (iterator.hasNext()) {
431        * di.mbeans.add(((ObjectInstance)iterator.next()).getObjectName()); }
432        */

433
434       if (metaData.getSecurityDomain() != null)
435       {
436          String JavaDoc secDomain = org.jboss.security.Util
437                .unprefixSecurityDomain(metaData.getSecurityDomain());
438          // Associate the Context Id with the Security Domain
439
String JavaDoc contextID = metaData.getJaccContextID();
440
441          //Check if an xacml policy file is present
442
URL JavaDoc xacmlPolicyFile = this.config.getXacmlPolicyURL();
443          if (xacmlPolicyFile != null)
444          {
445           AuthorizationManager authzmgr = org.jboss.security.Util
446           .getAuthorizationManager(secDomain);
447           if (authzmgr instanceof PolicyRegistration)
448           {
449              PolicyRegistration xam = (PolicyRegistration) authzmgr;
450              xam.registerPolicy(contextID, xacmlPolicyFile);
451           }
452          }
453       }
454
455       log.debug("Initialized: " + webApp + " " + objectName);
456    }
457
458    public Loader getWebLoader(DeploymentUnit unit, ClassLoader JavaDoc loader, URL JavaDoc url)
459          throws MalformedURLException JavaDoc
460    {
461       Loader webLoader = null;
462       
463       /*
464        * If we are using the jboss class loader we need to augment its path to
465        * include the WEB-INF/{lib,classes} dirs or else scoped class loading
466        * does not see the war level overrides. The call to setWarURL adds these
467        * paths to the deployment UCL.
468        */

469       ArrayList JavaDoc<URL JavaDoc> classpath = (ArrayList JavaDoc<URL JavaDoc>) unit.getAttachment("org.jboss.web.expandedWarClasspath");
470       if (config.isUseJBossWebLoader())
471       {
472          WebCtxLoader jbossLoader = new WebCtxLoader(loader, injectionContainer);
473          if( classpath != null )
474             jbossLoader.setClasspath(classpath);
475          webLoader = jbossLoader;
476       }
477       else
478       {
479          String JavaDoc[] pkgs = config.getFilteredPackages();
480          WebAppLoader jbossLoader = new WebAppLoader(loader, pkgs, injectionContainer);
481          jbossLoader.setDelegate(getJava2ClassLoadingCompliance());
482          if( classpath != null )
483             jbossLoader.setClasspath(classpath);
484          webLoader = jbossLoader;
485       }
486       return webLoader;
487    }
488
489    public void setInjectionContainer(TomcatInjectionContainer container)
490    {
491       this.injectionContainer = container;
492    }
493
494    /**
495     * Called as part of the undeploy() method template to ask the subclass for
496     * perform the web container specific undeployment steps.
497     */

498    protected void performUndeploy(WebApplication warInfo, String JavaDoc warUrl)
499          throws Exception JavaDoc
500    {
501       if (warInfo == null)
502       {
503          log.debug("performUndeploy, no WebApplication found for URL "+ warUrl);
504          return;
505       }
506
507       log.info("undeploy, ctxPath=" + warInfo.getMetaData().getContextRoot()
508             + ", warUrl=" + shortWarUrlFromServerHome(warUrl));
509
510       WebMetaData metaData = warInfo.getMetaData();
511       String JavaDoc hostName = null;
512       Iterator JavaDoc hostNames = metaData.getVirtualHosts();
513       if (hostNames.hasNext())
514       {
515          hostName = hostNames.next().toString();
516       }
517       performUndeployInternal(hostName, warUrl, warInfo);
518       while (hostNames.hasNext())
519       {
520          String JavaDoc additionalHostName = hostNames.next().toString();
521          performUndeployInternal(additionalHostName, warUrl, warInfo);
522       }
523
524    }
525
526    protected void performUndeployInternal(String JavaDoc hostName, String JavaDoc warUrl,
527          WebApplication warInfo) throws Exception JavaDoc
528    {
529
530       WebMetaData metaData = warInfo.getMetaData();
531       String JavaDoc ctxPath = metaData.getContextRoot();
532
533       // TODO: Need to remove the dependency on MBeanServer
534
MBeanServer JavaDoc server = MBeanServerLocator.locateJBoss();
535       // If the server is gone, all apps were stopped already
536
if (server == null)
537          return;
538
539       ObjectName JavaDoc objectName = new ObjectName JavaDoc(config.getCatalinaDomain()
540             + ":j2eeType=WebModule,name=//"
541             + ((hostName == null) ? "localhost" : hostName) + ctxPath
542             + ",J2EEApplication=none,J2EEServer=none");
543
544       if (server.isRegistered(objectName))
545       {
546          // Contexts should be stopped by the host already
547
server.invoke(objectName, "destroy", new Object JavaDoc[] {}, new String JavaDoc[] {});
548       }
549
550    }
551
552    /**
553     * Resolve the input virtual host names to the names of the configured Hosts
554     * @param vhostNames Iterator<String> for the jboss-web/virtual-host elements
555     * @return Iterator<String> of the unique Host names
556     * @throws Exception
557     */

558    protected synchronized Iterator JavaDoc mapVirtualHosts(Iterator JavaDoc vhostNames)
559       throws Exception JavaDoc
560    {
561       if (vhostToHostNames.size() == 0)
562       {
563          // Query the configured Host mbeans
564
String JavaDoc hostQuery = config.getCatalinaDomain() + ":type=Host,*";
565          ObjectName JavaDoc query = new ObjectName JavaDoc(hostQuery);
566          Set JavaDoc hosts = server.queryNames(query, null);
567          Iterator JavaDoc iter = hosts.iterator();
568          while (iter.hasNext())
569          {
570             ObjectName JavaDoc host = (ObjectName JavaDoc)iter.next();
571             String JavaDoc name = host.getKeyProperty("host");
572             if (name != null)
573             {
574                vhostToHostNames.put(name, name);
575                String JavaDoc[] aliases = (String JavaDoc[])
576                   server.invoke(host, "findAliases", null, null);
577                int count = aliases != null ? aliases.length : 0;
578                for (int n = 0; n < count; n++)
579                {
580                   vhostToHostNames.put(aliases[n], name);
581                }
582             }
583          }
584       }
585
586       // Map the virtual host names to the hosts
587
HashSet JavaDoc hosts = new HashSet JavaDoc();
588       while (vhostNames.hasNext())
589       {
590          String JavaDoc vhost = (String JavaDoc)vhostNames.next();
591          String JavaDoc host = (String JavaDoc)vhostToHostNames.get(vhost);
592          if (host == null)
593          {
594             log.warn("Failed to map vhost: " + vhost);
595             // This will cause a new host to be created
596
host = vhost;
597          }
598          hosts.add(host);
599       }
600       return hosts.iterator();
601    }
602
603    private String JavaDoc findConfig(URL JavaDoc warURL) throws IOException JavaDoc
604    {
605       String JavaDoc result = null;
606       // See if the warUrl is a dir or a file
607
File JavaDoc warFile = new File JavaDoc(warURL.getFile());
608       if (warURL.getProtocol().equals("file") && warFile.isDirectory() == true)
609       {
610          File JavaDoc webDD = new File JavaDoc(warFile, CONTEXT_CONFIG_FILE);
611          if (webDD.exists() == true)
612             result = webDD.getAbsolutePath();
613       } else
614       {
615          ZipFile JavaDoc zipFile = new ZipFile JavaDoc(warFile);
616          ZipEntry JavaDoc entry = zipFile.getEntry(CONTEXT_CONFIG_FILE);
617          if (entry != null)
618          {
619             InputStream JavaDoc zipIS = zipFile.getInputStream(entry);
620             byte[] buffer = new byte[512];
621             int bytes;
622             result = warFile.getAbsolutePath() + "-context.xml";
623             FileOutputStream JavaDoc fos = new FileOutputStream JavaDoc(result);
624             while ((bytes = zipIS.read(buffer)) > 0)
625             {
626                fos.write(buffer, 0, bytes);
627             }
628             zipIS.close();
629             fos.close();
630          }
631          zipFile.close();
632       }
633       return result;
634    }
635
636 }
637
Popular Tags