From: funkman Date: Fri, 6 Nov 2009 18:53:57 +0000 (+0000) Subject: add stubs and remove / add some @overrides to allow compilation X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=a1a63b30e4e19aff58ab4023a2914e9867a33886;p=tomcat7.0 add stubs and remove / add some @overrides to allow compilation git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@833521 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/modules/tomcat-lite/java/org/apache/tomcat/integration/simple/SimpleObjectManager.java b/modules/tomcat-lite/java/org/apache/tomcat/integration/simple/SimpleObjectManager.java index 20854a550..212f1a891 100644 --- a/modules/tomcat-lite/java/org/apache/tomcat/integration/simple/SimpleObjectManager.java +++ b/modules/tomcat-lite/java/org/apache/tomcat/integration/simple/SimpleObjectManager.java @@ -13,40 +13,39 @@ import java.util.logging.Logger; 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 objects = new HashMap(); ObjectManager om; - + public SimpleObjectManager() { // Register PropertiesSpi } @@ -55,18 +54,18 @@ public class SimpleObjectManager extends ObjectManager { 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 @@ public class SimpleObjectManager extends ObjectManager { throw new RuntimeException("Error loading default config"); } } - + public Properties getProperties() { return props; } - + @Override public void unbind(String name) { } @@ -98,8 +97,8 @@ public class SimpleObjectManager extends ObjectManager { 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 @@ public class SimpleObjectManager extends ObjectManager { 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 @@ public class SimpleObjectManager extends ObjectManager { } 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 @@ public class SimpleObjectManager extends ObjectManager { 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 @@ public class SimpleObjectManager extends ObjectManager { if ("config".equals(arg)) { if (new File(value).exists()) { - load(new FileInputStream(value)); + load(new FileInputStream(value)); } else { loadResource(value); } @@ -207,5 +206,5 @@ public class SimpleObjectManager extends ObjectManager { } } return new String[] {}; - } + } } diff --git a/modules/tomcat-lite/java/org/apache/tomcat/lite/BodyWriter.java b/modules/tomcat-lite/java/org/apache/tomcat/lite/BodyWriter.java index cad571d7c..2e85fb706 100644 --- a/modules/tomcat-lite/java/org/apache/tomcat/lite/BodyWriter.java +++ b/modules/tomcat-lite/java/org/apache/tomcat/lite/BodyWriter.java @@ -14,18 +14,18 @@ import org.apache.tomcat.util.buf.C2BConverter; 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 @@ public class BodyWriter extends Writer { protected static final int WRITER_NOTE = 3; - private ByteChunk.ByteOutputChannel byteFlusher = + private ByteChunk.ByteOutputChannel byteFlusher = new ByteChunk.ByteOutputChannel() { @Override @@ -44,7 +44,7 @@ public class BodyWriter extends Writer { } }; - 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 @@ public class BodyWriter extends Writer { 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 @@ public class BodyWriter extends Writer { /** - * 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 @@ public class BodyWriter extends Writer { /** - * 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 @@ public class BodyWriter extends Writer { /** * Alternate constructor which allows specifying the initial buffer size. - * + * * @param size Buffer size to use */ public BodyWriter(int size) { @@ -179,7 +179,7 @@ public class BodyWriter extends Writer { cb.setLimit(size); } - + public void setConnector(Connector c, ServletResponseImpl res) { this.res = res; this.connector = c; @@ -191,7 +191,7 @@ public class BodyWriter extends Writer { /** * Is the response output suspended ? - * + * * @return suspended flag value */ public boolean isSuspended() { @@ -201,7 +201,7 @@ public class BodyWriter extends Writer { /** * Set the suspended flag. - * + * * @param suspended New suspended flag value */ public void setSuspended(boolean suspended) { @@ -216,31 +216,31 @@ public class BodyWriter extends Writer { * 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 @@ public class BodyWriter extends Writer { /** * Flush bytes or chars contained in the buffer. - * + * * @throws IOException An underlying IOException occurred */ public void flush() @@ -276,7 +276,7 @@ public class BodyWriter extends Writer { /** * Flush bytes or chars contained in the buffer. - * + * * @throws IOException An underlying IOException occurred */ protected void doFlush(boolean realFlush) @@ -294,10 +294,10 @@ public class BodyWriter extends Writer { if (state == CHAR_STATE) { cb.flushBuffer(); state = BYTE_STATE; - } + } if (state == BYTE_STATE) { bb.flushBuffer(); - } + } doFlush = false; if (realFlush) { @@ -310,14 +310,14 @@ public class BodyWriter extends Writer { // ------------------------------------------------- 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 @@ public class BodyWriter extends Writer { } - 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 class BodyWriter extends Writer { } - public void write(StringBuffer sb) + public void write(StringBuilder sb) throws IOException { if (suspended) @@ -477,7 +477,7 @@ public class BodyWriter extends Writer { s="null"; write(s, 0, s.length()); - } + } public void println() throws IOException { write("\n"); @@ -511,7 +511,7 @@ public class BodyWriter extends Writer { } - 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 class BodyWriter extends Writer { } - public void checkConverter() + public void checkConverter() throws IOException { if (!gotEnc) @@ -532,7 +532,7 @@ public class BodyWriter extends Writer { } - protected void setConverter() + protected void setConverter() throws IOException { enc = res.getCharacterEncoding(); @@ -542,7 +542,7 @@ public class BodyWriter extends Writer { enc = DEFAULT_ENCODING; conv = (C2BConverter) encoders.get(enc); if (conv == null) { - + if (System.getSecurityManager() != null){ try{ conv = (C2BConverter)AccessController.doPrivileged( @@ -553,22 +553,22 @@ public class BodyWriter extends Writer { } } - ); + ); }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 @@ public class BodyWriter extends Writer { } - /** + /** * 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 class BodyWriter extends Writer { // 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 class BodyWriter extends Writer { // } // 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 diff --git a/modules/tomcat-lite/java/org/apache/tomcat/lite/FilterConfigImpl.java b/modules/tomcat-lite/java/org/apache/tomcat/lite/FilterConfigImpl.java index bd0275f6a..b3b595140 100644 --- a/modules/tomcat-lite/java/org/apache/tomcat/lite/FilterConfigImpl.java +++ b/modules/tomcat-lite/java/org/apache/tomcat/lite/FilterConfigImpl.java @@ -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 @@ package org.apache.tomcat.lite; 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 javax.servlet.FilterRegistration.Dynamic; 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 @@ public final class FilterConfigImpl implements FilterConfig, FilterRegistration this.filterClassName = filterClass; this.initParams = params; } - + public void setFilter(Filter f) { filter = f; } - + public String getFilterName() { return filterName; } @@ -92,7 +93,7 @@ public final class FilterConfigImpl implements FilterConfig, FilterRegistration public void setFilterClass(Class filterClass2) { this.filterClass = filterClass2; } - + public String getInitParameter(String name) { if (initParams == null) return null; @@ -140,17 +141,17 @@ public final class FilterConfigImpl implements FilterConfig, FilterRegistration filterClass = (Class) 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,13 @@ public final class FilterConfigImpl implements FilterConfig, FilterRegistration this.filter = null; } - @Override + + @Override public void addMappingForServletNames(EnumSet 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 +190,13 @@ public final class FilterConfigImpl implements FilterConfig, FilterRegistration } } - @Override + + @Override public void addMappingForUrlPatterns(EnumSet 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 +210,138 @@ public final class FilterConfigImpl implements FilterConfig, FilterRegistration } } - @Override + + @Override public boolean setInitParameter(String name, String value) throws IllegalArgumentException, IllegalStateException { - return ServletContextImpl.setInitParameter(ctx, initParams, + return ServletContextImpl.setInitParameter(ctx, initParams, name, value); } - @Override + + @Override public Set setInitParameters(Map 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 + + @Override public void addMappingForServletNames(EnumSet dispatcherTypes, boolean isMatchAfter, String... servletNames) { FilterConfigImpl.this.addMappingForServletNames(dispatcherTypes, isMatchAfter, servletNames); } - @Override + + @Override public void addMappingForUrlPatterns(EnumSet dispatcherTypes, boolean isMatchAfter, String... urlPatterns) { FilterConfigImpl.this.addMappingForUrlPatterns(dispatcherTypes, isMatchAfter, urlPatterns); } - @Override + + @Override public boolean setInitParameter(String name, String value) throws IllegalArgumentException, IllegalStateException { - return ServletContextImpl.setInitParameter(ctx, initParams, + return ServletContextImpl.setInitParameter(ctx, initParams, name, value); } - @Override + + @Override public Set setInitParameters(Map initParameters) throws IllegalArgumentException, IllegalStateException { - return ServletContextImpl.setInitParameters(ctx, initParams, + return ServletContextImpl.setInitParameters(ctx, initParams, initParameters); } - @Override + + @Override public void setAsyncSupported(boolean isAsyncSupported) throws IllegalStateException { asyncSupported = isAsyncSupported; } - @Override + public void setDescription(String description) throws IllegalStateException { FilterConfigImpl.this.descryption = description; } + + @Override + public Collection getUrlPatternMappings() { + // implement me + return null; + } + + @Override + public Collection getServletNameMappings() { + // implement me + return null; + } + + @Override + public Map getInitParameters() { + // implement me + return null; + } + + @Override + public String getInitParameter(String name) { + if (initParams == null) return null; + return initParams.get(name); + } + + @Override + public String getClassName() { + // implement me + return null; + } + + @Override + public String getName() { + // implement me + return null; + } + } + + @Override + public Collection getUrlPatternMappings() { + // implement me + return null; + } + + @Override + public Collection getServletNameMappings() { + // implement me + return null; + } + + @Override + public Map getInitParameters() { + // implement me + return null; + } + + @Override + public String getClassName() { + // implement me + return null; + } + + @Override + public String getName() { + // implement me + return null; } - } diff --git a/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletConfigImpl.java b/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletConfigImpl.java index b68b32c72..dee9826d1 100644 --- a/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletConfigImpl.java +++ b/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletConfigImpl.java @@ -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 @@ package org.apache.tomcat.lite; 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.Stack; 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 @@ import org.apache.tomcat.util.IntrospectionUtils; /** * Based on Wrapper. - * + * * Standard implementation of the Wrapper interface that represents * an individual servlet definition. No child Containers are allowed, and * the parent Container must be a Context. @@ -52,11 +56,11 @@ import org.apache.tomcat.util.IntrospectionUtils; */ @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 @@ public class ServletConfigImpl implements ServletConfig, ServletRegistration { 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 @@ public class ServletConfigImpl implements ServletConfig, ServletRegistration { * 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 @@ public class ServletConfigImpl implements ServletConfig, ServletRegistration { */ 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 class ServletConfigImpl implements ServletConfig, ServletRegistration { 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 @@ public class ServletConfigImpl implements ServletConfig, ServletRegistration { HashSet allow = new HashSet(); allow.add("TRACE"); allow.add("OPTIONS"); - + Method[] methods = getAllDeclaredMethods(servletClazz); for (int i=0; methods != null && i 0)) { if ((nRetries % 10) == 0) { - log.info("Servlet.unload() timeout " + + log.info("Servlet.unload() timeout " + countAllocated); } try { @@ -610,7 +614,7 @@ public class ServletConfigImpl implements ServletConfig, ServletRegistration { 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 @@ public class ServletConfigImpl implements ServletConfig, ServletRegistration { 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 @@ public class ServletConfigImpl implements ServletConfig, ServletRegistration { unloading = false; } - - + + /** * Return the initialization parameter value for the specified name, * if any; otherwise return null. @@ -772,33 +776,33 @@ public class ServletConfigImpl implements ServletConfig, ServletRegistration { 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 @@ public class ServletConfigImpl implements ServletConfig, ServletRegistration { this.loadOnStartup = loadOnStartup; } - @Override + @Override public Set 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,154 @@ public class ServletConfigImpl implements ServletConfig, ServletRegistration { return failed; } - @Override + + @Override public boolean setInitParameter(String name, String value) throws IllegalArgumentException, IllegalStateException { - return ServletContextImpl.setInitParameter(ctx, initParams, + return ServletContextImpl.setInitParameter(ctx, initParams, name, value); } - @Override + + @Override public Set setInitParameters(Map 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; } - + + @Override + public Set setServletSecurity(ServletSecurityElement constraint) { + //implement me + return null; + } + + @Override + public void setLoadOnStartup(int loadOnStartup) { + //implement me - here to compile + } + + @Override + public void setMultipartConfig(MultipartConfigElement multipartConfig) { + //implement me - here to compile + } + + @Override + public void setRunAsRole(String roleName) { + //implement me - here to compile + } + + @Override + public String getRunAsRole() { + //implement me - here to compile + return null; + } + + @Override + public Collection getMappings() { + //implement me + return null; + } + + @Override + public Set addMapping(String... urlPatterns) { + //implement me + return null; + } + + @Override + public Map getInitParameters() { + // implement me + return null; + } + + @Override + public Set setInitParameters(Map initParameters) + throws IllegalArgumentException, IllegalStateException { + // implement me + return null; + } + + @Override + public String getClassName() { + // implement me + return null; + } + + @Override + public String getName() { + // implement me + return null; + } + + @Override + public String getInitParameter(String name) { + // implement me + return null; + } + + @Override + public boolean setInitParameter(String name, String value) + throws IllegalArgumentException, IllegalStateException { + // implement me + return false; + } + + } + + @Override + public Collection getMappings() { + //implement me + return null; } public void setServletClass(Class servletClass2) { servletClass = servletClass2; } + + + @Override + public String getRunAsRole() { + //implement me + return null; + } + + + @Override + public Map getInitParameters() { + // implement me + return null; + } + + @Override + public String getClassName() { + // implement me + return null; + } + + @Override + public String getName() { + // implement me + return null; + } + } diff --git a/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletContextImpl.java b/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletContextImpl.java index 061e9d452..7157cded9 100644 --- a/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletContextImpl.java +++ b/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletContextImpl.java @@ -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.MalformedURLException; 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.ServletRegistration; 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 @@ import org.apache.tomcat.util.http.MimeMap; /** * 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 @@ import org.apache.tomcat.util.http.MimeMap; */ 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 @@ public class ServletContextImpl implements ServletContext { protected transient ArrayList lifecycleListeners = new ArrayList(); protected UserSessionManager manager; - + HashMap filters = new HashMap(); HashMap servlets = new HashMap(); @@ -133,16 +135,16 @@ public class ServletContextImpl implements ServletContext { /** 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 @@ public class ServletContextImpl implements ServletContext { boolean initDone = false; boolean startDone = false; - + // ------------------------------------------------- ServletContext Methods public ServletContextImpl() { } @@ -159,7 +161,7 @@ public class ServletContextImpl implements ServletContext { 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 @@ public class ServletContextImpl implements ServletContext { } return om; } - + public void setObjectManager(ObjectManager om) { this.om = om; } - + public Locale2Charset getCharsetMapper() { return charsetMapper; } @@ -188,29 +190,29 @@ public class ServletContextImpl implements ServletContext { 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 class ServletContextImpl implements ServletContext { public List getListeners() { return lifecycleListeners; } - - public void addListener(EventListener listener) { - lifecycleListeners.add(listener); + + public void addListener(Class listenerClass) { + // implement me + } + + public void addListener(String className) { + // implement me + } + + public void addListener(T t) { + lifecycleListeners.add(t); } + public void removeListener(EventListener listener) { lifecycleListeners.remove(listener); } @@ -256,7 +267,7 @@ public class ServletContextImpl implements ServletContext { public ServletConfigImpl getServletConfig(String jsp_servlet_name) { return (ServletConfigImpl)servlets.get(jsp_servlet_name); } - + public Map getServletConfigs() { return servlets; } @@ -264,27 +275,27 @@ public class ServletContextImpl implements ServletContext { /** * 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 @@ public class ServletContextImpl implements ServletContext { return mapper; } - + public WebappFilterMapper getFilterMapper() { if (webappFilterMapper == null) { Object customMapper = getObjectManager().get(WebappFilterMapper.class); @@ -316,7 +327,7 @@ public class ServletContextImpl implements ServletContext { return webappFilterMapper ; } - + public FilterConfigImpl getFilter(String name) { return (FilterConfigImpl)filters.get(name); } @@ -349,7 +360,7 @@ public class ServletContextImpl implements ServletContext { public void addSecurityRole(String role) { securityRoles.add(role); } - + public List getSecurityRoles() { return securityRoles; } @@ -392,14 +403,14 @@ public class ServletContextImpl implements ServletContext { } } - + /** * Return the main path associated with this context. */ public String getContextPath() { return contextPath; } - + /** * Return the value of the specified initialization parameter, or @@ -473,10 +484,10 @@ public class ServletContextImpl implements ServletContext { */ 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 class ServletContextImpl implements ServletContext { */ 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 @@ public class ServletContextImpl implements ServletContext { ThreadLocal requestDispatcherStack = new ThreadLocal(); protected ClassLoader classLoader; - + // protected RequestDispatcherImpl getRequestDispatcher() { -// ArrayList/**/ list = +// ArrayList/**/ 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 @@ public class ServletContextImpl implements ServletContext { if (path == null || !path.startsWith("/")) { throw new MalformedURLException("getResource() " + path); } - + path = UrlUtils.normalize(path); if (path == null) return (null); @@ -585,9 +596,9 @@ public class ServletContextImpl implements ServletContext { 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 @@ public class ServletContextImpl implements ServletContext { 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 @@ public class ServletContextImpl implements ServletContext { event = new ServletContextAttributeEvent(this.getServletContext(), name, value); - + } if (replaced) { listener.attributeReplaced(event); @@ -843,7 +854,7 @@ public class ServletContextImpl implements ServletContext { removeAttribute(key); } } - + public void initFilters() throws ServletException { Iterator fI = getFilters().values().iterator(); while (fI.hasNext()) { @@ -851,16 +862,16 @@ public class ServletContextImpl implements ServletContext { 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/*>*/ onStartup = + Map/*>*/ onStartup = new TreeMap/*>*/(); while (fI.hasNext()) { ServletConfigImpl fc = (ServletConfigImpl)fI.next(); @@ -877,15 +888,15 @@ public class ServletContextImpl implements ServletContext { Iterator keys = onStartup.keySet().iterator(); while (keys.hasNext()) { Integer key = (Integer)keys.next(); - List/**/ servlets = (List)onStartup.get(key); + List/**/ 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 @@ public class ServletContextImpl implements ServletContext { 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 class ServletContextImpl implements ServletContext { 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 class ServletContextImpl implements ServletContext { } 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,64 +962,64 @@ public class ServletContextImpl implements ServletContext { 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); @@ -1016,41 +1027,41 @@ public class ServletContextImpl implements ServletContext { } @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 @@ public class ServletContextImpl implements ServletContext { 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 @@ public class ServletContextImpl implements ServletContext { 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 @@ public class ServletContextImpl implements ServletContext { 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 class ServletContextImpl implements ServletContext { } } - + public ArrayList getClasspath(File directory, File classesDir) { ArrayList res = new ArrayList(); if (classesDir.isDirectory() && classesDir.exists() && @@ -1151,13 +1162,13 @@ public class ServletContextImpl implements ServletContext { || !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 @@ public class ServletContextImpl implements ServletContext { 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 @@ public class ServletContextImpl implements ServletContext { 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 @@ public class ServletContextImpl implements ServletContext { } } - + initFilters(); initServlets(); - + startDone = true; } @@ -1238,13 +1249,13 @@ public class ServletContextImpl implements ServletContext { } - // 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 class ServletContextImpl implements ServletContext { public TomcatLite getEngine() { return facade; } - + public String findStatusPage(int status) { if (contextConfig.errorPageCode.size() == 0) { return null; @@ -1283,9 +1294,9 @@ public class ServletContextImpl implements ServletContext { 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 @@ public class ServletContextImpl implements ServletContext { 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 @@ public class ServletContextImpl implements ServletContext { 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 @@ public class ServletContextImpl implements ServletContext { } } - 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 @@ public class ServletContextImpl implements ServletContext { // TODO } } - + protected String findErrorPage(Throwable exception) { if (contextConfig.errorPageException.size() == 0) { return null; @@ -1382,32 +1393,38 @@ public class ServletContextImpl implements ServletContext { } + @Override public EnumSet getDefaultSessionTrackingModes() { return null; } + @Override public EnumSet getEffectiveSessionTrackingModes() { return null; } + @Override public SessionCookieConfig getSessionCookieConfig() { return null; } + @Override public void setSessionTrackingModes(EnumSet 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); @@ -1416,6 +1433,7 @@ public class ServletContextImpl implements ServletContext { return fc.getDynamic(); } + @Override public Dynamic addFilter(String filterName, Filter filter) { FilterConfigImpl fc = new FilterConfigImpl(this); @@ -1425,6 +1443,7 @@ public class ServletContextImpl implements ServletContext { return fc.getDynamic(); } + @Override public Dynamic addFilter(String filterName, Class filterClass) { FilterConfigImpl fc = new FilterConfigImpl(this); @@ -1434,16 +1453,18 @@ public class ServletContextImpl implements ServletContext { 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 servletClass) { ServletConfigImpl sc = new ServletConfigImpl(this, servletName, servletClass.getName()); sc.setServletClass(servletClass); @@ -1451,10 +1472,11 @@ public class ServletContextImpl implements ServletContext { 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 createFilter(Class c) throws ServletException { FilterConfigImpl fc = new FilterConfigImpl(this); @@ -1476,6 +1498,7 @@ public class ServletContextImpl implements ServletContext { } } + @Override public T createServlet(Class c) throws ServletException { String filterName = "_tomcat_auto_servlet_" + autoName.incrementAndGet(); @@ -1490,23 +1513,25 @@ public class ServletContextImpl implements ServletContext { } } - @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 params = contextConfig.contextParam; return setInitParameter(this, params, name, value); } - - static Set setInitParameters(ServletContextImpl ctx, + + + static Set setInitParameters(ServletContextImpl ctx, Map params, Map initParameters) throws IllegalArgumentException, IllegalStateException { @@ -1524,14 +1549,14 @@ public class ServletContextImpl implements ServletContext { } } 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 params, + static boolean setInitParameter(ServletContextImpl ctx, Map params, String name, String value) { if (name == null || value == null) { throw new IllegalArgumentException(); @@ -1547,5 +1572,57 @@ public class ServletContextImpl implements ServletContext { return true; } } + + public JspConfigDescriptor getJspConfigDescriptor() { + // fix me - just here to compile + return null; + } + + + + public void declareRoles(String... roleNames) { + // implement me + } + + public T createListener(Class c) throws ServletException { + // implement me + return null; + } + + public Collection getMappings() { + // implement me + return null; + } + + public Map getFilterRegistrations() { + // implement me + return null; + } + + public FilterRegistration getFilterRegistration(String filterName) { + // implement me + return null; + } + + public Map 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; + } + } diff --git a/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletRequestImpl.java b/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletRequestImpl.java index 644c4603a..4d9a6224e 100644 --- a/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletRequestImpl.java +++ b/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletRequestImpl.java @@ -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.io.UnsupportedEncodingException; 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 @@ import org.apache.tomcat.util.http.mapper.MappingData; /** - * + * * Wrapper object for the Coyote request. * * @author Remy Maucherat @@ -95,13 +96,13 @@ public class ServletRequestImpl implements HttpServletRequest { /** * 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 class ServletRequestImpl implements HttpServletRequest { 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 class ServletRequestImpl implements HttpServletRequest { 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 @@ public class ServletRequestImpl implements HttpServletRequest { * 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,7 +243,7 @@ public class ServletRequestImpl implements HttpServletRequest { * declare formats[] as a static variable. */ protected SimpleDateFormat formats[] = null; - + /** * The attributes associated with this Request, keyed by attribute name. @@ -295,14 +296,14 @@ public class ServletRequestImpl implements HttpServletRequest { /** * ServletInputStream. */ - protected ServletInputStreamImpl inputStream; + protected ServletInputStreamImpl inputStream; /** * Reader. */ protected BufferedReader reader; - + /** * Using stream flag. @@ -395,7 +396,7 @@ public class ServletRequestImpl implements HttpServletRequest { * Filter chain associated with the request. */ protected FilterChainImpl filterChain = new FilterChainImpl(); - + /** * Mapping data. */ @@ -408,7 +409,7 @@ public class ServletRequestImpl implements HttpServletRequest { * The response with which this request is associated. */ protected ServletResponseImpl response = new ServletResponseImpl(); - + /** * URI byte to char converter (not recycled). */ @@ -423,13 +424,13 @@ public class ServletRequestImpl implements HttpServletRequest { * 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 class ServletRequestImpl implements HttpServletRequest { public void setConnector(Connector c) { connector = c; } - + public Connector getConnector() { return connector; } @@ -563,7 +564,7 @@ public class ServletRequestImpl implements HttpServletRequest { * * @exception IOException if an input/output error occurs */ - public ServletInputStream createInputStream() + public ServletInputStream createInputStream() throws IOException { return inputStream; } @@ -588,11 +589,11 @@ public class ServletRequestImpl implements HttpServletRequest { 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 @@ public class ServletRequestImpl implements HttpServletRequest { // 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 @@ public class ServletRequestImpl implements HttpServletRequest { /** * Get the context path. - * + * * @return the context path */ public MessageBytes getContextPathMB() { @@ -783,7 +784,7 @@ public class ServletRequestImpl implements HttpServletRequest { 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 @@ public class ServletRequestImpl implements HttpServletRequest { /** * Get the decoded request URI. - * + * * @return the URL decoded request URI */ public String getDecodedRequestURI() { @@ -806,7 +807,7 @@ public class ServletRequestImpl implements HttpServletRequest { /** * Get the decoded request URI. - * + * * @return the URL decoded request URI */ public MessageBytes getDecodedRequestURIMB() { @@ -833,7 +834,7 @@ public class ServletRequestImpl implements HttpServletRequest { public String getHeader(String name) { return httpRequest.getHeader(name); } - + /** * Return the names of all headers received with this request. */ @@ -897,7 +898,7 @@ public class ServletRequestImpl implements HttpServletRequest { /** * 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 @@ public class ServletRequestImpl implements HttpServletRequest { /** * Get the path info. - * + * * @return the path info */ public MessageBytes getPathInfoMB() { @@ -1086,14 +1087,14 @@ public class ServletRequestImpl implements HttpServletRequest { } } - + /** * 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 @@ public class ServletRequestImpl implements HttpServletRequest { /** * 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 @@ public class ServletRequestImpl implements HttpServletRequest { 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 @@ public class ServletRequestImpl implements HttpServletRequest { } return conv; } - + /** * Return the real path of the specified virtual path. * @@ -1213,7 +1214,7 @@ public class ServletRequestImpl implements HttpServletRequest { /** * 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 class ServletRequestImpl implements HttpServletRequest { 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 @@ public class ServletRequestImpl implements HttpServletRequest { /** * Get the request path. - * + * * @return the request path */ public MessageBytes getRequestPathMB() { @@ -1330,13 +1331,13 @@ public class ServletRequestImpl implements HttpServletRequest { 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 @@ public class ServletRequestImpl implements HttpServletRequest { /** * Get the servlet path. - * + * * @return the servlet path */ public MessageBytes getServletPathMB() { @@ -1537,8 +1538,8 @@ public class ServletRequestImpl implements HttpServletRequest { public boolean isSecure() { return (secure); } - - + + /** * Return true if the authenticated user principal * possesses the specified role name. @@ -1566,7 +1567,7 @@ public class ServletRequestImpl implements HttpServletRequest { if (role.equals(userPrincipal.getName())) { return true; } - + // TODO: check !!!! // Check for a role defined directly as a return false; @@ -1652,7 +1653,7 @@ public class ServletRequestImpl implements HttpServletRequest { (ServletRequestAttributeListener) listeners.get(i); try { if (event == null) { - event = + event = new ServletRequestAttributeEvent(context.getServletContext(), getRequest(), name, value); } @@ -1673,7 +1674,7 @@ public class ServletRequestImpl implements HttpServletRequest { * @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 @@ public class ServletRequestImpl implements HttpServletRequest { // 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 @@ public class ServletRequestImpl implements HttpServletRequest { /** * Set the decoded request URI. - * + * * @param uri The decoded request URI */ public void setDecodedRequestURI(String uri) { @@ -2051,18 +2052,18 @@ public class ServletRequestImpl implements HttpServletRequest { 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 @@ public class ServletRequestImpl implements HttpServletRequest { 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 @@ public class ServletRequestImpl implements HttpServletRequest { 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 @@ public class ServletRequestImpl implements HttpServletRequest { */ protected void parseSessionCookiesId() { String sessionCookieName = context.getSessionCookieName(); - + // Parse session id from cookies Cookies serverCookies = httpRequest.getCookies(); int count = serverCookies.getCookieCount(); @@ -2374,7 +2375,7 @@ public class ServletRequestImpl implements HttpServletRequest { if (!isRequestedSessionIdFromCookie()) { // Accept only the first session id cookie //scookie.getValue().convertToAscii(); - + setRequestedSessionId (scookie.getValue().toString()); setRequestedSessionCookie(true); @@ -2409,18 +2410,18 @@ public class ServletRequestImpl implements HttpServletRequest { 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,57 @@ public class ServletRequestImpl implements HttpServletRequest { } - @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 + + @Override public AsyncContext startAsync() throws IllegalStateException { return null; } - @Override + @Override public AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse) throws IllegalStateException { @@ -2519,45 +2523,50 @@ public class ServletRequestImpl implements HttpServletRequest { } - @Override + + @Override public boolean authenticate(HttpServletResponse response) throws IOException, ServletException { return false; } - @Override + + @Override public Part getPart(String name) { return null; } - @Override - public Iterable getParts() { - return null; - } - - @Override + @Override public void login(String username, String password) throws ServletException { } - @Override + + @Override public void logout() throws ServletException { } - @Override + public long getAsyncTimeout() { return 0; } - @Override + + @Override public DispatcherType getDispatcherType() { return null; } + @Override + public Collection getParts() throws IOException, ServletException { + return null; + } + + } diff --git a/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletResponseImpl.java b/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletResponseImpl.java index 24d6c3cc0..d876697ec 100644 --- a/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletResponseImpl.java +++ b/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletResponseImpl.java @@ -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.MalformedURLException; 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 @@ import org.apache.tomcat.util.http.ServerCookie; public class ServletResponseImpl implements HttpServletResponse { - /** + /** * Format for http response header date field * From DateTool */ @@ -61,8 +62,8 @@ public class ServletResponseImpl "EEE, dd MMM yyyy HH:mm:ss zzz"; // ----------------------------------------------------------- Constructors - - + + ServletResponseImpl() { urlEncoder.addSafeCharacter('/'); } @@ -103,12 +104,12 @@ public class ServletResponseImpl */ protected boolean included = false; - + /** * The characterEncoding flag */ private boolean isCharacterEncodingSet = false; - + /** * The error flag. */ @@ -151,19 +152,19 @@ public class ServletResponseImpl 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 @@ public class ServletResponseImpl included = false; error = false; isCharacterEncodingSet = false; - + cookies.clear(); outputBuffer.recycle(); - + resB.recycle(); } @@ -209,7 +210,7 @@ public class ServletResponseImpl /** * Set the application commit flag. - * + * * @param appCommitted The new application committed flag value */ public void setAppCommitted(boolean appCommitted) { @@ -222,7 +223,7 @@ public class ServletResponseImpl */ public boolean isAppCommitted() { return (this.appCommitted || isCommitted() || isSuspended() - || ((getHttpResponse().getContentLength() > 0) + || ((getHttpResponse().getContentLength() > 0) && (getContentCount() >= getHttpResponse().getContentLength()))); } @@ -283,7 +284,7 @@ public class ServletResponseImpl /** * Set the suspended flag. - * + * * @param suspended The new suspended flag value */ public void setSuspended(boolean suspended) throws IOException { @@ -323,7 +324,7 @@ public class ServletResponseImpl * * @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 class ServletResponseImpl public String getContentType() { String ret = contentType; - if (ret != null + if (ret != null && characterEncoding != null && charsetSet) { ret = ret + ";charset=" + characterEncoding; @@ -379,7 +380,7 @@ public class ServletResponseImpl * * @exception IOException if an input/output error occurs */ - public void flushBuffer() + public void flushBuffer() throws IOException { outputBuffer.flush(); } @@ -408,7 +409,7 @@ public class ServletResponseImpl * 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 @@ public class ServletResponseImpl * 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 @@ public class ServletResponseImpl 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 @@ public class ServletResponseImpl /** * 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 @@ public class ServletResponseImpl // 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 @@ public class ServletResponseImpl 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 @@ public class ServletResponseImpl isCharacterEncodingSet = true; } - - + + /** * Set the Locale that is appropriate for this response, including * setting the appropriate character encoding. @@ -670,7 +671,7 @@ public class ServletResponseImpl 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 @@ public class ServletResponseImpl * 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 getHeaderNames() { + public Collection getHeaderNames() { MimeHeaders headers = getHttpResponse().getMimeHeaders(); int n = headers.size(); @@ -809,10 +810,10 @@ public class ServletResponseImpl 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 @@ public class ServletResponseImpl * @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 @@ public class ServletResponseImpl /** * Send an acknowledgment of a request. - * + * * @exception IOException if an input/output error occurs */ public void sendAcknowledgement() @@ -994,7 +995,7 @@ public class ServletResponseImpl // Ignore any call from an included servlet if (included) - return; + return; req.getConnector().acknowledge(this); } @@ -1010,7 +1011,7 @@ public class ServletResponseImpl * 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 @@ public class ServletResponseImpl * 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 @@ public class ServletResponseImpl // Ignore any call from an included servlet if (included) - return; + return; setError(); @@ -1055,10 +1056,10 @@ public class ServletResponseImpl // 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,15 +1067,15 @@ public class ServletResponseImpl setContentType("text/html"); if (status > 400 && status < 600) { if (getOutputBuffer().getBytesWritten() == 0) { - getOutputBuffer().write("

Status: " + - status + "

Message: " + message + + getOutputBuffer().write("

Status: " + + status + "

Message: " + message + "

"); getOutputBuffer().flush(); } } } - + /** * Send a temporary redirect to the specified redirect location URL. @@ -1085,7 +1086,7 @@ public class ServletResponseImpl * 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 @@ public class ServletResponseImpl // Ignore any call from an included servlet if (included) - return; + return; // Clear any data content that has been buffered resetBuffer(); @@ -1248,7 +1249,7 @@ public class ServletResponseImpl return (false); if (hreq.isRequestedSessionIdFromCookie()) return (false); - + // Is this a valid absolute URL? URL url = null; try { @@ -1333,7 +1334,7 @@ public class ServletResponseImpl 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 @@ public class ServletResponseImpl c == '+' || c == '-' || c == '.'; } - + /** * Return the specified URL with the specified session identifier * suitably encoded. @@ -1409,7 +1410,7 @@ public class ServletResponseImpl 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 class ServletResponseImpl public BodyWriter getOutputBuffer() { return outputBuffer; } - + public void setWriter(BodyWriter ob) { outputBuffer = ob; outputStream = new ServletOutputStreamImpl(outputBuffer); @@ -1451,8 +1452,9 @@ public class ServletResponseImpl } - @Override - public Iterable getHeaders(String name) { + + @Override + public Collection getHeaders(String name) { return null; } diff --git a/modules/tomcat-lite/java/org/apache/tomcat/lite/coyote/CoyoteConnector.java b/modules/tomcat-lite/java/org/apache/tomcat/lite/coyote/CoyoteConnector.java index 88669e53e..a4e45f03e 100644 --- a/modules/tomcat-lite/java/org/apache/tomcat/lite/coyote/CoyoteConnector.java +++ b/modules/tomcat-lite/java/org/apache/tomcat/lite/coyote/CoyoteConnector.java @@ -39,18 +39,18 @@ public class CoyoteConnector implements Adapter, Connector { 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 @@ public class CoyoteConnector implements Adapter, Connector { 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 @@ public class CoyoteConnector implements Adapter, Connector { 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 @@ public class CoyoteConnector implements Adapter, Connector { cres.sendHeaders(); } res.getOutputBuffer().flush(); - + BodyWriter mw = res.getBodyWriter(); //MessageWriter.getWriter(creq, cres, 0); mw.flush(); @@ -204,7 +204,7 @@ public class CoyoteConnector implements Adapter, Connector { BodyReader reader = req.getBodyReader(); //getReader(creq); reader.recycle(); - + cres.finish(); creq.recycle(); @@ -215,7 +215,7 @@ public class CoyoteConnector implements Adapter, Connector { } } } - + @Override public boolean event(Request req, Response res, SocketStatus status) throws Exception { @@ -230,7 +230,7 @@ public class CoyoteConnector implements Adapter, Connector { 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 class CoyoteConnector implements Adapter, Connector { 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 @@ public class CoyoteConnector implements Adapter, Connector { @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 class CoyoteConnector implements Adapter, Connector { 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 @@ public class CoyoteConnector implements Adapter, Connector { @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 @@ public class CoyoteConnector implements Adapter, Connector { @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 @@ public class CoyoteConnector implements Adapter, Connector { 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 class CoyoteConnector implements Adapter, Connector { public void setDaemon(boolean b) { daemon = b; } - + protected void initAdapters() { if (proto == null) { addProtocolHandler(port, daemon); @@ -380,7 +380,7 @@ public class CoyoteConnector implements Adapter, Connector { proto.destroy(); started = false; } - + // /** // * Simple CLI support - arg is a path:className pair. // */ @@ -394,14 +394,14 @@ public class CoyoteConnector implements Adapter, Connector { // 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 @@ public class CoyoteConnector implements Adapter, Connector { 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 @@ public class CoyoteConnector implements Adapter, Connector { // 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; + } + }