1 4 package org.jfox.deployment.web; 5 6 import org.jfox.ioc.deploy.DeployException; 7 import org.jfox.jetty.JettyWebContainer; 8 import org.mortbay.http.HttpContext; 9 import org.mortbay.j2ee.J2EEWebApplicationContext; 10 import org.mortbay.j2ee.session.Manager; 11 12 15 16 public class JettyWebDeployer extends WebDeployer { 17 18 private JettyWebContainer jetty; 19 20 public JettyWebDeployer(JettyWebContainer jetty) { 21 this.jetty = jetty; 22 } 23 24 protected void doDeploy(WebModule webModule) throws DeployException { 25 try { 26 J2EEWebApplicationContext webApp = new JettyWebApplicationContext(webModule.getTempDeployDirectory().getCanonicalPath()); 27 webApp.setTempDirectory(webModule.getTempDeployDirectory()); 28 if(webModule.getWebContext().equals(jetty.getRootWebApp())) { 29 webApp.setContextPath("/"); 30 } 31 else { 32 webApp.setContextPath("/" + webModule.getWebContext()); 33 } 34 webApp.setParentClassLoader(webModule.getClassLoader()); 37 webApp.setClassLoaderJava2Compliant(true); 38 39 Manager manager = jetty.getDistributableSessionManagerPrototype(); 40 if(manager != null) { 41 webApp.setDistributableSessionManager((Manager) manager.clone()); 42 if(jetty.getForceDistributable()) webApp.setDistributable(true); 43 } 44 jetty.addContext(webApp); 45 webApp.start(); 46 } 47 catch(Exception e) { 48 throw new DeployException("deploy web module " + webModule.getWebContext() + " failed", e); 49 } 50 51 } 52 53 protected void doUndeploy(WebModule webModule) { 54 HttpContext httpContext = jetty.getContext(webModule.getWebContext()); 55 try { 56 httpContext.stop(true); 57 } 58 catch(Exception e) { 59 e.printStackTrace(); 60 } 61 jetty.removeContext(httpContext); 62 } 63 64 protected boolean isStarted() { 65 return jetty.isStarted(); 66 } 67 68 protected void doInit() throws Exception { 69 if(!jetty.isStarted()) { 70 jetty.start(); 71 } 72 } 73 74 protected void doDestroy() throws Exception { 75 76 } 77 78 public static void main(String [] args) { 79 80 } 81 } 82 83 | Popular Tags |