mx4j/src/tools/mx4j/tools/remote/http/jetty JettyWebContainer.java,1.3,1.4
Simone Bordet <[email protected]> Wed, 20 Oct 2004 17:15:02 +0000
| Newsgroups | gmane.comp.java.mx4j.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/mx4j/mx4j/src/tools/mx4j/tools/remote/http/jetty In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21518/src/tools/mx4j/tools/remote/http/jetty Modified Files: JettyWebContainer.java Log Message: Added possibility to configure Jetty via a configuration file using a property passed in the environment map. Jetty will figure out if it is an external file, a classpath resource, or a remote resource. Index: JettyWebContainer.java =================================================================== RCS file: /cvsroot/mx4j/mx4j/src/tools/mx4j/tools/remote/http/jetty/JettyWebContainer.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** JettyWebContainer.java 13 Oct 2004 07:40:32 -0000 1.3 --- JettyWebContainer.java 20 Oct 2004 17:14:59 -0000 1.4 *************** *** 13,17 **** --- 13,21 ---- import javax.management.remote.JMXServiceURL; + import mx4j.log.Log; + import mx4j.log.Logger; + import mx4j.remote.MX4JRemoteConstants; import mx4j.tools.remote.http.WebContainer; + import org.mortbay.http.HttpListener; import org.mortbay.jetty.Server; import org.mortbay.jetty.servlet.ServletHandler; *************** *** 21,25 **** * Jetty's implementation of WebContainer interface * - * @author <a href="mailto:[email protected]">Alireza Taherkordi</a> * @version $Revision$ */ --- 25,28 ---- *************** *** 33,43 **** } public void start(JMXServiceURL url, Map environment) throws IOException { try { ! server.addListener(":" + url.getPort()); server.start(); } catch (Exception x) { --- 36,56 ---- } + private Logger getLogger() + { + return Log.getLogger(getClass().getName()); + } + public void start(JMXServiceURL url, Map environment) throws IOException { + try { ! configure(url, environment); server.start(); } + catch (IOException x) + { + throw x; + } catch (Exception x) { *************** *** 46,49 **** --- 59,108 ---- } + private void configure(JMXServiceURL url, Map environment) throws IOException + { + Logger logger = getLogger(); + + if (environment != null) + { + Object config = environment.get(MX4JRemoteConstants.HTTP_SERVER_CONFIGURATION); + if (config instanceof String) + { + if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Configuring Jetty with configuration " + config); + server.configure((String)config); + + // Be sure there is at least one listener on the port specified by the JMXServiceURL + HttpListener[] listeners = server.getListeners(); + if (listeners != null) + { + boolean found = false; + for (int i = 0; i < listeners.length; ++i) + { + HttpListener listener = listeners[i]; + if (listener.getPort() == url.getPort()) + { + found = true; + break; + } + } + if (!found) throw new IOException("No listener configured with configuration " + config + " matches JMXServiceURL " + url); + // Configured successfully, return + if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Configured Jetty successfully with configuration " + config); + return; + } + else + { + if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Jetty configuration " + config + " does not have any listener"); + } + } + else + { + if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Skipping Jetty configuration " + config + " (must be a String)"); + } + } + + if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Configuring Jetty with a default listener on port " + url.getPort()); + server.addListener(":" + url.getPort()); + } + public void stop() throws IOException { ------------------------------------------------------- This SF.net email is sponsored by: IT Product Guide on ITManagersJournal Use IT products in your business? Tell us what you think of them. Give us Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more http://productguide.itmanagersjournal.com/guidepromo.tmpl