KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > web > jetty50 > JettyJWebContainerServiceImpl


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999-2004 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  * Initial developer(s): Miroslav Halas based on Catalina service
22  * --------------------------------------------------------------------------
23  * $Id: JettyJWebContainerServiceImpl.java,v 1.14.2.1 2005/08/12 17:39:32 benoitf Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas.web.jetty50;
28
29 import java.io.File JavaDoc;
30 import java.io.IOException JavaDoc;
31 import java.net.URL JavaDoc;
32 import java.net.URLClassLoader JavaDoc;
33 import java.util.Map JavaDoc;
34 import java.util.StringTokenizer JavaDoc;
35 import java.util.Vector JavaDoc;
36
37 import javax.management.MalformedObjectNameException JavaDoc;
38 import javax.management.ObjectName JavaDoc;
39 import javax.naming.Context JavaDoc;
40 import javax.naming.NamingException JavaDoc;
41
42 import org.objectweb.util.monolog.api.BasicLevel;
43
44 import org.objectweb.jonas.jmx.JmxService;
45 import org.objectweb.jonas.jmx.JonasObjectName;
46 import org.objectweb.jonas.service.ServiceException;
47 import org.objectweb.jonas.service.ServiceManager;
48 import org.objectweb.jonas.web.AbsJWebContainerServiceImpl;
49 import org.objectweb.jonas.web.JWebContainerServiceException;
50
51 import org.mortbay.http.HttpContext;
52 import org.mortbay.http.HttpListener;
53 import org.mortbay.jetty.Server;
54 import org.mortbay.jetty.servlet.WebApplicationContext;
55
56 /**
57  * This class provides an implementation of the Jetty service (as web container
58  * service).
59  * @author Miroslav Halas (initial developer)
60  * @author Florent Benoit
61  */

62 public class JettyJWebContainerServiceImpl extends AbsJWebContainerServiceImpl {
63
64     /**
65      * Name of the default web.xml file
66      */

67     private static final String JavaDoc JETTY_DEFAULT_WEB_XML_FILE = AbsJWebContainerServiceImpl.JONAS_BASE + File.separator + "conf" + File.separator + "jetty5-webdefault.xml";
68
69     /**
70      * Configuration used to configure Jetty.
71      */

72     private static String JavaDoc config = null;
73
74     /**
75      * Name of the variable specifying configuration file for Jetty
76      */

77     private static final String JavaDoc JETTY_CONFIG = "config";
78
79     /**
80      * Our own instance of Jetty server.
81      */

82     private Server jettyServer = null;
83
84     /**
85      * Initialize the Jetty service.
86      * @param ctx the configuration context of the service.
87      * @throws ServiceException if the initialization failed.
88      */

89     protected void doInit(javax.naming.Context JavaDoc ctx) throws ServiceException {
90
91         super.doInit(ctx);
92
93         String JavaDoc strJettyHome = System.getProperty("jetty.home");
94         if (strJettyHome != null) {
95             if (getLogger().isLoggable(BasicLevel.DEBUG)) {
96                 getLogger().log(BasicLevel.DEBUG, "");
97             }
98
99             try {
100                 config = (String JavaDoc) ctx.lookup(JETTY_CONFIG);
101             } catch (NamingException JavaDoc neExc) {
102                 // by default we take jetty5.xml under JONAS_BASE/conf
103
String JavaDoc jonasbase = System.getProperties().getProperty("jonas.base");
104                 config = jonasbase + "/conf/jetty5.xml";
105             }
106             getLogger().log(BasicLevel.LEVEL_DEBUG, "using configuration file " + config);
107
108             jettyServer = new Server();
109         }
110
111     }
112
113     /**
114      * Start the Jetty service in a new thread
115      * @throws ServiceException if the startup failed.
116      */

117     public void doStart() throws ServiceException {
118         if (getLogger().isLoggable(BasicLevel.DEBUG)) {
119             getLogger().log(BasicLevel.DEBUG, "");
120         }
121
122         if (jettyServer != null) {
123             JmxService srvcJMX = null;
124
125             // Start Jetty directly and just pass it to JMX if available
126
if (config != null) {
127                 try {
128                     jettyServer.configure(config);
129                     jettyServer.start();
130                 } catch (Exception JavaDoc eExc) {
131                     getLogger().log(BasicLevel.LEVEL_ERROR,
132                             "error has occured while starting Jetty server using configuration file " + config, eExc);
133                 }
134             }
135
136             ServiceManager sm = null;
137             try {
138                 sm = ServiceManager.getInstance();
139             } catch (Exception JavaDoc e) {
140                 String JavaDoc err = "Cannot get ServiceManager instance.";
141                 getLogger().log(BasicLevel.ERROR, err);
142                 throw new ServiceException(err, e);
143             }
144
145             try {
146                 srvcJMX = (JmxService) sm.getJmxService();
147                 if (srvcJMX != null) {
148                     // Register JettyService MBean : JettyService
149
Object JavaDoc obj;
150                     ObjectName JavaDoc objname;
151                     // Once we register this bean, it will start Jetty using
152
// given configuration
153
// file. That's why we have to do it in run() instead in
154
// doStart()
155
obj = new JettyJonasServerMBean(jettyServer);
156                     objname = JonasObjectName.wwwService();
157                     srvcJMX.getJmxServer().registerMBean(obj, objname);
158                 }
159             } catch (ServiceException seExc) {
160                 // Jmx Service not available, do nothing
161
getLogger().log(
162                         BasicLevel.LEVEL_DEBUG,
163                         "cannot start Jetty server using configuration file " + config
164                                 + " using JMX. Will start without JMX.", seExc);
165             } catch (Exception JavaDoc eExc) {
166                 getLogger().log(BasicLevel.LEVEL_ERROR, "cannot start Jetty server using configuration file " + config,
167                         eExc);
168                 throw new ServiceException("Cannot start Jetty server using configuration file " + config, eExc);
169             }
170
171             // ... and deploy wars of the jonas.properties
172
super.doStart();
173         } else {
174             throw new ServiceException("Cannot start Jetty server.");
175         }
176     }
177
178     /**
179      * Stop the Jetty service.
180      * @throws ServiceException if the stop failed.
181      */

182     protected void doStop() throws ServiceException {
183         // Undeploy the wars ...
184
super.doStop();
185
186         // ... and shut down embedded jetty
187
if (getLogger().isLoggable(BasicLevel.DEBUG)) {
188             getLogger().log(BasicLevel.DEBUG, "");
189         }
190         if (isStarted()) {
191             JmxService srvcJMX = null;
192
193             ServiceManager sm = null;
194             try {
195                 sm = ServiceManager.getInstance();
196             } catch (Exception JavaDoc e) {
197                 String JavaDoc err = "Cannot get ServiceManager instance.";
198                 getLogger().log(BasicLevel.ERROR, err);
199                 throw new ServiceException(err, e);
200             }
201
202             try {
203                 srvcJMX = (JmxService) sm.getJmxService();
204                 if (srvcJMX != null) {
205                     ObjectName JavaDoc objname;
206
207                     objname = new ObjectName JavaDoc("jonas:type=service,name=jetty");
208                     srvcJMX.getJmxServer().unregisterMBean(objname);
209                     jettyServer = null;
210                     objname = new ObjectName JavaDoc("jonas:type=jetty,name=jettylog");
211                     srvcJMX.getJmxServer().unregisterMBean(objname);
212                     objname = new ObjectName JavaDoc("jonas:type=jetty,name=jettycode");
213                     srvcJMX.getJmxServer().unregisterMBean(objname);
214                 }
215             } catch (ServiceException seExc) {
216                 getLogger().log(BasicLevel.LEVEL_ERROR, "JMX Service not available", seExc);
217             } catch (Exception JavaDoc eExc) {
218                 getLogger().log(BasicLevel.LEVEL_ERROR, "Cannot stop Jetty server", eExc);
219                 throw new ServiceException("Cannot stop Jetty server", eExc);
220             }
221
222             if (jettyServer != null) {
223                 try {
224                     jettyServer.stop();
225                     jettyServer.destroy();
226                     jettyServer = null;
227                 } catch (Exception JavaDoc eExc) {
228                     getLogger().log(BasicLevel.LEVEL_ERROR,
229                             "error has occured while stopping Jetty server using configuration file " + config, eExc);
230                 }
231             }
232         }
233     }
234
235     /**
236      * Create the environment and delegate the operation to the implementation
237      * of the web container.
238      * @param ctx the context which contains the configuration in order to
239      * deploy a WAR.
240      * @throws JWebContainerServiceException if the registration of the WAR
241      * failed.
242      */

243     protected void doRegisterWar(Context JavaDoc ctx) throws JWebContainerServiceException {
244         // Get the 5 parameters :
245
// - warURL is the URL of the war to register (required param).
246
// - contextRoot is the context root to which this application
247
// should be installed (must be unique) (required param).
248
// - hostName is the name of the host on which deploy the war
249
// (optional param taken into account only if no <context> element
250
// was declared in server.xml for this web application) .
251
// - java2DelegationModel the compliance to java2 delegation model
252
// - parentCL the war classloader of this war.
253
//URL warURL = null;
254
URL JavaDoc unpackedWarURL = null;
255         String JavaDoc contextRoot = null;
256         boolean java2DelegationModel = true;
257         try {
258             unpackedWarURL = (URL JavaDoc) ctx.lookup("unpackedWarURL");
259             contextRoot = (String JavaDoc) ctx.lookup("contextRoot");
260             Boolean JavaDoc bool = (Boolean JavaDoc) ctx.lookup("java2DelegationModel");
261             java2DelegationModel = bool.booleanValue();
262         } catch (NamingException JavaDoc e) {
263             String JavaDoc err = "Error while getting parameter from context param ";
264             getLogger().log(BasicLevel.ERROR, err + e.getMessage());
265             throw new JWebContainerServiceException(err, e);
266         }
267
268         ClassLoader JavaDoc webClassLoader = null;
269         try {
270             webClassLoader = (ClassLoader JavaDoc) ctx.lookup("parentCL");
271         } catch (NamingException JavaDoc e) {
272             String JavaDoc err = "error while getting parameter from context param ";
273             getLogger().log(BasicLevel.ERROR, err + e.getMessage());
274             throw new JWebContainerServiceException(err, e);
275         }
276
277         String JavaDoc hostName = null;
278         try {
279             hostName = (String JavaDoc) ctx.lookup("hostName");
280         } catch (NamingException JavaDoc e) {
281             hostName = "";
282         }
283
284         String JavaDoc earAppName = null;
285         try {
286             earAppName = (String JavaDoc) ctx.lookup("earAppName");
287         } catch (NamingException JavaDoc e) {
288             // no ear case, so no ear application name
289
earAppName = null;
290         }
291
292         // Install a new web application, whose web application archive is
293
// at the specified URL, into this container with the specified
294
// context root.
295
// A context root of "" (the empty string) should be used for the root
296
// application for this container. Otherwise, the context root must
297
// start with a slash.
298

299         if (contextRoot.equals("/")) {
300             contextRoot = "";
301         } else if (contextRoot.equalsIgnoreCase("ROOT")) {
302             // Jetty uses ROOT.war and ROOT directory to as root context
303
contextRoot = "";
304         }
305
306         // install the war.
307
File JavaDoc fWar = new File JavaDoc(unpackedWarURL.getFile());
308         String JavaDoc fileName = fWar.getAbsolutePath();
309
310         if (jettyServer != null) {
311             try {
312                 WebApplicationContext contextWebApp;
313
314                 if ((hostName == null) || (hostName.length() == 0)) {
315                     // There is no host
316
if (getLogger().isLoggable(BasicLevel.DEBUG)) {
317                         getLogger().log(BasicLevel.DEBUG,
318                                 "Jetty server installing web app " + fileName + " and context " + contextRoot);
319                     }
320                     contextWebApp = jettyServer.addWebApplication(contextRoot, fileName);
321                 } else {
322                     // Host was specified
323
if (getLogger().isLoggable(BasicLevel.DEBUG)) {
324                         getLogger().log(
325                                 BasicLevel.DEBUG,
326                                 "Jetty server installing web app " + fileName + " on host " + hostName + " and context "
327                                 + contextRoot);
328                     }
329                     contextWebApp = jettyServer.addWebApplication(hostName, contextRoot, fileName);
330
331                 }
332
333                 contextWebApp.setAttribute("J2EEDomainName", getDomainName());
334                 contextWebApp.setAttribute("J2EEServerName", getJonasServerName());
335                 contextWebApp.setAttribute("J2EEApplicationName", earAppName);
336
337                 // Add default xml descriptor
338
File JavaDoc webDefaults = new File JavaDoc(JETTY_DEFAULT_WEB_XML_FILE);
339                 if (webDefaults.exists()) {
340                     contextWebApp.setDefaultsDescriptor(webDefaults.toURL().toExternalForm());
341                 } else {
342                     getLogger().log(BasicLevel.WARN, "The file '" + JETTY_DEFAULT_WEB_XML_FILE + "' is not present. Check that your JONAS_BASE is up-to-date.");
343                 }
344
345                 // Specifying the jsp class path used by jasper
346
contextWebApp.setAttribute("org.apache.catalina.jsp_classpath", getJOnASClassPath(webClassLoader));
347
348                 // Set the parent class loader
349
contextWebApp.setParentClassLoader(webClassLoader);
350
351                 // Set this classloader to the Java2 compliant mode ?
352
contextWebApp.setClassLoaderJava2Compliant(java2DelegationModel);
353
354                 if (getLogger().isLoggable(BasicLevel.DEBUG)) {
355                     getLogger().log(BasicLevel.DEBUG,
356                         "Webapp class loader java 2 delegation model set to " + java2DelegationModel);
357
358                     getLogger().log(BasicLevel.DEBUG, "Jetty server starting web app " + fileName);
359                 }
360                 contextWebApp.start();
361                 if (getLogger().isLoggable(BasicLevel.DEBUG)) {
362                     getLogger().log(BasicLevel.DEBUG, "Jetty server is running web app " + fileName);
363                 }
364
365             } catch (IOException JavaDoc ioeExc) {
366                 String JavaDoc err = "Cannot install this web application " + ioeExc;
367                 getLogger().log(BasicLevel.ERROR, err);
368                 throw new JWebContainerServiceException(err, ioeExc);
369             } catch (Exception JavaDoc eExc) {
370                 String JavaDoc err = "Cannot start this web application " + eExc;
371                 getLogger().log(BasicLevel.ERROR, err);
372                 throw new JWebContainerServiceException(err, eExc);
373             }
374         } else {
375             if (getLogger().isLoggable(BasicLevel.DEBUG)) {
376                 getLogger().log(BasicLevel.DEBUG, "No Jetty server to install web app " + fileName);
377             }
378         }
379
380         // TODO We need to have the J2EE WebModule MBean here, should add it to the Context
381
// Store WebModule ObjectName in Context
382
try {
383             ctx.rebind("WebModule", getDummyJSR77ObjectName(hostName, contextRoot, earAppName));
384         } catch (Exception JavaDoc e) {
385             // NamingException or Mbean related Exception
386
// TODO i18n
387
String JavaDoc err = "Cannot rebind WebModule ObjectName in Context";
388             getLogger().log(BasicLevel.ERROR, err, e);
389             throw new JWebContainerServiceException(err, e);
390         }
391
392     }
393
394     /**
395      * Create a fake, JSR77 MBean ObjectName
396      * @param hostName host name
397      * @param contextRoot context root name
398      * @param earAppName application name
399      * @return a fake JSR77 WebModule ObjectName
400      * @throws MalformedObjectNameException if ObjectName incorrect
401      */

402     private ObjectName JavaDoc getDummyJSR77ObjectName(String JavaDoc hostName, String JavaDoc contextRoot, String JavaDoc earAppName) throws MalformedObjectNameException JavaDoc {
403         // jonas:j2eeType=WebModule,name=//localhost/,J2EEApplication=none,J2EEServer=jonas
404
return ObjectName.getInstance(getDomainName() + ":j2eeType=WebModule,name=" + "/" + contextRoot + ",J2EEApplication=" + earAppName + ",J2EEServer=" + getJonasServerName());
405     }
406
407     /**
408      * Return the classpath which can be used for jsp compiling by Jasper. This
409      * classpath is extracted from the web classloader.
410      * @param webClassLoader the ClassLoader used for extract URLs.
411      * @return the jonas classpath which is useful for JSP compiling.
412      */

413     public String JavaDoc getJOnASClassPath(ClassLoader JavaDoc webClassLoader) {
414
415         StringBuffer JavaDoc classpath = new StringBuffer JavaDoc();
416         int n = 0;
417         while (webClassLoader != null) {
418             if (!(webClassLoader instanceof URLClassLoader JavaDoc)) {
419                 break;
420             }
421             URL JavaDoc[] repositories = ((URLClassLoader JavaDoc) webClassLoader).getURLs();
422             for (int i = 0; i < repositories.length; i++) {
423                 String JavaDoc repository = repositories[i].toString();
424                 if (repository.startsWith("file://")) {
425                     repository = repository.substring("file://".length());
426                 } else if (repository.startsWith("file:")) {
427                     repository = repository.substring("file:".length());
428                 } else {
429                     continue;
430                 }
431                 if (repository == null) {
432                     continue;
433                 }
434                 if (n > 0) {
435                     classpath.append(File.pathSeparator);
436                 }
437                 classpath.append(repository);
438                 n++;
439             }
440             webClassLoader = webClassLoader.getParent();
441         }
442
443         return classpath.toString();
444     }
445
446     /**
447      * Delegate the unregistration to the implementation of the web container.
448      * @param ctx the context which contains the configuration in order to
449      * undeploy a WAR.
450      * @throws JWebContainerServiceException if the unregistration failed.
451      */

452     protected void doUnRegisterWar(Context JavaDoc ctx) throws JWebContainerServiceException {
453         // Get the 2 parameters :
454
// - contextRoot is the context root to be removed (required param).
455
// - hostName is the name of the host to remove the war (optional).
456
String JavaDoc contextRoot = null;
457         try {
458             contextRoot = (String JavaDoc) ctx.lookup("contextRoot");
459         } catch (NamingException JavaDoc e) {
460             String JavaDoc err = "Error while getting parameter from context param ";
461             getLogger().log(BasicLevel.ERROR, err + e.getMessage());
462             throw new JWebContainerServiceException(err, e);
463         }
464
465         String JavaDoc hostName = null;
466         try {
467             hostName = (String JavaDoc) ctx.lookup("hostName");
468         } catch (NamingException JavaDoc e) {
469             hostName = "";
470         }
471         // A context root of "" (the empty string) should be used for the root
472
// application for this container. Otherwise, the context root must
473
// start with a slash.
474

475         if (contextRoot.equals("/")) {
476             contextRoot = "";
477         } else if (contextRoot.equalsIgnoreCase("ROOT")) {
478             // Jetty uses ROOT.war and ROOT directory to as root context
479
contextRoot = "";
480         }
481
482         if (jettyServer != null) {
483             HttpContext contextWebApp;
484
485             if ((hostName == null) || (hostName.length() == 0)) {
486                 // There is no host
487
if (getLogger().isLoggable(BasicLevel.DEBUG)) {
488                     getLogger().log(BasicLevel.DEBUG, "Jetty server looking upweb app " + " from context " + contextRoot);
489                 }
490                 contextWebApp = jettyServer.getContext(contextRoot);
491             } else {
492                 // Host was specified
493
if (getLogger().isLoggable(BasicLevel.DEBUG)) {
494                 getLogger().log(BasicLevel.DEBUG,
495                         "Jetty server looking up web app " + " on host " + hostName + " and context " + contextRoot);
496                 }
497                 contextWebApp = jettyServer.getContext(hostName, contextRoot);
498             }
499
500             if (contextWebApp != null) {
501                 if (getLogger().isLoggable(BasicLevel.DEBUG)) {
502                     getLogger().log(BasicLevel.DEBUG,
503                             "Jetty server found and is stopping web app at context " + contextRoot);
504                 }
505                 // Stop it gracefully
506
try {
507                     contextWebApp.stop(true);
508                 } catch (InterruptedException JavaDoc ieExc) {
509                     getLogger().log(BasicLevel.LEVEL_DEBUG,
510                             "Jetty server encoutered exception while stopping web application ", ieExc);
511                 }
512                 if (getLogger().isLoggable(BasicLevel.DEBUG)) {
513                     getLogger().log(BasicLevel.DEBUG,
514                             "Jetty server stopped and is removing web app at context " + contextRoot);
515                 }
516
517                 jettyServer.removeContext(contextWebApp);
518                 if (getLogger().isLoggable(BasicLevel.DEBUG)) {
519                     getLogger().log(BasicLevel.DEBUG,
520                             "Jetty server removed and is destroying web app at context " + contextRoot);
521                 }
522                 contextWebApp.destroy();
523
524                 if (getLogger().isLoggable(BasicLevel.DEBUG)) {
525                     getLogger().log(BasicLevel.DEBUG, "Jetty server unloaded web app at context " + contextRoot);
526                 }
527
528             } else {
529                 if (getLogger().isLoggable(BasicLevel.DEBUG)) {
530                     getLogger().log(BasicLevel.DEBUG, "Jetty server didn't find web app at context " + contextRoot);
531                 }
532             }
533
534         } else {
535             if (getLogger().isLoggable(BasicLevel.DEBUG)) {
536                 getLogger().log(BasicLevel.DEBUG, "No Jetty server to install web app at context " + contextRoot);
537             }
538         }
539     }
540
541     /**
542      * Update info of the serverName and serverVersion
543      */

544     protected void updateServerInfos() {
545         String JavaDoc infos = org.mortbay.http.Version.getImplVersion();
546
547         StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(infos, "/");
548         if (st.countTokens() != 2) {
549             setServerName(infos);
550             setServerVersion("");
551         } else {
552             setServerName(st.nextToken());
553             setServerVersion(st.nextToken());
554         }
555     }
556
557     /**
558      * Return the Default host name of the web container.
559      * @return the Default host name of the web container.
560      * @throws JWebContainerServiceException when default host cannot be
561      * resolved (multiple services).
562      */

563     public String JavaDoc getDefaultHost() throws JWebContainerServiceException {
564         Map JavaDoc hosts = jettyServer.getHostMap();
565         // If we have more than 1 host, we cannot determine default host!
566
if (hosts.isEmpty()) {
567             String JavaDoc err = "Cannot determine default host : Jetty server has no host!";
568             throw new JWebContainerServiceException(err);
569         }
570
571         String JavaDoc vHost = (String JavaDoc) hosts.keySet().iterator().next();
572         if (vHost == null) {
573             vHost = "localhost";
574         }
575
576         if (hosts.size() > 1) {
577             if (getLogger().isLoggable(BasicLevel.WARN)) {
578                 getLogger().log(BasicLevel.WARN, "More than 1 host found, using the first one : " + vHost);
579             }
580         }
581         return vHost;
582     }
583
584     /**
585      * Return the Default HTTP port number of the web container (can be null if
586      * multiple HTTP connector has been set).
587      * @return the Default HTTP port number of the web container.
588      * @throws JWebContainerServiceException when default HTTP port cannot be
589      * resolved (multiple occurences).
590      */

591     public String JavaDoc getDefaultHttpPort() throws JWebContainerServiceException {
592         return String.valueOf(getFirstListenerFromScheme("http").getPort());
593     }
594
595     /**
596      * Return the Default HTTPS port number of the web container (can be null if
597      * multiple HTTPS connector has been set).
598      * @return the Default HTTPS port number of the web container.
599      * @throws JWebContainerServiceException when default HTTPS port cannot be
600      * resolved (multiple occurences).
601      */

602     public String JavaDoc getDefaultHttpsPort() throws JWebContainerServiceException {
603         return String.valueOf(getFirstListenerFromScheme("https").getPort());
604     }
605
606     /**
607      * @param myScheme matching URL scheme (http, https, ...)
608      * @return Returns the first HttpListener found
609      */

610     private HttpListener getFirstListenerFromScheme(String JavaDoc myScheme) {
611         HttpListener[] listeners = jettyServer.getListeners();
612         Vector JavaDoc http = new Vector JavaDoc();
613         for (int i = 0; i < listeners.length; i++) {
614             String JavaDoc scheme = listeners[i].getDefaultScheme();
615             if (scheme.equalsIgnoreCase(myScheme)) {
616                 http.add(listeners[i]);
617             }
618         }
619         if (http.isEmpty()) {
620             String JavaDoc err = "Cannot determine default '" + myScheme + "' port :" + " Jetty server has 0 '" + myScheme + "' Listener";
621             throw new JWebContainerServiceException(err);
622         }
623
624         HttpListener hl = (HttpListener) http.get(0);
625         // Check if there are more than one HTTP connectors specified, if so, warn the administrator.
626
if (http.size() > 1) {
627             if (getLogger().isLoggable(BasicLevel.WARN)) {
628                 getLogger().log(BasicLevel.WARN, "Found multiple Listener for scheme '" + myScheme + "'"
629                         + ", using first by default! (port:" + hl.getPort() + ")");
630             }
631         }
632
633         return hl;
634     }
635
636 }
637
638
Popular Tags