1 17 package org.apache.geronimo.jetty; 18 19 import java.io.IOException ; 20 import java.util.Collections ; 21 import java.util.Map ; 22 import java.util.Set ; 23 24 import javax.security.jacc.PolicyContext ; 25 import javax.servlet.ServletContext ; 26 import javax.servlet.ServletException ; 27 import javax.servlet.ServletRequest ; 28 import javax.servlet.ServletResponse ; 29 import javax.servlet.UnavailableException ; 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.kernel.StoredObject; 36 import org.apache.geronimo.webservices.POJOWebServiceServlet; 37 import org.apache.geronimo.webservices.WebServiceContainer; 38 import org.apache.geronimo.webservices.WebServiceContainerInvoker; 39 import org.mortbay.jetty.servlet.ServletHolder; 40 import org.mortbay.jetty.servlet.ServletHttpRequest; 41 42 43 49 public class JettyPOJOWebServiceHolder extends ServletHolder implements GBeanLifecycle { 50 private StoredObject storedWebServiceContainer; 51 private Set servletMappings; 52 private Map webRoleRefPermissions; 53 private JettyServletRegistration context; 54 private String pojoClassName; 55 56 public JettyPOJOWebServiceHolder() { 58 59 } 60 61 public JettyPOJOWebServiceHolder(String pojoClassName, 62 String servletName, 63 Map initParams, 64 Integer loadOnStartup, 65 Set servletMappings, 66 Map webRoleRefPermissions, 67 StoredObject storedWebServiceContainer, 68 JettyServletRegistration context) throws Exception { 69 super(context == null ? null : context.getServletHandler(), servletName, POJOWebServiceServlet.class.getName(), null); 70 72 this.pojoClassName = pojoClassName; 73 this.context = context; 74 this.storedWebServiceContainer = storedWebServiceContainer; 75 if (context != null) { 76 putAll(initParams); 77 if (loadOnStartup != null) { 78 setInitOrder(loadOnStartup.intValue()); 79 } 80 this.servletMappings = servletMappings; 81 this.webRoleRefPermissions = webRoleRefPermissions == null ? Collections.EMPTY_MAP : webRoleRefPermissions; 82 } 83 } 84 85 88 public String getServletName() { 89 return getName(); 90 } 91 92 96 public void handle(ServletRequest request, ServletResponse response) 97 throws ServletException , UnavailableException , IOException { 98 99 102 JettyServletHolder.setCurrentServletName(getServletName()); 103 PolicyContext.setHandlerData(ServletHttpRequest.unwrap(request)); 104 105 super.handle(request, response); 106 } 107 108 public static final GBeanInfo GBEAN_INFO; 109 110 static { 111 GBeanInfoBuilder infoBuilder = new GBeanInfoBuilder(JettyPOJOWebServiceHolder.class, NameFactory.SERVLET_WEB_SERVICE_TEMPLATE); 112 infoBuilder.addInterface(ServletHolder.class); 114 115 infoBuilder.addAttribute("pojoClassName", String .class, true); 116 infoBuilder.addAttribute("servletName", String .class, true); 117 infoBuilder.addAttribute("initParams", Map .class, true); 118 infoBuilder.addAttribute("loadOnStartup", Integer .class, true); 119 infoBuilder.addAttribute("servletMappings", Set .class, true); 120 infoBuilder.addAttribute("webRoleRefPermissions", Map .class, true); 121 infoBuilder.addAttribute("webServiceContainer", StoredObject.class, true); 122 infoBuilder.addReference("JettyServletRegistration", JettyServletRegistration.class); 123 124 infoBuilder.setConstructor(new String []{"pojoClassName", 125 "servletName", 126 "initParams", 127 "loadOnStartup", 128 "servletMappings", 129 "webRoleRefPermissions", 130 "webServiceContainer", 131 "JettyServletRegistration"}); 132 133 GBEAN_INFO = infoBuilder.getBeanInfo(); 134 } 135 136 public static GBeanInfo getGBeanInfo() { 137 return GBEAN_INFO; 138 } 139 140 public void doStart() throws Exception { 141 if (context != null) { 142 Class pojoClass = context.getWebClassLoader().loadClass(pojoClassName); 143 WebServiceContainer webServiceContainer = (WebServiceContainer) storedWebServiceContainer.getObject(context.getWebClassLoader()); 144 145 148 ServletContext servletContext = this.context.getServletHandler().getServletContext(); 149 150 String webServicecontainerID = getServletName() + WebServiceContainerInvoker.WEBSERVICE_CONTAINER + webServiceContainer.hashCode(); 154 put(WebServiceContainerInvoker.WEBSERVICE_CONTAINER, webServicecontainerID); 155 servletContext.setAttribute(webServicecontainerID, webServiceContainer); 156 157 String pojoClassID = getServletName() + POJOWebServiceServlet.POJO_CLASS + pojoClass.hashCode(); 159 put(POJOWebServiceServlet.POJO_CLASS, pojoClassID); 160 servletContext.setAttribute(pojoClassID, pojoClass); 161 162 context.registerServletHolder(this, getServletName(), this.servletMappings, this.webRoleRefPermissions); 164 } 166 } 167 168 public void doStop() throws Exception { 169 } 170 171 public void doFail() { 172 } 173 174 175 } 176 | Popular Tags |