Author: costin
Date: Tue Sep 5 08:14:12 2006
New Revision: 440368
URL: http://svn.apache.org/viewvc?view=rev&rev=440368
Log:
Few more fixes
Modified:
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/ServletConfigImpl.java
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/ServletContextImpl.java
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/servlets/jsp/JspCompileServlet.java
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/servlets/jsp/JspProxyServlet.java
tomcat/sandbox/tomcat-lite/webapps/ROOT/WEB-INF/web.xml
Modified:
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/ServletConfigImpl.java
URL:
http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/ServletConfigImpl.java?view=diff&rev=440368&r1=440367&r2=440368
==============================================================================
---
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/ServletConfigImpl.java
(original)
+++
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/ServletConfigImpl.java
Tue Sep 5 08:14:12 2006
@@ -23,6 +23,7 @@
import java.lang.reflect.Method;
import java.util.Enumeration;
import java.util.HashSet;
+import java.util.Map;
import java.util.Stack;
import javax.servlet.Servlet;
@@ -57,10 +58,16 @@
public static final String JSP_SERVLET_CLASS =
"org.apache.tomcat.servlets.jsp.JspProxyServlet";
+ public static final String JSP_SERVLET_NAME = "jsp";
+
+ public static final String JSP_SERVLET_COMPILER_CLASS =
+ "org.apache.tomcat.servlets.jsp.JspCompileServlet";
+
+ public static final String JSP_SERVLET_COMPILER_NAME = "jspCompiler";
+
public static final String SINGLE_THREADED_PROXY =
"org.apache.tomcat.servlets.jsp.SingleThreadedProxyServlet";
- public static final String JSP_SERVLET_NAME = "jsp";
ServletData data;
@@ -110,6 +117,14 @@
ctx.facade.notifyAdd(this);
}
+ public ServletConfigImpl(ServletContextImpl ctx, String name,
+ String classname) {
+ data = new ServletData();
+ data.servletName = name;
+ data.servletClass = classname;
+ this.ctx = ctx;
+ ctx.facade.notifyAdd(this);
+ }
/**
* Return the available date/time for this servlet, in milliseconds since
Modified:
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/ServletContextImpl.java
URL:
http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/ServletContextImpl.java?view=diff&rev=440368&r1=440367&r2=440368
==============================================================================
---
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/ServletContextImpl.java
(original)
+++
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/ServletContextImpl.java
Tue Sep 5 08:14:12 2006
@@ -36,6 +36,7 @@
import java.util.Properties;
import java.util.Set;
import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
import javax.servlet.Filter;
import javax.servlet.RequestDispatcher;
@@ -97,6 +98,8 @@
transient Log log;
+ public static String CONTAINER_PREFIX = "__x_";
+
/**
* Prefix to use in servlet names that are used internally.
*/
@@ -125,7 +128,7 @@
/**
* The context attributes for this context.
*/
- private transient HashMap attributes = new HashMap();
+ private transient Map attributes = new ConcurrentHashMap();
/**
* List of read only attributes for this context.
@@ -291,11 +294,48 @@
* @param name Name of the context attribute to return
*/
public Object getAttribute(String name) {
+ if (name.startsWith(CONTAINER_PREFIX)) {
+ Object o = getContainerAttribute(name);
+ if (o != null) return o;
+ }
+ return (attributes.get(name));
+ }
- synchronized (attributes) {
- return (attributes.get(name));
+ /**
+ * Tomcat-lite core has the goal to provide maximum power to webapps, by
+ * exposing internals and allowing apps to take container-specific
+ * optimizations. However it tries to avoid the need for a servlet to
+ * depend on tomcat-lite, so servlets can be generic, but still check
+ * and use special features if tomcat-lite is detected.
+ *
+ * Example use of attributes ( and the tomcat-lite independent way ):
+ * - CONTAINER_PREFIX + servlet_ + servletname -> returns a servlet,
+ * similar with the old deprecated getServlet() method. Equivalent
+ * mechanism: have the serlvet load-on-startup and set the attribute with
+ * 'this'. Benefit: more power to the app on controlling the lifecycle,
+ * more flexiblity, use servlets as java beans, with real methods insted
+ * of just service() - a mini-component model based on servlets.
+ *
+ *
+ * @param name
+ */
+ private Object getContainerAttribute(String name) {
+ // special code to avoid load-on-startup for container servlets
+ // like jsp
+ if (name.startsWith(CONTAINER_PREFIX + "servlet_")) {
+ String sname = name.substring(CONTAINER_PREFIX.length() +
+ "servlet_".length());
+
+ ServletConfigImpl sc = getServletConfig(sname);
+ if (sc == null) return null;
+ try {
+ Servlet s = sc.loadServlet();
+ return s;
+ } catch (ServletException e) {
+ e.printStackTrace();
+ }
}
-
+ return null;
}
@@ -304,11 +344,7 @@
* associated with this context.
*/
public Enumeration getAttributeNames() {
-
- synchronized (attributes) {
- return new Enumerator(attributes.keySet(), true);
- }
-
+ return new Enumerator(attributes.keySet(), true);
}
@@ -684,15 +720,13 @@
boolean found = false;
// Remove the specified attribute
- synchronized (attributes) {
- // Check for read only attribute
- found = attributes.containsKey(name);
- if (found) {
- value = attributes.get(name);
- attributes.remove(name);
- } else {
- return;
- }
+ // Check for read only attribute
+ found = attributes.containsKey(name);
+ if (found) {
+ value = attributes.get(name);
+ attributes.remove(name);
+ } else {
+ return;
}
// Notify interested application event listeners
@@ -860,8 +894,6 @@
}
}
- public static final String INTERNAL_PREFIX = "_SERVLET_IMPL_";
-
public void initListeners() throws ServletException {
Iterator fI = webAppData.listenerClass.iterator();
while (fI.hasNext()) {
@@ -873,12 +905,9 @@
} catch (Throwable e) {
log.warn("Error initializing listener " + listenerClass, e);
}
-
}
- setAttribute(INTERNAL_PREFIX + ".EventListeners", lifecycleListeners);
-
+ setAttribute(CONTAINER_PREFIX + ".EventListeners", lifecycleListeners);
}
- public static String CONTAINER_PREFIX = "__x_";
public ClassLoader getClassLoader() {
if( repository != null )
@@ -1014,17 +1043,30 @@
ServletData sd = new ServletData();
sd.servletName = "default";
ServletConfigImpl fileS = new ServletConfigImpl(this, sd);
-
+ addServletConfig(fileS);
Servlet defaultS = new WebdavServlet();
defaultS.init(fileS);
fileS.setServlet(defaultS);
addMapping("/", fileS);
- sd = new ServletData();
- sd.servletName = ServletConfigImpl.JSP_SERVLET_NAME;
- fileS = new ServletConfigImpl(this, sd);
- sd.servletClass = ServletConfigImpl.JSP_SERVLET_CLASS;
+ File f = new File(basePath + "/WEB-INF/tmp");
+ f.mkdirs();
+ setAttribute("javax.servlet.context.tempdir",
+ f.getAbsolutePath());
+
+ fileS = new ServletConfigImpl(this,
+ ServletConfigImpl.JSP_SERVLET_NAME,
+ ServletConfigImpl.JSP_SERVLET_CLASS);
addMapping("*.jsp", fileS);
+ addServletConfig(fileS);
+
+ fileS = new ServletConfigImpl(this,
+ ServletConfigImpl.JSP_SERVLET_COMPILER_NAME,
+ ServletConfigImpl.JSP_SERVLET_COMPILER_CLASS);
+ f = new File(basePath + "/WEB-INF/classes");
+ f.mkdirs();
+ fileS.data.initParams.put("scratchdir", f.getAbsolutePath());
+ addServletConfig(fileS);
}
private void readWebXml(String base) throws ServletException {
Modified:
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/servlets/jsp/JspCompileServlet.java
URL:
http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/servlets/jsp/JspCompileServlet.java?view=diff&rev=440368&r1=440367&r2=440368
==============================================================================
---
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/servlets/jsp/JspCompileServlet.java
(original)
+++
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/servlets/jsp/JspCompileServlet.java
Tue Sep 5 08:14:12 2006
@@ -17,8 +17,7 @@
package org.apache.tomcat.servlets.jsp;
import java.io.IOException;
-import java.lang.reflect.Constructor;
-import java.util.Enumeration;
+import java.io.PrintWriter;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
@@ -28,16 +27,10 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import org.apache.jasper.Constants;
import org.apache.jasper.EmbeddedServletOptions;
import org.apache.jasper.Options;
import org.apache.jasper.compiler.JspRuntimeContext;
-import org.apache.jasper.compiler.Localizer;
import org.apache.jasper.servlet.JspServletWrapper;
-import org.apache.tomcat.servlets.jsp.*;
/**
* Based on JspServlet, but specialized in compiling servlets.
@@ -46,12 +39,6 @@
public class JspCompileServlet extends HttpServlet
implements JspProxyServlet.PageCompiler {
- // Logger
- private Log log = LogFactory.getLog(JspCompileServlet.class);
-
- private ServletContext context;
- private ServletConfig config;
-
private Options options;
private JspRuntimeContext rctxt;
@@ -60,126 +47,16 @@
*/
public void init(ServletConfig config) throws ServletException {
super.init(config);
- this.config = config;
- this.context = config.getServletContext();
+ ServletContext context = config.getServletContext();
+ // Initialize the JSP Runtime Context
+ options = new EmbeddedServletOptions(config, context);
- // Initialize the JSP Runtime Context
- // Check for a custom Options implementation
- String engineOptionsName =
- config.getInitParameter("engineOptionsClass");
- if (engineOptionsName != null) {
- // Instantiate the indicated Options implementation
- try {
- ClassLoader loader = Thread.currentThread()
- .getContextClassLoader();
- Class engineOptionsClass = loader.loadClass(engineOptionsName);
- Class[] ctorSig = { ServletConfig.class, ServletContext.class
};
- Constructor ctor = engineOptionsClass.getConstructor(ctorSig);
- Object[] args = { config, context };
- options = (Options) ctor.newInstance(args);
- } catch (Throwable e) {
- // Need to localize this.
- log.warn("Failed to load engineOptionsClass", e);
- // Use the default Options implementation
- options = new EmbeddedServletOptions(config, context);
- }
- } else {
- // Use the default Options implementation
- options = new EmbeddedServletOptions(config, context);
- }
rctxt = new JspRuntimeContext(context, options);
- if (log.isDebugEnabled()) {
- log.debug(Localizer.getMessage("jsp.message.scratch.dir.is",
- options.getScratchDir().toString()));
-
log.debug(Localizer.getMessage("jsp.message.dont.modify.servlets"));
- }
-
- context.setAttribute(JspProxyServlet.CONTAINER_PREFIX + "jspCompiler",
- this);
- }
-
-
- /**
- * Returns the number of JSPs for which JspServletWrappers exist, i.e.,
- * the number of JSPs that have been loaded into the webapp with which
- * this JspServlet is associated.
- *
- * <p>This info may be used for monitoring purposes.
- *
- * @return The number of JSPs that have been loaded into the webapp with
- * which this JspServlet is associated
- */
- public int getJspCount() {
- return this.rctxt.getJspCount();
- }
-
-
- /**
- * Resets the JSP reload counter.
- *
- * @param count Value to which to reset the JSP reload counter
- */
- public void setJspReloadCount(int count) {
- this.rctxt.setJspReloadCount(count);
- }
-
-
- /**
- * Gets the number of JSPs that have been reloaded.
- *
- * <p>This info may be used for monitoring purposes.
- *
- * @return The number of JSPs (in the webapp with which this JspServlet is
- * associated) that have been reloaded
- */
- public int getJspReloadCount() {
- return this.rctxt.getJspReloadCount();
- }
-
-
- boolean preCompile(HttpServletRequest request) throws ServletException {
- String queryString = request.getQueryString();
- if (queryString == null) {
- return (false);
- }
- int start = queryString.indexOf(Constants.PRECOMPILE);
- if (start < 0) {
- return (false);
- }
- queryString =
- queryString.substring(start + Constants.PRECOMPILE.length());
- if (queryString.length() == 0) {
- return (true); // ?jsp_precompile
- }
- if (queryString.startsWith("&")) {
- return (true); // ?jsp_precompile&foo=bar...
- }
- if (!queryString.startsWith("=")) {
- return (false); // part of some other name or value
- }
- int limit = queryString.length();
- int ampersand = queryString.indexOf("&");
- if (ampersand > 0) {
- limit = ampersand;
- }
- String value = queryString.substring(1, limit);
- if (value.equals("true")) {
- return (true); // ?jsp_precompile=true
- } else if (value.equals("false")) {
- // Spec says if jsp_precompile=false, the request should not
- // be delivered to the JSP page; the easiest way to implement
- // this is to set the flag to true, and precompile the page anyway.
- // This still conforms to the spec, since it says the
- // precompilation request can be ignored.
- return (true); // ?jsp_precompile=false
- } else {
- throw new ServletException("Cannot have request parameter " +
- Constants.PRECOMPILE + " set to " +
- value);
- }
+ // if load-on-startup: allow other servlets to find us
+ context.setAttribute(JspProxyServlet.CONTAINER_PREFIX +
+ "servlet_jspCompiler", this);
}
-
/** This is no longer 'compiling' or invoking jsps. Just some status info
* for debugging.
@@ -187,113 +64,28 @@
public void service (HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
-
- String jspUri = null;
-
- String jspFile = (String) request.getAttribute(Constants.JSP_FILE);
- if (jspFile != null) {
- // JSP is specified via <jsp-file> in <servlet> declaration
- jspUri = jspFile;
- } else {
- /*
- * Check to see if the requested JSP has been the target of a
- * RequestDispatcher.include()
- */
- jspUri = (String) request.getAttribute(Constants.INC_SERVLET_PATH);
- if (jspUri != null) {
- /*
- * Requested JSP has been target of
- * RequestDispatcher.include(). Its path is assembled from the
- * relevant javax.servlet.include.* request attributes
- */
- String pathInfo = (String) request.getAttribute(
- "javax.servlet.include.path_info");
- if (pathInfo != null) {
- jspUri += pathInfo;
- }
- } else {
- /*
- * Requested JSP has not been the target of a
- * RequestDispatcher.include(). Reconstruct its path from the
- * request's getServletPath() and getPathInfo()
- */
- jspUri = request.getServletPath();
- String pathInfo = request.getPathInfo();
- if (pathInfo != null) {
- jspUri += pathInfo;
- }
- }
- }
-
- if (log.isDebugEnabled()) {
- log.debug("JspEngine --> " + jspUri);
- log.debug("\t ServletPath: " + request.getServletPath());
- log.debug("\t PathInfo: " + request.getPathInfo());
- log.debug("\t RealPath: " + context.getRealPath(jspUri));
- log.debug("\t RequestURI: " + request.getRequestURI());
- log.debug("\t QueryString: " + request.getQueryString());
- log.debug("\t Request Params: ");
- Enumeration e = request.getParameterNames();
- while (e.hasMoreElements()) {
- String name = (String) e.nextElement();
- log.debug("\t\t " + name + " = "
- + request.getParameter(name));
- }
+ String preCompile = request.getParameter("preCompile");
+ if (null != preCompile) {
+ compileAndInitPage(getServletContext(), preCompile,
+ getServletConfig());
+ return;
+ }
+ String action = request.getParameter("action");
+ if (action == null) {
+ PrintWriter out = response.getWriter();
+ // info about the context
+ out.println("jspCount=" + rctxt.getJspCount());
+ out.println("jspReloadCount=" + rctxt.getJspReloadCount());
+ out.println("scratchDir='" + options.getScratchDir().toString() +
+ "'");
+ return;
}
-
- try {
- boolean precompile = preCompile(request);
- serviceJspFile(request, response, jspUri, null, precompile);
- } catch (RuntimeException e) {
- throw e;
- } catch (ServletException e) {
- throw e;
- } catch (IOException e) {
- throw e;
- } catch (Throwable e) {
- throw new ServletException(e);
- }
-
}
public void destroy() {
rctxt.destroy();
}
-
- // -------------------------------------------------------- Private Methods
-
- private void serviceJspFile(HttpServletRequest request,
- HttpServletResponse response, String jspUri,
- Throwable exception, boolean precompile)
- throws ServletException, IOException {
-
- JspServletWrapper wrapper =
- (JspServletWrapper) rctxt.getWrapper(jspUri);
- if (wrapper == null) {
- synchronized(this) {
- wrapper = (JspServletWrapper) rctxt.getWrapper(jspUri);
- if (wrapper == null) {
- // Check if the requested JSP page exists, to avoid
- // creating unnecessary directories and files.
- if (null == context.getResource(jspUri)) {
- response.sendError(HttpServletResponse.SC_NOT_FOUND,
- jspUri);
- return;
- }
- boolean isErrorPage = exception != null;
- wrapper = new JspServletWrapper(config, options, jspUri,
- isErrorPage, rctxt);
- rctxt.addWrapper(jspUri,wrapper);
- }
- }
- }
-
- wrapper.service(request, response, precompile);
-
- }
-
-
public Servlet compileAndInitPage(ServletContext ctx,
String jspUri,
ServletConfig cfg)
@@ -307,11 +99,11 @@
if (wrapper == null) {
// Check if the requested JSP page exists, to avoid
// creating unnecessary directories and files.
- if (null == context.getResource(jspUri)) {
+ if (null == ctx.getResource(jspUri)) {
return null;
}
//boolean isErrorPage = exception != null;
- wrapper = new JspServletWrapper(config, options, jspUri,
+ wrapper = new JspServletWrapper(cfg, options, jspUri,
false, rctxt);
rctxt.addWrapper(jspUri,wrapper);
}
Modified:
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/servlets/jsp/JspProxyServlet.java
URL:
http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/servlets/jsp/JspProxyServlet.java?view=diff&rev=440368&r1=440367&r2=440368
==============================================================================
---
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/servlets/jsp/JspProxyServlet.java
(original)
+++
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/servlets/jsp/JspProxyServlet.java
Tue Sep 5 08:14:12 2006
@@ -14,6 +14,7 @@
import org.apache.coyote.Request;
import org.apache.coyote.Response;
+import org.apache.jasper.Constants;
import org.apache.jasper.JasperException;
import org.apache.jasper.JspC;
import org.apache.tomcat.lite.ServletConfigImpl;
@@ -64,7 +65,7 @@
super.init(arg0);
jspFile = arg0.getInitParameter(CONTAINER_PREFIX + "jspFile");
- pageCompiler =
(PageCompiler)getServletContext().getAttribute(CONTAINER_PREFIX +
"jspCompiler");
+ pageCompiler =
(PageCompiler)getServletContext().getAttribute(CONTAINER_PREFIX +
"servlet_jspCompiler");
if (jspFile != null) {
realJspServlet = loadProxy(jspFile);
if (realJspServlet == null) {
@@ -140,6 +141,49 @@
realJspServlet.service(req, arg1);
}
+
+ boolean preCompile(HttpServletRequest request) throws ServletException {
+ String queryString = request.getQueryString();
+ if (queryString == null) {
+ return (false);
+ }
+ int start = queryString.indexOf("jsp_precompile");
+ if (start < 0) {
+ return (false);
+ }
+ queryString =
+ queryString.substring(start + "jsp_precompile".length());
+ if (queryString.length() == 0) {
+ return (true); // ?jsp_precompile
+ }
+ if (queryString.startsWith("&")) {
+ return (true); // ?jsp_precompile&foo=bar...
+ }
+ if (!queryString.startsWith("=")) {
+ return (false); // part of some other name or value
+ }
+ int limit = queryString.length();
+ int ampersand = queryString.indexOf("&");
+ if (ampersand > 0) {
+ limit = ampersand;
+ }
+ String value = queryString.substring(1, limit);
+ if (value.equals("true")) {
+ return (true); // ?jsp_precompile=true
+ } else if (value.equals("false")) {
+ // Spec says if jsp_precompile=false, the request should not
+ // be delivered to the JSP page; the easiest way to implement
+ // this is to set the flag to true, and precompile the page anyway.
+ // This still conforms to the spec, since it says the
+ // precompilation request can be ignored.
+ return (true); // ?jsp_precompile=false
+ } else {
+ throw new ServletException("Cannot have request parameter " +
+ Constants.PRECOMPILE + " set to " +
+ value);
+ }
+ }
+
public HttpServlet loadProxy(String jspFile) {
Modified: tomcat/sandbox/tomcat-lite/webapps/ROOT/WEB-INF/web.xml
URL:
http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/webapps/ROOT/WEB-INF/web.xml?view=diff&rev=440368&r1=440367&r2=440368
==============================================================================
--- tomcat/sandbox/tomcat-lite/webapps/ROOT/WEB-INF/web.xml (original)
+++ tomcat/sandbox/tomcat-lite/webapps/ROOT/WEB-INF/web.xml Tue Sep 5 08:14:12
2006
@@ -4,13 +4,10 @@
<filter-mapping><filter-name>simpleIP</filter-name><url-pattern>/dav/*</url-pattern></filter-mapping>
<!-- Jsp compiler - will be moved to container, but can be used in any
webapp regardless of container -->
-
<servlet><servlet-name>_jspCompiler</servlet-name><servlet-class>org.apache.tomcat.servlets.jsp.JspCompileServlet</servlet-class>
- <load-on-startup>1</load-on-startup>
- </servlet>
<servlet><servlet-name>_tc_users</servlet-name><servlet-class>org.apache.tomcat.servlets.sec.DigestAuthenticator</servlet-class>
<init-param><param-name>u.test</param-name><param-value>pass</param-value></init-param>
</servlet>
-
<servlet-mapping><servlet-name>_jspCompiler</servlet-name><url-pattern>/_jspcOA</url-pattern></servlet-mapping>
+
<servlet-mapping><servlet-name>jspCompiler</servlet-name><url-pattern>/_jspc</url-pattern></servlet-mapping>
<servlet-mapping><servlet-name>dav</servlet-name><url-pattern>/dav/*</url-pattern></servlet-mapping>
</web-app>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]