mx4j/src/tools/mx4j/tools/remote/http/jetty JettyWebContainer.java,NONE,1.1
Simone Bordet <[email protected]>
| 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-serv25164/src/tools/mx4j/tools/remote/http/jetty Added Files: JettyWebContainer.java Log Message: Refactoring of JSR 160 JMXConnector and JMXConnectorServer for protocols that runs over HTTP: SOAP, Hessian and Burlap --- NEW FILE: JettyWebContainer.java --- /* * Copyright (C) MX4J. * All rights reserved. * * This software is distributed under the terms of the MX4J License version 1.0. * See the terms of the MX4J License in the documentation provided with this software. */ package mx4j.tools.remote.http.jetty; import java.io.IOException; import java.util.Map; import javax.management.remote.JMXServiceURL; import mx4j.tools.remote.http.WebContainer; import org.mortbay.jetty.Server; import org.mortbay.jetty.servlet.ServletHandler; import org.mortbay.jetty.servlet.ServletHttpContext; import org.mortbay.util.MultiException; /** * Jetty's implementation of WebContainer interface * * @author <a href="mailto:[email protected]">Alireza Taherkordi</a> * @version $Revision: 1.1 $ */ public class JettyWebContainer implements WebContainer { private final Server server; public JettyWebContainer() { server = new Server(); } public void start(JMXServiceURL url, Map environment) throws IOException { try { server.addListener(":" + url.getPort()); server.start(); } catch (MultiException x) { throw new IOException(x.toString()); } } public void stop() throws IOException { try { server.stop(); } catch (InterruptedException x) { Thread.currentThread().interrupt(); } } public void deploy(String servletClassName, JMXServiceURL url, Map environment) throws IOException { try { String urlPattern = resolveServletMapping(url); ServletHttpContext context = (ServletHttpContext)server.getContext("/"); context.addServlet(urlPattern, servletClassName); // TODO: be sure an undeployed url is not restarted ! if (!context.isStarted()) context.start(); } catch (Exception x) { throw new IOException(x.toString()); } } public void undeploy(String servletName, JMXServiceURL url, Map environment) { String urlPattern = resolveServletMapping(url); ServletHttpContext context = (ServletHttpContext)server.getContext("/"); ServletHandler handler = context.getServletHandler(); handler.getServletMap().remove(urlPattern); } private String resolveServletMapping(JMXServiceURL url) { String path = url.getURLPath(); String urlPattern = null; if (path.endsWith("/")) urlPattern = path + "*"; else urlPattern = path + "/*"; if (!urlPattern.startsWith("/")) urlPattern = "/" + urlPattern; return urlPattern; } } ------------------------------------------------------- SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media 100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33 Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift. http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285