package pt.ist.struts.dispatch.servlets; import java.util.Map; import java.util.Set; import javax.servlet.MultipartConfigElement; import javax.servlet.ServletContainerInitializer; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.ServletRegistration.Dynamic; import javax.servlet.annotation.HandlesTypes; import org.apache.struts.action.Action; import org.apache.struts.action.ActionServlet; import pt.ist.struts.dispatch.annotation.Mapping; import pt.ist.struts.dispatch.annotation.StrutsConfiguration; @HandlesTypes({ Mapping.class, StrutsConfiguration.class }) public class StrutsFrameworkInitializer implements ServletContainerInitializer { @Override public void onStartup(Set> classes, ServletContext context) throws ServletException { System.out.println("Starting up struts framework"); if (classes != null) { for (Class clazz : classes) { Mapping mapping = clazz.getAnnotation(Mapping.class); if (mapping != null) { RuntimeModuleConfigFactory.registerAction((Class) clazz); } StrutsConfiguration strutsConfig = clazz.getAnnotation(StrutsConfiguration.class); if (strutsConfig != null) { RuntimeModuleConfigFactory.registerConfiguration(strutsConfig); } } } Dynamic struts = context.addServlet("action", ActionServlet.class.getName()); struts.setLoadOnStartup(2); struts.addMapping("*.do"); struts.setMultipartConfig(new MultipartConfigElement("/tmp")); Map parameters = RuntimeModuleConfigFactory.getModuleConfigMap(); if (!parameters.containsKey("config")) { parameters.put("config", "/WEB-INF/conf/struts-empty.xml"); } parameters.put("debug", "3"); parameters.put("detail", "3"); parameters.put("validating", "true"); parameters.put("configFactory", RuntimeModuleConfigFactory.class.getName()); struts.setInitParameters(parameters); } }