|
View:
New views
6 Messages
—
Rating Filter:
Alert me
|
|
|
patch for allowing tomcat-lite to compileI had some free to take a glance at tomcat lite but noticed it didn't
compile. So here's a patch to let it compile on my machine. There were 3 classes changes of changes 1) Use StringBuilder instead of StringBuffer when required 2) remove @Override 3) Added stubs to adhere to 3.0 interfaces Any objections for committing? -Tim Index: java/org/apache/tomcat/integration/simple/SimpleObjectManager.java =================================================================== --- java/org/apache/tomcat/integration/simple/SimpleObjectManager.java (revision 833452) +++ java/org/apache/tomcat/integration/simple/SimpleObjectManager.java (working copy) @@ -13,40 +13,39 @@ import org.apache.tomcat.integration.ObjectManager; import org.apache.tomcat.util.IntrospectionUtils; -import org.apache.tools.ant.taskdefs.LoadResource; /** - * This is a very small 'dependency injection'/registry poor-man substitute, + * This is a very small 'dependency injection'/registry poor-man substitute, * based on old tomcat IntrospectionUtils ( which is based on ant ). * Alternative would be to just pick one of spring/guice/etc and use it. * This class is a bit smaller and should be enough for simple use. - * - * How it works: + * + * How it works: * - when bound, simple properties are injected in the objects using * the old IntrospectionUtils, same as in original Tomcat server.xml - * + * * - object creation using class name - properties injected as well. * Similar with how server.xml or ant works. - * - * - it is based on a big Properties file, with command line arguments + * + * - it is based on a big Properties file, with command line arguments * merged in. - * + * * Tomcat doesn't require any of the features - they are just used to - * allow configuration in 'default' mode, when no other framework is - * used. - * + * allow configuration in 'default' mode, when no other framework is + * used. + * * See the Spring example for an alternative. I believe most POJO frameworks - * can be supported. - * + * can be supported. + * * @author Costin Manolache */ public class SimpleObjectManager extends ObjectManager { static Logger log = Logger.getLogger(SimpleObjectManager.class.getName()); - + protected Properties props = new Properties(); protected Map<String, Object> objects = new HashMap(); ObjectManager om; - + public SimpleObjectManager() { // Register PropertiesSpi } @@ -55,18 +54,18 @@ this(); bind("Main.args", args); } - + public void loadResource(String res) { InputStream in = this.getClass().getClassLoader() .getResourceAsStream(res); load(in); } - + public void register(ObjectManager om) { this.om = om; super.register(om); } - + public ObjectManager getObjectManager() { return om; } @@ -78,11 +77,11 @@ throw new RuntimeException("Error loading default config"); } } - + public Properties getProperties() { return props; } - + @Override public void unbind(String name) { } @@ -98,8 +97,8 @@ throw new RuntimeException(e); } } - - // TODO: can I make 'inject' public - Guice seems to + + // TODO: can I make 'inject' public - Guice seems to // support this. inject(name, o); } @@ -125,10 +124,10 @@ for (String k: props.stringPropertyNames()) { if (k.startsWith(pref)) { if (k.endsWith(")")) { - continue; // special + continue; // special } String value = props.getProperty(k); - value = IntrospectionUtils.replaceProperties(value, + value = IntrospectionUtils.replaceProperties(value, props, null); String p = k.substring(prefLen); int idx = p.indexOf("."); @@ -151,23 +150,23 @@ } catch (Throwable e) { e.printStackTrace(); return null; - } + } } - + /** * Populate properties based on CLI: * -key value * --key=value - * + * * --config=FILE - load a properties file - * + * * @param args * @param p * @param meta * @return everything after the first non arg not starting with '-' - * @throws IOException + * @throws IOException */ - public String[] processArgs(String[] args, Properties props) + public String[] processArgs(String[] args, Properties props) throws IOException { for (int i = 0; i < args.length; i++) { @@ -181,8 +180,8 @@ System.arraycopy(args, i, res, 0, res.length); return res; } - - String name = arg; + + String name = arg; int eq = arg.indexOf("="); String value = null; if (eq > 0) { @@ -198,7 +197,7 @@ if ("config".equals(arg)) { if (new File(value).exists()) { - load(new FileInputStream(value)); + load(new FileInputStream(value)); } else { loadResource(value); } @@ -207,5 +206,5 @@ } } return new String[] {}; - } + } } Index: java/org/apache/tomcat/lite/ServletContextImpl.java =================================================================== --- java/org/apache/tomcat/lite/ServletContextImpl.java (revision 833452) +++ java/org/apache/tomcat/lite/ServletContextImpl.java (working copy) @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -27,6 +27,7 @@ import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; +import java.util.Collection; import java.util.EnumSet; import java.util.Enumeration; import java.util.EventListener; @@ -57,6 +58,7 @@ import javax.servlet.SessionCookieConfig; import javax.servlet.SessionTrackingMode; import javax.servlet.FilterRegistration.Dynamic; +import javax.servlet.descriptor.JspConfigDescriptor; import org.apache.tomcat.addons.UserSessionManager; import org.apache.tomcat.integration.ObjectManager; @@ -72,15 +74,15 @@ /** * Context - initialized from web.xml or using APIs. - * + * * Initialization order: - * + * * - add all listeners * - add all filters * - add all servlets - * + * * - session parameters - * - + * - * * @author Craig R. McClanahan * @author Remy Maucherat @@ -88,14 +90,14 @@ */ public class ServletContextImpl implements ServletContext { - + /** * Empty collection to serve as the basis for empty enumerations. */ private transient static final ArrayList empty = new ArrayList(); - + transient Logger log; - + /** * Base path - the directory root of the webapp */ @@ -123,7 +125,7 @@ protected transient ArrayList<EventListener> lifecycleListeners = new ArrayList(); protected UserSessionManager manager; - + HashMap<String, FilterConfigImpl> filters = new HashMap<String, FilterConfigImpl>(); HashMap<String, ServletConfigImpl> servlets = new HashMap<String, ServletConfigImpl>(); @@ -133,16 +135,16 @@ /** Mapper for filters. */ protected WebappFilterMapper webappFilterMapper; - - /** Internal mapper for request dispatcher, must have all - * context mappings. - */ + + /** Internal mapper for request dispatcher, must have all + * context mappings. + */ protected WebappServletMapper mapper; - + transient Locale2Charset charsetMapper = new Locale2Charset(); transient TomcatLite facade; - + ObjectManager om; private String hostname; @@ -151,7 +153,7 @@ boolean initDone = false; boolean startDone = false; - + // ------------------------------------------------- ServletContext Methods public ServletContextImpl() { } @@ -159,7 +161,7 @@ public void setTomcat(TomcatLite facade) { this.facade = facade; } - + /** * Registry/framework interface associated with the context. * Also available as a context attribute. @@ -171,11 +173,11 @@ } return om; } - + public void setObjectManager(ObjectManager om) { this.om = om; } - + public Locale2Charset getCharsetMapper() { return charsetMapper; } @@ -188,29 +190,29 @@ this.contextPath = path; log = Logger.getLogger("webapp" + path.replace('/', '.')); } - + public void setHostname(String hostname) { this.hostname = hostname; } - + public String getHostname() { return hostname; } - + /** The directory where this app is based. May be null. - * + * * @param basePath */ public void setBasePath(String basePath) { - this.basePath = basePath; + this.basePath = basePath; } public ServletContextConfig getContextConfig() { return contextConfig; } - + /** The directory where this app is based. - * + * * @param basePath */ public String getBasePath() { @@ -234,11 +236,20 @@ public List<EventListener> getListeners() { return lifecycleListeners; } - - public void addListener(EventListener listener) { - lifecycleListeners.add(listener); + + public void addListener(Class <? extends EventListener> listenerClass) { + // implement me } + public void addListener(String className) { + // implement me + } + + public <T extends EventListener> void addListener(T t) { + lifecycleListeners.add(t); + } + + public void removeListener(EventListener listener) { lifecycleListeners.remove(listener); } @@ -256,7 +267,7 @@ public ServletConfigImpl getServletConfig(String jsp_servlet_name) { return (ServletConfigImpl)servlets.get(jsp_servlet_name); } - + public Map getServletConfigs() { return servlets; } @@ -264,27 +275,27 @@ /** * Add a servlet to the context. * Called from processWebAppData() - * + * * @param servletConfig */ public void addServletConfig(ServletConfigImpl servletConfig) { servlets.put(servletConfig.getServletName(), servletConfig); } - + public boolean getPrivileged() { return false; } - + public Map getFilters() { return filters; } - + protected boolean getCrossContext() { return true; } - + public void addMimeType(String ext, String type) { contentTypes.addContentType(ext, type); } @@ -302,7 +313,7 @@ return mapper; } - + public WebappFilterMapper getFilterMapper() { if (webappFilterMapper == null) { Object customMapper = getObjectManager().get(WebappFilterMapper.class); @@ -316,7 +327,7 @@ return webappFilterMapper ; } - + public FilterConfigImpl getFilter(String name) { return (FilterConfigImpl)filters.get(name); } @@ -349,7 +360,7 @@ public void addSecurityRole(String role) { securityRoles.add(role); } - + public List getSecurityRoles() { return securityRoles; } @@ -392,15 +403,15 @@ } } - + /** * Return the main path associated with this context. */ public String getContextPath() { return contextPath; } - + /** * Return the value of the specified initialization parameter, or * <code>null</code> if this parameter does not exist. @@ -473,10 +484,10 @@ */ public RequestDispatcher getNamedDispatcher(String name) { if (name == null) return null; - ServletConfigImpl wrapper = + ServletConfigImpl wrapper = (ServletConfigImpl) this.getServletConfig(name); if (wrapper == null) return null; - + return new RequestDispatcherImpl(wrapper, name); } @@ -490,18 +501,18 @@ */ public RequestDispatcher getRequestDispatcher(String path) { if (path == null) return null; - + if (!path.startsWith("/")) throw new IllegalArgumentException(path); path = UrlUtils.normalize(path); if (path == null) return (null); - + return new RequestDispatcherImpl(this, path); } - public RequestDispatcher getRequestDispatcher(String path, + public RequestDispatcher getRequestDispatcher(String path, int type, String dispatcherPath) { RequestDispatcher dispatcher = getRequestDispatcher(path); @@ -512,23 +523,23 @@ ThreadLocal requestDispatcherStack = new ThreadLocal(); protected ClassLoader classLoader; - + // protected RequestDispatcherImpl getRequestDispatcher() { -// ArrayList/*<RequestDispatcherImpl>*/ list = +// ArrayList/*<RequestDispatcherImpl>*/ list = // (ArrayList)requestDispatcherStack.get(); // if (list == null) { // list = new ArrayList(); // requestDispatcherStack.set(list); // } -// -// +// +// // return null; // } public void resetDispatcherStack() { - + } - + /** * Return the URL to the resource that is mapped to a specified path. * The path must begin with a "/" and is interpreted as relative to the @@ -545,7 +556,7 @@ if (path == null || !path.startsWith("/")) { throw new MalformedURLException("getResource() " + path); } - + path = UrlUtils.normalize(path); if (path == null) return (null); @@ -585,9 +596,9 @@ return (null); File resFile = new File(basePath + path); - if (!resFile.exists()) + if (!resFile.exists()) return null; - + try { return new FileInputStream(resFile); } catch (FileNotFoundException e) { @@ -624,7 +635,7 @@ if (!path.endsWith("/")) { path = path + "/"; } - + HashSet result = new HashSet(); for (int i=0; i < files.length; i++) { if (files[i].isDirectory() ) { @@ -807,7 +818,7 @@ event = new ServletContextAttributeEvent(this.getServletContext(), name, value); - + } if (replaced) { listener.attributeReplaced(event); @@ -843,7 +854,7 @@ removeAttribute(key); } } - + public void initFilters() throws ServletException { Iterator fI = getFilters().values().iterator(); while (fI.hasNext()) { @@ -851,16 +862,16 @@ try { fc.getFilter(); // will triger init() } catch (Throwable e) { - log.log(Level.WARNING, getContextPath() + " Filter.init() " + + log.log(Level.WARNING, getContextPath() + " Filter.init() " + fc.getFilterName(), e); - } - + } + } } - + public void initServlets() throws ServletException { Iterator fI = getServletConfigs().values().iterator(); - Map/*<Integer, List<ServletConfigImpl>>*/ onStartup = + Map/*<Integer, List<ServletConfigImpl>>*/ onStartup = new TreeMap/*<Integer, List<ServletConfigImpl>>*/(); while (fI.hasNext()) { ServletConfigImpl fc = (ServletConfigImpl)fI.next(); @@ -877,15 +888,15 @@ Iterator keys = onStartup.keySet().iterator(); while (keys.hasNext()) { Integer key = (Integer)keys.next(); - List/*<ServletConfigImpl>*/ servlets = (List)onStartup.get(key); + List/*<ServletConfigImpl>*/ servlets = (List)onStartup.get(key); Iterator servletsI = servlets.iterator(); while (servletsI.hasNext()) { ServletConfigImpl fc = (ServletConfigImpl) servletsI.next(); try { - fc.loadServlet(); + fc.loadServlet(); } catch (Throwable e) { log.log(Level.WARNING, "Error initializing " + fc.getServletName(), e); - } + } } } } @@ -895,19 +906,19 @@ while (fI.hasNext()) { String listenerClass = (String)fI.next(); try { - Object l = + Object l = getClassLoader().loadClass(listenerClass).newInstance(); lifecycleListeners.add((EventListener) l); } catch (Throwable e) { log.log(Level.WARNING, "Error initializing listener " + listenerClass, e); - } + } } } public ClassLoader getClassLoader() { return classLoader; } - + public void addMapping(String path, String name) { ServletConfigImpl wrapper = getServletConfig(name); addMapping(path, wrapper); @@ -916,9 +927,9 @@ public void addMapping(String path, ServletConfig wrapper) { getMapper().addWrapper(getMapper().contextMapElement, path, wrapper); } - - - + + + public void setWelcomeFiles(String[] name) { getMapper().contextMapElement.welcomeResources = name; } @@ -928,21 +939,21 @@ } public void setSessionTimeout(int to) { - getManager().setSessionTimeout(to); + getManager().setSessionTimeout(to); } - + /** * Initialize the context from the parsed config. - * + * * Note that WebAppData is serializable. */ public void processWebAppData(ServletContextConfig d) throws ServletException { this.contextConfig = d; - + for (String k: d.mimeMapping.keySet()) { - addMimeType(k, d.mimeMapping.get(k)); + addMimeType(k, d.mimeMapping.get(k)); } - + String[] wFiles = (String[])d.welcomeFileList.toArray(new String[0]); if (wFiles.length == 0) { wFiles = new String[] {"index.html" }; @@ -951,106 +962,106 @@ getMapper().contextMapElement.resources = new File(getBasePath()); } setWelcomeFiles(wFiles); - + Iterator i2 = d.filters.values().iterator(); while (i2.hasNext()) { FilterData fd = (FilterData)i2.next(); addFilter(fd.filterName, fd.filterClass, fd.initParams); } - + Iterator i3 = d.servlets.values().iterator(); while (i3.hasNext()) { ServletData sd = (ServletData) i3.next(); - // jsp-file + // jsp-file if (sd.servletClass == null) { if (sd.jspFile == null) { log.log(Level.WARNING, "Missing servlet class for " + sd.servletName); continue; } } - - ServletConfigImpl sw = + + ServletConfigImpl sw = new ServletConfigImpl(this, sd.servletName, sd.servletClass); sw.setConfig(sd.initParams); sw.setJspFile(sd.jspFile); sw.setLoadOnStartup(sd.loadOnStartup); //sw.setRunAs(sd.runAs); sw.setSecurityRoleRef(sd.securityRoleRef); - + addServletConfig(sw); } - + for (String k: d.servletMapping.keySet()) { - addMapping(k, d.servletMapping.get(k)); + addMapping(k, d.servletMapping.get(k)); } - + Iterator i5 = d.filterMappings.iterator(); while (i5.hasNext()) { - FilterMappingData k = (FilterMappingData) i5.next(); + FilterMappingData k = (FilterMappingData) i5.next(); String[] disp = new String[k.dispatcher.size()]; if (k.urlPattern != null) { - addFilterMapping(k.urlPattern, - k.filterName, + addFilterMapping(k.urlPattern, + k.filterName, (String[])k.dispatcher.toArray(disp)); } if (k.servletName != null) { - addFilterServletMapping(k.servletName, - k.filterName, + addFilterServletMapping(k.servletName, + k.filterName, (String[])k.dispatcher.toArray(disp)); } } - + for (String n: d.localeEncodingMapping.keySet()) { - getCharsetMapper().addCharsetMapping(n, + getCharsetMapper().addCharsetMapping(n, d.localeEncodingMapping.get(n)); } } - - public void addServlet(String servletName, String servletClass, + + public void addServlet(String servletName, String servletClass, String jspFile, Map params) { - ServletConfigImpl sc = new ServletConfigImpl(this, servletName, + ServletConfigImpl sc = new ServletConfigImpl(this, servletName, servletClass); sc.setJspFile(jspFile); sc.setConfig(params); addServletConfig(sc); } - @Override - public javax.servlet.Registration.Dynamic addServlet(String servletName, Servlet servlet) { + + public javax.servlet.ServletRegistration.Dynamic addServlet(String servletName, Servlet servlet) { ServletConfigImpl sc = new ServletConfigImpl(this, servletName, null); sc.setServlet(servlet); addServletConfig(sc); return sc.getDynamic(); } - + public void addServletSec(String serlvetName, String runAs, Map roles) { // TODO } - - - - public void addFilterMapping(String path, String filterName, + + + + public void addFilterMapping(String path, String filterName, String[] dispatcher) { - getFilterMapper().addMapping(filterName, + getFilterMapper().addMapping(filterName, path, null, dispatcher, true); - + } - public void addFilterServletMapping(String servlet, - String filterName, + public void addFilterServletMapping(String servlet, + String filterName, String[] dispatcher) { - getFilterMapper().addMapping(filterName, - null, servlet, - dispatcher, true); + getFilterMapper().addMapping(filterName, + null, servlet, + dispatcher, true); } - + /** * Called from TomcatLite.init(), required before start. - * - * Will initialize defaults and load web.xml unless webAppData is + * + * Will initialize defaults and load web.xml unless webAppData is * already set and recent. No other processing is done except reading * the config - you can add or alter it before start() is called. - * + * * @throws ServletException */ public void init() throws ServletException { @@ -1060,51 +1071,51 @@ initDone = true; // Load global init params from the facade initEngineDefaults(); - + initTempDir(); - + // Merge in web.xml - or other config source ( programmatic, etc ) - ContextPreinitListener cfg = - (ContextPreinitListener) getObjectManager().get( + ContextPreinitListener cfg = + (ContextPreinitListener) getObjectManager().get( ContextPreinitListener.class); if (cfg != null) { cfg.preInit(this); } processWebAppData(contextConfig); - + // if not defined yet: addDefaultServlets(); } - - + + protected void initTempDir() throws ServletException { - // We need a base path - at least for temp files, req. by spec + // We need a base path - at least for temp files, req. by spec if (basePath == null) { basePath = ("/".equals(contextPath)) ? facade.getWork().getAbsolutePath() + "/ROOT" : facade.getWork().getAbsolutePath() + contextPath; } - + File f = new File(basePath + "/WEB-INF/tmp"); f.mkdirs(); setAttribute("javax.servlet.context.tempdir", f); } - + /** * Static file handler ( default ) * *.jsp support - * + * */ protected void addDefaultServlets() throws ServletException { if (servlets.get("default") == null) { - ServletConfigImpl fileS = new ServletConfigImpl(this, - "default", null); + ServletConfigImpl fileS = new ServletConfigImpl(this, + "default", null); addServletConfig(fileS); addMapping("/", fileS); } - + // *.jsp support if (servlets.get("jspwildcard") == null) { ServletConfigImpl fileS = new ServletConfigImpl(this, @@ -1113,9 +1124,9 @@ addMapping("*.jsp", fileS); } } - + protected void initEngineDefaults() throws ServletException { - + // TODO: make this customizable, avoid loading it on startup // Set the class name as default in the addon support for (String sname: facade.ctxDefaultInitParam.keySet()) { @@ -1128,7 +1139,7 @@ ServletConfigImpl fileS = new ServletConfigImpl(this, sname, sclass); addServletConfig(fileS); } - + for (String sname: facade.preloadMappings.keySet()) { String path = facade.preloadMappings.get(sname); ServletConfigImpl servletConfig = getServletConfig(sname); @@ -1136,7 +1147,7 @@ } } - + public ArrayList getClasspath(File directory, File classesDir) { ArrayList res = new ArrayList(); if (classesDir.isDirectory() && classesDir.exists() && @@ -1151,13 +1162,13 @@ || !directory.canRead()) { return res; } - + File[] jars = directory.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith(".jar"); } }); - + for (int j = 0; j < jars.length; j++) { try { URL url = jars[j].toURL(); @@ -1174,13 +1185,13 @@ return; } String base = getBasePath(); - + ArrayList urls = getClasspath(new File(base + "/WEB-INF/lib"), new File(base + "/WEB-INF/classes")); URL[] urlsA = new URL[urls.size()]; urls.toArray(urlsA); - URLClassLoader parentLoader = + URLClassLoader parentLoader = getEngine().getContextParentLoader(); // create a class loader. @@ -1192,14 +1203,14 @@ ctxRepo.addURL(urlsA); repository = ctxRepo; */ - + classLoader = new URLClassLoader(urlsA, parentLoader); - + // JMX should know about us ( TODO: is it too early ? ) facade.notifyAdd(this); initListeners(); - + List listeners = this.getListeners(); ServletContextEvent event = null; for (int i = 0; i < listeners.size(); i++) { @@ -1218,10 +1229,10 @@ } } - + initFilters(); initServlets(); - + startDone = true; } @@ -1238,13 +1249,13 @@ } - // TODO: configurable ? init-params + // TODO: configurable ? init-params public String getSessionCookieName() { return "JSESSIONID"; } - - + + public void destroy() throws ServletException { // destroy filters Iterator fI = filters.values().iterator(); @@ -1271,7 +1282,7 @@ public TomcatLite getEngine() { return facade; } - + public String findStatusPage(int status) { if (contextConfig.errorPageCode.size() == 0) { return null; @@ -1283,9 +1294,9 @@ return (String) contextConfig.errorPageCode.get(Integer.toString(status)); } - public void handleStatusPage(ServletRequestImpl req, - ServletResponseImpl res, - int status, + public void handleStatusPage(ServletRequestImpl req, + ServletResponseImpl res, + int status, String statusPage) { String message = RequestUtil.filter(res.getMessage()); if (message == null) @@ -1297,20 +1308,20 @@ protected void setErrorAttributes(ServletRequestImpl req, int status, String message) { - req.setAttribute("javax.servlet.error.status_code", + req.setAttribute("javax.servlet.error.status_code", new Integer(status)); if (req.getWrapper() != null) { - req.setAttribute("javax.servlet.error.servlet_name", + req.setAttribute("javax.servlet.error.servlet_name", req.getWrapper().servletName); } - req.setAttribute("javax.servlet.error.request_uri", + req.setAttribute("javax.servlet.error.request_uri", req.getRequestURI()); - req.setAttribute("javax.servlet.error.message", + req.setAttribute("javax.servlet.error.message", message); } - - public void handleError(ServletRequestImpl req, + + public void handleError(ServletRequestImpl req, ServletResponseImpl res, Throwable t) { Throwable realError = t; @@ -1335,7 +1346,7 @@ dispatchError(req, res, errorPage); } else { log("Unhandled error", t); - if (t instanceof ServletException && + if (t instanceof ServletException && ((ServletException)t).getRootCause() != null) { log("RootCause:", ((ServletException)t).getRootCause()); } @@ -1345,13 +1356,13 @@ } } - protected void dispatchError(ServletRequestImpl req, - ServletResponseImpl res, + protected void dispatchError(ServletRequestImpl req, + ServletResponseImpl res, String errorPage) { RequestDispatcher rd = getRequestDispatcher(errorPage); try { - // will clean up the buffer + // will clean up the buffer rd.forward(req, res); return; // handled } catch (ServletException e) { @@ -1360,7 +1371,7 @@ // TODO } } - + protected String findErrorPage(Throwable exception) { if (contextConfig.errorPageException.size() == 0) { return null; @@ -1382,33 +1393,33 @@ } - @Override + public EnumSet<SessionTrackingMode> getDefaultSessionTrackingModes() { return null; } - @Override + public EnumSet<SessionTrackingMode> getEffectiveSessionTrackingModes() { return null; } - @Override + public SessionCookieConfig getSessionCookieConfig() { return null; } - @Override + public void setSessionTrackingModes(EnumSet<SessionTrackingMode> sessionTrackingModes) { } - public void addFilter(String filterName, String filterClass, + public void addFilter(String filterName, String filterClass, Map params) { FilterConfigImpl fc = new FilterConfigImpl(this); fc.setData(filterName, filterClass, params); filters.put(filterName, fc); } - - @Override + + public Dynamic addFilter(String filterName, String className) { FilterConfigImpl fc = new FilterConfigImpl(this); fc.setData(filterName, className, new HashMap()); @@ -1416,7 +1427,7 @@ return fc.getDynamic(); } - @Override + public Dynamic addFilter(String filterName, Filter filter) { FilterConfigImpl fc = new FilterConfigImpl(this); fc.setData(filterName, null, new HashMap()); @@ -1425,7 +1436,7 @@ return fc.getDynamic(); } - @Override + public Dynamic addFilter(String filterName, Class<? extends Filter> filterClass) { FilterConfigImpl fc = new FilterConfigImpl(this); fc.setData(filterName, null, new HashMap()); @@ -1434,16 +1445,16 @@ return fc.getDynamic(); } - @Override - public javax.servlet.Registration.Dynamic addServlet(String servletName, + + public javax.servlet.ServletRegistration.Dynamic addServlet(String servletName, String className) { ServletConfigImpl sc = new ServletConfigImpl(this, servletName, className); addServletConfig(sc); return sc.getDynamic(); } - @Override - public javax.servlet.Registration.Dynamic addServlet(String servletName, + + public javax.servlet.ServletRegistration.Dynamic addServlet(String servletName, Class<? extends Servlet> servletClass) { ServletConfigImpl sc = new ServletConfigImpl(this, servletName, servletClass.getName()); sc.setServletClass(servletClass); @@ -1451,11 +1462,11 @@ return sc.getDynamic(); } - // That's tricky - this filter will have no name. We need to generate one + // That's tricky - this filter will have no name. We need to generate one // because our code relies on names. AtomicInteger autoName = new AtomicInteger(); - - @Override + + public <T extends Filter> T createFilter(Class<T> c) throws ServletException { FilterConfigImpl fc = new FilterConfigImpl(this); String filterName = "_tomcat_auto_filter_" + autoName.incrementAndGet(); @@ -1476,7 +1487,7 @@ } } - @Override + public <T extends Servlet> T createServlet(Class<T> c) throws ServletException { String filterName = "_tomcat_auto_servlet_" + autoName.incrementAndGet(); ServletConfigImpl fc = new ServletConfigImpl(this, filterName, null); @@ -1490,23 +1501,23 @@ } } - @Override + public FilterRegistration findFilterRegistration(String filterName) { return filters.get(filterName); } - @Override + public ServletRegistration findServletRegistration(String servletName) { return servlets.get(servletName); } - - @Override + + public boolean setInitParameter(String name, String value) { HashMap<String, String> params = contextConfig.contextParam; return setInitParameter(this, params, name, value); } - - static Set<String> setInitParameters(ServletContextImpl ctx, + + static Set<String> setInitParameters(ServletContextImpl ctx, Map<String, String> params, Map<String, String> initParameters) throws IllegalArgumentException, IllegalStateException { @@ -1524,14 +1535,14 @@ } } return result; - } + } /** * true if the context initialization parameter with the given name and value was set successfully on this ServletContext, and false if it was not set because this ServletContext already contains a context initialization parameter with a matching name * Throws: * java.lang.IllegalStateException - if this ServletContext has already been initialized */ - static boolean setInitParameter(ServletContextImpl ctx, Map<String, String> params, + static boolean setInitParameter(ServletContextImpl ctx, Map<String, String> params, String name, String value) { if (name == null || value == null) { throw new IllegalArgumentException(); @@ -1547,5 +1558,57 @@ return true; } } + + public JspConfigDescriptor getJspConfigDescriptor() { + // fix me - just here to compile + return null; + } + + + + public void declareRoles(String... roleNames) { + // implement me + } + + public <T extends EventListener> T createListener(Class<T> c) throws ServletException { + // implement me + return null; + } + + public Collection<String> getMappings() { + // implement me + return null; + } + + public Map<String, ? extends FilterRegistration> getFilterRegistrations() { + // implement me + return null; + } + + public FilterRegistration getFilterRegistration(String filterName) { + // implement me + return null; + } + + public Map<String, ? extends ServletRegistration> getServletRegistrations() { + // implement me + return null; + } + + public ServletRegistration getServletRegistration(String servletName) { + // implement me + return null; + } + + public int getEffectiveMinorVersion() { + // implement me + return -1; + } + + public int getEffectiveMajorVersion() { + // implement me + return -1; + } + } Index: java/org/apache/tomcat/lite/ServletRequestImpl.java =================================================================== --- java/org/apache/tomcat/lite/ServletRequestImpl.java (revision 833452) +++ java/org/apache/tomcat/lite/ServletRequestImpl.java (working copy) @@ -1,12 +1,12 @@ /* * Copyright 1999,2004 The Apache Software Foundation. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -23,6 +23,7 @@ import java.security.Principal; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Collection; import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; @@ -68,7 +69,7 @@ /** - * + * * Wrapper object for the Coyote request. * * @author Remy Maucherat @@ -95,13 +96,13 @@ /** * Request dispatcher state. */ - public static final String DISPATCHER_TYPE_ATTR = + public static final String DISPATCHER_TYPE_ATTR = "org.apache.catalina.core.DISPATCHER_TYPE"; /** * Request dispatcher path. */ - public static final String DISPATCHER_REQUEST_PATH_ATTR = + public static final String DISPATCHER_REQUEST_PATH_ATTR = "org.apache.catalina.core.DISPATCHER_REQUEST_PATH"; /** @@ -175,7 +176,7 @@ public static final String SERVLET_NAME_ATTR = "javax.servlet.error.servlet_name"; - + /** * The name of the cookie used to pass the session identifier back * and forth with the client. @@ -204,7 +205,7 @@ public static final String SUBJECT_ATTR = "javax.security.auth.subject"; - + /** * The servlet context attribute under which we store a temporary * working directory (as an object of type File) for use by servlets @@ -228,7 +229,7 @@ * The match string for identifying a session ID parameter. */ private static final String match = ";" + SESSION_PARAMETER_NAME + "="; - + /** * The set of cookies associated with this Request. */ @@ -242,8 +243,8 @@ * declare formats[] as a static variable. */ protected SimpleDateFormat formats[] = null; - + /** * The attributes associated with this Request, keyed by attribute name. */ @@ -295,15 +296,15 @@ /** * ServletInputStream. */ - protected ServletInputStreamImpl inputStream; + protected ServletInputStreamImpl inputStream; /** * Reader. */ protected BufferedReader reader; - + /** * Using stream flag. */ @@ -395,7 +396,7 @@ * Filter chain associated with the request. */ protected FilterChainImpl filterChain = new FilterChainImpl(); - + /** * Mapping data. */ @@ -408,7 +409,7 @@ * The response with which this request is associated. */ protected ServletResponseImpl response = new ServletResponseImpl(); - + /** * URI byte to char converter (not recycled). */ @@ -423,13 +424,13 @@ * Post data buffer. */ public final static int CACHED_POST_LEN = 8192; - + public byte[] postData = null; - + private HttpRequest httpRequest; - - /** New IO/buffer model + + /** New IO/buffer model */ //protected Http11Connection con; @@ -499,7 +500,7 @@ public void setConnector(Connector c) { connector = c; } - + public Connector getConnector() { return connector; } @@ -563,7 +564,7 @@ * * @exception IOException if an input/output error occurs */ - public ServletInputStream createInputStream() + public ServletInputStream createInputStream() throws IOException { return inputStream; } @@ -588,11 +589,11 @@ public Object getAttribute(String name) { if (name.equals(ServletRequestImpl.DISPATCHER_TYPE_ATTR)) { - return (dispatcherType == null) + return (dispatcherType == null) ? REQUEST_INTEGER : dispatcherType; } else if (name.equals(ServletRequestImpl.DISPATCHER_REQUEST_PATH_ATTR)) { - return (requestDispatcherPath == null) + return (requestDispatcherPath == null) ? getRequestPathMB().toString() : requestDispatcherPath.toString(); } @@ -606,7 +607,7 @@ // if(attr != null) // return attr; // if( isSSLAttribute(name) ) { -// reqB.action(ActionCode.ACTION_REQ_SSL_ATTRIBUTE, +// reqB.action(ActionCode.ACTION_REQ_SSL_ATTRIBUTE, // reqB); // attr = reqB.getAttribute(ServletRequestImpl.CERTIFICATES_ATTR); // if( attr != null) { @@ -738,7 +739,7 @@ /** * Get the context path. - * + * * @return the context path */ public MessageBytes getContextPathMB() { @@ -783,7 +784,7 @@ formats[1].setTimeZone(GMT_ZONE); formats[2].setTimeZone(GMT_ZONE); } - + // Attempt to convert the date header in a variety of formats long result = FastHttpDateFormat.parseDate(value, formats); if (result != (-1L)) { @@ -796,7 +797,7 @@ /** * Get the decoded request URI. - * + * * @return the URL decoded request URI */ public String getDecodedRequestURI() { @@ -806,7 +807,7 @@ /** * Get the decoded request URI. - * + * * @return the URL decoded request URI */ public MessageBytes getDecodedRequestURIMB() { @@ -833,7 +834,7 @@ public String getHeader(String name) { return httpRequest.getHeader(name); } - + /** * Return the names of all headers received with this request. */ @@ -897,7 +898,7 @@ /** * Returns the Internet Protocol (IP) address of the interface on * which the request was received. - */ + */ public String getLocalAddr(){ return httpRequest.localAddr().toString(); } @@ -1062,7 +1063,7 @@ /** * Get the path info. - * + * * @return the path info */ public MessageBytes getPathInfoMB() { @@ -1086,14 +1087,14 @@ } } - + /** * Return the principal that has been authenticated for this Request. */ public Principal getPrincipal() { return (userPrincipal); } - + /** * Return the protocol and version used to make this Request. */ @@ -1145,7 +1146,7 @@ /** * Converter for the encoding associated with the request. * If encoding is changed - a different encoder will be returned. - * + * * Encoders are cached ( per request ) - at least 8K per charset */ public B2CConverter getB2C() throws IOException { @@ -1153,7 +1154,7 @@ if (enc == null) { enc = DEFAULT_CHARACTER_ENCODING; } - B2CConverter conv = + B2CConverter conv = (B2CConverter) encoders.get(enc); if (conv == null) { conv = new B2CConverter(enc); @@ -1161,7 +1162,7 @@ } return conv; } - + /** * Return the real path of the specified virtual path. * @@ -1213,7 +1214,7 @@ /** * Returns the Internet Protocol (IP) source port of the client * or last proxy that sent the request. - */ + */ public int getRemotePort(){ return httpRequest.getRemotePort(); } @@ -1241,11 +1242,11 @@ public HttpServletRequest getRequest() { return this; } - + public HttpRequest getHttpRequest() { return httpRequest; } - + public void setHttpRequest(HttpRequest req, BodyReader in) { this.httpRequest = req; inputBuffer = in; @@ -1316,7 +1317,7 @@ /** * Get the request path. - * + * * @return the request path */ public MessageBytes getRequestPathMB() { @@ -1330,13 +1331,13 @@ public String getRequestURI() { return httpRequest.requestURI().toString(); } - + /** */ public void setRequestURI(String uri) { httpRequest.decodedURI().setString(uri); try { - UriNormalizer.decodeRequest(httpRequest.decodedURI(), + UriNormalizer.decodeRequest(httpRequest.decodedURI(), httpRequest.requestURI(), httpRequest.getURLDecoder()); } catch(IOException ioe) { ioe.printStackTrace(); @@ -1432,7 +1433,7 @@ /** * Get the servlet path. - * + * * @return the servlet path */ public MessageBytes getServletPathMB() { @@ -1537,8 +1538,8 @@ public boolean isSecure() { return (secure); } - - + + /** * Return <code>true</code> if the authenticated user principal * possesses the specified role name. @@ -1566,7 +1567,7 @@ if (role.equals(userPrincipal.getName())) { return true; } - + // TODO: check !!!! // Check for a role defined directly as a <security-role> return false; @@ -1652,7 +1653,7 @@ (ServletRequestAttributeListener) listeners.get(i); try { if (event == null) { - event = + event = new ServletRequestAttributeEvent(context.getServletContext(), getRequest(), name, value); } @@ -1673,7 +1674,7 @@ * @param value The associated value */ public void setAttribute(String name, Object value) { - + // Name cannot be null if (name == null) throw new IllegalArgumentException @@ -1712,7 +1713,7 @@ // if (name.startsWith("org.apache.tomcat.")) { // reqB.setAttribute(name, value); // } -// +// // Notify interested application event listeners List listeners = context.getListeners(); if (listeners.size() == 0) @@ -1862,7 +1863,7 @@ /** * Set the decoded request URI. - * + * * @param uri The decoded request URI */ public void setDecodedRequestURI(String uri) { @@ -2051,18 +2052,18 @@ if (System.getSecurityManager() != null){ HttpSession session = getSession(false); - if ( (subject != null) && + if ( (subject != null) && (!subject.getPrincipals().contains(principal)) ){ - subject.getPrincipals().add(principal); + subject.getPrincipals().add(principal); } else if (session != null && session.getAttribute(ServletRequestImpl.SUBJECT_ATTR) == null) { subject = new Subject(); - subject.getPrincipals().add(principal); + subject.getPrincipals().add(principal); } if (session != null){ session.setAttribute(ServletRequestImpl.SUBJECT_ATTR, subject); } - } + } this.userPrincipal = principal; } @@ -2092,7 +2093,7 @@ protected void configureSessionCookie(Cookie cookie) { cookie.setMaxAge(-1); String contextPath = null; - if (//!connector.getEmptySessionPath() && + if (//!connector.getEmptySessionPath() && (getContext() != null)) { contextPath = getContext().getEncodedPath(); } @@ -2129,14 +2130,14 @@ manager = context.getManager(); if (manager == null) return (null); // Sessions are not supported - + // Return the current session if it exists and is valid if ((session != null) && !manager.isValid(session)) session = null; if (session != null) return (session); - - + + if (requestedSessionId != null) { try { session = manager.findSession(requestedSessionId); @@ -2360,7 +2361,7 @@ */ protected void parseSessionCookiesId() { String sessionCookieName = context.getSessionCookieName(); - + // Parse session id from cookies Cookies serverCookies = httpRequest.getCookies(); int count = serverCookies.getCookieCount(); @@ -2374,7 +2375,7 @@ if (!isRequestedSessionIdFromCookie()) { // Accept only the first session id cookie //scookie.getValue().convertToAscii(); - + setRequestedSessionId (scookie.getValue().toString()); setRequestedSessionCookie(true); @@ -2409,18 +2410,18 @@ int semicolon2 = uriBC.indexOf(';', sessionIdStart); if (semicolon2 >= 0) { request.setRequestedSessionId - (new String(uriBC.getBuffer(), start + sessionIdStart, + (new String(uriBC.getBuffer(), start + sessionIdStart, semicolon2 - sessionIdStart)); // Extract session ID from request URI byte[] buf = uriBC.getBuffer(); for (int i = 0; i < end - start - semicolon2; i++) { - buf[start + semicolon + i] + buf[start + semicolon + i] = buf[start + i + semicolon2]; } uriBC.setBytes(buf, start, end - start - semicolon2 + semicolon); } else { request.setRequestedSessionId - (new String(uriBC.getBuffer(), start + sessionIdStart, + (new String(uriBC.getBuffer(), start + sessionIdStart, (end - start) - sessionIdStart)); uriBC.setEnd(start + semicolon); } @@ -2464,54 +2465,54 @@ } - @Override + public void addAsyncListener(AsyncListener listener) { } - @Override + public void addAsyncListener(AsyncListener listener, ServletRequest servletRequest, ServletResponse servletResponse) { } - @Override + public AsyncContext getAsyncContext() { return null; } - @Override + public ServletContext getServletContext() { return null; } - @Override + public boolean isAsyncStarted() { return false; } - @Override + public boolean isAsyncSupported() { return false; } - @Override + public void setAsyncTimeout(long timeout) { } - @Override + public AsyncContext startAsync() throws IllegalStateException { return null; } - @Override + public AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse) throws IllegalStateException { @@ -2519,45 +2520,46 @@ } - @Override + public boolean authenticate(HttpServletResponse response) throws IOException, ServletException { return false; } - @Override + public Part getPart(String name) { return null; } - @Override - public Iterable<Part> getParts() { - return null; - } - @Override + public void login(String username, String password) throws ServletException { } - @Override + public void logout() throws ServletException { } - @Override + public long getAsyncTimeout() { return 0; } - @Override + public DispatcherType getDispatcherType() { return null; } + public Collection<Part> getParts() throws IOException, ServletException { + return null; + } + + } Index: java/org/apache/tomcat/lite/coyote/CoyoteConnector.java =================================================================== --- java/org/apache/tomcat/lite/coyote/CoyoteConnector.java (revision 833452) +++ java/org/apache/tomcat/lite/coyote/CoyoteConnector.java (working copy) @@ -39,18 +39,18 @@ public void acknowledge(HttpServletResponse res) throws IOException { Response cres = (Response) ((ServletResponseImpl) res).getHttpResponse().nativeResponse; - cres.acknowledge(); + cres.acknowledge(); } public void reset(HttpServletResponse res) { Response cres = (Response) ((ServletResponseImpl) res).getHttpResponse().nativeResponse; - cres.reset(); + cres.reset(); } - + public void recycle(HttpServletRequest req, HttpServletResponse res) { - + } - + public static HttpResponse getResponse(final Response cres) { HttpResponse hres = new HttpResponse() { public int getStatus() { @@ -75,101 +75,101 @@ cres.setCommitted(b); } }; - + hres.setMimeHeaders(cres.getMimeHeaders()); hres.nativeResponse = cres; - + return hres; } - + public static HttpRequest getRequest(Request req) { - + HttpRequest httpReq = new HttpRequest(req.scheme(), - req.method(), + req.method(), req.unparsedURI(), req.protocol(), req.getMimeHeaders(), req.requestURI(), req.decodedURI(), req.query(), req.getParameters(), - req.serverName(), + req.serverName(), req.getCookies()) { - + }; httpReq.nativeRequest = req; - + // TODO: anything else computed in coyote ? - + return httpReq; } @Override public void initRequest(HttpServletRequest hreq, HttpServletResponse hres) { ServletRequestImpl req = (ServletRequestImpl) hreq; - ServletResponseImpl res = (ServletResponseImpl) hres; + ServletResponseImpl res = (ServletResponseImpl) hres; req.setConnector(this); - + Request creq = new Request(); Response cres = new Response(); HttpResponse nRes = getResponse(cres); BodyWriter out = new BodyWriter(4096); out.setConnector(this, res); - + res.setHttpResponse(nRes, out); - + cres.setRequest(creq); cres.setHook(new ActionHook() { - public void action(ActionCode actionCode, + public void action(ActionCode actionCode, Object param) { } }); - + BodyReader in = new BodyReader(); in.setConnector(this, req); HttpRequest nReq = getRequest(creq); req.setHttpRequest(nReq, in); - + } - + // ---- Coyote Adapter interface --- - + @Override public void service(Request creq, Response cres) throws Exception { long t0 = System.currentTimeMillis(); // compute decodedURI - not done by connector UriNormalizer.decodeRequest(creq.decodedURI(), creq.requestURI(), creq.getURLDecoder()); - + // find the facades ServletRequestImpl req = (ServletRequestImpl) creq.getNote(ADAPTER_REQ_NOTE); ServletResponseImpl res = (ServletResponseImpl) cres.getNote(ADAPTER_RES_NOTE); - + if (req == null) { req = new ServletRequestImpl(); res = req.getResponse(); - + BodyReader in = new BodyReader(); in.setConnector(this, req); HttpRequest nReq = getRequest(creq); nReq.setServerPort(creq.getServerPort()); HttpResponse nRes = getResponse(cres); - + req.setHttpRequest(nReq, in); BodyWriter out = new BodyWriter(4096); out.setConnector(this, res); - + res.setHttpResponse(nRes, out); - + creq.setNote(ADAPTER_REQ_NOTE, req); cres.setNote(ADAPTER_RES_NOTE, res); - + } req.setConnector(this); - + try { lite.service(req, res); } catch(IOException ex) { @@ -178,14 +178,14 @@ t.printStackTrace(); } finally { long t1 = System.currentTimeMillis(); - -// log.info("<<<<<<<< DONE: " + creq.method() + " " + -// creq.decodedURI() + " " + -// res.getStatus() + " " + + +// log.info("<<<<<<<< DONE: " + creq.method() + " " + +// creq.decodedURI() + " " + +// res.getStatus() + " " + // (t1 - t0)); - + // Final processing - // TODO: only if not commet, this doesn't work with the + // TODO: only if not commet, this doesn't work with the // other connectors since we don't have the info // TODO: add this note in the nio/apr connectors // TODO: play nice with TomcatLite, other adapters that flush/close @@ -195,7 +195,7 @@ cres.sendHeaders(); } res.getOutputBuffer().flush(); - + BodyWriter mw = res.getBodyWriter(); //MessageWriter.getWriter(creq, cres, 0); mw.flush(); @@ -204,7 +204,7 @@ BodyReader reader = req.getBodyReader(); //getReader(creq); reader.recycle(); - + cres.finish(); creq.recycle(); @@ -215,7 +215,7 @@ } } } - + @Override public boolean event(Request req, Response res, SocketStatus status) throws Exception { @@ -230,7 +230,7 @@ public String getRemoteHost(HttpServletRequest hreq) { ServletRequestImpl req = (ServletRequestImpl) hreq; - + Request creq = (Request) req.getHttpRequest().nativeRequest; creq.action(ActionCode.ACTION_REQ_HOST_ATTRIBUTE, creq); return creq.remoteHost().toString(); @@ -238,7 +238,7 @@ public String getRemoteAddr(HttpServletRequest hreq) { ServletRequestImpl req = (ServletRequestImpl) hreq; - + Request creq = (Request) req.getHttpRequest().nativeRequest; creq.action(ActionCode.ACTION_REQ_HOST_ADDR_ATTRIBUTE, creq); return creq.remoteAddr().toString(); @@ -248,8 +248,8 @@ @Override public void beforeClose(HttpServletResponse res, int len) throws IOException { Response cres = (Response) ((ServletResponseImpl) res).getHttpResponse().nativeResponse; - - if ((!cres.isCommitted()) + + if ((!cres.isCommitted()) && (cres.getContentLengthLong() == -1)) { // Flushing the char buffer // If this didn't cause a commit of the response, the final content @@ -262,7 +262,7 @@ public int doRead(ServletRequestImpl hreq, ByteChunk bb) throws IOException { ServletRequestImpl req = (ServletRequestImpl) hreq; - + Request creq = (Request) req.getHttpRequest().nativeRequest; return creq.doRead(bb); } @@ -279,7 +279,7 @@ @Override public void realFlush(HttpServletResponse res) throws IOException { Response cres = (Response) ((ServletResponseImpl) res).getHttpResponse().nativeResponse; - cres.action(ActionCode.ACTION_CLIENT_FLUSH, + cres.action(ActionCode.ACTION_CLIENT_FLUSH, cres); // If some exception occurred earlier, or if some IOE occurred // here, notify the servlet with an IOE @@ -294,7 +294,7 @@ @Override public void sendHeaders(HttpServletResponse res) throws IOException { Response cres = (Response) ((ServletResponseImpl) res).getHttpResponse().nativeResponse; - + // This should happen before 'prepareResponse' is called !! // Now update coyote response based on response // don't set charset/locale - they're computed in lite @@ -312,43 +312,43 @@ protected boolean daemon = false; /** - * Note indicating the response is COMET. + * Note indicating the response is COMET. */ public static final int COMET_RES_NOTE = 2; public static final int COMET_REQ_NOTE = 2; - - public static final int ADAPTER_RES_NOTE = 1; - public static final int ADAPTER_REQ_NOTE = 1; - + + public static final int ADAPTER_RES_NOTE = 1; + public static final int ADAPTER_REQ_NOTE = 1; + protected ProtocolHandler proto; //protected Adapter adapter = new MapperAdapter(); protected int maxThreads = 20; boolean started = false; boolean async = false; // use old nio connector - + protected ObjectManager om; - - + + public void setObjectManager(ObjectManager om) { this.om = om; } - - /** + + /** * Add an adapter. If more than the 'default' adapter is * added, a MapperAdapter will be inserted. - * + * * @param path Use "/" for the default. * @param adapter */ // public void addAdapter(String path, Adapter added) { // if ("/".equals(path)) { -// ((MapperAdapter) adapter).setDefaultAdapter(added); +// ((MapperAdapter) adapter).setDefaultAdapter(added); // } else { // ((MapperAdapter) adapter).getMapper().addWrapper(path, added); // } // } - + /** */ public void run() { @@ -363,7 +363,7 @@ public void setDaemon(boolean b) { daemon = b; } - + protected void initAdapters() { if (proto == null) { addProtocolHandler(port, daemon); @@ -380,7 +380,7 @@ proto.destroy(); started = false; } - + // /** // * Simple CLI support - arg is a path:className pair. // */ @@ -394,14 +394,14 @@ // e.printStackTrace(); // } // } - + public void setConnector(ProtocolHandler h) { this.proto = h; h.setAttribute("port", Integer.toString(port)); om.bind("ProtocolHandler:" + "ep-" + port, proto); } - + public void addProtocolHandler(int port, boolean daemon) { Http11NioProtocol proto = new Http11NioProtocol(); proto.setCompression("on"); @@ -412,29 +412,29 @@ setPort(port); setDaemon(daemon); } - - public void addProtocolHandler(ProtocolHandler proto, + + public void addProtocolHandler(ProtocolHandler proto, int port, boolean daemon) { setConnector(proto); setPort(port); setDaemon(daemon); } - + public void setPort(int port) { if (proto != null) { proto.setAttribute("port", Integer.toString(port)); } this.port = port; } - - + + public void init() { //JdkLoggerConfig.loadCustom(); - om.bind("CoyoteConnector:" + "CoyoteConnector-" + port, + om.bind("CoyoteConnector:" + "CoyoteConnector-" + port, this); } - + public void start() throws IOException { try { if (started) { @@ -446,20 +446,25 @@ // not required - should run fine without a connector. if (proto != null) { proto.setAdapter(this); - + proto.init(); proto.start(); } - + started = true; } catch (Throwable e) { e.printStackTrace(); throw new RuntimeException(e); } } - + public boolean getStarted() { return started; - } - + } + + public boolean asyncDispatch(Request req,Response res, SocketStatus status) throws Exception { + // implement me + return false; + } + } Index: java/org/apache/tomcat/lite/ServletResponseImpl.java =================================================================== --- java/org/apache/tomcat/lite/ServletResponseImpl.java (revision 833452) +++ java/org/apache/tomcat/lite/ServletResponseImpl.java (working copy) @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -24,6 +24,7 @@ import java.net.URL; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Collection; import java.util.Enumeration; import java.util.Locale; import java.util.TimeZone; @@ -53,7 +54,7 @@ public class ServletResponseImpl implements HttpServletResponse { - /** + /** * Format for http response header date field * From DateTool */ @@ -61,8 +62,8 @@ "EEE, dd MMM yyyy HH:mm:ss zzz"; // ----------------------------------------------------------- Constructors - - + + ServletResponseImpl() { urlEncoder.addSafeCharacter('/'); } @@ -103,12 +104,12 @@ */ protected boolean included = false; - + /** * The characterEncoding flag */ private boolean isCharacterEncodingSet = false; - + /** * The error flag. */ @@ -151,19 +152,19 @@ private HttpResponse resB; - - + + // Cached/derived information - reflected in headers protected static Locale DEFAULT_LOCALE = Locale.getDefault(); - + public static final String DEFAULT_CHARACTER_ENCODING="ISO-8859-1"; protected Locale locale = DEFAULT_LOCALE; - // XXX + // XXX protected boolean commited = false; protected String contentType = null; - + /** * Has the charset been explicitly set. */ @@ -187,11 +188,11 @@ included = false; error = false; isCharacterEncodingSet = false; - + cookies.clear(); outputBuffer.recycle(); - + resB.recycle(); } @@ -209,7 +210,7 @@ /** * Set the application commit flag. - * + * * @param appCommitted The new application committed flag value */ public void setAppCommitted(boolean appCommitted) { @@ -222,7 +223,7 @@ */ public boolean isAppCommitted() { return (this.appCommitted || isCommitted() || isSuspended() - || ((getHttpResponse().getContentLength() > 0) + || ((getHttpResponse().getContentLength() > 0) && (getContentCount() >= getHttpResponse().getContentLength()))); } @@ -283,7 +284,7 @@ /** * Set the suspended flag. - * + * * @param suspended The new suspended flag value */ public void setSuspended(boolean suspended) throws IOException { @@ -323,7 +324,7 @@ * * @exception IOException if an input/output error occurs */ - public ServletOutputStream createOutputStream() + public ServletOutputStream createOutputStream() throws IOException { // Probably useless return outputStream; @@ -336,7 +337,7 @@ public String getContentType() { String ret = contentType; - if (ret != null + if (ret != null && characterEncoding != null && charsetSet) { ret = ret + ";charset=" + characterEncoding; @@ -379,7 +380,7 @@ * * @exception IOException if an input/output error occurs */ - public void flushBuffer() + public void flushBuffer() throws IOException { outputBuffer.flush(); } @@ -408,7 +409,7 @@ * already been called for this response * @exception IOException if an input/output error occurs */ - public ServletOutputStream getOutputStream() + public ServletOutputStream getOutputStream() throws IOException { if (usingWriter) @@ -439,7 +440,7 @@ * already been called for this response * @exception IOException if an input/output error occurs */ - public PrintWriter getWriter() + public PrintWriter getWriter() throws IOException { if (usingOutputStream) @@ -490,14 +491,14 @@ if (isCommitted()) throw new IllegalStateException("isCommitted"); - + resB.recycle(); // reset headers, status code, message req.getConnector().reset(this); contentType = null; locale = DEFAULT_LOCALE; characterEncoding = DEFAULT_CHARACTER_ENCODING; charsetSet = false; - + outputBuffer.reset(); } @@ -539,7 +540,7 @@ /** * Set the content length (in bytes) for this Response. - * Ignored for writers if non-ISO-8859-1 encoding ( we could add more + * Ignored for writers if non-ISO-8859-1 encoding ( we could add more * encodings that are constant. */ public void setContentLength(int length) { @@ -550,8 +551,8 @@ // Ignore any call from an included servlet if (included) return; - - // writers can use variable-length encoding. + + // writers can use variable-length encoding. if (usingWriter && !"ISO-8859-1".equals(getCharacterEncoding())) { return; } @@ -622,11 +623,11 @@ if (isCommitted()) return; - + // Ignore any call from an included servlet if (included) - return; - + return; + // Ignore any call made after the getWriter has been invoked // The default should be used if (usingWriter) @@ -642,8 +643,8 @@ isCharacterEncodingSet = true; } - - + + /** * Set the Locale that is appropriate for this response, including * setting the appropriate character encoding. @@ -670,7 +671,7 @@ String contentLanguage = locale.getLanguage(); if ((contentLanguage != null) && (contentLanguage.length() > 0)) { String country = locale.getCountry(); - StringBuilder value = new StringBuilder(contentLanguage); + StringBuffer value = new StringBuffer(contentLanguage); if ((country != null) && (country.length() > 0)) { value.append('-'); value.append(country); @@ -726,7 +727,7 @@ * Return an array of all the header names set for this response, or * a zero-length array if no headers have been set. */ - public Iterable<String> getHeaderNames() { + public Collection<String> getHeaderNames() { MimeHeaders headers = getHttpResponse().getMimeHeaders(); int n = headers.size(); @@ -809,10 +810,10 @@ cookies.add(cookie); - final StringBuilder sb = new StringBuilder(); + final StringBuffer sb = new StringBuffer(); ServerCookie.appendCookieValue (sb, cookie.getVersion(), cookie.getName(), cookie.getValue(), - cookie.getPath(), cookie.getDomain(), cookie.getComment(), + cookie.getPath(), cookie.getDomain(), cookie.getComment(), cookie.getMaxAge(), cookie.getSecure(), false); // the header name is Set-Cookie for both "old" and v.1 ( RFC2109 ) @@ -952,10 +953,10 @@ * @param url URL to be encoded */ public String encodeURL(String url) { - + String absolute = toAbsolute(url); if (isEncodeable(absolute)) { - // W3c spec clearly said + // W3c spec clearly said if (url.equalsIgnoreCase("")){ url = absolute; } @@ -983,7 +984,7 @@ /** * Send an acknowledgment of a request. - * + * * @exception IOException if an input/output error occurs */ public void sendAcknowledgement() @@ -994,7 +995,7 @@ // Ignore any call from an included servlet if (included) - return; + return; req.getConnector().acknowledge(this); } @@ -1010,7 +1011,7 @@ * already been committed * @exception IOException if an input/output error occurs */ - public void sendError(int status) + public void sendError(int status) throws IOException { sendError(status, null); } @@ -1026,7 +1027,7 @@ * already been committed * @exception IOException if an input/output error occurs */ - public void sendError(int status, String message) + public void sendError(int status, String message) throws IOException { if (isCommitted()) @@ -1035,7 +1036,7 @@ // Ignore any call from an included servlet if (included) - return; + return; setError(); @@ -1055,10 +1056,10 @@ // TODO: maybe other mechanism to customize default. defaultStatusPage(status, message); } - setSuspended(true); + setSuspended(true); } - /** + /** * Default handler for status code != 200 */ void defaultStatusPage(int status, String message) @@ -1066,16 +1067,16 @@ setContentType("text/html"); if (status > 400 && status < 600) { if (getOutputBuffer().getBytesWritten() == 0) { - getOutputBuffer().write("<html><body><h1>Status: " + - status + "</h1><h1>Message: " + message + + getOutputBuffer().write("<html><body><h1>Status: " + + status + "</h1><h1>Message: " + message + "</h1></body></html>"); getOutputBuffer().flush(); } } } - + /** * Send a temporary redirect to the specified redirect location URL. * @@ -1085,7 +1086,7 @@ * already been committed * @exception IOException if an input/output error occurs */ - public void sendRedirect(String location) + public void sendRedirect(String location) throws IOException { if (isCommitted()) @@ -1094,7 +1095,7 @@ // Ignore any call from an included servlet if (included) - return; + return; // Clear any data content that has been buffered resetBuffer(); @@ -1248,7 +1249,7 @@ return (false); if (hreq.isRequestedSessionIdFromCookie()) return (false); - + // Is this a valid absolute URL? URL url = null; try { @@ -1333,7 +1334,7 @@ String relativePath = req.getDecodedRequestURI(); int pos = relativePath.lastIndexOf('/'); relativePath = relativePath.substring(0, pos); - + String encodedURI = null; encodedURI = urlEncoder.encodeURL(relativePath); redirectURLCC.append(encodedURI, 0, encodedURI.length()); @@ -1383,7 +1384,7 @@ c == '+' || c == '-' || c == '.'; } - + /** * Return the specified URL with the specified session identifier * suitably encoded. @@ -1409,7 +1410,7 @@ anchor = path.substring(pound); path = path.substring(0, pound); } - StringBuilder sb = new StringBuilder(path); + StringBuffer sb = new StringBuffer(path); if( sb.length() > 0 ) { // jsessionid can't be first. sb.append(";jsessionid="); sb.append(sessionId); @@ -1428,7 +1429,7 @@ public BodyWriter getOutputBuffer() { return outputBuffer; } - + public void setWriter(BodyWriter ob) { outputBuffer = ob; outputStream = new ServletOutputStreamImpl(outputBuffer); @@ -1451,8 +1452,8 @@ } - @Override - public Iterable<String> getHeaders(String name) { + + public Collection<String> getHeaders(String name) { return null; } Index: java/org/apache/tomcat/lite/BodyWriter.java =================================================================== --- java/org/apache/tomcat/lite/BodyWriter.java (revision 833452) +++ java/org/apache/tomcat/lite/BodyWriter.java (working copy) @@ -14,18 +14,18 @@ import org.apache.tomcat.util.buf.CharChunk; /** - * Implement buffering and character translation acording to the - * servlet spec. - * + * Implement buffering and character translation acording to the + * servlet spec. + * * This class handles both chars and bytes. - * + * * It is tightly integrated with servlet response, sending headers * and updating the commit state. - * - * TODO: add 'extension' interface that allows direct access to - * the async connector non-copy non-blocking queue. Same for the - * OutputStream. Maybe switch the buffer to the brigade. - * + * + * TODO: add 'extension' interface that allows direct access to + * the async connector non-copy non-blocking queue. Same for the + * OutputStream. Maybe switch the buffer to the brigade. + * * @author Costin Manolache */ public class BodyWriter extends Writer { @@ -34,7 +34,7 @@ protected static final int WRITER_NOTE = 3; - private ByteChunk.ByteOutputChannel byteFlusher = + private ByteChunk.ByteOutputChannel byteFlusher = new ByteChunk.ByteOutputChannel() { @Override @@ -44,7 +44,7 @@ } }; - private CharChunk.CharOutputChannel charFlusher = + private CharChunk.CharOutputChannel charFlusher = new CharChunk.CharOutputChannel() { @Override public void realWriteChars(char[] cbuf, int off, int len) @@ -52,9 +52,9 @@ BodyWriter.this.realWriteChars(cbuf, off, len); } }; - - public static final String DEFAULT_ENCODING = + + public static final String DEFAULT_ENCODING = org.apache.coyote.Constants.DEFAULT_CHARACTER_ENCODING; public static final int DEFAULT_BUFFER_SIZE = 8*1024; @@ -119,7 +119,7 @@ /** - * Encoding to use. + * Encoding to use. * TODO: isn't it redundant ? enc, gotEnc, conv plus the enc in the bb */ protected String enc; @@ -132,7 +132,7 @@ /** - * List of encoders. The writer is reused - the encoder mapping + * List of encoders. The writer is reused - the encoder mapping * avoids creating expensive objects. In future it'll contain nio.Charsets */ protected HashMap encoders = new HashMap(); @@ -166,7 +166,7 @@ /** * Alternate constructor which allows specifying the initial buffer size. - * + * * @param size Buffer size to use */ public BodyWriter(int size) { @@ -179,7 +179,7 @@ cb.setLimit(size); } - + public void setConnector(Connector c, ServletResponseImpl res) { this.res = res; this.connector = c; @@ -191,7 +191,7 @@ /** * Is the response output suspended ? - * + * * @return suspended flag value */ public boolean isSuspended() { @@ -201,7 +201,7 @@ /** * Set the suspended flag. - * + * * @param suspended New suspended flag value */ public void setSuspended(boolean suspended) { @@ -216,31 +216,31 @@ * Recycle the output buffer. */ public void recycle() { - + state = BYTE_STATE; headersSent = false; bytesWritten = 0; charsWritten = 0; - + cb.recycle(); - bb.recycle(); + bb.recycle(); closed = false; suspended = false; - + if (conv!= null) { conv.recycle(); } - + gotEnc = false; enc = null; - + } /** - * Close the output buffer. This tries to calculate the response size if + * Close the output buffer. This tries to calculate the response size if * the response has not been committed yet. - * + * * @throws IOException An underlying IOException occurred */ public void close() @@ -266,7 +266,7 @@ /** * Flush bytes or chars contained in the buffer. - * + * * @throws IOException An underlying IOException occurred */ public void flush() @@ -276,7 +276,7 @@ /** * Flush bytes or chars contained in the buffer. - * + * * @throws IOException An underlying IOException occurred */ protected void doFlush(boolean realFlush) @@ -294,10 +294,10 @@ if (state == CHAR_STATE) { cb.flushBuffer(); state = BYTE_STATE; - } + } if (state == BYTE_STATE) { bb.flushBuffer(); - } + } doFlush = false; if (realFlush) { @@ -310,14 +310,14 @@ // ------------------------------------------------- Bytes Handling Methods - /** + /** * Sends the buffer data to the client output, checking the * state of Response and calling the right interceptors. - * + * * @param buf Byte buffer to be written to the response * @param off Offset * @param cnt Length - * + * * @throws IOException An underlying IOException occurred */ private void realWriteBytes(byte buf[], int off, int cnt) @@ -356,7 +356,7 @@ } - private void writeBytes(byte b[], int off, int len) + private void writeBytes(byte b[], int off, int len) throws IOException { if (closed) @@ -432,7 +432,7 @@ } - public void write(StringBuffer sb) + public void write(StringBuilder sb) throws IOException { if (suspended) @@ -477,7 +477,7 @@ s="null"; write(s, 0, s.length()); - } + } public void println() throws IOException { write("\n"); @@ -511,7 +511,7 @@ } - private void realWriteChars(char c[], int off, int len) + private void realWriteChars(char c[], int off, int len) throws IOException { if (!gotEnc) @@ -523,7 +523,7 @@ } - public void checkConverter() + public void checkConverter() throws IOException { if (!gotEnc) @@ -532,7 +532,7 @@ } - protected void setConverter() + protected void setConverter() throws IOException { enc = res.getCharacterEncoding(); @@ -542,7 +542,7 @@ enc = DEFAULT_ENCODING; conv = (C2BConverter) encoders.get(enc); if (conv == null) { - + if (System.getSecurityManager() != null){ try{ conv = (C2BConverter)AccessController.doPrivileged( @@ -553,22 +553,22 @@ } } - ); + ); }catch(PrivilegedActionException ex){ Exception e = ex.getException(); if (e instanceof IOException) - throw (IOException)e; + throw (IOException)e; } } else { conv = new C2BConverter(bb, enc); } - + encoders.put(enc, conv); } } - + // -------------------- BufferedOutputStream compatibility @@ -598,9 +598,9 @@ } - /** + /** * True if this buffer hasn't been used ( since recycle() ) - - * i.e. no chars or bytes have been added to the buffer. + * i.e. no chars or bytes have been added to the buffer. */ public boolean isNew() { return (bytesWritten == 0) && (charsWritten == 0); @@ -642,7 +642,7 @@ // public abstract void recycle(); // public abstract void setSuspended(boolean suspended); // public abstract boolean isSuspended(); -// +// // public abstract void reset(); // public abstract int getBufferSize(); // public abstract void setBufferSize(int n); @@ -652,5 +652,5 @@ // } // public abstract void write(byte[] b, int off, int len) throws IOException; // public abstract void writeByte(int b) throws IOException; -// +// //} \ No newline at end of file Index: java/org/apache/tomcat/lite/ServletConfigImpl.java =================================================================== --- java/org/apache/tomcat/lite/ServletConfigImpl.java (revision 833452) +++ java/org/apache/tomcat/lite/ServletConfigImpl.java (working copy) @@ -1,12 +1,12 @@ /* * Copyright 1999-2002,2004 The Apache Software Foundation. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -19,6 +19,7 @@ import java.io.PrintStream; import java.lang.reflect.Method; +import java.util.Collection; import java.util.Enumeration; import java.util.HashMap; import java.util.HashSet; @@ -28,11 +29,14 @@ import java.util.logging.Level; import java.util.logging.Logger; + +import javax.servlet.MultipartConfigElement; import javax.servlet.Servlet; import javax.servlet.ServletConfig; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.ServletRegistration; +import javax.servlet.ServletSecurityElement; import javax.servlet.SingleThreadModel; import javax.servlet.UnavailableException; @@ -42,7 +46,7 @@ /** * Based on Wrapper. - * + * * Standard implementation of the <b>Wrapper</b> interface that represents * an individual servlet definition. No child Containers are allowed, and * the parent Container must be a Context. @@ -52,11 +56,11 @@ */ @SuppressWarnings("deprecation") public class ServletConfigImpl implements ServletConfig, ServletRegistration { - + ServletDynamicRegistration dynamic = new ServletDynamicRegistration(); - + protected boolean asyncSupported; - + private static Logger log= Logger.getLogger(ServletConfigImpl.class.getName()); @@ -75,7 +79,7 @@ protected int loadOnStartup = -1; protected String runAs; protected Map securityRoleRef = new HashMap(); // roleName -> [roleLink] - + /** * The date and time at which this servlet will become available (in * milliseconds since the epoch), or zero if the servlet is available. @@ -83,14 +87,14 @@ * servlet is considered permanent. */ private transient long available = 0L; - + private ServletContextImpl ctx; /** * The (single) initialized instance of this servlet. */ private transient Servlet instance = null; - + /** * Are we unloading our servlet instance at the moment? */ @@ -111,13 +115,13 @@ */ private transient Stack instancePool = null; - + // Statistics private transient long loadTime=0; private transient int classLoadTime=0; // ------------------------------------------------------------- Properties - public ServletConfigImpl(ServletContextImpl ctx, String name, + public ServletConfigImpl(ServletContextImpl ctx, String name, String classname) { this.servletName = name; this.servletClassName = classname; @@ -177,7 +181,7 @@ public void setJspFile(String s) { this.jspFile = s; } - + /** * Return the load-on-startup order value (negative value means * load on first call). @@ -229,11 +233,11 @@ HashSet allow = new HashSet(); allow.add("TRACE"); allow.add("OPTIONS"); - + Method[] methods = getAllDeclaredMethods(servletClazz); for (int i=0; methods != null && i<methods.length; i++) { Method m = methods[i]; - + if (m.getName().equals("doGet")) { allow.add("GET"); allow.add("HEAD"); @@ -257,7 +261,7 @@ /** * Extract the root cause from a servlet exception. - * + * * @param e The servlet exception */ public static Throwable getRootCause(ServletException e) { @@ -280,15 +284,15 @@ /** * MUST be called before service() - * This method should be called to get the servlet. After + * This method should be called to get the servlet. After * service(), dealocate should be called. This deals with STM and * update use counters. - * + * * Normally called from RequestDispatcher and TomcatLite. */ public Servlet allocate() throws ServletException { // If we are currently unloading this servlet, throw an exception - if (unloading) + if (unloading) throw new ServletException ("allocate() while unloading " + getServletName()); @@ -316,10 +320,10 @@ countAllocated++; return (instance); } - + // Simpler policy for ST: unbound number of servlets ( can grow to // one per thread ) - + synchronized (instancePool) { if (instancePool.isEmpty()) { try { @@ -330,7 +334,7 @@ } countAllocated++; Servlet newServlet = loadServlet(); - log.fine("New STM servet " + newServlet + " " + + log.fine("New STM servet " + newServlet + " " + countAllocated); return newServlet; } catch (ServletException e) { @@ -344,7 +348,7 @@ countAllocated); Servlet s = (Servlet) instancePool.pop(); countAllocated++; - log.fine("After get " + instancePool.size() + " " + s + + log.fine("After get " + instancePool.size() + " " + s + " " + countAllocated); return s; } @@ -365,11 +369,11 @@ synchronized (instancePool) { countAllocated--; if (instancePool.contains(servlet)) { - System.err.println("Aleady in pool " + servlet + " " + System.err.println("Aleady in pool " + servlet + " " + instancePool.size()+ " " + countAllocated); return; } - System.err.println("return pool " + servlet + " " + + System.err.println("return pool " + servlet + " " + instancePool.size() + " " + countAllocated); instancePool.push(servlet); } @@ -384,7 +388,7 @@ if (actualClass == null) { // No explicit name. Try to use the framework if (jspFile != null) { - + // Named JSPs can be handled by a servlet or by the mapper. Servlet res = (Servlet) ctx.getObjectManager().get("filetemplate-servlet"); if (res != null) { @@ -393,7 +397,7 @@ initParams.put("jsp-file", jspFile); return res; } else { - UserTemplateClassMapper mapper = + UserTemplateClassMapper mapper = (UserTemplateClassMapper) ctx.getObjectManager().get( UserTemplateClassMapper.class); if (mapper != null) { @@ -415,36 +419,36 @@ //ctx.getObjectManager().getObject(c); //ctx.getObjectManager().getObject(servletName); } - - + + if (servletClass == null) { // set classClass loadClass(actualClass); } - - // jsp-file case. Load the JspProxyServlet instead, with the - // right params. Note the JspProxyServlet is _not_ jasper, - // nor 'jsp' servlet - it is just a proxy with no special + + // jsp-file case. Load the JspProxyServlet instead, with the + // right params. Note the JspProxyServlet is _not_ jasper, + // nor 'jsp' servlet - it is just a proxy with no special // params. It calls the jsp servlet and jasper to generate the // real class. - + // this is quite different from catalina, where an ugly kludge was // used to use the same jsp servlet in 2 roles - + // the jsp proxy is replaced by the web.xml processor - + if (servletClass == null) { unavailable(null); throw new UnavailableException("ClassNotFound: " + actualClass); } - + // Instantiate and initialize an instance of the servlet class itself try { return (Servlet) servletClass.newInstance(); } catch (ClassCastException e) { unavailable(null); - throw new UnavailableException("ClassCast: (Servlet)" + + throw new UnavailableException("ClassCast: (Servlet)" + actualClass); } catch (Throwable e) { unavailable(null); @@ -452,13 +456,13 @@ // Added extra log statement for Bugzilla 36630: // http://issues.apache.org/bugzilla/show_bug.cgi?id=36630 if(log.isLoggable(Level.FINE)) { - log.log(Level.FINE, "newInstance() error: servlet-name: " + + log.log(Level.FINE, "newInstance() error: servlet-name: " + getServletName() + " servlet-class: " + actualClass, e); } // Restore the context ClassLoader - throw new ServletException("newInstance() error " + getServletName() + + throw new ServletException("newInstance() error " + getServletName() + " " + actualClass, e); } } @@ -473,13 +477,13 @@ // Nothing to do if we already have an instance or an instance pool if (!singleThreadModel && (instance != null)) return instance; - + long t1=System.currentTimeMillis(); Servlet servlet = newInstance(); - + classLoadTime=(int) (System.currentTimeMillis() -t1); - + // Call the initialization method of this servlet try { servlet.init(this); @@ -500,7 +504,7 @@ instancePool = new Stack(); } loadTime=System.currentTimeMillis() -t1; - + return servlet; } @@ -509,14 +513,14 @@ // Complain if no servlet class has been specified if (actualClass == null) { unavailable(null); - throw new ServletException("servlet-class missing " + + throw new ServletException("servlet-class missing " + getServletName()); } - - ClassLoader classLoader = ctx.getClassLoader(); - if (classLoader == null ) + + ClassLoader classLoader = ctx.getClassLoader(); + if (classLoader == null ) classLoader = this.getClass().getClassLoader(); - + // Load the specified servlet class from the appropriate class loader try { servletClass = classLoader.loadClass(actualClass); @@ -580,7 +584,7 @@ * destroy() method */ public synchronized void unload() throws ServletException { - setAvailable(Long.MAX_VALUE); + setAvailable(Long.MAX_VALUE); // Nothing to do if we have never loaded the instance if (!singleThreadModel && (instance == null)) @@ -594,7 +598,7 @@ long delay = ctx.getUnloadDelay() / 20; while ((nRetries < 21) && (countAllocated > 0)) { if ((nRetries % 10) == 0) { - log.info("Servlet.unload() timeout " + + log.info("Servlet.unload() timeout " + countAllocated); } try { @@ -610,7 +614,7 @@ Thread.currentThread().getContextClassLoader(); if (instance != null) { ClassLoader classLoader = instance.getClass().getClassLoader(); - + PrintStream out = System.out; // Call the servlet destroy() method try { @@ -620,13 +624,13 @@ instance = null; //instancePool = null; unloading = false; - throw new ServletException("Servlet.destroy() " + + throw new ServletException("Servlet.destroy() " + getServletName(), t); } finally { // restore the context ClassLoader Thread.currentThread().setContextClassLoader(oldCtxClassLoader); } - + // Deregister the destroyed instance instance = null; } @@ -653,8 +657,8 @@ unloading = false; } - - + + /** * Return the initialization parameter value for the specified name, * if any; otherwise return <code>null</code>. @@ -772,33 +776,33 @@ if ((parentMethods != null) && (parentMethods.length > 0)) { Method[] allMethods = new Method[parentMethods.length + thisMethods.length]; - System.arraycopy(parentMethods, 0, allMethods, 0, + System.arraycopy(parentMethods, 0, allMethods, 0, parentMethods.length); - System.arraycopy(thisMethods, 0, allMethods, parentMethods.length, + System.arraycopy(thisMethods, 0, allMethods, parentMethods.length, thisMethods.length); - thisMethods = allMethods; - } + thisMethods = allMethods; + } - return thisMethods; + return thisMethods; } /** Specify the instance. Avoids the class lookup, disables unloading. * Use for embedded case, or to control the allocation. - * + * * @param servlet */ public void setServlet(Servlet servlet) { instance = servlet; ctx.getObjectManager().bind("Servlet:" + - ctx.getContextPath() + ":" + getServletName(), + ctx.getContextPath() + ":" + getServletName(), this); } public String getSecurityRoleRef(String role) { return (String)securityRoleRef.get(role); } - + public void setSecurityRoleRef(Map securityRoles) { this.securityRoleRef = securityRoles; } @@ -811,10 +815,10 @@ this.loadOnStartup = loadOnStartup; } - @Override + public Set<String> addMapping(String... urlPatterns) { if (ctx.startDone) { - // Use the context method instead of the servlet API to + // Use the context method instead of the servlet API to // add mappings after context init. throw new IllegalStateException(); } @@ -833,41 +837,128 @@ return failed; } - @Override + public boolean setInitParameter(String name, String value) throws IllegalArgumentException, IllegalStateException { - return ServletContextImpl.setInitParameter(ctx, initParams, + return ServletContextImpl.setInitParameter(ctx, initParams, name, value); } - @Override + public Set<String> setInitParameters(Map<String, String> initParameters) throws IllegalArgumentException, IllegalStateException { - return ServletContextImpl.setInitParameters(ctx, initParams, + return ServletContextImpl.setInitParameters(ctx, initParams, initParameters); } public Dynamic getDynamic() { return dynamic; } - + class ServletDynamicRegistration implements Dynamic { - @Override + public void setAsyncSupported(boolean isAsyncSupported) throws IllegalStateException { asyncSupported = isAsyncSupported; } - @Override + public void setDescription(String description) throws IllegalStateException { ServletConfigImpl.this.description = description; } - + + public Set<String> setServletSecurity(ServletSecurityElement constraint) { + //implement me + return null; + } + + public void setLoadOnStartup(int loadOnStartup) { + //implement me - here to compile + } + public void setMultipartConfig(MultipartConfigElement multipartConfig) { + //implement me - here to compile + } + public void setRunAsRole(String roleName) { + //implement me - here to compile + } + public String getRunAsRole() { + //implement me - here to compile + return null; + } + public Collection<String> getMappings() { + //implement me + return null; + } + + public Set<String> addMapping(String... urlPatterns) { + //implement me + return null; + } + + public Map<String, String> getInitParameters() { + // implement me + return null; + } + + public Set<String> setInitParameters(Map<String, String> initParameters) + throws IllegalArgumentException, IllegalStateException { + // implement me + return null; + } + + public String getClassName() { + // implement me + return null; + } + + public String getName() { + // implement me + return null; + } + + public String getInitParameter(String name) { + // implement me + return null; + } + + public boolean setInitParameter(String name, String value) + throws IllegalArgumentException, IllegalStateException { + // implement me + return false; + } + } + public Collection<String> getMappings() { + //implement me + return null; + } + public void setServletClass(Class<? extends Servlet> servletClass2) { servletClass = servletClass2; } + + public String getRunAsRole() { + //implement me + return null; + } + + + public Map<String, String> getInitParameters() { + // implement me + return null; + } + + public String getClassName() { + // implement me + return null; + } + + public String getName() { + // implement me + return null; + } + } Index: java/org/apache/tomcat/lite/FilterConfigImpl.java =================================================================== --- java/org/apache/tomcat/lite/FilterConfigImpl.java (revision 833452) +++ java/org/apache/tomcat/lite/FilterConfigImpl.java (working copy) @@ -1,12 +1,12 @@ /* * Copyright 1999,2004 The Apache Software Foundation. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -19,6 +19,7 @@ import java.util.ArrayList; +import java.util.Collection; import java.util.EnumSet; import java.util.Enumeration; import java.util.HashSet; @@ -36,36 +37,36 @@ import org.apache.tomcat.servlets.util.Enumerator; -/** +/** * A Filter is configured in web.xml by: * - name - used in mappings * - className - used to instantiate the filter * - init params * - other things not used in the servlet container ( icon, descr, etc ) - * + * * Alternatively, in API mode you can pass the actual filter. - * + * * @see ServletConfigImpl */ public final class FilterConfigImpl implements FilterConfig, FilterRegistration { DynamicFilterRegistration dynamic = new DynamicFilterRegistration(); - + public FilterConfigImpl(ServletContextImpl context) { this.ctx = context; } - + boolean asyncSupported; - + private ServletContextImpl ctx = null; /** * The application Filter we are configured for. */ private transient Filter filter = null; - + String descryption; - + private String filterName; private String filterClassName; @@ -80,11 +81,11 @@ this.filterClassName = filterClass; this.initParams = params; } - + public void setFilter(Filter f) { filter = f; } - + public String getFilterName() { return filterName; } @@ -92,8 +93,8 @@ public void setFilterClass(Class<? extends Filter> filterClass2) { this.filterClass = filterClass2; } - + public String getInitParameter(String name) { if (initParams == null) return null; return initParams.get(name); @@ -140,17 +141,17 @@ filterClass = (Class<? extends Filter>) classLoader.loadClass(filterClassName); } this.filter = (Filter) filterClass.newInstance(); - } finally { + } finally { if (classLoader != oldCtxClassLoader) { Thread.currentThread().setContextClassLoader(oldCtxClassLoader); } } - + // TODO: resource injection - + return filter; } - + public Filter getFilter() throws ClassCastException, ClassNotFoundException, IllegalAccessException, InstantiationException, ServletException { Filter filter = createFilter(); filter.init(this); @@ -169,12 +170,12 @@ this.filter = null; } - @Override + public void addMappingForServletNames(EnumSet<DispatcherType> dispatcherTypes, boolean isMatchAfter, String... servletNames) { if (ctx.startDone) { - // Use the context method instead of the servlet API to + // Use the context method instead of the servlet API to // add mappings after context init. throw new IllegalStateException(); } @@ -188,12 +189,12 @@ } } - @Override + public void addMappingForUrlPatterns(EnumSet<DispatcherType> dispatcherTypes, boolean isMatchAfter, String... urlPatterns) { if (ctx.startDone) { - // Use the context method instead of the servlet API to + // Use the context method instead of the servlet API to // add mappings after context init. throw new IllegalStateException(); } @@ -207,66 +208,120 @@ } } - @Override + public boolean setInitParameter(String name, String value) throws IllegalArgumentException, IllegalStateException { - return ServletContextImpl.setInitParameter(ctx, initParams, + return ServletContextImpl.setInitParameter(ctx, initParams, name, value); } - @Override + public Set<String> setInitParameters(Map<String, String> initParameters) throws IllegalArgumentException, IllegalStateException { - return ServletContextImpl.setInitParameters(ctx, initParams, + return ServletContextImpl.setInitParameters(ctx, initParams, initParameters); } - + public Dynamic getDynamic() { return dynamic; } - + public class DynamicFilterRegistration implements Dynamic { - @Override + public void addMappingForServletNames(EnumSet<DispatcherType> dispatcherTypes, boolean isMatchAfter, String... servletNames) { FilterConfigImpl.this.addMappingForServletNames(dispatcherTypes, isMatchAfter, servletNames); } - @Override + public void addMappingForUrlPatterns(EnumSet<DispatcherType> dispatcherTypes, boolean isMatchAfter, String... urlPatterns) { FilterConfigImpl.this.addMappingForUrlPatterns(dispatcherTypes, isMatchAfter, urlPatterns); } - @Override + public boolean setInitParameter(String name, String value) throws IllegalArgumentException, IllegalStateException { - return ServletContextImpl.setInitParameter(ctx, initParams, + return ServletContextImpl.setInitParameter(ctx, initParams, name, value); } - @Override + public Set<String> setInitParameters(Map<String, String> initParameters) throws IllegalArgumentException, IllegalStateException { - return ServletContextImpl.setInitParameters(ctx, initParams, + return ServletContextImpl.setInitParameters(ctx, initParams, initParameters); } - @Override + public void setAsyncSupported(boolean isAsyncSupported) throws IllegalStateException { asyncSupported = isAsyncSupported; } - @Override + public void setDescription(String description) throws IllegalStateException { FilterConfigImpl.this.descryption = description; } + + public Collection<String> getUrlPatternMappings() { + // implement me + return null; + } + + public Collection<String> getServletNameMappings() { + // implement me + return null; + } + + public Map<String, String> getInitParameters() { + // implement me + return null; + } + + public String getInitParameter(String name) { + if (initParams == null) return null; + return initParams.get(name); + } + + public String getClassName() { + // implement me + return null; + } + + public String getName() { + // implement me + return null; + } } - + public Collection<String> getUrlPatternMappings() { + // implement me + return null; + } + + public Collection<String> getServletNameMappings() { + // implement me + return null; + } + + public Map<String, String> getInitParameters() { + // implement me + return null; + } + + public String getClassName() { + // implement me + return null; + } + + public String getName() { + // implement me + return null; + } + } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@... For additional commands, e-mail: dev-help@... |
|
|
Re: patch for allowing tomcat-lite to compileMy text editor also chucks trailing spaces (and converts tabs to spaces)
which might be one reason the patch looks big -Tim Tim Funk wrote: > I had some free to take a glance at tomcat lite but noticed it didn't > compile. So here's a patch to let it compile on my machine. There were 3 > classes changes of changes > 1) Use StringBuilder instead of StringBuffer when required > 2) remove @Override > 3) Added stubs to adhere to 3.0 interfaces > > Any objections for committing? --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@... For additional commands, e-mail: dev-help@... |
|
|
Re: patch for allowing tomcat-lite to compileTim Funk wrote:
> I had some free to take a glance at tomcat lite but noticed it didn't > compile. So here's a patch to let it compile on my machine. There were 3 > classes changes of changes > 1) Use StringBuilder instead of StringBuffer when required > 2) remove @Override Those should be OK as is (although I may have messed up applying them). Maybe a Java 5/6 issue? > 3) Added stubs to adhere to 3.0 interfaces > > Any objections for committing? Other than checking the @Override annotations, +1 Mark --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@... For additional commands, e-mail: dev-help@... |
|
|
Re: patch for allowing tomcat-lite to compileThe @Override is probably due to JDK1.6.
Thanks for the patch ! I should mention I have a very large set of changes for tomcat-lite - including implementations for some of the 3.0 interfaces. I guess it's time to start committing them... Costin On Fri, Nov 6, 2009 at 10:17 AM, Tim Funk <funkman@...> wrote: > I had some free to take a glance at tomcat lite but noticed it didn't > compile. So here's a patch to let it compile on my machine. There were 3 > classes changes of changes > 1) Use StringBuilder instead of StringBuffer when required > 2) remove @Override > 3) Added stubs to adhere to 3.0 interfaces > > Any objections for committing? > > -Tim > > Index: java/org/apache/tomcat/integration/simple/SimpleObjectManager.java > =================================================================== > --- java/org/apache/tomcat/integration/simple/SimpleObjectManager.java > (revision 833452) > +++ java/org/apache/tomcat/integration/simple/SimpleObjectManager.java > (working copy) > @@ -13,40 +13,39 @@ > > import org.apache.tomcat.integration.ObjectManager; > import org.apache.tomcat.util.IntrospectionUtils; > -import org.apache.tools.ant.taskdefs.LoadResource; > > /** > - * This is a very small 'dependency injection'/registry poor-man > substitute, > + * This is a very small 'dependency injection'/registry poor-man > substitute, > * based on old tomcat IntrospectionUtils ( which is based on ant ). > * Alternative would be to just pick one of spring/guice/etc and use it. > * This class is a bit smaller and should be enough for simple use. > - * > - * How it works: > + * > + * How it works: > * - when bound, simple properties are injected in the objects using > * the old IntrospectionUtils, same as in original Tomcat server.xml > - * > + * > * - object creation using class name - properties injected as well. > * Similar with how server.xml or ant works. > - * > - * - it is based on a big Properties file, with command line arguments > + * > + * - it is based on a big Properties file, with command line arguments > * merged in. > - * > + * > * Tomcat doesn't require any of the features - they are just used to > - * allow configuration in 'default' mode, when no other framework is > - * used. > - * > + * allow configuration in 'default' mode, when no other framework is > + * used. > + * > * See the Spring example for an alternative. I believe most POJO > frameworks > - * can be supported. > - * > + * can be supported. > + * > * @author Costin Manolache > */ > public class SimpleObjectManager extends ObjectManager { > static Logger log = > Logger.getLogger(SimpleObjectManager.class.getName()); > - > + > protected Properties props = new Properties(); > protected Map<String, Object> objects = new HashMap(); > ObjectManager om; > - > + > public SimpleObjectManager() { > // Register PropertiesSpi > } > @@ -55,18 +54,18 @@ > this(); > bind("Main.args", args); > } > - > + > public void loadResource(String res) { > InputStream in = this.getClass().getClassLoader() > .getResourceAsStream(res); > load(in); > } > - > + > public void register(ObjectManager om) { > this.om = om; > super.register(om); > } > - > + > public ObjectManager getObjectManager() { > return om; > } > @@ -78,11 +77,11 @@ > throw new RuntimeException("Error loading default config"); > } > } > - > + > public Properties getProperties() { > return props; > } > - > + > @Override > public void unbind(String name) { > } > @@ -98,8 +97,8 @@ > throw new RuntimeException(e); > } > } > - > - // TODO: can I make 'inject' public - Guice seems to > + > + // TODO: can I make 'inject' public - Guice seems to > // support this. > inject(name, o); > } > @@ -125,10 +124,10 @@ > for (String k: props.stringPropertyNames()) { > if (k.startsWith(pref)) { > if (k.endsWith(")")) { > - continue; // special > + continue; // special > } > String value = props.getProperty(k); > - value = IntrospectionUtils.replaceProperties(value, > + value = IntrospectionUtils.replaceProperties(value, > props, null); > String p = k.substring(prefLen); > int idx = p.indexOf("."); > @@ -151,23 +150,23 @@ > } catch (Throwable e) { > e.printStackTrace(); > return null; > - } > + } > } > - > + > /** > * Populate properties based on CLI: > * -key value > * --key=value > - * > + * > * --config=FILE - load a properties file > - * > + * > * @param args > * @param p > * @param meta > * @return everything after the first non arg not starting with '-' > - * @throws IOException > + * @throws IOException > */ > - public String[] processArgs(String[] args, Properties props) > + public String[] processArgs(String[] args, Properties props) > throws IOException { > > for (int i = 0; i < args.length; i++) { > @@ -181,8 +180,8 @@ > System.arraycopy(args, i, res, 0, res.length); > return res; > } > - > - String name = arg; > + > + String name = arg; > int eq = arg.indexOf("="); > String value = null; > if (eq > 0) { > @@ -198,7 +197,7 @@ > > if ("config".equals(arg)) { > if (new File(value).exists()) { > - load(new FileInputStream(value)); > + load(new FileInputStream(value)); > } else { > loadResource(value); > } > @@ -207,5 +206,5 @@ > } > } > return new String[] {}; > - } > + } > } > Index: java/org/apache/tomcat/lite/ServletContextImpl.java > =================================================================== > --- java/org/apache/tomcat/lite/ServletContextImpl.java (revision 833452) > +++ java/org/apache/tomcat/lite/ServletContextImpl.java (working copy) > @@ -5,9 +5,9 @@ > * The ASF licenses this file to You under the Apache License, Version 2.0 > * (the "License"); you may not use this file except in compliance with > * the License. You may obtain a copy of the License at > - * > + * > * http://www.apache.org/licenses/LICENSE-2.0 > - * > + * > * Unless required by applicable law or agreed to in writing, software > * distributed under the License is distributed on an "AS IS" BASIS, > * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. > @@ -27,6 +27,7 @@ > import java.net.URL; > import java.net.URLClassLoader; > import java.util.ArrayList; > +import java.util.Collection; > import java.util.EnumSet; > import java.util.Enumeration; > import java.util.EventListener; > @@ -57,6 +58,7 @@ > import javax.servlet.SessionCookieConfig; > import javax.servlet.SessionTrackingMode; > import javax.servlet.FilterRegistration.Dynamic; > +import javax.servlet.descriptor.JspConfigDescriptor; > > import org.apache.tomcat.addons.UserSessionManager; > import org.apache.tomcat.integration.ObjectManager; > @@ -72,15 +74,15 @@ > > /** > * Context - initialized from web.xml or using APIs. > - * > + * > * Initialization order: > - * > + * > * - add all listeners > * - add all filters > * - add all servlets > - * > + * > * - session parameters > - * - > + * - > * > * @author Craig R. McClanahan > * @author Remy Maucherat > @@ -88,14 +90,14 @@ > */ > > public class ServletContextImpl implements ServletContext { > - > + > /** > * Empty collection to serve as the basis for empty enumerations. > */ > private transient static final ArrayList empty = new ArrayList(); > - > + > transient Logger log; > - > + > /** > * Base path - the directory root of the webapp > */ > @@ -123,7 +125,7 @@ > protected transient ArrayList<EventListener> lifecycleListeners = new > ArrayList(); > > protected UserSessionManager manager; > - > + > HashMap<String, FilterConfigImpl> filters = new HashMap<String, > FilterConfigImpl>(); > > HashMap<String, ServletConfigImpl> servlets = new HashMap<String, > ServletConfigImpl>(); > @@ -133,16 +135,16 @@ > /** Mapper for filters. > */ > protected WebappFilterMapper webappFilterMapper; > - > - /** Internal mapper for request dispatcher, must have all > - * context mappings. > - */ > + > + /** Internal mapper for request dispatcher, must have all > + * context mappings. > + */ > protected WebappServletMapper mapper; > - > + > transient Locale2Charset charsetMapper = new Locale2Charset(); > > transient TomcatLite facade; > - > + > ObjectManager om; > > private String hostname; > @@ -151,7 +153,7 @@ > boolean initDone = false; > > boolean startDone = false; > - > + > // ------------------------------------------------- ServletContext > Methods > public ServletContextImpl() { > } > @@ -159,7 +161,7 @@ > public void setTomcat(TomcatLite facade) { > this.facade = facade; > } > - > + > /** > * Registry/framework interface associated with the context. > * Also available as a context attribute. > @@ -171,11 +173,11 @@ > } > return om; > } > - > + > public void setObjectManager(ObjectManager om) { > this.om = om; > } > - > + > public Locale2Charset getCharsetMapper() { > return charsetMapper; > } > @@ -188,29 +190,29 @@ > this.contextPath = path; > log = Logger.getLogger("webapp" + path.replace('/', '.')); > } > - > + > public void setHostname(String hostname) { > this.hostname = hostname; > } > - > + > public String getHostname() { > return hostname; > } > - > + > /** The directory where this app is based. May be null. > - * > + * > * @param basePath > */ > public void setBasePath(String basePath) { > - this.basePath = basePath; > + this.basePath = basePath; > } > > public ServletContextConfig getContextConfig() { > return contextConfig; > } > - > + > /** The directory where this app is based. > - * > + * > * @param basePath > */ > public String getBasePath() { > @@ -234,11 +236,20 @@ > public List<EventListener> getListeners() { > return lifecycleListeners; > } > - > - public void addListener(EventListener listener) { > - lifecycleListeners.add(listener); > + > + public void addListener(Class <? extends EventListener> listenerClass) > { > + // implement me > } > > + public void addListener(String className) { > + // implement me > + } > + > + public <T extends EventListener> void addListener(T t) { > + lifecycleListeners.add(t); > + } > + > + > public void removeListener(EventListener listener) { > lifecycleListeners.remove(listener); > } > @@ -256,7 +267,7 @@ > public ServletConfigImpl getServletConfig(String jsp_servlet_name) { > return (ServletConfigImpl)servlets.get(jsp_servlet_name); > } > - > + > public Map getServletConfigs() { > return servlets; > } > @@ -264,27 +275,27 @@ > /** > * Add a servlet to the context. > * Called from processWebAppData() > - * > + * > * @param servletConfig > */ > public void addServletConfig(ServletConfigImpl servletConfig) { > servlets.put(servletConfig.getServletName(), servletConfig); > } > - > + > public boolean getPrivileged() { > return false; > } > > - > + > public Map getFilters() { > return filters; > } > - > > + > protected boolean getCrossContext() { > return true; > } > - > + > public void addMimeType(String ext, String type) { > contentTypes.addContentType(ext, type); > } > @@ -302,7 +313,7 @@ > > return mapper; > } > - > + > public WebappFilterMapper getFilterMapper() { > if (webappFilterMapper == null) { > Object customMapper = > getObjectManager().get(WebappFilterMapper.class); > @@ -316,7 +327,7 @@ > > return webappFilterMapper ; > } > - > + > public FilterConfigImpl getFilter(String name) { > return (FilterConfigImpl)filters.get(name); > } > @@ -349,7 +360,7 @@ > public void addSecurityRole(String role) { > securityRoles.add(role); > } > - > + > public List getSecurityRoles() { > return securityRoles; > } > @@ -392,15 +403,15 @@ > } > } > > - > + > /** > * Return the main path associated with this context. > */ > public String getContextPath() { > return contextPath; > } > - > > + > /** > * Return the value of the specified initialization parameter, or > * <code>null</code> if this parameter does not exist. > @@ -473,10 +484,10 @@ > */ > public RequestDispatcher getNamedDispatcher(String name) { > if (name == null) return null; > - ServletConfigImpl wrapper = > + ServletConfigImpl wrapper = > (ServletConfigImpl) this.getServletConfig(name); > if (wrapper == null) return null; > - > + > return new RequestDispatcherImpl(wrapper, name); > } > > @@ -490,18 +501,18 @@ > */ > public RequestDispatcher getRequestDispatcher(String path) { > if (path == null) return null; > - > + > if (!path.startsWith("/")) > throw new IllegalArgumentException(path); > > path = UrlUtils.normalize(path); > if (path == null) return (null); > > - > + > return new RequestDispatcherImpl(this, path); > } > > - public RequestDispatcher getRequestDispatcher(String path, > + public RequestDispatcher getRequestDispatcher(String path, > int type, > String dispatcherPath) { > RequestDispatcher dispatcher = getRequestDispatcher(path); > @@ -512,23 +523,23 @@ > ThreadLocal requestDispatcherStack = new ThreadLocal(); > > protected ClassLoader classLoader; > - > + > // protected RequestDispatcherImpl getRequestDispatcher() { > -// ArrayList/*<RequestDispatcherImpl>*/ list = > +// ArrayList/*<RequestDispatcherImpl>*/ list = > // (ArrayList)requestDispatcherStack.get(); > // if (list == null) { > // list = new ArrayList(); > // requestDispatcherStack.set(list); > // } > -// > -// > +// > +// > // return null; > // } > > public void resetDispatcherStack() { > - > + > } > - > + > /** > * Return the URL to the resource that is mapped to a specified path. > * The path must begin with a "/" and is interpreted as relative to the > @@ -545,7 +556,7 @@ > if (path == null || !path.startsWith("/")) { > throw new MalformedURLException("getResource() " + path); > } > - > + > path = UrlUtils.normalize(path); > if (path == null) > return (null); > @@ -585,9 +596,9 @@ > return (null); > > File resFile = new File(basePath + path); > - if (!resFile.exists()) > + if (!resFile.exists()) > return null; > - > + > try { > return new FileInputStream(resFile); > } catch (FileNotFoundException e) { > @@ -624,7 +635,7 @@ > if (!path.endsWith("/")) { > path = path + "/"; > } > - > + > HashSet result = new HashSet(); > for (int i=0; i < files.length; i++) { > if (files[i].isDirectory() ) { > @@ -807,7 +818,7 @@ > event = > new > ServletContextAttributeEvent(this.getServletContext(), > name, value); > - > + > } > if (replaced) { > listener.attributeReplaced(event); > @@ -843,7 +854,7 @@ > removeAttribute(key); > } > } > - > + > public void initFilters() throws ServletException { > Iterator fI = getFilters().values().iterator(); > while (fI.hasNext()) { > @@ -851,16 +862,16 @@ > try { > fc.getFilter(); // will triger init() > } catch (Throwable e) { > - log.log(Level.WARNING, getContextPath() + " Filter.init() > " + > + log.log(Level.WARNING, getContextPath() + " Filter.init() > " + > fc.getFilterName(), e); > - } > - > + } > + > } > } > - > + > public void initServlets() throws ServletException { > Iterator fI = getServletConfigs().values().iterator(); > - Map/*<Integer, List<ServletConfigImpl>>*/ onStartup = > + Map/*<Integer, List<ServletConfigImpl>>*/ onStartup = > new TreeMap/*<Integer, List<ServletConfigImpl>>*/(); > while (fI.hasNext()) { > ServletConfigImpl fc = (ServletConfigImpl)fI.next(); > @@ -877,15 +888,15 @@ > Iterator keys = onStartup.keySet().iterator(); > while (keys.hasNext()) { > Integer key = (Integer)keys.next(); > - List/*<ServletConfigImpl>*/ servlets = > (List)onStartup.get(key); > + List/*<ServletConfigImpl>*/ servlets = > (List)onStartup.get(key); > Iterator servletsI = servlets.iterator(); > while (servletsI.hasNext()) { > ServletConfigImpl fc = (ServletConfigImpl) > servletsI.next(); > try { > - fc.loadServlet(); > + fc.loadServlet(); > } catch (Throwable e) { > log.log(Level.WARNING, "Error initializing " + > fc.getServletName(), e); > - } > + } > } > } > } > @@ -895,19 +906,19 @@ > while (fI.hasNext()) { > String listenerClass = (String)fI.next(); > try { > - Object l = > + Object l = > > getClassLoader().loadClass(listenerClass).newInstance(); > lifecycleListeners.add((EventListener) l); > } catch (Throwable e) { > log.log(Level.WARNING, "Error initializing listener " + > listenerClass, e); > - } > + } > } > } > > public ClassLoader getClassLoader() { > return classLoader; > } > - > + > public void addMapping(String path, String name) { > ServletConfigImpl wrapper = getServletConfig(name); > addMapping(path, wrapper); > @@ -916,9 +927,9 @@ > public void addMapping(String path, ServletConfig wrapper) { > getMapper().addWrapper(getMapper().contextMapElement, path, > wrapper); > } > - > - > - > + > + > + > public void setWelcomeFiles(String[] name) { > getMapper().contextMapElement.welcomeResources = name; > } > @@ -928,21 +939,21 @@ > } > > public void setSessionTimeout(int to) { > - getManager().setSessionTimeout(to); > + getManager().setSessionTimeout(to); > } > - > + > /** > * Initialize the context from the parsed config. > - * > + * > * Note that WebAppData is serializable. > */ > public void processWebAppData(ServletContextConfig d) throws > ServletException { > this.contextConfig = d; > - > + > for (String k: d.mimeMapping.keySet()) { > - addMimeType(k, d.mimeMapping.get(k)); > + addMimeType(k, d.mimeMapping.get(k)); > } > - > + > String[] wFiles = (String[])d.welcomeFileList.toArray(new > String[0]); > if (wFiles.length == 0) { > wFiles = new String[] {"index.html" }; > @@ -951,106 +962,106 @@ > getMapper().contextMapElement.resources = new > File(getBasePath()); > } > setWelcomeFiles(wFiles); > - > + > Iterator i2 = d.filters.values().iterator(); > while (i2.hasNext()) { > FilterData fd = (FilterData)i2.next(); > addFilter(fd.filterName, fd.filterClass, fd.initParams); > } > - > + > Iterator i3 = d.servlets.values().iterator(); > while (i3.hasNext()) { > ServletData sd = (ServletData) i3.next(); > - // jsp-file > + // jsp-file > if (sd.servletClass == null) { > if (sd.jspFile == null) { > log.log(Level.WARNING, "Missing servlet class for " + > sd.servletName); > continue; > } > } > - > - ServletConfigImpl sw = > + > + ServletConfigImpl sw = > new ServletConfigImpl(this, sd.servletName, sd.servletClass); > sw.setConfig(sd.initParams); > sw.setJspFile(sd.jspFile); > sw.setLoadOnStartup(sd.loadOnStartup); > //sw.setRunAs(sd.runAs); > sw.setSecurityRoleRef(sd.securityRoleRef); > - > + > addServletConfig(sw); > } > - > + > for (String k: d.servletMapping.keySet()) { > - addMapping(k, d.servletMapping.get(k)); > + addMapping(k, d.servletMapping.get(k)); > } > - > + > Iterator i5 = d.filterMappings.iterator(); > while (i5.hasNext()) { > - FilterMappingData k = (FilterMappingData) i5.next(); > + FilterMappingData k = (FilterMappingData) i5.next(); > String[] disp = new String[k.dispatcher.size()]; > if (k.urlPattern != null) { > - addFilterMapping(k.urlPattern, > - k.filterName, > + addFilterMapping(k.urlPattern, > + k.filterName, > (String[])k.dispatcher.toArray(disp)); > } > if (k.servletName != null) { > - addFilterServletMapping(k.servletName, > - k.filterName, > + addFilterServletMapping(k.servletName, > + k.filterName, > (String[])k.dispatcher.toArray(disp)); > } > } > - > + > for (String n: d.localeEncodingMapping.keySet()) { > - getCharsetMapper().addCharsetMapping(n, > + getCharsetMapper().addCharsetMapping(n, > d.localeEncodingMapping.get(n)); > } > } > - > - public void addServlet(String servletName, String servletClass, > + > + public void addServlet(String servletName, String servletClass, > String jspFile, Map params) { > - ServletConfigImpl sc = new ServletConfigImpl(this, servletName, > + ServletConfigImpl sc = new ServletConfigImpl(this, servletName, > servletClass); > sc.setJspFile(jspFile); > sc.setConfig(params); > addServletConfig(sc); > } > > - @Override > - public javax.servlet.Registration.Dynamic addServlet(String > servletName, Servlet servlet) { > + > + public javax.servlet.ServletRegistration.Dynamic addServlet(String > servletName, Servlet servlet) { > ServletConfigImpl sc = new ServletConfigImpl(this, servletName, > null); > sc.setServlet(servlet); > addServletConfig(sc); > return sc.getDynamic(); > } > - > + > public void addServletSec(String serlvetName, String runAs, Map roles) > { > // TODO > } > - > - > - > - public void addFilterMapping(String path, String filterName, > + > + > + > + public void addFilterMapping(String path, String filterName, > String[] dispatcher) { > - getFilterMapper().addMapping(filterName, > + getFilterMapper().addMapping(filterName, > path, null, dispatcher, true); > - > + > } > > - public void addFilterServletMapping(String servlet, > - String filterName, > + public void addFilterServletMapping(String servlet, > + String filterName, > String[] dispatcher) { > - getFilterMapper().addMapping(filterName, > - null, servlet, > - dispatcher, true); > + getFilterMapper().addMapping(filterName, > + null, servlet, > + dispatcher, true); > } > - > + > /** > * Called from TomcatLite.init(), required before start. > - * > - * Will initialize defaults and load web.xml unless webAppData is > + * > + * Will initialize defaults and load web.xml unless webAppData is > * already set and recent. No other processing is done except reading > * the config - you can add or alter it before start() is called. > - * > + * > * @throws ServletException > */ > public void init() throws ServletException { > @@ -1060,51 +1071,51 @@ > initDone = true; > // Load global init params from the facade > initEngineDefaults(); > - > + > initTempDir(); > - > > + > // Merge in web.xml - or other config source ( programmatic, etc ) > - ContextPreinitListener cfg = > - (ContextPreinitListener) getObjectManager().get( > + ContextPreinitListener cfg = > + (ContextPreinitListener) getObjectManager().get( > ContextPreinitListener.class); > if (cfg != null) { > cfg.preInit(this); > } > > processWebAppData(contextConfig); > - > + > // if not defined yet: > addDefaultServlets(); > } > - > - > + > + > protected void initTempDir() throws ServletException { > - // We need a base path - at least for temp files, req. by spec > + // We need a base path - at least for temp files, req. by spec > if (basePath == null) { > basePath = ("/".equals(contextPath)) ? > facade.getWork().getAbsolutePath() + "/ROOT" : > facade.getWork().getAbsolutePath() + contextPath; > } > - > + > File f = new File(basePath + "/WEB-INF/tmp"); > f.mkdirs(); > setAttribute("javax.servlet.context.tempdir", f); > } > - > + > /** > * Static file handler ( default ) > * *.jsp support > - * > + * > */ > protected void addDefaultServlets() throws ServletException { > if (servlets.get("default") == null) { > - ServletConfigImpl fileS = new ServletConfigImpl(this, > - "default", null); > + ServletConfigImpl fileS = new ServletConfigImpl(this, > + "default", null); > addServletConfig(fileS); > addMapping("/", fileS); > } > - > + > // *.jsp support > if (servlets.get("jspwildcard") == null) { > ServletConfigImpl fileS = new ServletConfigImpl(this, > @@ -1113,9 +1124,9 @@ > addMapping("*.jsp", fileS); > } > } > - > + > protected void initEngineDefaults() throws ServletException { > - > + > // TODO: make this customizable, avoid loading it on startup > // Set the class name as default in the addon support > for (String sname: facade.ctxDefaultInitParam.keySet()) { > @@ -1128,7 +1139,7 @@ > ServletConfigImpl fileS = new ServletConfigImpl(this, sname, > sclass); > addServletConfig(fileS); > } > - > + > for (String sname: facade.preloadMappings.keySet()) { > String path = facade.preloadMappings.get(sname); > ServletConfigImpl servletConfig = getServletConfig(sname); > @@ -1136,7 +1147,7 @@ > } > } > > - > + > public ArrayList getClasspath(File directory, File classesDir) { > ArrayList res = new ArrayList(); > if (classesDir.isDirectory() && classesDir.exists() && > @@ -1151,13 +1162,13 @@ > || !directory.canRead()) { > return res; > } > - > + > File[] jars = directory.listFiles(new FilenameFilter() { > public boolean accept(File dir, String name) { > return name.endsWith(".jar"); > } > }); > - > + > for (int j = 0; j < jars.length; j++) { > try { > URL url = jars[j].toURL(); > @@ -1174,13 +1185,13 @@ > return; > } > String base = getBasePath(); > - > + > ArrayList urls = getClasspath(new File(base + "/WEB-INF/lib"), > new File(base + "/WEB-INF/classes")); > URL[] urlsA = new URL[urls.size()]; > urls.toArray(urlsA); > > - URLClassLoader parentLoader = > + URLClassLoader parentLoader = > getEngine().getContextParentLoader(); > > // create a class loader. > @@ -1192,14 +1203,14 @@ > ctxRepo.addURL(urlsA); > repository = ctxRepo; > */ > - > + > classLoader = new URLClassLoader(urlsA, parentLoader); > - > + > // JMX should know about us ( TODO: is it too early ? ) > facade.notifyAdd(this); > > initListeners(); > - > + > List listeners = this.getListeners(); > ServletContextEvent event = null; > for (int i = 0; i < listeners.size(); i++) { > @@ -1218,10 +1229,10 @@ > } > } > > - > + > initFilters(); > initServlets(); > - > + > startDone = true; > } > > @@ -1238,13 +1249,13 @@ > } > > > - // TODO: configurable ? init-params > + // TODO: configurable ? init-params > public String getSessionCookieName() { > return "JSESSIONID"; > } > - > > - > + > + > public void destroy() throws ServletException { > // destroy filters > Iterator fI = filters.values().iterator(); > @@ -1271,7 +1282,7 @@ > public TomcatLite getEngine() { > return facade; > } > - > + > public String findStatusPage(int status) { > if (contextConfig.errorPageCode.size() == 0) { > return null; > @@ -1283,9 +1294,9 @@ > return (String) > contextConfig.errorPageCode.get(Integer.toString(status)); > } > > - public void handleStatusPage(ServletRequestImpl req, > - ServletResponseImpl res, > - int status, > + public void handleStatusPage(ServletRequestImpl req, > + ServletResponseImpl res, > + int status, > String statusPage) { > String message = RequestUtil.filter(res.getMessage()); > if (message == null) > @@ -1297,20 +1308,20 @@ > protected void setErrorAttributes(ServletRequestImpl req, > int status, > String message) { > - req.setAttribute("javax.servlet.error.status_code", > + req.setAttribute("javax.servlet.error.status_code", > new Integer(status)); > if (req.getWrapper() != null) { > - req.setAttribute("javax.servlet.error.servlet_name", > + req.setAttribute("javax.servlet.error.servlet_name", > req.getWrapper().servletName); > } > - req.setAttribute("javax.servlet.error.request_uri", > + req.setAttribute("javax.servlet.error.request_uri", > req.getRequestURI()); > - req.setAttribute("javax.servlet.error.message", > + req.setAttribute("javax.servlet.error.message", > message); > > } > - > - public void handleError(ServletRequestImpl req, > + > + public void handleError(ServletRequestImpl req, > ServletResponseImpl res, > Throwable t) { > Throwable realError = t; > @@ -1335,7 +1346,7 @@ > dispatchError(req, res, errorPage); > } else { > log("Unhandled error", t); > - if (t instanceof ServletException && > + if (t instanceof ServletException && > ((ServletException)t).getRootCause() != null) { > log("RootCause:", ((ServletException)t).getRootCause()); > } > @@ -1345,13 +1356,13 @@ > } > } > > - protected void dispatchError(ServletRequestImpl req, > - ServletResponseImpl res, > + protected void dispatchError(ServletRequestImpl req, > + ServletResponseImpl res, > String errorPage) { > RequestDispatcher rd = > getRequestDispatcher(errorPage); > try { > - // will clean up the buffer > + // will clean up the buffer > rd.forward(req, res); > return; // handled > } catch (ServletException e) { > @@ -1360,7 +1371,7 @@ > // TODO > } > } > - > + > protected String findErrorPage(Throwable exception) { > if (contextConfig.errorPageException.size() == 0) { > return null; > @@ -1382,33 +1393,33 @@ > > } > > - @Override > + > public EnumSet<SessionTrackingMode> getDefaultSessionTrackingModes() { > return null; > } > > - @Override > + > public EnumSet<SessionTrackingMode> getEffectiveSessionTrackingModes() { > return null; > } > > - @Override > + > public SessionCookieConfig getSessionCookieConfig() { > return null; > } > > - @Override > + > public void setSessionTrackingModes(EnumSet<SessionTrackingMode> > sessionTrackingModes) { > } > > - public void addFilter(String filterName, String filterClass, > + public void addFilter(String filterName, String filterClass, > Map params) { > FilterConfigImpl fc = new FilterConfigImpl(this); > fc.setData(filterName, filterClass, params); > filters.put(filterName, fc); > } > - > - @Override > + > + > public Dynamic addFilter(String filterName, String className) { > FilterConfigImpl fc = new FilterConfigImpl(this); > fc.setData(filterName, className, new HashMap()); > @@ -1416,7 +1427,7 @@ > return fc.getDynamic(); > } > > - @Override > + > public Dynamic addFilter(String filterName, Filter filter) { > FilterConfigImpl fc = new FilterConfigImpl(this); > fc.setData(filterName, null, new HashMap()); > @@ -1425,7 +1436,7 @@ > return fc.getDynamic(); > } > > - @Override > + > public Dynamic addFilter(String filterName, Class<? extends Filter> > filterClass) { > FilterConfigImpl fc = new FilterConfigImpl(this); > fc.setData(filterName, null, new HashMap()); > @@ -1434,16 +1445,16 @@ > return fc.getDynamic(); > } > > - @Override > - public javax.servlet.Registration.Dynamic addServlet(String > servletName, > + > + public javax.servlet.ServletRegistration.Dynamic addServlet(String > servletName, > String className) { > ServletConfigImpl sc = new ServletConfigImpl(this, servletName, > className); > addServletConfig(sc); > return sc.getDynamic(); > } > > - @Override > - public javax.servlet.Registration.Dynamic addServlet(String > servletName, > + > + public javax.servlet.ServletRegistration.Dynamic addServlet(String > servletName, > Class<? extends > Servlet> servletClass) { > ServletConfigImpl sc = new ServletConfigImpl(this, servletName, > servletClass.getName()); > sc.setServletClass(servletClass); > @@ -1451,11 +1462,11 @@ > return sc.getDynamic(); > } > > - // That's tricky - this filter will have no name. We need to generate > one > + // That's tricky - this filter will have no name. We need to generate > one > // because our code relies on names. > AtomicInteger autoName = new AtomicInteger(); > - > - @Override > + > + > public <T extends Filter> T createFilter(Class<T> c) throws > ServletException { > FilterConfigImpl fc = new FilterConfigImpl(this); > String filterName = "_tomcat_auto_filter_" + > autoName.incrementAndGet(); > @@ -1476,7 +1487,7 @@ > } > } > > - @Override > + > public <T extends Servlet> T createServlet(Class<T> c) throws > ServletException { > String filterName = "_tomcat_auto_servlet_" + > autoName.incrementAndGet(); > ServletConfigImpl fc = new ServletConfigImpl(this, filterName, > null); > @@ -1490,23 +1501,23 @@ > } > } > > - @Override > + > public FilterRegistration findFilterRegistration(String filterName) { > return filters.get(filterName); > } > > - @Override > + > public ServletRegistration findServletRegistration(String servletName) { > return servlets.get(servletName); > } > - > - @Override > + > + > public boolean setInitParameter(String name, String value) { > HashMap<String, String> params = contextConfig.contextParam; > return setInitParameter(this, params, name, value); > } > - > - static Set<String> setInitParameters(ServletContextImpl ctx, > + > + static Set<String> setInitParameters(ServletContextImpl ctx, > Map<String, String> params, > Map<String, String> initParameters) > throws IllegalArgumentException, IllegalStateException { > @@ -1524,14 +1535,14 @@ > } > } > return result; > - } > + } > > /** > * true if the context initialization parameter with the given name and > value was set successfully on this ServletContext, and false if it was not > set because this ServletContext already contains a context initialization > parameter with a matching name > * Throws: > * java.lang.IllegalStateException - if this ServletContext has already > been initialized > */ > - static boolean setInitParameter(ServletContextImpl ctx, Map<String, > String> params, > + static boolean setInitParameter(ServletContextImpl ctx, Map<String, > String> params, > String name, String value) { > if (name == null || value == null) { > throw new IllegalArgumentException(); > @@ -1547,5 +1558,57 @@ > return true; > } > } > + > + public JspConfigDescriptor getJspConfigDescriptor() { > + // fix me - just here to compile > + return null; > + } > + > + > + > + public void declareRoles(String... roleNames) { > + // implement me > + } > + > + public <T extends EventListener> T createListener(Class<T> c) throws > ServletException { > + // implement me > + return null; > + } > + > + public Collection<String> getMappings() { > + // implement me > + return null; > + } > + > + public Map<String, ? extends FilterRegistration> > getFilterRegistrations() { > + // implement me > + return null; > + } > + > + public FilterRegistration getFilterRegistration(String filterName) { > + // implement me > + return null; > + } > + > + public Map<String, ? extends ServletRegistration> > getServletRegistrations() { > + // implement me > + return null; > + } > + > + public ServletRegistration getServletRegistration(String servletName) > { > + // implement me > + return null; > + } > + > + public int getEffectiveMinorVersion() { > + // implement me > + return -1; > + } > + > + public int getEffectiveMajorVersion() { > + // implement me > + return -1; > + } > + > } > > Index: java/org/apache/tomcat/lite/ServletRequestImpl.java > =================================================================== > --- java/org/apache/tomcat/lite/ServletRequestImpl.java (revision 833452) > +++ java/org/apache/tomcat/lite/ServletRequestImpl.java (working copy) > @@ -1,12 +1,12 @@ > /* > * Copyright 1999,2004 The Apache Software Foundation. > - * > + * > * Licensed under the Apache License, Version 2.0 (the "License"); > * you may not use this file except in compliance with the License. > * You may obtain a copy of the License at > - * > + * > * http://www.apache.org/licenses/LICENSE-2.0 > - * > + * > * Unless required by applicable law or agreed to in writing, software > * distributed under the License is distributed on an "AS IS" BASIS, > * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. > @@ -23,6 +23,7 @@ > import java.security.Principal; > import java.text.SimpleDateFormat; > import java.util.ArrayList; > +import java.util.Collection; > import java.util.Enumeration; > import java.util.HashMap; > import java.util.Iterator; > @@ -68,7 +69,7 @@ > > > /** > - * > + * > * Wrapper object for the Coyote request. > * > * @author Remy Maucherat > @@ -95,13 +96,13 @@ > /** > * Request dispatcher state. > */ > - public static final String DISPATCHER_TYPE_ATTR = > + public static final String DISPATCHER_TYPE_ATTR = > "org.apache.catalina.core.DISPATCHER_TYPE"; > > /** > * Request dispatcher path. > */ > - public static final String DISPATCHER_REQUEST_PATH_ATTR = > + public static final String DISPATCHER_REQUEST_PATH_ATTR = > "org.apache.catalina.core.DISPATCHER_REQUEST_PATH"; > > /** > @@ -175,7 +176,7 @@ > public static final String SERVLET_NAME_ATTR = > "javax.servlet.error.servlet_name"; > > - > + > /** > * The name of the cookie used to pass the session identifier back > * and forth with the client. > @@ -204,7 +205,7 @@ > public static final String SUBJECT_ATTR = > "javax.security.auth.subject"; > > - > + > /** > * The servlet context attribute under which we store a temporary > * working directory (as an object of type File) for use by servlets > @@ -228,7 +229,7 @@ > * The match string for identifying a session ID parameter. > */ > private static final String match = ";" + SESSION_PARAMETER_NAME + "="; > - > + > /** > * The set of cookies associated with this Request. > */ > @@ -242,8 +243,8 @@ > * declare formats[] as a static variable. > */ > protected SimpleDateFormat formats[] = null; > - > > + > /** > * The attributes associated with this Request, keyed by attribute > name. > */ > @@ -295,15 +296,15 @@ > /** > * ServletInputStream. > */ > - protected ServletInputStreamImpl inputStream; > + protected ServletInputStreamImpl inputStream; > > > /** > * Reader. > */ > protected BufferedReader reader; > - > > + > /** > * Using stream flag. > */ > @@ -395,7 +396,7 @@ > * Filter chain associated with the request. > */ > protected FilterChainImpl filterChain = new FilterChainImpl(); > - > + > /** > * Mapping data. > */ > @@ -408,7 +409,7 @@ > * The response with which this request is associated. > */ > protected ServletResponseImpl response = new ServletResponseImpl(); > - > + > /** > * URI byte to char converter (not recycled). > */ > @@ -423,13 +424,13 @@ > * Post data buffer. > */ > public final static int CACHED_POST_LEN = 8192; > - > + > public byte[] postData = null; > > - > + > private HttpRequest httpRequest; > - > - /** New IO/buffer model > + > + /** New IO/buffer model > */ > //protected Http11Connection con; > > @@ -499,7 +500,7 @@ > public void setConnector(Connector c) { > connector = c; > } > - > + > public Connector getConnector() { > return connector; > } > @@ -563,7 +564,7 @@ > * > * @exception IOException if an input/output error occurs > */ > - public ServletInputStream createInputStream() > + public ServletInputStream createInputStream() > throws IOException { > return inputStream; > } > @@ -588,11 +589,11 @@ > public Object getAttribute(String name) { > > if (name.equals(ServletRequestImpl.DISPATCHER_TYPE_ATTR)) { > - return (dispatcherType == null) > + return (dispatcherType == null) > ? REQUEST_INTEGER > : dispatcherType; > } else if > (name.equals(ServletRequestImpl.DISPATCHER_REQUEST_PATH_ATTR)) { > - return (requestDispatcherPath == null) > + return (requestDispatcherPath == null) > ? getRequestPathMB().toString() > : requestDispatcherPath.toString(); > } > @@ -606,7 +607,7 @@ > // if(attr != null) > // return attr; > // if( isSSLAttribute(name) ) { > -// reqB.action(ActionCode.ACTION_REQ_SSL_ATTRIBUTE, > +// reqB.action(ActionCode.ACTION_REQ_SSL_ATTRIBUTE, > // reqB); > // attr = > reqB.getAttribute(ServletRequestImpl.CERTIFICATES_ATTR); > // if( attr != null) { > @@ -738,7 +739,7 @@ > > /** > * Get the context path. > - * > + * > * @return the context path > */ > public MessageBytes getContextPathMB() { > @@ -783,7 +784,7 @@ > formats[1].setTimeZone(GMT_ZONE); > formats[2].setTimeZone(GMT_ZONE); > } > - > + > // Attempt to convert the date header in a variety of formats > long result = FastHttpDateFormat.parseDate(value, formats); > if (result != (-1L)) { > @@ -796,7 +797,7 @@ > > /** > * Get the decoded request URI. > - * > + * > * @return the URL decoded request URI > */ > public String getDecodedRequestURI() { > @@ -806,7 +807,7 @@ > > /** > * Get the decoded request URI. > - * > + * > * @return the URL decoded request URI > */ > public MessageBytes getDecodedRequestURIMB() { > @@ -833,7 +834,7 @@ > public String getHeader(String name) { > return httpRequest.getHeader(name); > } > - > + > /** > * Return the names of all headers received with this request. > */ > @@ -897,7 +898,7 @@ > /** > * Returns the Internet Protocol (IP) address of the interface on > * which the request was received. > - */ > + */ > public String getLocalAddr(){ > return httpRequest.localAddr().toString(); > } > @@ -1062,7 +1063,7 @@ > > /** > * Get the path info. > - * > + * > * @return the path info > */ > public MessageBytes getPathInfoMB() { > @@ -1086,14 +1087,14 @@ > } > > } > - > + > /** > * Return the principal that has been authenticated for this Request. > */ > public Principal getPrincipal() { > return (userPrincipal); > } > - > + > /** > * Return the protocol and version used to make this Request. > */ > @@ -1145,7 +1146,7 @@ > /** > * Converter for the encoding associated with the request. > * If encoding is changed - a different encoder will be returned. > - * > + * > * Encoders are cached ( per request ) - at least 8K per charset > */ > public B2CConverter getB2C() throws IOException { > @@ -1153,7 +1154,7 @@ > if (enc == null) { > enc = DEFAULT_CHARACTER_ENCODING; > } > - B2CConverter conv = > + B2CConverter conv = > (B2CConverter) encoders.get(enc); > if (conv == null) { > conv = new B2CConverter(enc); > @@ -1161,7 +1162,7 @@ > } > return conv; > } > - > + > /** > * Return the real path of the specified virtual path. > * > @@ -1213,7 +1214,7 @@ > /** > * Returns the Internet Protocol (IP) source port of the client > * or last proxy that sent the request. > - */ > + */ > public int getRemotePort(){ > return httpRequest.getRemotePort(); > } > @@ -1241,11 +1242,11 @@ > public HttpServletRequest getRequest() { > return this; > } > - > + > public HttpRequest getHttpRequest() { > return httpRequest; > } > - > + > public void setHttpRequest(HttpRequest req, BodyReader in) { > this.httpRequest = req; > inputBuffer = in; > @@ -1316,7 +1317,7 @@ > > /** > * Get the request path. > - * > + * > * @return the request path > */ > public MessageBytes getRequestPathMB() { > @@ -1330,13 +1331,13 @@ > public String getRequestURI() { > return httpRequest.requestURI().toString(); > } > - > + > /** > */ > public void setRequestURI(String uri) { > httpRequest.decodedURI().setString(uri); > try { > - UriNormalizer.decodeRequest(httpRequest.decodedURI(), > + UriNormalizer.decodeRequest(httpRequest.decodedURI(), > httpRequest.requestURI(), httpRequest.getURLDecoder()); > } catch(IOException ioe) { > ioe.printStackTrace(); > @@ -1432,7 +1433,7 @@ > > /** > * Get the servlet path. > - * > + * > * @return the servlet path > */ > public MessageBytes getServletPathMB() { > @@ -1537,8 +1538,8 @@ > public boolean isSecure() { > return (secure); > } > - > - > + > + > /** > * Return <code>true</code> if the authenticated user principal > * possesses the specified role name. > @@ -1566,7 +1567,7 @@ > if (role.equals(userPrincipal.getName())) { > return true; > } > - > + > // TODO: check !!!! > // Check for a role defined directly as a <security-role> > return false; > @@ -1652,7 +1653,7 @@ > (ServletRequestAttributeListener) listeners.get(i); > try { > if (event == null) { > - event = > + event = > new > ServletRequestAttributeEvent(context.getServletContext(), > getRequest(), name, value); > } > @@ -1673,7 +1674,7 @@ > * @param value The associated value > */ > public void setAttribute(String name, Object value) { > - > + > // Name cannot be null > if (name == null) > throw new IllegalArgumentException > @@ -1712,7 +1713,7 @@ > // if (name.startsWith("org.apache.tomcat.")) { > // reqB.setAttribute(name, value); > // } > -// > +// > // Notify interested application event listeners > List listeners = context.getListeners(); > if (listeners.size() == 0) > @@ -1862,7 +1863,7 @@ > > /** > * Set the decoded request URI. > - * > + * > * @param uri The decoded request URI > */ > public void setDecodedRequestURI(String uri) { > @@ -2051,18 +2052,18 @@ > > if (System.getSecurityManager() != null){ > HttpSession session = getSession(false); > - if ( (subject != null) && > + if ( (subject != null) && > (!subject.getPrincipals().contains(principal)) ){ > - subject.getPrincipals().add(principal); > + subject.getPrincipals().add(principal); > } else if (session != null && > > session.getAttribute(ServletRequestImpl.SUBJECT_ATTR) == null) { > subject = new Subject(); > - subject.getPrincipals().add(principal); > + subject.getPrincipals().add(principal); > } > if (session != null){ > session.setAttribute(ServletRequestImpl.SUBJECT_ATTR, > subject); > } > - } > + } > > this.userPrincipal = principal; > } > @@ -2092,7 +2093,7 @@ > protected void configureSessionCookie(Cookie cookie) { > cookie.setMaxAge(-1); > String contextPath = null; > - if (//!connector.getEmptySessionPath() && > + if (//!connector.getEmptySessionPath() && > (getContext() != null)) { > contextPath = getContext().getEncodedPath(); > } > @@ -2129,14 +2130,14 @@ > manager = context.getManager(); > if (manager == null) > return (null); // Sessions are not supported > - > + > // Return the current session if it exists and is valid > if ((session != null) && !manager.isValid(session)) > session = null; > if (session != null) > return (session); > - > - > + > + > if (requestedSessionId != null) { > try { > session = manager.findSession(requestedSessionId); > @@ -2360,7 +2361,7 @@ > */ > protected void parseSessionCookiesId() { > String sessionCookieName = context.getSessionCookieName(); > - > + > // Parse session id from cookies > Cookies serverCookies = httpRequest.getCookies(); > int count = serverCookies.getCookieCount(); > @@ -2374,7 +2375,7 @@ > if (!isRequestedSessionIdFromCookie()) { > // Accept only the first session id cookie > //scookie.getValue().convertToAscii(); > - > + > setRequestedSessionId > (scookie.getValue().toString()); > setRequestedSessionCookie(true); > @@ -2409,18 +2410,18 @@ > int semicolon2 = uriBC.indexOf(';', sessionIdStart); > if (semicolon2 >= 0) { > request.setRequestedSessionId > - (new String(uriBC.getBuffer(), start + sessionIdStart, > + (new String(uriBC.getBuffer(), start + sessionIdStart, > semicolon2 - sessionIdStart)); > // Extract session ID from request URI > byte[] buf = uriBC.getBuffer(); > for (int i = 0; i < end - start - semicolon2; i++) { > - buf[start + semicolon + i] > + buf[start + semicolon + i] > = buf[start + i + semicolon2]; > } > uriBC.setBytes(buf, start, end - start - semicolon2 + > semicolon); > } else { > request.setRequestedSessionId > - (new String(uriBC.getBuffer(), start + sessionIdStart, > + (new String(uriBC.getBuffer(), start + sessionIdStart, > (end - start) - sessionIdStart)); > uriBC.setEnd(start + semicolon); > } > @@ -2464,54 +2465,54 @@ > } > > > - @Override > + > public void addAsyncListener(AsyncListener listener) { > } > > > - @Override > + > public void addAsyncListener(AsyncListener listener, > ServletRequest servletRequest, > ServletResponse servletResponse) { > } > > > - @Override > + > public AsyncContext getAsyncContext() { > return null; > } > > > - @Override > + > public ServletContext getServletContext() { > return null; > } > > > - @Override > + > public boolean isAsyncStarted() { > return false; > } > > > - @Override > + > public boolean isAsyncSupported() { > return false; > } > > > - @Override > + > public void setAsyncTimeout(long timeout) { > } > > > - @Override > + > public AsyncContext startAsync() throws IllegalStateException { > return null; > } > > > - @Override > + > public AsyncContext startAsync(ServletRequest servletRequest, > ServletResponse servletResponse) > throws IllegalStateException { > @@ -2519,45 +2520,46 @@ > } > > > - @Override > + > public boolean authenticate(HttpServletResponse response) > throws IOException, ServletException { > return false; > } > > > - @Override > + > public Part getPart(String name) { > return null; > } > > > - @Override > - public Iterable<Part> getParts() { > - return null; > - } > > > - @Override > + > public void login(String username, String password) throws > ServletException { > } > > > - @Override > + > public void logout() throws ServletException { > } > > > - @Override > + > public long getAsyncTimeout() { > return 0; > } > > > - @Override > + > public DispatcherType getDispatcherType() { > return null; > } > > > + public Collection<Part> getParts() throws IOException, > ServletException { > + return null; > + } > + > + > } > Index: java/org/apache/tomcat/lite/coyote/CoyoteConnector.java > =================================================================== > --- java/org/apache/tomcat/lite/coyote/CoyoteConnector.java (revision > 833452) > +++ java/org/apache/tomcat/lite/coyote/CoyoteConnector.java (working > copy) > @@ -39,18 +39,18 @@ > > public void acknowledge(HttpServletResponse res) throws IOException { > Response cres = (Response) ((ServletResponseImpl) > res).getHttpResponse().nativeResponse; > - cres.acknowledge(); > + cres.acknowledge(); > } > > public void reset(HttpServletResponse res) { > Response cres = (Response) ((ServletResponseImpl) > res).getHttpResponse().nativeResponse; > - cres.reset(); > + cres.reset(); > } > - > + > public void recycle(HttpServletRequest req, HttpServletResponse res) { > - > + > } > - > + > public static HttpResponse getResponse(final Response cres) { > HttpResponse hres = new HttpResponse() { > public int getStatus() { > @@ -75,101 +75,101 @@ > cres.setCommitted(b); > } > }; > - > + > hres.setMimeHeaders(cres.getMimeHeaders()); > hres.nativeResponse = cres; > - > + > return hres; > } > - > + > public static HttpRequest getRequest(Request req) { > - > + > HttpRequest httpReq = new HttpRequest(req.scheme(), > - req.method(), > + req.method(), > req.unparsedURI(), > req.protocol(), > req.getMimeHeaders(), > req.requestURI(), > req.decodedURI(), > req.query(), req.getParameters(), > - req.serverName(), > + req.serverName(), > req.getCookies()) { > - > + > }; > httpReq.nativeRequest = req; > - > + > // TODO: anything else computed in coyote ? > - > + > return httpReq; > } > > @Override > public void initRequest(HttpServletRequest hreq, HttpServletResponse > hres) { > ServletRequestImpl req = (ServletRequestImpl) hreq; > - ServletResponseImpl res = (ServletResponseImpl) hres; > + ServletResponseImpl res = (ServletResponseImpl) hres; > req.setConnector(this); > - > + > Request creq = new Request(); > Response cres = new Response(); > HttpResponse nRes = getResponse(cres); > > BodyWriter out = new BodyWriter(4096); > out.setConnector(this, res); > - > + > res.setHttpResponse(nRes, out); > - > + > cres.setRequest(creq); > cres.setHook(new ActionHook() { > - public void action(ActionCode actionCode, > + public void action(ActionCode actionCode, > Object param) { > } > }); > - > + > BodyReader in = new BodyReader(); > in.setConnector(this, req); > HttpRequest nReq = getRequest(creq); > req.setHttpRequest(nReq, in); > - > + > } > - > > + > // ---- Coyote Adapter interface --- > - > + > @Override > public void service(Request creq, Response cres) throws Exception { > long t0 = System.currentTimeMillis(); > > // compute decodedURI - not done by connector > UriNormalizer.decodeRequest(creq.decodedURI(), creq.requestURI(), > creq.getURLDecoder()); > - > + > // find the facades > ServletRequestImpl req = (ServletRequestImpl) > creq.getNote(ADAPTER_REQ_NOTE); > ServletResponseImpl res = (ServletResponseImpl) > cres.getNote(ADAPTER_RES_NOTE); > > - > + > if (req == null) { > req = new ServletRequestImpl(); > res = req.getResponse(); > - > + > BodyReader in = new BodyReader(); > in.setConnector(this, req); > > HttpRequest nReq = getRequest(creq); > nReq.setServerPort(creq.getServerPort()); > HttpResponse nRes = getResponse(cres); > - > + > req.setHttpRequest(nReq, in); > BodyWriter out = new BodyWriter(4096); > out.setConnector(this, res); > - > + > res.setHttpResponse(nRes, out); > - > + > creq.setNote(ADAPTER_REQ_NOTE, req); > cres.setNote(ADAPTER_RES_NOTE, res); > - > + > } > req.setConnector(this); > - > + > try { > lite.service(req, res); > } catch(IOException ex) { > @@ -178,14 +178,14 @@ > t.printStackTrace(); > } finally { > long t1 = System.currentTimeMillis(); > - > -// log.info("<<<<<<<< DONE: " + creq.method() + " " + > -// creq.decodedURI() + " " + > -// res.getStatus() + " " + > + > +// log.info("<<<<<<<< DONE: " + creq.method() + " " + > +// creq.decodedURI() + " " + > +// res.getStatus() + " " + > // (t1 - t0)); > - > + > // Final processing > - // TODO: only if not commet, this doesn't work with the > + // TODO: only if not commet, this doesn't work with the > // other connectors since we don't have the info > // TODO: add this note in the nio/apr connectors > // TODO: play nice with TomcatLite, other adapters that > flush/close > @@ -195,7 +195,7 @@ > cres.sendHeaders(); > } > res.getOutputBuffer().flush(); > - > + > BodyWriter mw = res.getBodyWriter(); > //MessageWriter.getWriter(creq, cres, 0); > mw.flush(); > @@ -204,7 +204,7 @@ > BodyReader reader = req.getBodyReader(); > //getReader(creq); > reader.recycle(); > - > + > cres.finish(); > > creq.recycle(); > @@ -215,7 +215,7 @@ > } > } > } > - > + > @Override > public boolean event(Request req, Response res, SocketStatus status) > throws Exception { > @@ -230,7 +230,7 @@ > > public String getRemoteHost(HttpServletRequest hreq) { > ServletRequestImpl req = (ServletRequestImpl) hreq; > - > + > Request creq = (Request) req.getHttpRequest().nativeRequest; > creq.action(ActionCode.ACTION_REQ_HOST_ATTRIBUTE, creq); > return creq.remoteHost().toString(); > @@ -238,7 +238,7 @@ > > public String getRemoteAddr(HttpServletRequest hreq) { > ServletRequestImpl req = (ServletRequestImpl) hreq; > - > + > Request creq = (Request) req.getHttpRequest().nativeRequest; > creq.action(ActionCode.ACTION_REQ_HOST_ADDR_ATTRIBUTE, creq); > return creq.remoteAddr().toString(); > @@ -248,8 +248,8 @@ > @Override > public void beforeClose(HttpServletResponse res, int len) throws > IOException { > Response cres = (Response) ((ServletResponseImpl) > res).getHttpResponse().nativeResponse; > - > - if ((!cres.isCommitted()) > + > + if ((!cres.isCommitted()) > && (cres.getContentLengthLong() == -1)) { > // Flushing the char buffer > // If this didn't cause a commit of the response, the final > content > @@ -262,7 +262,7 @@ > > public int doRead(ServletRequestImpl hreq, ByteChunk bb) throws > IOException { > ServletRequestImpl req = (ServletRequestImpl) hreq; > - > + > Request creq = (Request) req.getHttpRequest().nativeRequest; > return creq.doRead(bb); > } > @@ -279,7 +279,7 @@ > @Override > public void realFlush(HttpServletResponse res) throws IOException { > Response cres = (Response) ((ServletResponseImpl) > res).getHttpResponse().nativeResponse; > - cres.action(ActionCode.ACTION_CLIENT_FLUSH, > + cres.action(ActionCode.ACTION_CLIENT_FLUSH, > cres); > // If some exception occurred earlier, or if some IOE occurred > // here, notify the servlet with an IOE > @@ -294,7 +294,7 @@ > @Override > public void sendHeaders(HttpServletResponse res) throws IOException { > Response cres = (Response) ((ServletResponseImpl) > res).getHttpResponse().nativeResponse; > - > + > // This should happen before 'prepareResponse' is called !! > // Now update coyote response based on response > // don't set charset/locale - they're computed in lite > @@ -312,43 +312,43 @@ > protected boolean daemon = false; > > /** > - * Note indicating the response is COMET. > + * Note indicating the response is COMET. > */ > public static final int COMET_RES_NOTE = 2; > public static final int COMET_REQ_NOTE = 2; > - > - public static final int ADAPTER_RES_NOTE = 1; > - public static final int ADAPTER_REQ_NOTE = 1; > - > + > + public static final int ADAPTER_RES_NOTE = 1; > + public static final int ADAPTER_REQ_NOTE = 1; > + > protected ProtocolHandler proto; > > //protected Adapter adapter = new MapperAdapter(); > protected int maxThreads = 20; > boolean started = false; > boolean async = false; // use old nio connector > - > + > protected ObjectManager om; > - > - > + > + > public void setObjectManager(ObjectManager om) { > this.om = om; > } > - > - /** > + > + /** > * Add an adapter. If more than the 'default' adapter is > * added, a MapperAdapter will be inserted. > - * > + * > * @param path Use "/" for the default. > * @param adapter > */ > // public void addAdapter(String path, Adapter added) { > // if ("/".equals(path)) { > -// ((MapperAdapter) adapter).setDefaultAdapter(added); > +// ((MapperAdapter) adapter).setDefaultAdapter(added); > // } else { > // ((MapperAdapter) adapter).getMapper().addWrapper(path, > added); > // } > // } > - > + > /** > */ > public void run() { > @@ -363,7 +363,7 @@ > public void setDaemon(boolean b) { > daemon = b; > } > - > + > protected void initAdapters() { > if (proto == null) { > addProtocolHandler(port, daemon); > @@ -380,7 +380,7 @@ > proto.destroy(); > started = false; > } > - > + > // /** > // * Simple CLI support - arg is a path:className pair. > // */ > @@ -394,14 +394,14 @@ > // e.printStackTrace(); > // } > // } > - > + > public void setConnector(ProtocolHandler h) { > this.proto = h; > h.setAttribute("port", Integer.toString(port)); > > om.bind("ProtocolHandler:" + "ep-" + port, proto); > } > - > + > public void addProtocolHandler(int port, boolean daemon) { > Http11NioProtocol proto = new Http11NioProtocol(); > proto.setCompression("on"); > @@ -412,29 +412,29 @@ > setPort(port); > setDaemon(daemon); > } > - > - public void addProtocolHandler(ProtocolHandler proto, > + > + public void addProtocolHandler(ProtocolHandler proto, > int port, boolean daemon) { > setConnector(proto); > setPort(port); > setDaemon(daemon); > } > - > + > public void setPort(int port) { > if (proto != null) { > proto.setAttribute("port", Integer.toString(port)); > } > this.port = port; > } > - > - > + > + > public void init() { > //JdkLoggerConfig.loadCustom(); > - om.bind("CoyoteConnector:" + "CoyoteConnector-" + port, > + om.bind("CoyoteConnector:" + "CoyoteConnector-" + port, > this); > } > > - > + > public void start() throws IOException { > try { > if (started) { > @@ -446,20 +446,25 @@ > // not required - should run fine without a connector. > if (proto != null) { > proto.setAdapter(this); > - > + > proto.init(); > proto.start(); > } > - > + > started = true; > } catch (Throwable e) { > e.printStackTrace(); > throw new RuntimeException(e); > } > } > - > + > public boolean getStarted() { > return started; > - } > - > + } > + > + public boolean asyncDispatch(Request req,Response res, SocketStatus > status) throws Exception { > + // implement me > + return false; > + } > + > } > Index: java/org/apache/tomcat/lite/ServletResponseImpl.java > =================================================================== > --- java/org/apache/tomcat/lite/ServletResponseImpl.java (revision > 833452) > +++ java/org/apache/tomcat/lite/ServletResponseImpl.java (working > copy) > @@ -5,9 +5,9 @@ > * The ASF licenses this file to You under the Apache License, Version 2.0 > * (the "License"); you may not use this file except in compliance with > * the License. You may obtain a copy of the License at > - * > + * > * http://www.apache.org/licenses/LICENSE-2.0 > - * > + * > * Unless required by applicable law or agreed to in writing, software > * distributed under the License is distributed on an "AS IS" BASIS, > * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. > @@ -24,6 +24,7 @@ > import java.net.URL; > import java.text.SimpleDateFormat; > import java.util.ArrayList; > +import java.util.Collection; > import java.util.Enumeration; > import java.util.Locale; > import java.util.TimeZone; > @@ -53,7 +54,7 @@ > public class ServletResponseImpl > implements HttpServletResponse { > > - /** > + /** > * Format for http response header date field > * From DateTool > */ > @@ -61,8 +62,8 @@ > "EEE, dd MMM yyyy HH:mm:ss zzz"; > > // ----------------------------------------------------------- > Constructors > - > - > + > + > ServletResponseImpl() { > urlEncoder.addSafeCharacter('/'); > } > @@ -103,12 +104,12 @@ > */ > protected boolean included = false; > > - > + > /** > * The characterEncoding flag > */ > private boolean isCharacterEncodingSet = false; > - > + > /** > * The error flag. > */ > @@ -151,19 +152,19 @@ > > > private HttpResponse resB; > - > - > + > + > // Cached/derived information - reflected in headers > protected static Locale DEFAULT_LOCALE = Locale.getDefault(); > - > + > public static final String DEFAULT_CHARACTER_ENCODING="ISO-8859-1"; > > protected Locale locale = DEFAULT_LOCALE; > > - // XXX > + // XXX > protected boolean commited = false; > protected String contentType = null; > - > + > /** > * Has the charset been explicitly set. > */ > @@ -187,11 +188,11 @@ > included = false; > error = false; > isCharacterEncodingSet = false; > - > + > cookies.clear(); > > outputBuffer.recycle(); > - > + > resB.recycle(); > } > > @@ -209,7 +210,7 @@ > > /** > * Set the application commit flag. > - * > + * > * @param appCommitted The new application committed flag value > */ > public void setAppCommitted(boolean appCommitted) { > @@ -222,7 +223,7 @@ > */ > public boolean isAppCommitted() { > return (this.appCommitted || isCommitted() || isSuspended() > - || ((getHttpResponse().getContentLength() > 0) > + || ((getHttpResponse().getContentLength() > 0) > && (getContentCount() >= > getHttpResponse().getContentLength()))); > } > > @@ -283,7 +284,7 @@ > > /** > * Set the suspended flag. > - * > + * > * @param suspended The new suspended flag value > */ > public void setSuspended(boolean suspended) throws IOException { > @@ -323,7 +324,7 @@ > * > * @exception IOException if an input/output error occurs > */ > - public ServletOutputStream createOutputStream() > + public ServletOutputStream createOutputStream() > throws IOException { > // Probably useless > return outputStream; > @@ -336,7 +337,7 @@ > public String getContentType() { > String ret = contentType; > > - if (ret != null > + if (ret != null > && characterEncoding != null > && charsetSet) { > ret = ret + ";charset=" + characterEncoding; > @@ -379,7 +380,7 @@ > * > * @exception IOException if an input/output error occurs > */ > - public void flushBuffer() > + public void flushBuffer() > throws IOException { > outputBuffer.flush(); > } > @@ -408,7 +409,7 @@ > * already been called for this response > * @exception IOException if an input/output error occurs > */ > - public ServletOutputStream getOutputStream() > + public ServletOutputStream getOutputStream() > throws IOException { > > if (usingWriter) > @@ -439,7 +440,7 @@ > * already been called for this response > * @exception IOException if an input/output error occurs > */ > - public PrintWriter getWriter() > + public PrintWriter getWriter() > throws IOException { > > if (usingOutputStream) > @@ -490,14 +491,14 @@ > > if (isCommitted()) > throw new IllegalStateException("isCommitted"); > - > + > resB.recycle(); // reset headers, status code, message > req.getConnector().reset(this); > contentType = null; > locale = DEFAULT_LOCALE; > characterEncoding = DEFAULT_CHARACTER_ENCODING; > charsetSet = false; > - > + > outputBuffer.reset(); > } > > @@ -539,7 +540,7 @@ > > /** > * Set the content length (in bytes) for this Response. > - * Ignored for writers if non-ISO-8859-1 encoding ( we could add more > + * Ignored for writers if non-ISO-8859-1 encoding ( we could add more > * encodings that are constant. > */ > public void setContentLength(int length) { > @@ -550,8 +551,8 @@ > // Ignore any call from an included servlet > if (included) > return; > - > - // writers can use variable-length encoding. > + > + // writers can use variable-length encoding. > if (usingWriter && !"ISO-8859-1".equals(getCharacterEncoding())) { > return; > } > @@ -622,11 +623,11 @@ > > if (isCommitted()) > return; > - > + > // Ignore any call from an included servlet > if (included) > - return; > - > + return; > + > // Ignore any call made after the getWriter has been invoked > // The default should be used > if (usingWriter) > @@ -642,8 +643,8 @@ > isCharacterEncodingSet = true; > } > > - > - > + > + > /** > * Set the Locale that is appropriate for this response, including > * setting the appropriate character encoding. > @@ -670,7 +671,7 @@ > String contentLanguage = locale.getLanguage(); > if ((contentLanguage != null) && (contentLanguage.length() > 0)) { > String country = locale.getCountry(); > - StringBuilder value = new StringBuilder(contentLanguage); > + StringBuffer value = new StringBuffer(contentLanguage); > if ((country != null) && (country.length() > 0)) { > value.append('-'); > value.append(country); > @@ -726,7 +727,7 @@ > * Return an array of all the header names set for this response, or > * a zero-length array if no headers have been set. > */ > - public Iterable<String> getHeaderNames() { > + public Collection<String> getHeaderNames() { > > MimeHeaders headers = getHttpResponse().getMimeHeaders(); > int n = headers.size(); > @@ -809,10 +810,10 @@ > > cookies.add(cookie); > > - final StringBuilder sb = new StringBuilder(); > + final StringBuffer sb = new StringBuffer(); > ServerCookie.appendCookieValue > (sb, cookie.getVersion(), cookie.getName(), cookie.getValue(), > - cookie.getPath(), cookie.getDomain(), cookie.getComment(), > + cookie.getPath(), cookie.getDomain(), cookie.getComment(), > cookie.getMaxAge(), cookie.getSecure(), false); > > // the header name is Set-Cookie for both "old" and v.1 ( RFC2109 ) > @@ -952,10 +953,10 @@ > * @param url URL to be encoded > */ > public String encodeURL(String url) { > - > + > String absolute = toAbsolute(url); > if (isEncodeable(absolute)) { > - // W3c spec clearly said > + // W3c spec clearly said > if (url.equalsIgnoreCase("")){ > url = absolute; > } > @@ -983,7 +984,7 @@ > > /** > * Send an acknowledgment of a request. > - * > + * > * @exception IOException if an input/output error occurs > */ > public void sendAcknowledgement() > @@ -994,7 +995,7 @@ > > // Ignore any call from an included servlet > if (included) > - return; > + return; > > req.getConnector().acknowledge(this); > } > @@ -1010,7 +1011,7 @@ > * already been committed > * @exception IOException if an input/output error occurs > */ > - public void sendError(int status) > + public void sendError(int status) > throws IOException { > sendError(status, null); > } > @@ -1026,7 +1027,7 @@ > * already been committed > * @exception IOException if an input/output error occurs > */ > - public void sendError(int status, String message) > + public void sendError(int status, String message) > throws IOException { > > if (isCommitted()) > @@ -1035,7 +1036,7 @@ > > // Ignore any call from an included servlet > if (included) > - return; > + return; > > setError(); > > @@ -1055,10 +1056,10 @@ > // TODO: maybe other mechanism to customize default. > defaultStatusPage(status, message); > } > - setSuspended(true); > + setSuspended(true); > } > > - /** > + /** > * Default handler for status code != 200 > */ > void defaultStatusPage(int status, String message) > @@ -1066,16 +1067,16 @@ > setContentType("text/html"); > if (status > 400 && status < 600) { > if (getOutputBuffer().getBytesWritten() == 0) { > - getOutputBuffer().write("<html><body><h1>Status: " + > - status + "</h1><h1>Message: " + message + > + getOutputBuffer().write("<html><body><h1>Status: " + > + status + "</h1><h1>Message: " + message + > "</h1></body></html>"); > getOutputBuffer().flush(); > } > } > } > > - > > + > /** > * Send a temporary redirect to the specified redirect location URL. > * > @@ -1085,7 +1086,7 @@ > * already been committed > * @exception IOException if an input/output error occurs > */ > - public void sendRedirect(String location) > + public void sendRedirect(String location) > throws IOException { > > if (isCommitted()) > @@ -1094,7 +1095,7 @@ > > // Ignore any call from an included servlet > if (included) > - return; > + return; > > // Clear any data content that has been buffered > resetBuffer(); > @@ -1248,7 +1249,7 @@ > return (false); > if (hreq.isRequestedSessionIdFromCookie()) > return (false); > - > + > // Is this a valid absolute URL? > URL url = null; > try { > @@ -1333,7 +1334,7 @@ > String relativePath = req.getDecodedRequestURI(); > int pos = relativePath.lastIndexOf('/'); > relativePath = relativePath.substring(0, pos); > - > + > String encodedURI = null; > encodedURI = urlEncoder.encodeURL(relativePath); > redirectURLCC.append(encodedURI, 0, > encodedURI.length()); > @@ -1383,7 +1384,7 @@ > c == '+' || c == '-' || c == '.'; > } > > - > + > /** > * Return the specified URL with the specified session identifier > * suitably encoded. > @@ -1409,7 +1410,7 @@ > anchor = path.substring(pound); > path = path.substring(0, pound); > } > - StringBuilder sb = new StringBuilder(path); > + StringBuffer sb = new StringBuffer(path); > if( sb.length() > 0 ) { // jsessionid can't be first. > sb.append(";jsessionid="); > sb.append(sessionId); > @@ -1428,7 +1429,7 @@ > public BodyWriter getOutputBuffer() { > return outputBuffer; > } > - > + > public void setWriter(BodyWriter ob) { > outputBuffer = ob; > outputStream = new ServletOutputStreamImpl(outputBuffer); > @@ -1451,8 +1452,8 @@ > } > > > - @Override > - public Iterable<String> getHeaders(String name) { > + > + public Collection<String> getHeaders(String name) { > return null; > } > > Index: java/org/apache/tomcat/lite/BodyWriter.java > =================================================================== > --- java/org/apache/tomcat/lite/BodyWriter.java (revision 833452) > +++ java/org/apache/tomcat/lite/BodyWriter.java (working copy) > @@ -14,18 +14,18 @@ > import org.apache.tomcat.util.buf.CharChunk; > > /** > - * Implement buffering and character translation acording to the > - * servlet spec. > - * > + * Implement buffering and character translation acording to the > + * servlet spec. > + * > * This class handles both chars and bytes. > - * > + * > * It is tightly integrated with servlet response, sending headers > * and updating the commit state. > - * > - * TODO: add 'extension' interface that allows direct access to > - * the async connector non-copy non-blocking queue. Same for the > - * OutputStream. Maybe switch the buffer to the brigade. > - * > + * > + * TODO: add 'extension' interface that allows direct access to > + * the async connector non-copy non-blocking queue. Same for the > + * OutputStream. Maybe switch the buffer to the brigade. > + * > * @author Costin Manolache > */ > public class BodyWriter extends Writer { > @@ -34,7 +34,7 @@ > protected static final int WRITER_NOTE = 3; > > > - private ByteChunk.ByteOutputChannel byteFlusher = > + private ByteChunk.ByteOutputChannel byteFlusher = > new ByteChunk.ByteOutputChannel() { > > @Override > @@ -44,7 +44,7 @@ > } > }; > > - private CharChunk.CharOutputChannel charFlusher = > + private CharChunk.CharOutputChannel charFlusher = > new CharChunk.CharOutputChannel() { > @Override > public void realWriteChars(char[] cbuf, int off, int len) > @@ -52,9 +52,9 @@ > BodyWriter.this.realWriteChars(cbuf, off, len); > } > }; > - > > - public static final String DEFAULT_ENCODING = > + > + public static final String DEFAULT_ENCODING = > org.apache.coyote.Constants.DEFAULT_CHARACTER_ENCODING; > public static final int DEFAULT_BUFFER_SIZE = 8*1024; > > @@ -119,7 +119,7 @@ > > > /** > - * Encoding to use. > + * Encoding to use. > * TODO: isn't it redundant ? enc, gotEnc, conv plus the enc in the bb > */ > protected String enc; > @@ -132,7 +132,7 @@ > > > /** > - * List of encoders. The writer is reused - the encoder mapping > + * List of encoders. The writer is reused - the encoder mapping > * avoids creating expensive objects. In future it'll contain > nio.Charsets > */ > protected HashMap encoders = new HashMap(); > @@ -166,7 +166,7 @@ > > /** > * Alternate constructor which allows specifying the initial buffer > size. > - * > + * > * @param size Buffer size to use > */ > public BodyWriter(int size) { > @@ -179,7 +179,7 @@ > cb.setLimit(size); > > } > - > + > public void setConnector(Connector c, ServletResponseImpl res) { > this.res = res; > this.connector = c; > @@ -191,7 +191,7 @@ > > /** > * Is the response output suspended ? > - * > + * > * @return suspended flag value > */ > public boolean isSuspended() { > @@ -201,7 +201,7 @@ > > /** > * Set the suspended flag. > - * > + * > * @param suspended New suspended flag value > */ > public void setSuspended(boolean suspended) { > @@ -216,31 +216,31 @@ > * Recycle the output buffer. > */ > public void recycle() { > - > + > state = BYTE_STATE; > headersSent = false; > bytesWritten = 0; > charsWritten = 0; > - > + > cb.recycle(); > - bb.recycle(); > + bb.recycle(); > closed = false; > suspended = false; > - > + > if (conv!= null) { > conv.recycle(); > } > - > + > gotEnc = false; > enc = null; > - > + > } > > > /** > - * Close the output buffer. This tries to calculate the response size > if > + * Close the output buffer. This tries to calculate the response size > if > * the response has not been committed yet. > - * > + * > * @throws IOException An underlying IOException occurred > */ > public void close() > @@ -266,7 +266,7 @@ > > /** > * Flush bytes or chars contained in the buffer. > - * > + * > * @throws IOException An underlying IOException occurred > */ > public void flush() > @@ -276,7 +276,7 @@ > > /** > * Flush bytes or chars contained in the buffer. > - * > + * > * @throws IOException An underlying IOException occurred > */ > protected void doFlush(boolean realFlush) > @@ -294,10 +294,10 @@ > if (state == CHAR_STATE) { > cb.flushBuffer(); > state = BYTE_STATE; > - } > + } > if (state == BYTE_STATE) { > bb.flushBuffer(); > - } > + } > doFlush = false; > > if (realFlush) { > @@ -310,14 +310,14 @@ > // ------------------------------------------------- Bytes Handling > Methods > > > - /** > + /** > * Sends the buffer data to the client output, checking the > * state of Response and calling the right interceptors. > - * > + * > * @param buf Byte buffer to be written to the response > * @param off Offset > * @param cnt Length > - * > + * > * @throws IOException An underlying IOException occurred > */ > private void realWriteBytes(byte buf[], int off, int cnt) > @@ -356,7 +356,7 @@ > } > > > - private void writeBytes(byte b[], int off, int len) > + private void writeBytes(byte b[], int off, int len) > throws IOException { > > if (closed) > @@ -432,7 +432,7 @@ > } > > > - public void write(StringBuffer sb) > + public void write(StringBuilder sb) > throws IOException { > > if (suspended) > @@ -477,7 +477,7 @@ > s="null"; > write(s, 0, s.length()); > > - } > + } > > public void println() throws IOException { > write("\n"); > @@ -511,7 +511,7 @@ > } > > > - private void realWriteChars(char c[], int off, int len) > + private void realWriteChars(char c[], int off, int len) > throws IOException { > > if (!gotEnc) > @@ -523,7 +523,7 @@ > } > > > - public void checkConverter() > + public void checkConverter() > throws IOException { > > if (!gotEnc) > @@ -532,7 +532,7 @@ > } > > > - protected void setConverter() > + protected void setConverter() > throws IOException { > > enc = res.getCharacterEncoding(); > @@ -542,7 +542,7 @@ > enc = DEFAULT_ENCODING; > conv = (C2BConverter) encoders.get(enc); > if (conv == null) { > - > + > if (System.getSecurityManager() != null){ > try{ > conv = (C2BConverter)AccessController.doPrivileged( > @@ -553,22 +553,22 @@ > } > > } > - ); > + ); > }catch(PrivilegedActionException ex){ > Exception e = ex.getException(); > if (e instanceof IOException) > - throw (IOException)e; > + throw (IOException)e; > } > } else { > conv = new C2BConverter(bb, enc); > } > - > + > encoders.put(enc, conv); > > } > } > > - > + > // -------------------- BufferedOutputStream compatibility > > > @@ -598,9 +598,9 @@ > } > > > - /** > + /** > * True if this buffer hasn't been used ( since recycle() ) - > - * i.e. no chars or bytes have been added to the buffer. > + * i.e. no chars or bytes have been added to the buffer. > */ > public boolean isNew() { > return (bytesWritten == 0) && (charsWritten == 0); > @@ -642,7 +642,7 @@ > // public abstract void recycle(); > // public abstract void setSuspended(boolean suspended); > // public abstract boolean isSuspended(); > -// > +// > // public abstract void reset(); > // public abstract int getBufferSize(); > // public abstract void setBufferSize(int n); > @@ -652,5 +652,5 @@ > // } > // public abstract void write(byte[] b, int off, int len) throws > IOException; > // public abstract void writeByte(int b) throws IOException; > -// > +// > //} > \ No newline at end of file > Index: java/org/apache/tomcat/lite/ServletConfigImpl.java > =================================================================== > --- java/org/apache/tomcat/lite/ServletConfigImpl.java (revision 833452) > +++ java/org/apache/tomcat/lite/ServletConfigImpl.java (working copy) > @@ -1,12 +1,12 @@ > /* > * Copyright 1999-2002,2004 The Apache Software Foundation. > - * > + * > * Licensed under the Apache License, Version 2.0 (the "License"); > * you may not use this file except in compliance with the License. > * You may obtain a copy of the License at > - * > + * > * http://www.apache.org/licenses/LICENSE-2.0 > - * > + * > * Unless required by applicable law or agreed to in writing, software > * distributed under the License is distributed on an "AS IS" BASIS, > * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. > @@ -19,6 +19,7 @@ > > import java.io.PrintStream; > import java.lang.reflect.Method; > +import java.util.Collection; > import java.util.Enumeration; > import java.util.HashMap; > import java.util.HashSet; > @@ -28,11 +29,14 @@ > import java.util.logging.Level; > import java.util.logging.Logger; > > + > +import javax.servlet.MultipartConfigElement; > import javax.servlet.Servlet; > import javax.servlet.ServletConfig; > import javax.servlet.ServletContext; > import javax.servlet.ServletException; > import javax.servlet.ServletRegistration; > +import javax.servlet.ServletSecurityElement; > import javax.servlet.SingleThreadModel; > import javax.servlet.UnavailableException; > > @@ -42,7 +46,7 @@ > > /** > * Based on Wrapper. > - * > + * > * Standard implementation of the <b>Wrapper</b> interface that represents > * an individual servlet definition. No child Containers are allowed, and > * the parent Container must be a Context. > @@ -52,11 +56,11 @@ > */ > @SuppressWarnings("deprecation") > public class ServletConfigImpl implements ServletConfig, > ServletRegistration { > - > + > ServletDynamicRegistration dynamic = new ServletDynamicRegistration(); > - > + > protected boolean asyncSupported; > - > + > private static Logger log= > Logger.getLogger(ServletConfigImpl.class.getName()); > > @@ -75,7 +79,7 @@ > protected int loadOnStartup = -1; > protected String runAs; > protected Map securityRoleRef = new HashMap(); // roleName -> > [roleLink] > - > + > /** > * The date and time at which this servlet will become available (in > * milliseconds since the epoch), or zero if the servlet is available. > @@ -83,14 +87,14 @@ > * servlet is considered permanent. > */ > private transient long available = 0L; > - > + > private ServletContextImpl ctx; > > /** > * The (single) initialized instance of this servlet. > */ > private transient Servlet instance = null; > - > + > /** > * Are we unloading our servlet instance at the moment? > */ > @@ -111,13 +115,13 @@ > */ > private transient Stack instancePool = null; > > - > + > // Statistics > private transient long loadTime=0; > private transient int classLoadTime=0; > > // ------------------------------------------------------------- > Properties > - public ServletConfigImpl(ServletContextImpl ctx, String name, > + public ServletConfigImpl(ServletContextImpl ctx, String name, > String classname) { > this.servletName = name; > this.servletClassName = classname; > @@ -177,7 +181,7 @@ > public void setJspFile(String s) { > this.jspFile = s; > } > - > + > /** > * Return the load-on-startup order value (negative value means > * load on first call). > @@ -229,11 +233,11 @@ > HashSet allow = new HashSet(); > allow.add("TRACE"); > allow.add("OPTIONS"); > - > + > Method[] methods = getAllDeclaredMethods(servletClazz); > for (int i=0; methods != null && i<methods.length; i++) { > Method m = methods[i]; > - > + > if (m.getName().equals("doGet")) { > allow.add("GET"); > allow.add("HEAD"); > @@ -257,7 +261,7 @@ > > /** > * Extract the root cause from a servlet exception. > - * > + * > * @param e The servlet exception > */ > public static Throwable getRootCause(ServletException e) { > @@ -280,15 +284,15 @@ > > /** > * MUST be called before service() > - * This method should be called to get the servlet. After > + * This method should be called to get the servlet. After > * service(), dealocate should be called. This deals with STM and > * update use counters. > - * > + * > * Normally called from RequestDispatcher and TomcatLite. > */ > public Servlet allocate() throws ServletException { > // If we are currently unloading this servlet, throw an exception > - if (unloading) > + if (unloading) > throw new ServletException > ("allocate() while unloading " + getServletName()); > > @@ -316,10 +320,10 @@ > countAllocated++; > return (instance); > } > - > + > // Simpler policy for ST: unbound number of servlets ( can grow to > // one per thread ) > - > + > synchronized (instancePool) { > if (instancePool.isEmpty()) { > try { > @@ -330,7 +334,7 @@ > } > countAllocated++; > Servlet newServlet = loadServlet(); > - log.fine("New STM servet " + newServlet + " " + > + log.fine("New STM servet " + newServlet + " " + > countAllocated); > return newServlet; > } catch (ServletException e) { > @@ -344,7 +348,7 @@ > countAllocated); > Servlet s = (Servlet) instancePool.pop(); > countAllocated++; > - log.fine("After get " + instancePool.size() + " " + s + > + log.fine("After get " + instancePool.size() + " " + s + > " " + countAllocated); > return s; > } > @@ -365,11 +369,11 @@ > synchronized (instancePool) { > countAllocated--; > if (instancePool.contains(servlet)) { > - System.err.println("Aleady in pool " + servlet + " " > + System.err.println("Aleady in pool " + servlet + " " > + instancePool.size()+ " " + countAllocated); > return; > } > - System.err.println("return pool " + servlet + " " + > + System.err.println("return pool " + servlet + " " + > instancePool.size() + " " + countAllocated); > instancePool.push(servlet); > } > @@ -384,7 +388,7 @@ > if (actualClass == null) { > // No explicit name. Try to use the framework > if (jspFile != null) { > - > + > // Named JSPs can be handled by a servlet or by the mapper. > Servlet res = (Servlet) > ctx.getObjectManager().get("filetemplate-servlet"); > if (res != null) { > @@ -393,7 +397,7 @@ > initParams.put("jsp-file", jspFile); > return res; > } else { > - UserTemplateClassMapper mapper = > + UserTemplateClassMapper mapper = > (UserTemplateClassMapper) > ctx.getObjectManager().get( > UserTemplateClassMapper.class); > if (mapper != null) { > @@ -415,36 +419,36 @@ > //ctx.getObjectManager().getObject(c); > //ctx.getObjectManager().getObject(servletName); > } > - > - > + > + > if (servletClass == null) { > // set classClass > loadClass(actualClass); > } > > - > - // jsp-file case. Load the JspProxyServlet instead, with the > - // right params. Note the JspProxyServlet is _not_ jasper, > - // nor 'jsp' servlet - it is just a proxy with no special > + > + // jsp-file case. Load the JspProxyServlet instead, with the > + // right params. Note the JspProxyServlet is _not_ jasper, > + // nor 'jsp' servlet - it is just a proxy with no special > // params. It calls the jsp servlet and jasper to generate the > // real class. > - > + > // this is quite different from catalina, where an ugly kludge was > // used to use the same jsp servlet in 2 roles > - > + > // the jsp proxy is replaced by the web.xml processor > - > + > if (servletClass == null) { > unavailable(null); > throw new UnavailableException("ClassNotFound: " + > actualClass); > } > - > + > // Instantiate and initialize an instance of the servlet class > itself > try { > return (Servlet) servletClass.newInstance(); > } catch (ClassCastException e) { > unavailable(null); > - throw new UnavailableException("ClassCast: (Servlet)" + > + throw new UnavailableException("ClassCast: (Servlet)" + > actualClass); > } catch (Throwable e) { > unavailable(null); > @@ -452,13 +456,13 @@ > // Added extra log statement for Bugzilla 36630: > // http://issues.apache.org/bugzilla/show_bug.cgi?id=36630 > if(log.isLoggable(Level.FINE)) { > - log.log(Level.FINE, "newInstance() error: servlet-name: " > + > + log.log(Level.FINE, "newInstance() error: servlet-name: " > + > getServletName() + > " servlet-class: " + actualClass, e); > } > > // Restore the context ClassLoader > - throw new ServletException("newInstance() error " + > getServletName() + > + throw new ServletException("newInstance() error " + > getServletName() + > " " + actualClass, e); > } > } > @@ -473,13 +477,13 @@ > // Nothing to do if we already have an instance or an instance pool > if (!singleThreadModel && (instance != null)) > return instance; > - > + > long t1=System.currentTimeMillis(); > > Servlet servlet = newInstance(); > - > + > classLoadTime=(int) (System.currentTimeMillis() -t1); > - > + > // Call the initialization method of this servlet > try { > servlet.init(this); > @@ -500,7 +504,7 @@ > instancePool = new Stack(); > } > loadTime=System.currentTimeMillis() -t1; > - > + > return servlet; > } > > @@ -509,14 +513,14 @@ > // Complain if no servlet class has been specified > if (actualClass == null) { > unavailable(null); > - throw new ServletException("servlet-class missing " + > + throw new ServletException("servlet-class missing " + > getServletName()); > } > - > - ClassLoader classLoader = ctx.getClassLoader(); > - if (classLoader == null ) > + > + ClassLoader classLoader = ctx.getClassLoader(); > + if (classLoader == null ) > classLoader = this.getClass().getClassLoader(); > - > + > // Load the specified servlet class from the appropriate class > loader > try { > servletClass = classLoader.loadClass(actualClass); > @@ -580,7 +584,7 @@ > * destroy() method > */ > public synchronized void unload() throws ServletException { > - setAvailable(Long.MAX_VALUE); > + setAvailable(Long.MAX_VALUE); > > // Nothing to do if we have never loaded the instance > if (!singleThreadModel && (instance == null)) > @@ -594,7 +598,7 @@ > long delay = ctx.getUnloadDelay() / 20; > while ((nRetries < 21) && (countAllocated > 0)) { > if ((nRetries % 10) == 0) { > - log.info("Servlet.unload() timeout " + > + log.info("Servlet.unload() timeout " + > countAllocated); > } > try { > @@ -610,7 +614,7 @@ > Thread.currentThread().getContextClassLoader(); > if (instance != null) { > ClassLoader classLoader = instance.getClass().getClassLoader(); > - > + > PrintStream out = System.out; > // Call the servlet destroy() method > try { > @@ -620,13 +624,13 @@ > instance = null; > //instancePool = null; > unloading = false; > - throw new ServletException("Servlet.destroy() " + > + throw new ServletException("Servlet.destroy() " + > getServletName(), t); > } finally { > // restore the context ClassLoader > > Thread.currentThread().setContextClassLoader(oldCtxClassLoader); > } > - > + > // Deregister the destroyed instance > instance = null; > } > @@ -653,8 +657,8 @@ > > unloading = false; > } > - > - > + > + > /** > * Return the initialization parameter value for the specified name, > * if any; otherwise return <code>null</code>. > @@ -772,33 +776,33 @@ > if ((parentMethods != null) && (parentMethods.length > 0)) { > Method[] allMethods = > new Method[parentMethods.length + thisMethods.length]; > - System.arraycopy(parentMethods, 0, allMethods, 0, > + System.arraycopy(parentMethods, 0, allMethods, 0, > parentMethods.length); > - System.arraycopy(thisMethods, 0, allMethods, > parentMethods.length, > + System.arraycopy(thisMethods, 0, allMethods, parentMethods.length, > thisMethods.length); > > - thisMethods = allMethods; > - } > + thisMethods = allMethods; > + } > > - return thisMethods; > + return thisMethods; > } > > /** Specify the instance. Avoids the class lookup, disables unloading. > * Use for embedded case, or to control the allocation. > - * > + * > * @param servlet > */ > public void setServlet(Servlet servlet) { > instance = servlet; > ctx.getObjectManager().bind("Servlet:" + > - ctx.getContextPath() + ":" + getServletName(), > + ctx.getContextPath() + ":" + getServletName(), > this); > } > > public String getSecurityRoleRef(String role) { > return (String)securityRoleRef.get(role); > } > - > + > public void setSecurityRoleRef(Map securityRoles) { > this.securityRoleRef = securityRoles; > } > @@ -811,10 +815,10 @@ > this.loadOnStartup = loadOnStartup; > } > > - @Override > + > public Set<String> addMapping(String... urlPatterns) { > if (ctx.startDone) { > - // Use the context method instead of the servlet API to > + // Use the context method instead of the servlet API to > // add mappings after context init. > throw new IllegalStateException(); > } > @@ -833,41 +837,128 @@ > return failed; > } > > - > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscribe@... > For additional commands, e-mail: dev-help@... > |
|
|
Re: patch for allowing tomcat-lite to compileFWIW - Here is a way to launch tomcat lite via a bsh script - so via bsh
- you can easily kick the tires of Tomcat Lite and change by just doing some scripting. What I haven't played with is creating Filters/Servlets in bsh and injecting them instead [instead of writing java files and then compiling] -Tim /* Assumptions 0) I used java6 1) $JAVA_HOME/bin/java -cp bsh-2.0b4.jar bsh.Interpreter tomcat.bsh 2) Your jars are in the same dir as tomcat.bsh 3) your webapp is here: C:/opt/data/src/TOMCAT/tc6-trunk/webapps/ROOT Apologies for assumption 3 */ // Set up your classpath String scriptDir = dirname(pathToFile(getSourceFileInfo()).getAbsolutePath()); addClassPath((new File(scriptDir, "tomcat-lite_javax_coyote.jar")).toURL()); addClassPath((new File(scriptDir, "tomcat-lite-all.jar")).toURL()); // Create your tomcat lite and set the connector org.apache.tomcat.lite.TomcatLite lite = new org.apache.tomcat.lite.TomcatLite(); lite.setConnector(new org.apache.tomcat.lite.coyote.CoyoteConnector()); // Add a servlet context lite.addServletContext("", "C:/opt/data/src/TOMCAT/tc6-trunk/webapps/ROOT", "/"); /* Inititialize and go */ lite.init(); lite.start(); lite.startConnector(); --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@... For additional commands, e-mail: dev-help@... |
|
|
Re: patch for allowing tomcat-lite to compileThere are also some unit tests that should do that...
See the other mail I sent - my changes would pretty much break the current tomcat-lite ( different connector with very different I/O and charset conversion ), but the API is almost the same. Costin On Fri, Nov 6, 2009 at 11:33 AM, Tim Funk <funkman@...> wrote: > FWIW - Here is a way to launch tomcat lite via a bsh script - so via bsh - > you can easily kick the tires of Tomcat Lite and change by just doing some > scripting. > > What I haven't played with is creating Filters/Servlets in bsh and > injecting them instead [instead of writing java files and then compiling] > > -Tim > > > /* > Assumptions > 0) I used java6 > 1) $JAVA_HOME/bin/java -cp bsh-2.0b4.jar bsh.Interpreter tomcat.bsh > 2) Your jars are in the same dir as tomcat.bsh > 3) your webapp is here: C:/opt/data/src/TOMCAT/tc6-trunk/webapps/ROOT > > Apologies for assumption 3 > */ > > > // Set up your classpath > String scriptDir = > dirname(pathToFile(getSourceFileInfo()).getAbsolutePath()); > addClassPath((new File(scriptDir, > "tomcat-lite_javax_coyote.jar")).toURL()); > addClassPath((new File(scriptDir, "tomcat-lite-all.jar")).toURL()); > > > // Create your tomcat lite and set the connector > org.apache.tomcat.lite.TomcatLite lite = new > org.apache.tomcat.lite.TomcatLite(); > lite.setConnector(new org.apache.tomcat.lite.coyote.CoyoteConnector()); > > > // Add a servlet context > lite.addServletContext("", "C:/opt/data/src/TOMCAT/tc6-trunk/webapps/ROOT", > "/"); > > > /* Inititialize and go */ > lite.init(); > lite.start(); > lite.startConnector(); > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscribe@... > For additional commands, e-mail: dev-help@... > |
| Free embeddable forum powered by Nabble | Forum Help |