1 17 package org.apache.geronimo.jetty6; 18 19 import java.io.IOException ; 20 import java.util.Map ; 21 import java.util.Set ; 22 23 import javax.security.jacc.PolicyContext ; 24 import javax.servlet.ServletContext ; 25 import javax.servlet.ServletException ; 26 import javax.servlet.ServletRequest ; 27 import javax.servlet.ServletResponse ; 28 import javax.servlet.UnavailableException ; 29 import javax.servlet.http.HttpServletRequest ; 30 31 import org.apache.geronimo.gbean.GBeanInfo; 32 import org.apache.geronimo.gbean.GBeanInfoBuilder; 33 import org.apache.geronimo.gbean.GBeanLifecycle; 34 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory; 35 import org.apache.geronimo.webservices.POJOWebServiceServlet; 36 import org.apache.geronimo.webservices.WebServiceContainer; 37 import org.apache.geronimo.webservices.WebServiceContainerInvoker; 38 import org.apache.geronimo.webservices.WebServiceContainerFactory; 39 import org.mortbay.jetty.Request; 40 import org.mortbay.jetty.servlet.ServletHolder; 41 42 43 49 public class JettyPOJOWebServiceHolder implements GBeanLifecycle { 50 private final ServletHolder servletHolder; 51 private final WebServiceContainer webServiceContainer; 52 private final Set servletMappings; 53 private final JettyServletRegistration context; 54 private final String pojoClassName; 55 56 public JettyPOJOWebServiceHolder() { 58 servletHolder = null; 59 webServiceContainer = null; 60 servletMappings = null; 61 context = null; 62 pojoClassName = null; 63 } 64 65 public JettyPOJOWebServiceHolder(String pojoClassName, 66 String servletName, 67 Map initParams, 68 Integer loadOnStartup, 69 Set servletMappings, 70 WebServiceContainerFactory webServiceContainerFactory, 71 JettyServletRegistration context) throws Exception { 72 servletHolder = new ServletHolder(); 73 75 this.pojoClassName = pojoClassName; 76 this.context = context; 77 this.webServiceContainer = webServiceContainerFactory == null? null: webServiceContainerFactory.getWebServiceContainer(); 78 this.servletMappings = servletMappings; 79 if (context != null) { 80 servletHolder.setName(servletName); 81 servletHolder.setClassName(POJOWebServiceServlet.class.getName()); 82 servletHolder.setInitParameters(initParams); 83 if (loadOnStartup != null) { 84 servletHolder.setInitOrder(loadOnStartup.intValue()); 85 } 86 } 87 } 88 89 92 public String getServletName() { 93 return servletHolder.getName(); 94 } 95 96 101 public void handle(ServletRequest request, ServletResponse response) 102 throws ServletException , UnavailableException , IOException { 103 104 107 InternalJettyServletHolder.setCurrentServletName(getServletName()); 108 PolicyContext.setHandlerData(Request.getRequest((HttpServletRequest ) request)); 109 110 servletHolder.handle(request, response); 111 } 112 113 public void doStart() throws Exception { 114 if (context != null) { 115 Class pojoClass = context.getWebClassLoader().loadClass(pojoClassName); 116 117 120 ServletContext servletContext = this.context.getServletHandler().getServletContext(); 121 122 String webServicecontainerID = getServletName() + WebServiceContainerInvoker.WEBSERVICE_CONTAINER + webServiceContainer.hashCode(); 126 servletHolder.setInitParameter(WebServiceContainerInvoker.WEBSERVICE_CONTAINER, webServicecontainerID); 127 servletContext.setAttribute(webServicecontainerID, webServiceContainer); 128 129 String pojoClassID = getServletName() + POJOWebServiceServlet.POJO_CLASS + pojoClass.hashCode(); 131 servletHolder.setInitParameter(POJOWebServiceServlet.POJO_CLASS, pojoClassID); 132 servletContext.setAttribute(pojoClassID, pojoClass); 133 134 context.registerServletHolder(servletHolder, getServletName(), this.servletMappings, null); 137 servletHolder.start(); 138 } 139 } 140 141 public void doStop() throws Exception { 142 servletHolder.stop(); 143 } 144 145 public void doFail() { 146 try { 147 servletHolder.stop(); 148 } catch (Exception e) { 149 } 151 } 152 153 public static final GBeanInfo GBEAN_INFO; 154 155 static { 156 GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(JettyPOJOWebServiceHolder.class, NameFactory.SERVLET_WEB_SERVICE_TEMPLATE); 157 160 infoBuilder.addAttribute("pojoClassName", String .class, true); 161 infoBuilder.addAttribute("servletName", String .class, true); 162 infoBuilder.addAttribute("initParams", Map .class, true); 163 infoBuilder.addAttribute("loadOnStartup", Integer .class, true); 164 infoBuilder.addAttribute("servletMappings", Set .class, true); 165 infoBuilder.addReference("WebServiceContainerFactory", WebServiceContainerFactory.class); 166 infoBuilder.addReference("JettyServletRegistration", JettyServletRegistration.class); 167 168 infoBuilder.setConstructor(new String []{"pojoClassName", 169 "servletName", 170 "initParams", 171 "loadOnStartup", 172 "servletMappings", 173 "WebServiceContainerFactory", 174 "JettyServletRegistration"}); 175 176 GBEAN_INFO = infoBuilder.getBeanInfo(); 177 } 178 179 public static GBeanInfo getGBeanInfo() { 180 return GBEAN_INFO; 181 } 182 183 184 } 185 | Popular Tags |