1 17 package org.apache.geronimo.jetty; 18 19 import java.io.IOException ; 20 import java.util.Map ; 21 import java.util.Set ; 22 import java.util.Collections ; 23 import javax.security.jacc.PolicyContext ; 24 import javax.servlet.ServletException ; 25 import javax.servlet.ServletRequest ; 26 import javax.servlet.ServletResponse ; 27 import javax.servlet.UnavailableException ; 28 29 import org.apache.geronimo.gbean.GBeanInfo; 30 import org.apache.geronimo.gbean.GBeanInfoBuilder; 31 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory; 32 import org.mortbay.jetty.servlet.ServletHolder; 33 import org.mortbay.jetty.servlet.ServletHttpRequest; 34 35 36 46 public class JettyServletHolder extends ServletHolder { 47 private static final ThreadLocal currentServletName = new ThreadLocal (); 48 49 public JettyServletHolder() { 51 52 } 53 54 public JettyServletHolder(String servletName, 55 String servletClassName, 56 String jspFile, 57 Map initParams, 58 Integer loadOnStartup, 59 Set servletMappings, 60 Map webRoleRefPermissions, 61 JettyServletRegistration context) throws Exception { 62 super(context == null? null: context.getServletHandler(), servletName, servletClassName, jspFile); 63 65 if (context != null) { 66 putAll(initParams); 67 if (loadOnStartup != null) { 68 setInitOrder(loadOnStartup.intValue()); 69 } 70 context.registerServletHolder(this, servletName, servletMappings, webRoleRefPermissions == null? Collections.EMPTY_MAP: webRoleRefPermissions); 72 } 74 } 75 76 79 public String getServletName() { 80 return getName(); 81 } 82 83 87 public void handle(ServletRequest request, ServletResponse response) 88 throws ServletException , UnavailableException , IOException { 89 90 setCurrentServletName(getServletName()); 91 92 super.handle(request, response); 93 } 94 95 101 static String getCurrentServletName() { 102 return (String ) currentServletName.get(); 103 } 104 105 static void setCurrentServletName(String servletName) { 106 currentServletName.set(servletName); 107 } 108 109 public static final GBeanInfo GBEAN_INFO; 110 111 static { 112 GBeanInfoBuilder infoBuilder = new GBeanInfoBuilder(JettyServletHolder.class, NameFactory.DEFAULT_SERVLET); 113 infoBuilder.addInterface(ServletHolder.class); 115 116 infoBuilder.addAttribute("servletName", String .class, true); 117 infoBuilder.addAttribute("servletClass", String .class, true); 118 infoBuilder.addAttribute("jspFile", String .class, true); 119 infoBuilder.addAttribute("initParams", Map .class, true); 120 infoBuilder.addAttribute("loadOnStartup", Integer .class, true); 121 infoBuilder.addAttribute("servletMappings", Set .class, true); 122 infoBuilder.addAttribute("webRoleRefPermissions", Map .class, true); 123 infoBuilder.addReference("JettyServletRegistration", JettyServletRegistration.class, NameFactory.WEB_MODULE); 124 125 infoBuilder.setConstructor(new String [] {"servletName", 126 "servletClass", 127 "jspFile", 128 "initParams", 129 "loadOnStartup", 130 "servletMappings", 131 "webRoleRefPermissions", 132 "JettyServletRegistration"}); 133 134 GBEAN_INFO = infoBuilder.getBeanInfo(); 135 } 136 137 public static GBeanInfo getGBeanInfo() { 138 return GBEAN_INFO; 139 } 140 } 141 | Popular Tags |