Author: funkman
Date: Fri Nov 6 18:53:57 2009
New Revision: 833521
URL:
http://svn.apache.org/viewvc?rev=833521&view=revLog:
add stubs and remove / add some @overrides to allow compilation
Modified:
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/integration/simple/SimpleObjectManager.java
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/BodyWriter.java
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/FilterConfigImpl.java
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletConfigImpl.java
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletContextImpl.java
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletRequestImpl.java
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletResponseImpl.java
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/coyote/CoyoteConnector.java
Modified: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/integration/simple/SimpleObjectManager.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/integration/simple/SimpleObjectManager.java?rev=833521&r1=833520&r2=833521&view=diff==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/integration/simple/SimpleObjectManager.java (original)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/integration/simple/SimpleObjectManager.java Fri Nov 6 18:53:57 2009
@@ -13,40 +13,39 @@
import org.apache.tomcat.integration.ObjectManager;
import org.apache.tomcat.util.IntrospectionUtils;
-import org.apache.tools.ant.taskdefs.LoadResource;
/**
- * This is a very small 'dependency injection'/registry poor-man substitute,
+ * This is a very small 'dependency injection'/registry poor-man substitute,
* based on old tomcat IntrospectionUtils ( which is based on ant ).
* Alternative would be to just pick one of spring/guice/etc and use it.
* This class is a bit smaller and should be enough for simple use.
- *
- * How it works:
+ *
+ * How it works:
* - when bound, simple properties are injected in the objects using
* the old IntrospectionUtils, same as in original Tomcat server.xml
- *
+ *
* - object creation using class name - properties injected as well.
* Similar with how server.xml or ant works.
- *
- * - it is based on a big Properties file, with command line arguments
+ *
+ * - it is based on a big Properties file, with command line arguments
* merged in.
- *
+ *
* Tomcat doesn't require any of the features - they are just used to
- * allow configuration in 'default' mode, when no other framework is
- * used.
- *
+ * allow configuration in 'default' mode, when no other framework is
+ * used.
+ *
* See the Spring example for an alternative. I believe most POJO frameworks
- * can be supported.
- *
+ * can be supported.
+ *
* @author Costin Manolache
*/
public class SimpleObjectManager extends ObjectManager {
static Logger log = Logger.getLogger(SimpleObjectManager.class.getName());
-
+
protected Properties props = new Properties();
protected Map<String, Object> objects = new HashMap();
ObjectManager om;
-
+
public SimpleObjectManager() {
// Register PropertiesSpi
}
@@ -55,18 +54,18 @@
this();
bind("Main.args", args);
}
-
+
public void loadResource(String res) {
InputStream in = this.getClass().getClassLoader()
.getResourceAsStream(res);
load(in);
}
-
+
public void register(ObjectManager om) {
this.om = om;
super.register(om);
}
-
+
public ObjectManager getObjectManager() {
return om;
}
@@ -78,11 +77,11 @@
throw new RuntimeException("Error loading default config");
}
}
-
+
public Properties getProperties() {
return props;
}
-
+
@Override
public void unbind(String name) {
}
@@ -98,8 +97,8 @@
throw new RuntimeException(e);
}
}
-
- // TODO: can I make 'inject' public - Guice seems to
+
+ // TODO: can I make 'inject' public - Guice seems to
// support this.
inject(name, o);
}
@@ -125,10 +124,10 @@
for (String k: props.stringPropertyNames()) {
if (k.startsWith(pref)) {
if (k.endsWith(")")) {
- continue; // special
+ continue; // special
}
String value = props.getProperty(k);
- value = IntrospectionUtils.replaceProperties(value,
+ value = IntrospectionUtils.replaceProperties(value,
props, null);
String p = k.substring(prefLen);
int idx = p.indexOf(".");
@@ -151,23 +150,23 @@
} catch (Throwable e) {
e.printStackTrace();
return null;
- }
+ }
}
-
+
/**
* Populate properties based on CLI:
* -key value
* --key=value
- *
+ *
* --config=FILE - load a properties file
- *
+ *
* @param args
* @param p
* @param meta
* @return everything after the first non arg not starting with '-'
- * @throws IOException
+ * @throws IOException
*/
- public String[] processArgs(String[] args, Properties props)
+ public String[] processArgs(String[] args, Properties props)
throws IOException {
for (int i = 0; i < args.length; i++) {
@@ -181,8 +180,8 @@
System.arraycopy(args, i, res, 0, res.length);
return res;
}
-
- String name = arg;
+
+ String name = arg;
int eq = arg.indexOf("=");
String value = null;
if (eq > 0) {
@@ -198,7 +197,7 @@
if ("config".equals(arg)) {
if (new File(value).exists()) {
- load(new FileInputStream(value));
+ load(new FileInputStream(value));
} else {
loadResource(value);
}
@@ -207,5 +206,5 @@
}
}
return new String[] {};
- }
+ }
}
Modified: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/BodyWriter.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/BodyWriter.java?rev=833521&r1=833520&r2=833521&view=diff==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/BodyWriter.java (original)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/BodyWriter.java Fri Nov 6 18:53:57 2009
@@ -14,18 +14,18 @@
import org.apache.tomcat.util.buf.CharChunk;
/**
- * Implement buffering and character translation acording to the
- * servlet spec.
- *
+ * Implement buffering and character translation acording to the
+ * servlet spec.
+ *
* This class handles both chars and bytes.
- *
+ *
* It is tightly integrated with servlet response, sending headers
* and updating the commit state.
- *
- * TODO: add 'extension' interface that allows direct access to
- * the async connector non-copy non-blocking queue. Same for the
- * OutputStream. Maybe switch the buffer to the brigade.
- *
+ *
+ * TODO: add 'extension' interface that allows direct access to
+ * the async connector non-copy non-blocking queue. Same for the
+ * OutputStream. Maybe switch the buffer to the brigade.
+ *
* @author Costin Manolache
*/
public class BodyWriter extends Writer {
@@ -34,7 +34,7 @@
protected static final int WRITER_NOTE = 3;
- private ByteChunk.ByteOutputChannel byteFlusher =
+ private ByteChunk.ByteOutputChannel byteFlusher =
new ByteChunk.ByteOutputChannel() {
@Override
@@ -44,7 +44,7 @@
}
};
- private CharChunk.CharOutputChannel charFlusher =
+ private CharChunk.CharOutputChannel charFlusher =
new CharChunk.CharOutputChannel() {
@Override
public void realWriteChars(char[] cbuf, int off, int len)
@@ -52,9 +52,9 @@
BodyWriter.this.realWriteChars(cbuf, off, len);
}
};
-
- public static final String DEFAULT_ENCODING =
+
+ public static final String DEFAULT_ENCODING =
org.apache.coyote.Constants.DEFAULT_CHARACTER_ENCODING;
public static final int DEFAULT_BUFFER_SIZE = 8*1024;
@@ -119,7 +119,7 @@
/**
- * Encoding to use.
+ * Encoding to use.
* TODO: isn't it redundant ? enc, gotEnc, conv plus the enc in the bb
*/
protected String enc;
@@ -132,7 +132,7 @@
/**
- * List of encoders. The writer is reused - the encoder mapping
+ * List of encoders. The writer is reused - the encoder mapping
* avoids creating expensive objects. In future it'll contain nio.Charsets
*/
protected HashMap encoders = new HashMap();
@@ -166,7 +166,7 @@
/**
* Alternate constructor which allows specifying the initial buffer size.
- *
+ *
* @param size Buffer size to use
*/
public BodyWriter(int size) {
@@ -179,7 +179,7 @@
cb.setLimit(size);
}
-
+
public void setConnector(Connector c, ServletResponseImpl res) {
this.res = res;
this.connector = c;
@@ -191,7 +191,7 @@
/**
* Is the response output suspended ?
- *
+ *
* @return suspended flag value
*/
public boolean isSuspended() {
@@ -201,7 +201,7 @@
/**
* Set the suspended flag.
- *
+ *
* @param suspended New suspended flag value
*/
public void setSuspended(boolean suspended) {
@@ -216,31 +216,31 @@
* Recycle the output buffer.
*/
public void recycle() {
-
+
state = BYTE_STATE;
headersSent = false;
bytesWritten = 0;
charsWritten = 0;
-
+
cb.recycle();
- bb.recycle();
+ bb.recycle();
closed = false;
suspended = false;
-
+
if (conv!= null) {
conv.recycle();
}
-
+
gotEnc = false;
enc = null;
-
+
}
/**
- * Close the output buffer. This tries to calculate the response size if
+ * Close the output buffer. This tries to calculate the response size if
* the response has not been committed yet.
- *
+ *
* @throws IOException An underlying IOException occurred
*/
public void close()
@@ -266,7 +266,7 @@
/**
* Flush bytes or chars contained in the buffer.
- *
+ *
* @throws IOException An underlying IOException occurred
*/
public void flush()
@@ -276,7 +276,7 @@
/**
* Flush bytes or chars contained in the buffer.
- *
+ *
* @throws IOException An underlying IOException occurred
*/
protected void doFlush(boolean realFlush)
@@ -294,10 +294,10 @@
if (state == CHAR_STATE) {
cb.flushBuffer();
state = BYTE_STATE;
- }
+ }
if (state == BYTE_STATE) {
bb.flushBuffer();
- }
+ }
doFlush = false;
if (realFlush) {
@@ -310,14 +310,14 @@
// ------------------------------------------------- Bytes Handling Methods
- /**
+ /**
* Sends the buffer data to the client output, checking the
* state of Response and calling the right interceptors.
- *
+ *
* @param buf Byte buffer to be written to the response
* @param off Offset
* @param cnt Length
- *
+ *
* @throws IOException An underlying IOException occurred
*/
private void realWriteBytes(byte buf[], int off, int cnt)
@@ -356,7 +356,7 @@
}
- private void writeBytes(byte b[], int off, int len)
+ private void writeBytes(byte b[], int off, int len)
throws IOException {
if (closed)
@@ -432,7 +432,7 @@
}
- public void write(StringBuffer sb)
+ public void write(StringBuilder sb)
throws IOException {
if (suspended)
@@ -477,7 +477,7 @@
s="null";
write(s, 0, s.length());
- }
+ }
public void println() throws IOException {
write("\n");
@@ -511,7 +511,7 @@
}
- private void realWriteChars(char c[], int off, int len)
+ private void realWriteChars(char c[], int off, int len)
throws IOException {
if (!gotEnc)
@@ -523,7 +523,7 @@
}
- public void checkConverter()
+ public void checkConverter()
throws IOException {
if (!gotEnc)
@@ -532,7 +532,7 @@
}
- protected void setConverter()
+ protected void setConverter()
throws IOException {
enc = res.getCharacterEncoding();
@@ -542,7 +542,7 @@
enc = DEFAULT_ENCODING;
conv = (C2BConverter) encoders.get(enc);
if (conv == null) {
-
+
if (System.getSecurityManager() != null){
try{
conv = (C2BConverter)AccessController.doPrivileged(
@@ -553,22 +553,22 @@
}
}
- );
+ );
}catch(PrivilegedActionException ex){
Exception e = ex.getException();
if (e instanceof IOException)
- throw (IOException)e;
+ throw (IOException)e;
}
} else {
conv = new C2BConverter(bb, enc);
}
-
+
encoders.put(enc, conv);
}
}
-
+
// -------------------- BufferedOutputStream compatibility
@@ -598,9 +598,9 @@
}
- /**
+ /**
* True if this buffer hasn't been used ( since recycle() ) -
- * i.e. no chars or bytes have been added to the buffer.
+ * i.e. no chars or bytes have been added to the buffer.
*/
public boolean isNew() {
return (bytesWritten == 0) && (charsWritten == 0);
@@ -642,7 +642,7 @@
// public abstract void recycle();
// public abstract void setSuspended(boolean suspended);
// public abstract boolean isSuspended();
-//
+//
// public abstract void reset();
// public abstract int getBufferSize();
// public abstract void setBufferSize(int n);
@@ -652,5 +652,5 @@
// }
// public abstract void write(byte[] b, int off, int len) throws IOException;
// public abstract void writeByte(int b) throws IOException;
-//
+//
//}
\ No newline at end of file
Modified: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/FilterConfigImpl.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/FilterConfigImpl.java?rev=833521&r1=833520&r2=833521&view=diff==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/FilterConfigImpl.java (original)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/FilterConfigImpl.java Fri Nov 6 18:53:57 2009
@@ -1,12 +1,12 @@
/*
* Copyright 1999,2004 The Apache Software Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
*
http://www.apache.org/licenses/LICENSE-2.0- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -19,6 +19,7 @@
import java.util.ArrayList;
+import java.util.Collection;
import java.util.EnumSet;
import java.util.Enumeration;
import java.util.HashSet;
@@ -36,36 +37,36 @@
import org.apache.tomcat.servlets.util.Enumerator;
-/**
+/**
* A Filter is configured in web.xml by:
* - name - used in mappings
* - className - used to instantiate the filter
* - init params
* - other things not used in the servlet container ( icon, descr, etc )
- *
+ *
* Alternatively, in API mode you can pass the actual filter.
- *
+ *
* @see ServletConfigImpl
*/
public final class FilterConfigImpl implements FilterConfig, FilterRegistration {
DynamicFilterRegistration dynamic = new DynamicFilterRegistration();
-
+
public FilterConfigImpl(ServletContextImpl context) {
this.ctx = context;
}
-
+
boolean asyncSupported;
-
+
private ServletContextImpl ctx = null;
/**
* The application Filter we are configured for.
*/
private transient Filter filter = null;
-
+
String descryption;
-
+
private String filterName;
private String filterClassName;
@@ -80,11 +81,11 @@
this.filterClassName = filterClass;
this.initParams = params;
}
-
+
public void setFilter(Filter f) {
filter = f;
}
-
+
public String getFilterName() {
return filterName;
}
@@ -92,7 +93,7 @@
public void setFilterClass(Class<? extends Filter> filterClass2) {
this.filterClass = filterClass2;
}
-
+
public String getInitParameter(String name) {
if (initParams == null) return null;
@@ -140,17 +141,17 @@
filterClass = (Class<? extends Filter>) classLoader.loadClass(filterClassName);
}
this.filter = (Filter) filterClass.newInstance();
- } finally {
+ } finally {
if (classLoader != oldCtxClassLoader) {
Thread.currentThread().setContextClassLoader(oldCtxClassLoader);
}
}
-
+
// TODO: resource injection
-
+
return filter;
}
-
+
public Filter getFilter() throws ClassCastException, ClassNotFoundException, IllegalAccessException, InstantiationException, ServletException {
Filter filter = createFilter();
filter.init(this);
@@ -169,12 +170,13 @@
this.filter = null;
}
- @Override
+
+ @Override
public void addMappingForServletNames(EnumSet<DispatcherType> dispatcherTypes,
boolean isMatchAfter,
String... servletNames) {
if (ctx.startDone) {
- // Use the context method instead of the servlet API to
+ // Use the context method instead of the servlet API to
// add mappings after context init.
throw new IllegalStateException();
}
@@ -188,12 +190,13 @@
}
}
- @Override
+
+ @Override
public void addMappingForUrlPatterns(EnumSet<DispatcherType> dispatcherTypes,
boolean isMatchAfter,
String... urlPatterns) {
if (ctx.startDone) {
- // Use the context method instead of the servlet API to
+ // Use the context method instead of the servlet API to
// add mappings after context init.
throw new IllegalStateException();
}
@@ -207,66 +210,138 @@
}
}
- @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<String> setInitParameters(Map<String, String> initParameters)
throws IllegalArgumentException, IllegalStateException {
- return ServletContextImpl.setInitParameters(ctx, initParams,
+ return ServletContextImpl.setInitParameters(ctx, initParams,
initParameters);
}
-
+
public Dynamic getDynamic() {
return dynamic;
}
-
+
public class DynamicFilterRegistration implements Dynamic {
- @Override
+
+ @Override
public void addMappingForServletNames(EnumSet<DispatcherType> dispatcherTypes,
boolean isMatchAfter,
String... servletNames) {
FilterConfigImpl.this.addMappingForServletNames(dispatcherTypes, isMatchAfter, servletNames);
}
- @Override
+
+ @Override
public void addMappingForUrlPatterns(EnumSet<DispatcherType> 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<String> setInitParameters(Map<String, String> 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<String> getUrlPatternMappings() {
+ // implement me
+ return null;
+ }
+
+ @Override
+ public Collection<String> getServletNameMappings() {
+ // implement me
+ return null;
+ }
+
+ @Override
+ public Map<String, String> 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<String> getUrlPatternMappings() {
+ // implement me
+ return null;
+ }
+
+ @Override
+ public Collection<String> getServletNameMappings() {
+ // implement me
+ return null;
+ }
+
+ @Override
+ public Map<String, String> getInitParameters() {
+ // implement me
+ return null;
+ }
+
+ @Override
+ public String getClassName() {
+ // implement me
+ return null;
+ }
+
+ @Override
+ public String getName() {
+ // implement me
+ return null;
}
-
}
Modified: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletConfigImpl.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletConfigImpl.java?rev=833521&r1=833520&r2=833521&view=diff==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletConfigImpl.java (original)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletConfigImpl.java Fri Nov 6 18:53:57 2009
@@ -1,12 +1,12 @@
/*
* Copyright 1999-2002,2004 The Apache Software Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
*
http://www.apache.org/licenses/LICENSE-2.0- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -19,6 +19,7 @@
import java.io.PrintStream;
import java.lang.reflect.Method;
+import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
@@ -28,11 +29,14 @@
import java.util.logging.Level;
import java.util.logging.Logger;
+
+import javax.servlet.MultipartConfigElement;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
+import javax.servlet.ServletSecurityElement;
import javax.servlet.SingleThreadModel;
import javax.servlet.UnavailableException;
@@ -42,7 +46,7 @@
/**
* Based on Wrapper.
- *
+ *
* Standard implementation of the <b>Wrapper</b> interface that represents
* an individual servlet definition. No child Containers are allowed, and
* the parent Container must be a Context.
@@ -52,11 +56,11 @@
*/
@SuppressWarnings("deprecation")
public class ServletConfigImpl implements ServletConfig, ServletRegistration {
-
+
ServletDynamicRegistration dynamic = new ServletDynamicRegistration();
-
+
protected boolean asyncSupported;
-
+
private static Logger log=
Logger.getLogger(ServletConfigImpl.class.getName());
@@ -75,7 +79,7 @@
protected int loadOnStartup = -1;
protected String runAs;
protected Map securityRoleRef = new HashMap(); // roleName -> [roleLink]
-
+
/**
* The date and time at which this servlet will become available (in
* milliseconds since the epoch), or zero if the servlet is available.
@@ -83,14 +87,14 @@
* servlet is considered permanent.
*/
private transient long available = 0L;
-
+
private ServletContextImpl ctx;
/**
* The (single) initialized instance of this servlet.
*/
private transient Servlet instance = null;
-
+
/**
* Are we unloading our servlet instance at the moment?
*/
@@ -111,13 +115,13 @@
*/
private transient Stack instancePool = null;
-
+
// Statistics
private transient long loadTime=0;
private transient int classLoadTime=0;
// ------------------------------------------------------------- Properties
- public ServletConfigImpl(ServletContextImpl ctx, String name,
+ public ServletConfigImpl(ServletContextImpl ctx, String name,
String classname) {
this.servletName = name;
this.servletClassName = classname;
@@ -177,7 +181,7 @@
public void setJspFile(String s) {
this.jspFile = s;
}
-
+
/**
* Return the load-on-startup order value (negative value means
* load on first call).
@@ -229,11 +233,11 @@
HashSet allow = new HashSet();
allow.add("TRACE");
allow.add("OPTIONS");
-
+
Method[] methods = getAllDeclaredMethods(servletClazz);
for (int i=0; methods != null && i<methods.length; i++) {
Method m = methods[i];
-
+
if (m.getName().equals("doGet")) {
allow.add("GET");
allow.add("HEAD");
@@ -257,7 +261,7 @@
/**
* Extract the root cause from a servlet exception.
- *
+ *
* @param e The servlet exception
*/
public static Throwable getRootCause(ServletException e) {
@@ -280,15 +284,15 @@
/**
* MUST be called before service()
- * This method should be called to get the servlet. After
+ * This method should be called to get the servlet. After
* service(), dealocate should be called. This deals with STM and
* update use counters.
- *
+ *
* Normally called from RequestDispatcher and TomcatLite.
*/
public Servlet allocate() throws ServletException {
// If we are currently unloading this servlet, throw an exception
- if (unloading)
+ if (unloading)
throw new ServletException
("allocate() while unloading " + getServletName());
@@ -316,10 +320,10 @@
countAllocated++;
return (instance);
}
-
+
// Simpler policy for ST: unbound number of servlets ( can grow to
// one per thread )
-
+
synchronized (instancePool) {
if (instancePool.isEmpty()) {
try {
@@ -330,7 +334,7 @@
}
countAllocated++;
Servlet newServlet = loadServlet();
- log.fine("New STM servet " + newServlet + " " +
+ log.fine("New STM servet " + newServlet + " " +
countAllocated);
return newServlet;
} catch (ServletException e) {
@@ -344,7 +348,7 @@
countAllocated);
Servlet s = (Servlet) instancePool.pop();
countAllocated++;
- log.fine("After get " + instancePool.size() + " " + s +
+ log.fine("After get " + instancePool.size() + " " + s +
" " + countAllocated);
return s;
}
@@ -365,11 +369,11 @@
synchronized (instancePool) {
countAllocated--;
if (instancePool.contains(servlet)) {
- System.err.println("Aleady in pool " + servlet + " "
+ System.err.println("Aleady in pool " + servlet + " "
+ instancePool.size()+ " " + countAllocated);
return;
}
- System.err.println("return pool " + servlet + " " +
+ System.err.println("return pool " + servlet + " " +
instancePool.size() + " " + countAllocated);
instancePool.push(servlet);
}
@@ -384,7 +388,7 @@
if (actualClass == null) {
// No explicit name. Try to use the framework
if (jspFile != null) {
-
+
// Named JSPs can be handled by a servlet or by the mapper.
Servlet res = (Servlet) ctx.getObjectManager().get("filetemplate-servlet");
if (res != null) {
@@ -393,7 +397,7 @@
initParams.put("jsp-file", jspFile);
return res;
} else {
- UserTemplateClassMapper mapper =
+ UserTemplateClassMapper mapper =
(UserTemplateClassMapper) ctx.getObjectManager().get(
UserTemplateClassMapper.class);
if (mapper != null) {
@@ -415,36 +419,36 @@
//ctx.getObjectManager().getObject(c);
//ctx.getObjectManager().getObject(servletName);
}
-
-
+
+
if (servletClass == null) {
// set classClass
loadClass(actualClass);
}
-
- // jsp-file case. Load the JspProxyServlet instead, with the
- // right params. Note the JspProxyServlet is _not_ jasper,
- // nor 'jsp' servlet - it is just a proxy with no special
+
+ // jsp-file case. Load the JspProxyServlet instead, with the
+ // right params. Note the JspProxyServlet is _not_ jasper,
+ // nor 'jsp' servlet - it is just a proxy with no special
// params. It calls the jsp servlet and jasper to generate the
// real class.
-
+
// this is quite different from catalina, where an ugly kludge was
// used to use the same jsp servlet in 2 roles
-
+
// the jsp proxy is replaced by the web.xml processor
-
+
if (servletClass == null) {
unavailable(null);
throw new UnavailableException("ClassNotFound: " + actualClass);
}
-
+
// Instantiate and initialize an instance of the servlet class itself
try {
return (Servlet) servletClass.newInstance();
} catch (ClassCastException e) {
unavailable(null);
- throw new UnavailableException("ClassCast: (Servlet)" +
+ throw new UnavailableException("ClassCast: (Servlet)" +
actualClass);
} catch (Throwable e) {
unavailable(null);
@@ -452,13 +456,13 @@
// Added extra log statement for Bugzilla 36630:
//
http://issues.apache.org/bugzilla/show_bug.cgi?id=36630 if(log.isLoggable(Level.FINE)) {
- log.log(Level.FINE, "newInstance() error: servlet-name: " +
+ log.log(Level.FINE, "newInstance() error: servlet-name: " +
getServletName() +
" servlet-class: " + actualClass, e);
}
// Restore the context ClassLoader
- throw new ServletException("newInstance() error " + getServletName() +
+ throw new ServletException("newInstance() error " + getServletName() +
" " + actualClass, e);
}
}
@@ -473,13 +477,13 @@
// Nothing to do if we already have an instance or an instance pool
if (!singleThreadModel && (instance != null))
return instance;
-
+
long t1=System.currentTimeMillis();
Servlet servlet = newInstance();
-
+
classLoadTime=(int) (System.currentTimeMillis() -t1);
-
+
// Call the initialization method of this servlet
try {
servlet.init(this);
@@ -500,7 +504,7 @@
instancePool = new Stack();
}
loadTime=System.currentTimeMillis() -t1;
-
+
return servlet;
}
@@ -509,14 +513,14 @@
// Complain if no servlet class has been specified
if (actualClass == null) {
unavailable(null);
- throw new ServletException("servlet-class missing " +
+ throw new ServletException("servlet-class missing " +
getServletName());
}
-
- ClassLoader classLoader = ctx.getClassLoader();
- if (classLoader == null )
+
+ ClassLoader classLoader = ctx.getClassLoader();
+ if (classLoader == null )
classLoader = this.getClass().getClassLoader();
-
+
// Load the specified servlet class from the appropriate class loader
try {
servletClass = classLoader.loadClass(actualClass);
@@ -580,7 +584,7 @@
* destroy() method
*/
public synchronized void unload() throws ServletException {
- setAvailable(Long.MAX_VALUE);
+ setAvailable(Long.MAX_VALUE);
// Nothing to do if we have never loaded the instance
if (!singleThreadModel && (instance == null))
@@ -594,7 +598,7 @@
long delay = ctx.getUnloadDelay() / 20;
while ((nRetries < 21) && (countAllocated > 0)) {
if ((nRetries % 10) == 0) {
- log.info("Servlet.unload() timeout " +
+ log.info("Servlet.unload() timeout " +
countAllocated);
}
try {
@@ -610,7 +614,7 @@
Thread.currentThread().getContextClassLoader();
if (instance != null) {
ClassLoader classLoader = instance.getClass().getClassLoader();
-
+
PrintStream out = System.out;
// Call the servlet destroy() method
try {
@@ -620,13 +624,13 @@
instance = null;
//instancePool = null;
unloading = false;
- throw new ServletException("Servlet.destroy() " +
+ throw new ServletException("Servlet.destroy() " +
getServletName(), t);
} finally {
// restore the context ClassLoader
Thread.currentThread().setContextClassLoader(oldCtxClassLoader);
}
-
+
// Deregister the destroyed instance
instance = null;
}
@@ -653,8 +657,8 @@
unloading = false;
}
-
-
+
+
/**
* Return the initialization parameter value for the specified name,
* if any; otherwise return <code>null</code>.
@@ -772,33 +776,33 @@
if ((parentMethods != null) && (parentMethods.length > 0)) {
Method[] allMethods =
new Method[parentMethods.length + thisMethods.length];
- System.arraycopy(parentMethods, 0, allMethods, 0,
+ System.arraycopy(parentMethods, 0, allMethods, 0,
parentMethods.length);
- System.arraycopy(thisMethods, 0, allMethods, parentMethods.length,
+ System.arraycopy(thisMethods, 0, allMethods, parentMethods.length,
thisMethods.length);
- thisMethods = allMethods;
- }
+ thisMethods = allMethods;
+ }
- return thisMethods;
+ return thisMethods;
}
/** Specify the instance. Avoids the class lookup, disables unloading.
* Use for embedded case, or to control the allocation.
- *
+ *
* @param servlet
*/
public void setServlet(Servlet servlet) {
instance = servlet;
ctx.getObjectManager().bind("Servlet:" +
- ctx.getContextPath() + ":" + getServletName(),
+ ctx.getContextPath() + ":" + getServletName(),
this);
}
public String getSecurityRoleRef(String role) {
return (String)securityRoleRef.get(role);
}
-
+
public void setSecurityRoleRef(Map securityRoles) {
this.securityRoleRef = securityRoles;
}
@@ -811,10 +815,10 @@
this.loadOnStartup = loadOnStartup;
}
- @Override
+ @Override
public Set<String> addMapping(String... urlPatterns) {
if (ctx.startDone) {
- // Use the context method instead of the servlet API to
+ // Use the context method instead of the servlet API to
// add mappings after context init.
throw new IllegalStateException();
}
@@ -833,41 +837,154 @@
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<String> setInitParameters(Map<String, String> initParameters)
throws IllegalArgumentException, IllegalStateException {
- return ServletContextImpl.setInitParameters(ctx, initParams,
+ return ServletContextImpl.setInitParameters(ctx, initParams,
initParameters);
}
public Dynamic getDynamic() {
return dynamic;
}
-
+
class ServletDynamicRegistration implements Dynamic {
+
@Override
public void setAsyncSupported(boolean isAsyncSupported)
throws IllegalStateException {
asyncSupported = isAsyncSupported;
}
- @Override
+
public void setDescription(String description)
throws IllegalStateException {
ServletConfigImpl.this.description = description;
}
-
+
+ @Override
+ public Set<String> 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<String> getMappings() {
+ //implement me
+ return null;
+ }
+
+ @Override
+ public Set<String> addMapping(String... urlPatterns) {
+ //implement me
+ return null;
+ }
+
+ @Override
+ public Map<String, String> getInitParameters() {
+ // implement me
+ return null;
+ }
+
+ @Override
+ public Set<String> setInitParameters(Map<String, String> 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<String> getMappings() {
+ //implement me
+ return null;
}
public void setServletClass(Class<? extends Servlet> servletClass2) {
servletClass = servletClass2;
}
+
+
+ @Override
+ public String getRunAsRole() {
+ //implement me
+ return null;
+ }
+
+
+ @Override
+ public Map<String, String> getInitParameters() {
+ // implement me
+ return null;
+ }
+
+ @Override
+ public String getClassName() {
+ // implement me
+ return null;
+ }
+
+ @Override
+ public String getName() {
+ // implement me
+ return null;
+ }
+
}
Modified: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletContextImpl.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletContextImpl.java?rev=833521&r1=833520&r2=833521&view=diff==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletContextImpl.java (original)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletContextImpl.java Fri Nov 6 18:53:57 2009
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
*
http://www.apache.org/licenses/LICENSE-2.0- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -27,6 +27,7 @@
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.EnumSet;
import java.util.Enumeration;
import java.util.EventListener;
@@ -57,6 +58,7 @@
import javax.servlet.SessionCookieConfig;
import javax.servlet.SessionTrackingMode;
import javax.servlet.FilterRegistration.Dynamic;
+import javax.servlet.descriptor.JspConfigDescriptor;
import org.apache.tomcat.addons.UserSessionManager;
import org.apache.tomcat.integration.ObjectManager;
@@ -72,15 +74,15 @@
/**
* Context - initialized from web.xml or using APIs.
- *
+ *
* Initialization order:
- *
+ *
* - add all listeners
* - add all filters
* - add all servlets
- *
+ *
* - session parameters
- * -
+ * -
*
* @author Craig R. McClanahan
* @author Remy Maucherat
@@ -88,14 +90,14 @@
*/
public class ServletContextImpl implements ServletContext {
-
+
/**
* Empty collection to serve as the basis for empty enumerations.
*/
private transient static final ArrayList empty = new ArrayList();
-
+
transient Logger log;
-
+
/**
* Base path - the directory root of the webapp
*/
@@ -123,7 +125,7 @@
protected transient ArrayList<EventListener> lifecycleListeners = new ArrayList();
protected UserSessionManager manager;
-
+
HashMap<String, FilterConfigImpl> filters = new HashMap<String, FilterConfigImpl>();
HashMap<String, ServletConfigImpl> servlets = new HashMap<String, ServletConfigImpl>();
@@ -133,16 +135,16 @@
/** Mapper for filters.
*/
protected WebappFilterMapper webappFilterMapper;
-
- /** Internal mapper for request dispatcher, must have all
- * context mappings.
- */
+
+ /** Internal mapper for request dispatcher, must have all
+ * context mappings.
+ */
protected WebappServletMapper mapper;
-
+
transient Locale2Charset charsetMapper = new Locale2Charset();
transient TomcatLite facade;
-
+
ObjectManager om;
private String hostname;
@@ -151,7 +153,7 @@
boolean initDone = false;
boolean startDone = false;
-
+
// ------------------------------------------------- ServletContext Methods
public ServletContextImpl() {
}
@@ -159,7 +161,7 @@
public void setTomcat(TomcatLite facade) {
this.facade = facade;
}
-
+
/**
* Registry/framework interface associated with the context.
* Also available as a context attribute.
@@ -171,11 +173,11 @@
}
return om;
}
-
+
public void setObjectManager(ObjectManager om) {
this.om = om;
}
-
+
public Locale2Charset getCharsetMapper() {
return charsetMapper;
}
@@ -188,29 +190,29 @@
this.contextPath = path;
log = Logger.getLogger("webapp" + path.replace('/', '.'));
}
-
+
public void setHostname(String hostname) {
this.hostname = hostname;
}
-
+
public String getHostname() {
return hostname;
}
-
+
/** The directory where this app is based. May be null.
- *
+ *
* @param basePath
*/
public void setBasePath(String basePath) {
- this.basePath = basePath;
+ this.basePath = basePath;
}
public ServletContextConfig getContextConfig() {
return contextConfig;
}
-
+
/** The directory where this app is based.
- *
+ *
* @param basePath
*/
public String getBasePath() {
@@ -234,11 +236,20 @@
public List<EventListener> getListeners() {
return lifecycleListeners;
}
-
- public void addListener(EventListener listener) {
- lifecycleListeners.add(listener);
+
+ public void addListener(Class <? extends EventListener> listenerClass) {
+ // implement me
+ }
+
+ public void addListener(String className) {
+ // implement me
+ }
+
+ public <T extends EventListener> void addListener(T t) {
+ lifecycleListeners.add(t);
}
+
public void removeListener(EventListener listener) {
lifecycleListeners.remove(listener);
}
@@ -256,7 +267,7 @@
public ServletConfigImpl getServletConfig(String jsp_servlet_name) {
return (ServletConfigImpl)servlets.get(jsp_servlet_name);
}
-
+
public Map getServletConfigs() {
return servlets;
}
@@ -264,27 +275,27 @@
/**
* Add a servlet to the context.
* Called from processWebAppData()
- *
+ *
* @param servletConfig
*/
public void addServletConfig(ServletConfigImpl servletConfig) {
servlets.put(servletConfig.getServletName(), servletConfig);
}
-
+
public boolean getPrivileged() {
return false;
}
-
+
public Map getFilters() {
return filters;
}
-
+
protected boolean getCrossContext() {
return true;
}
-
+
public void addMimeType(String ext, String type) {
contentTypes.addContentType(ext, type);
}
@@ -302,7 +313,7 @@
return mapper;
}
-
+
public WebappFilterMapper getFilterMapper() {
if (webappFilterMapper == null) {
Object customMapper = getObjectManager().get(WebappFilterMapper.class);
@@ -316,7 +327,7 @@
return webappFilterMapper ;
}
-
+
public FilterConfigImpl getFilter(String name) {
return (FilterConfigImpl)filters.get(name);
}
@@ -349,7 +360,7 @@
public void addSecurityRole(String role) {
securityRoles.add(role);
}
-
+
public List getSecurityRoles() {
return securityRoles;
}
@@ -392,14 +403,14 @@
}
}
-
+
/**
* 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 RequestDispatcher getNamedDispatcher(String name) {
if (name == null) return null;
- ServletConfigImpl wrapper =
+ ServletConfigImpl wrapper =
(ServletConfigImpl) this.getServletConfig(name);
if (wrapper == null) return null;
-
+
return new RequestDispatcherImpl(wrapper, name);
}
@@ -490,18 +501,18 @@
*/
public RequestDispatcher getRequestDispatcher(String path) {
if (path == null) return null;
-
+
if (!path.startsWith("/"))
throw new IllegalArgumentException(path);
path = UrlUtils.normalize(path);
if (path == null) return (null);
-
+
return new RequestDispatcherImpl(this, path);
}
- public RequestDispatcher getRequestDispatcher(String path,
+ public RequestDispatcher getRequestDispatcher(String path,
int type,
String dispatcherPath) {
RequestDispatcher dispatcher = getRequestDispatcher(path);
@@ -512,23 +523,23 @@
ThreadLocal requestDispatcherStack = new ThreadLocal();
protected ClassLoader classLoader;
-
+
// protected RequestDispatcherImpl getRequestDispatcher() {
-// ArrayList/*<RequestDispatcherImpl>*/ list =
+// ArrayList/*<RequestDispatcherImpl>*/ list =
// (ArrayList)requestDispatcherStack.get();
// if (list == null) {
// list = new ArrayList();
// requestDispatcherStack.set(list);
// }
-//
-//
+//
+//
// return null;
// }
public void resetDispatcherStack() {
-
+
}
-
+
/**
* Return the URL to the resource that is mapped to a specified path.
* The path must begin with a "/" and is interpreted as relative to the
@@ -545,7 +556,7 @@
if (path == null || !path.startsWith("/")) {
throw new MalformedURLException("getResource() " + path);
}
-
+
path = UrlUtils.normalize(path);
if (path == null)
return (null);
@@ -585,9 +596,9 @@
return (null);
File resFile = new File(basePath + path);
- if (!resFile.exists())
+ if (!resFile.exists())
return null;
-
+
try {
return new FileInputStream(resFile);
} catch (FileNotFoundException e) {
@@ -624,7 +635,7 @@
if (!path.endsWith("/")) {
path = path + "/";
}
-
+
HashSet result = new HashSet();
for (int i=0; i < files.length; i++) {
if (files[i].isDirectory() ) {
@@ -807,7 +818,7 @@
event =
new ServletContextAttributeEvent(this.getServletContext(),
name, value);
-
+
}
if (replaced) {
listener.attributeReplaced(event);
@@ -843,7 +854,7 @@
removeAttribute(key);
}
}
-
+
public void initFilters() throws ServletException {
Iterator fI = getFilters().values().iterator();
while (fI.hasNext()) {
@@ -851,16 +862,16 @@
try {
fc.getFilter(); // will triger init()
} catch (Throwable e) {
- log.log(Level.WARNING, getContextPath() + " Filter.init() " +
+ log.log(Level.WARNING, getContextPath() + " Filter.init() " +
fc.getFilterName(), e);
- }
-
+ }
+
}
}
-
+
public void initServlets() throws ServletException {
Iterator fI = getServletConfigs().values().iterator();
- Map/*<Integer, List<ServletConfigImpl>>*/ onStartup =
+ Map/*<Integer, List<ServletConfigImpl>>*/ onStartup =
new TreeMap/*<Integer, List<ServletConfigImpl>>*/();
while (fI.hasNext()) {
ServletConfigImpl fc = (ServletConfigImpl)fI.next();
@@ -877,15 +888,15 @@
Iterator keys = onStartup.keySet().iterator();
while (keys.hasNext()) {
Integer key = (Integer)keys.next();
- List/*<ServletConfigImpl>*/ servlets = (List)onStartup.get(key);
+ List/*<ServletConfigImpl>*/ servlets = (List)onStartup.get(key);
Iterator servletsI = servlets.iterator();
while (servletsI.hasNext()) {
ServletConfigImpl fc = (ServletConfigImpl) servletsI.next();
try {
- fc.loadServlet();
+ fc.loadServlet();
} catch (Throwable e) {
log.log(Level.WARNING, "Error initializing " + fc.getServletName(), e);
- }
+ }
}
}
}
@@ -895,19 +906,19 @@
while (fI.hasNext()) {
String listenerClass = (String)fI.next();
try {
- Object l =
+ Object l =
getClassLoader().loadClass(listenerClass).newInstance();
lifecycleListeners.add((EventListener) l);
} catch (Throwable e) {
log.log(Level.WARNING, "Error initializing listener " + listenerClass, e);
- }
+ }
}
}
public ClassLoader getClassLoader() {
return classLoader;
}
-
+
public void addMapping(String path, String name) {
ServletConfigImpl wrapper = getServletConfig(name);
addMapping(path, wrapper);
@@ -916,9 +927,9 @@
public void addMapping(String path, ServletConfig wrapper) {
getMapper().addWrapper(getMapper().contextMapElement, path, wrapper);
}
-
-
-
+
+
+
public void setWelcomeFiles(String[] name) {
getMapper().contextMapElement.welcomeResources = name;
}
@@ -928,21 +939,21 @@
}
public void setSessionTimeout(int to) {
- getManager().setSessionTimeout(to);
+ getManager().setSessionTimeout(to);
}
-
+
/**
* Initialize the context from the parsed config.
- *
+ *
* Note that WebAppData is serializable.
*/
public void processWebAppData(ServletContextConfig d) throws ServletException {
this.contextConfig = d;
-
+
for (String k: d.mimeMapping.keySet()) {
- addMimeType(k, d.mimeMapping.get(k));
+ addMimeType(k, d.mimeMapping.get(k));
}
-
+
String[] wFiles = (String[])d.welcomeFileList.toArray(new String[0]);
if (wFiles.length == 0) {
wFiles = new String[] {"index.html" };
@@ -951,64 +962,64 @@
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 @@
}
@Override
- public javax.servlet.Registration.Dynamic addServlet(String servletName, Servlet servlet) {
+ public javax.servlet.ServletRegistration.Dynamic addServlet(String servletName, Servlet servlet) {
ServletConfigImpl sc = new ServletConfigImpl(this, servletName, null);
sc.setServlet(servlet);
addServletConfig(sc);
return sc.getDynamic();
}
-
+
public void addServletSec(String serlvetName, String runAs, Map roles) {
// TODO
}
-
-
-
- public void addFilterMapping(String path, String filterName,
+
+
+
+ public void addFilterMapping(String path, String filterName,
String[] dispatcher) {
- getFilterMapper().addMapping(filterName,
+ getFilterMapper().addMapping(filterName,
path, null, dispatcher, true);
-
+
}
- public void addFilterServletMapping(String servlet,
- String filterName,
+ public void addFilterServletMapping(String servlet,
+ String filterName,
String[] dispatcher) {
- getFilterMapper().addMapping(filterName,
- null, servlet,
- dispatcher, true);
+ getFilterMapper().addMapping(filterName,
+ null, servlet,
+ dispatcher, true);
}
-
+
/**
* Called from TomcatLite.init(), required before start.
- *
- * Will initialize defaults and load web.xml unless webAppData is
+ *
+ * Will initialize defaults and load web.xml unless webAppData is
* already set and recent. No other processing is done except reading
* the config - you can add or alter it before start() is called.
- *
+ *
* @throws ServletException
*/
public void init() throws ServletException {
@@ -1060,51 +1071,51 @@
initDone = true;
// Load global init params from the facade
initEngineDefaults();
-
+
initTempDir();
-
+
// Merge in web.xml - or other config source ( programmatic, etc )
- ContextPreinitListener cfg =
- (ContextPreinitListener) getObjectManager().get(
+ ContextPreinitListener cfg =
+ (ContextPreinitListener) getObjectManager().get(
ContextPreinitListener.class);
if (cfg != null) {
cfg.preInit(this);
}
processWebAppData(contextConfig);
-
+
// if not defined yet:
addDefaultServlets();
}
-
-
+
+
protected void initTempDir() throws ServletException {
- // We need a base path - at least for temp files, req. by spec
+ // We need a base path - at least for temp files, req. by spec
if (basePath == null) {
basePath = ("/".equals(contextPath)) ?
facade.getWork().getAbsolutePath() + "/ROOT" :
facade.getWork().getAbsolutePath() + contextPath;
}
-
+
File f = new File(basePath + "/WEB-INF/tmp");
f.mkdirs();
setAttribute("javax.servlet.context.tempdir", f);
}
-
+
/**
* Static file handler ( default )
* *.jsp support
- *
+ *
*/
protected void addDefaultServlets() throws ServletException {
if (servlets.get("default") == null) {
- ServletConfigImpl fileS = new ServletConfigImpl(this,
- "default", null);
+ ServletConfigImpl fileS = new ServletConfigImpl(this,
+ "default", null);
addServletConfig(fileS);
addMapping("/", fileS);
}
-
+
// *.jsp support
if (servlets.get("jspwildcard") == null) {
ServletConfigImpl fileS = new ServletConfigImpl(this,
@@ -1113,9 +1124,9 @@
addMapping("*.jsp", fileS);
}
}
-
+
protected void initEngineDefaults() throws ServletException {
-
+
// TODO: make this customizable, avoid loading it on startup
// Set the class name as default in the addon support
for (String sname: facade.ctxDefaultInitParam.keySet()) {
@@ -1128,7 +1139,7 @@
ServletConfigImpl fileS = new ServletConfigImpl(this, sname, sclass);
addServletConfig(fileS);
}
-
+
for (String sname: facade.preloadMappings.keySet()) {
String path = facade.preloadMappings.get(sname);
ServletConfigImpl servletConfig = getServletConfig(sname);
@@ -1136,7 +1147,7 @@
}
}
-
+
public ArrayList getClasspath(File directory, File classesDir) {
ArrayList res = new ArrayList();
if (classesDir.isDirectory() && classesDir.exists() &&
@@ -1151,13 +1162,13 @@
|| !directory.canRead()) {
return res;
}
-
+
File[] jars = directory.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.endsWith(".jar");
}
});
-
+
for (int j = 0; j < jars.length; j++) {
try {
URL url = jars[j].toURL();
@@ -1174,13 +1185,13 @@
return;
}
String base = getBasePath();
-
+
ArrayList urls = getClasspath(new File(base + "/WEB-INF/lib"),
new File(base + "/WEB-INF/classes"));
URL[] urlsA = new URL[urls.size()];
urls.toArray(urlsA);
- URLClassLoader parentLoader =
+ URLClassLoader parentLoader =
getEngine().getContextParentLoader();
// create a class loader.
@@ -1192,14 +1203,14 @@
ctxRepo.addURL(urlsA);
repository = ctxRepo;
*/
-
+
classLoader = new URLClassLoader(urlsA, parentLoader);
-
+
// JMX should know about us ( TODO: is it too early ? )
facade.notifyAdd(this);
initListeners();
-
+
List listeners = this.getListeners();
ServletContextEvent event = null;
for (int i = 0; i < listeners.size(); i++) {
@@ -1218,10 +1229,10 @@
}
}
-
+
initFilters();
initServlets();
-
+
startDone = true;
}
@@ -1238,13 +1249,13 @@
}
- // TODO: configurable ? init-params
+ // TODO: configurable ? init-params
public String getSessionCookieName() {
return "JSESSIONID";
}
-
-
+
+
public void destroy() throws ServletException {
// destroy filters
Iterator fI = filters.values().iterator();
@@ -1271,7 +1282,7 @@
public TomcatLite getEngine() {
return facade;
}
-
+
public String findStatusPage(int status) {
if (contextConfig.errorPageCode.size() == 0) {
return null;
@@ -1283,9 +1294,9 @@
return (String) contextConfig.errorPageCode.get(Integer.toString(status));
}
- public void handleStatusPage(ServletRequestImpl req,
- ServletResponseImpl res,
- int status,
+ public void handleStatusPage(ServletRequestImpl req,
+ ServletResponseImpl res,
+ int status,
String statusPage) {
String message = RequestUtil.filter(res.getMessage());
if (message == null)
@@ -1297,20 +1308,20 @@
protected void setErrorAttributes(ServletRequestImpl req,
int status,
String message) {
- req.setAttribute("javax.servlet.error.status_code",
+ req.setAttribute("javax.servlet.error.status_code",
new Integer(status));
if (req.getWrapper() != null) {
- req.setAttribute("javax.servlet.error.servlet_name",
+ req.setAttribute("javax.servlet.error.servlet_name",
req.getWrapper().servletName);
}
- req.setAttribute("javax.servlet.error.request_uri",
+ req.setAttribute("javax.servlet.error.request_uri",
req.getRequestURI());
- req.setAttribute("javax.servlet.error.message",
+ req.setAttribute("javax.servlet.error.message",
message);
}
-
- public void handleError(ServletRequestImpl req,
+
+ public void handleError(ServletRequestImpl req,
ServletResponseImpl res,
Throwable t) {
Throwable realError = t;
@@ -1335,7 +1346,7 @@
dispatchError(req, res, errorPage);
} else {
log("Unhandled error", t);
- if (t instanceof ServletException &&
+ if (t instanceof ServletException &&
((ServletException)t).getRootCause() != null) {
log("RootCause:", ((ServletException)t).getRootCause());
}
@@ -1345,13 +1356,13 @@
}
}
- protected void dispatchError(ServletRequestImpl req,
- ServletResponseImpl res,
+ protected void dispatchError(ServletRequestImpl req,
+ ServletResponseImpl res,
String errorPage) {
RequestDispatcher rd =
getRequestDispatcher(errorPage);
try {
- // will clean up the buffer
+ // will clean up the buffer
rd.forward(req, res);
return; // handled
} catch (ServletException e) {
@@ -1360,7 +1371,7 @@
// TODO
}
}
-
+
protected String findErrorPage(Throwable exception) {
if (contextConfig.errorPageException.size() == 0) {
return null;
@@ -1382,32 +1393,38 @@
}
+
@Override
public EnumSet<SessionTrackingMode> getDefaultSessionTrackingModes() {
return null;
}
+
@Override
public EnumSet<SessionTrackingMode> getEffectiveSessionTrackingModes() {
return null;
}
+
@Override
public SessionCookieConfig getSessionCookieConfig() {
return null;
}
+
@Override
public void setSessionTrackingModes(EnumSet<SessionTrackingMode> sessionTrackingModes) {
}
- public void addFilter(String filterName, String filterClass,
+
+ public void addFilter(String filterName, String filterClass,
Map params) {
FilterConfigImpl fc = new FilterConfigImpl(this);
fc.setData(filterName, filterClass, params);
filters.put(filterName, fc);
}
-
+
+
@Override
public Dynamic addFilter(String filterName, String className) {
FilterConfigImpl fc = new FilterConfigImpl(this);
@@ -1416,6 +1433,7 @@
return fc.getDynamic();
}
+
@Override
public Dynamic addFilter(String filterName, Filter filter) {
FilterConfigImpl fc = new FilterConfigImpl(this);
@@ -1425,6 +1443,7 @@
return fc.getDynamic();
}
+
@Override
public Dynamic addFilter(String filterName, Class<? extends Filter> filterClass) {
FilterConfigImpl fc = new FilterConfigImpl(this);
@@ -1434,16 +1453,18 @@
return fc.getDynamic();
}
+
@Override
- public javax.servlet.Registration.Dynamic addServlet(String servletName,
+ public javax.servlet.ServletRegistration.Dynamic addServlet(String servletName,
String className) {
ServletConfigImpl sc = new ServletConfigImpl(this, servletName, className);
addServletConfig(sc);
return sc.getDynamic();
}
+
@Override
- public javax.servlet.Registration.Dynamic addServlet(String servletName,
+ public javax.servlet.ServletRegistration.Dynamic addServlet(String servletName,
Class<? extends Servlet> servletClass) {
ServletConfigImpl sc = new ServletConfigImpl(this, servletName, servletClass.getName());
sc.setServletClass(servletClass);
@@ -1451,10 +1472,11 @@
return sc.getDynamic();
}
- // That's tricky - this filter will have no name. We need to generate one
+ // That's tricky - this filter will have no name. We need to generate one
// because our code relies on names.
AtomicInteger autoName = new AtomicInteger();
-
+
+
@Override
public <T extends Filter> T createFilter(Class<T> c) throws ServletException {
FilterConfigImpl fc = new FilterConfigImpl(this);
@@ -1476,6 +1498,7 @@
}
}
+
@Override
public <T extends Servlet> T createServlet(Class<T> c) throws ServletException {
String filterName = "_tomcat_auto_servlet_" + autoName.incrementAndGet();
@@ -1490,23 +1513,25 @@
}
}
- @Override
+
public FilterRegistration findFilterRegistration(String filterName) {
return filters.get(filterName);
}
- @Override
+
public ServletRegistration findServletRegistration(String servletName) {
return servlets.get(servletName);
}
-
+
+
@Override
public boolean setInitParameter(String name, String value) {
HashMap<String, String> params = contextConfig.contextParam;
return setInitParameter(this, params, name, value);
}
-
- static Set<String> setInitParameters(ServletContextImpl ctx,
+
+
+ static Set<String> setInitParameters(ServletContextImpl ctx,
Map<String, String> params,
Map<String, String> initParameters)
throws IllegalArgumentException, IllegalStateException {
@@ -1524,14 +1549,14 @@
}
}
return result;
- }
+ }
/**
* true if the context initialization parameter with the given name and value was set successfully on this ServletContext, and false if it was not set because this ServletContext already contains a context initialization parameter with a matching name
* Throws:
* java.lang.IllegalStateException - if this ServletContext has already been initialized
*/
- static boolean setInitParameter(ServletContextImpl ctx, Map<String, String> params,
+ static boolean setInitParameter(ServletContextImpl ctx, Map<String, String> params,
String name, String value) {
if (name == null || value == null) {
throw new IllegalArgumentException();
@@ -1547,5 +1572,57 @@
return true;
}
}
+
+ public JspConfigDescriptor getJspConfigDescriptor() {
+ // fix me - just here to compile
+ return null;
+ }
+
+
+
+ public void declareRoles(String... roleNames) {
+ // implement me
+ }
+
+ public <T extends EventListener> T createListener(Class<T> c) throws ServletException {
+ // implement me
+ return null;
+ }
+
+ public Collection<String> getMappings() {
+ // implement me
+ return null;
+ }
+
+ public Map<String, ? extends FilterRegistration> getFilterRegistrations() {
+ // implement me
+ return null;
+ }
+
+ public FilterRegistration getFilterRegistration(String filterName) {
+ // implement me
+ return null;
+ }
+
+ public Map<String, ? extends ServletRegistration> getServletRegistrations() {
+ // implement me
+ return null;
+ }
+
+ public ServletRegistration getServletRegistration(String servletName) {
+ // implement me
+ return null;
+ }
+
+ public int getEffectiveMinorVersion() {
+ // implement me
+ return -1;
+ }
+
+ public int getEffectiveMajorVersion() {
+ // implement me
+ return -1;
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail:
dev-unsubscribe@...
For additional commands, e-mail:
dev-help@...