*/
public boolean getPaused();
+
+ /**
+ * Is this context using version 2.2 of the Servlet spec?
+ */
+ boolean isServlet22();
}
public static final String ERROR_MESSAGE_ATTR =
"javax.servlet.error.message";
-
- /**
- * The request attribute under which we expose the value of the
- * <code><jsp-file></code> value associated with this servlet,
- * if any.
- */
- public static final String JSP_FILE_ATTR =
- "org.apache.catalina.jsp_file";
-
-
/**
* The request attribute under which we store the key size being used for
* this SSL connection (as an object of type java.lang.Integer).
/**
- * Return the context-relative URI of the JSP file for this servlet.
- */
- public String getJspFile();
-
-
- /**
- * Set the context-relative URI of the JSP file for this servlet.
- *
- * @param jspFile JSP file URI
- */
- public void setJspFile(String jspFile);
-
-
- /**
* Return the load-on-startup order value (negative value means
* load on first call).
*/
// Call the service() method for the allocated servlet instance
try {
- String jspFile = wrapper.getJspFile();
- if (jspFile != null)
- request.setAttribute(Globals.JSP_FILE_ATTR, jspFile);
- else
- request.removeAttribute(Globals.JSP_FILE_ATTR);
support.fireInstanceEvent(InstanceEvent.BEFORE_DISPATCH_EVENT,
servlet, request, response);
// for includes/forwards
filterChain.doFilter(request, response);
}
// Servlet Service Method is called by the FilterChain
- request.removeAttribute(Globals.JSP_FILE_ATTR);
support.fireInstanceEvent(InstanceEvent.AFTER_DISPATCH_EVENT,
servlet, request, response);
} catch (ClientAbortException e) {
- request.removeAttribute(Globals.JSP_FILE_ATTR);
support.fireInstanceEvent(InstanceEvent.AFTER_DISPATCH_EVENT,
servlet, request, response);
ioException = e;
} catch (IOException e) {
- request.removeAttribute(Globals.JSP_FILE_ATTR);
support.fireInstanceEvent(InstanceEvent.AFTER_DISPATCH_EVENT,
servlet, request, response);
wrapper.getLogger().error(sm.getString("applicationDispatcher.serviceException",
wrapper.getName()), e);
ioException = e;
} catch (UnavailableException e) {
- request.removeAttribute(Globals.JSP_FILE_ATTR);
support.fireInstanceEvent(InstanceEvent.AFTER_DISPATCH_EVENT,
servlet, request, response);
wrapper.getLogger().error(sm.getString("applicationDispatcher.serviceException",
servletException = e;
wrapper.unavailable(e);
} catch (ServletException e) {
- request.removeAttribute(Globals.JSP_FILE_ATTR);
support.fireInstanceEvent(InstanceEvent.AFTER_DISPATCH_EVENT,
servlet, request, response);
Throwable rootCause = StandardWrapper.getRootCause(e);
}
servletException = e;
} catch (RuntimeException e) {
- request.removeAttribute(Globals.JSP_FILE_ATTR);
support.fireInstanceEvent(InstanceEvent.AFTER_DISPATCH_EVENT,
servlet, request, response);
wrapper.getLogger().error(sm.getString("applicationDispatcher.serviceException",
}
}
- String jspFile = wrapper.getJspFile();
- if ((jspFile != null) && !jspFile.startsWith("/")) {
- if (isServlet22()) {
- if(log.isDebugEnabled())
- log.debug(sm.getString("standardContext.wrapper.warning",
- jspFile));
- wrapper.setJspFile("/" + jspFile);
- } else {
- throw new IllegalArgumentException
- (sm.getString("standardContext.wrapper.error", jspFile));
- }
- }
-
super.addChild(child);
if (isJspServlet && oldJspServlet != null) {
/**
* Are we processing a version 2.2 deployment descriptor?
*/
- protected boolean isServlet22() {
+ public boolean isServlet22() {
if (this.publicId == null)
return (false);
/**
- * The context-relative URI of the JSP file for this servlet.
- */
- protected String jspFile = null;
-
-
- /**
* The load-on-startup order value (negative value means load on
* first call) for this servlet.
*/
/**
- * Return the context-relative URI of the JSP file for this servlet.
- */
- public String getJspFile() {
-
- return (this.jspFile);
-
- }
-
-
- /**
- * Set the context-relative URI of the JSP file for this servlet.
- *
- * @param jspFile JSP file URI
- */
- public void setJspFile(String jspFile) {
-
- String oldJspFile = this.jspFile;
- this.jspFile = jspFile;
- support.firePropertyChange("jspFile", oldJspFile, this.jspFile);
-
- // Each jsp-file needs to be represented by its own JspServlet and
- // corresponding JspMonitoring mbean, because it may be initialized
- // with its own init params
- isJspServlet = true;
-
- }
-
-
- /**
* Return the load-on-startup order value (negative value means
* load on first call).
*/
Servlet servlet;
try {
long t1=System.currentTimeMillis();
- // If this "servlet" is really a JSP file, get the right class.
- // HOLD YOUR NOSE - this is a kludge that avoids having to do special
- // case Catalina-specific code in Jasper - it also requires that the
- // servlet path be replaced by the <jsp-file> element content in
- // order to be completely effective
- String actualClass = servletClass;
- if ((actualClass == null) && (jspFile != null)) {
- Wrapper jspWrapper = (Wrapper)
- ((Context) getParent()).findChild(Constants.JSP_SERVLET_NAME);
- if (jspWrapper != null) {
- actualClass = jspWrapper.getServletClass();
- // Merge init parameters
- String paramNames[] = jspWrapper.findInitParameters();
- for (int i = 0; i < paramNames.length; i++) {
- if (parameters.get(paramNames[i]) == null) {
- parameters.put
- (paramNames[i],
- jspWrapper.findInitParameter(paramNames[i]));
- }
- }
- }
- }
-
// Complain if no servlet class has been specified
- if (actualClass == null) {
+ if (servletClass == null) {
unavailable(null);
throw new ServletException
(sm.getString("standardWrapper.notClass", getName()));
InstanceManager instanceManager = ((StandardContext)getParent()).getInstanceManager();
try {
- servlet = (Servlet) instanceManager.newInstance(actualClass);
+ servlet = (Servlet) instanceManager.newInstance(servletClass);
} catch (ClassCastException e) {
unavailable(null);
// Restore the context ClassLoader
throw new ServletException
- (sm.getString("standardWrapper.notServlet", actualClass), e);
+ (sm.getString("standardWrapper.notServlet", servletClass), e);
} catch (Throwable e) {
ExceptionUtils.handleThrowable(e);
unavailable(null);
// Added extra log statement for Bugzilla 36630:
// http://issues.apache.org/bugzilla/show_bug.cgi?id=36630
if(log.isDebugEnabled()) {
- log.debug(sm.getString("standardWrapper.instantiate", actualClass), e);
+ log.debug(sm.getString("standardWrapper.instantiate", servletClass), e);
}
// Restore the context ClassLoader
throw new ServletException
- (sm.getString("standardWrapper.instantiate", actualClass), e);
+ (sm.getString("standardWrapper.instantiate", servletClass), e);
}
if (multipartConfigElement == null) {
// Special handling for ContainerServlet instances
if ((servlet instanceof ContainerServlet) &&
- (isContainerProvidedServlet(actualClass) ||
+ (isContainerProvidedServlet(servletClass) ||
((Context)getParent()).getPrivileged() )) {
((ContainerServlet) servlet).setWrapper(this);
}
servlet.init(facade);
}
- // Invoke jspInit on JSP pages
- if ((loadOnStartup >= 0) && (jspFile != null)) {
- // Invoking jspInit
- DummyRequest req = new DummyRequest();
- req.setServletPath(jspFile);
- req.setQueryString(Constants.PRECOMPILE + "=true");
- DummyResponse res = new DummyResponse();
-
- if( Globals.IS_SECURITY_ENABLED) {
- Object[] args = new Object[]{req, res};
- SecurityUtil.doAsPrivilege("service",
- servlet,
- classTypeUsedInService,
- args);
- args = null;
- } else {
- servlet.service(req, res);
- }
- }
instanceInitialized = true;
instanceSupport.fireInstanceEvent(InstanceEvent.AFTER_INIT_EVENT,
try {
response.sendAcknowledgement();
} catch (IOException e) {
- request.removeAttribute(Globals.JSP_FILE_ATTR);
container.getLogger().warn(sm.getString("standardWrapper.acknowledgeException",
wrapper.getName()), e);
throwable = e;
// Call the filter chain for this request
// NOTE: This also calls the servlet's service() method
try {
- String jspFile = wrapper.getJspFile();
- if (jspFile != null)
- request.setAttribute(Globals.JSP_FILE_ATTR, jspFile);
- else
- request.removeAttribute(Globals.JSP_FILE_ATTR);
if ((servlet != null) && (filterChain != null)) {
// Swallow output if needed
if (context.getSwallowOutput()) {
}
}
- request.removeAttribute(Globals.JSP_FILE_ATTR);
} catch (ClientAbortException e) {
- request.removeAttribute(Globals.JSP_FILE_ATTR);
throwable = e;
exception(request, response, e);
} catch (IOException e) {
- request.removeAttribute(Globals.JSP_FILE_ATTR);
container.getLogger().error(sm.getString(
"standardWrapper.serviceException", wrapper.getName(),
context.getName()), e);
throwable = e;
exception(request, response, e);
} catch (UnavailableException e) {
- request.removeAttribute(Globals.JSP_FILE_ATTR);
container.getLogger().error(sm.getString(
"standardWrapper.serviceException", wrapper.getName(),
context.getName()), e);
// Do not save exception in 'throwable', because we
// do not want to do exception(request, response, e) processing
} catch (ServletException e) {
- request.removeAttribute(Globals.JSP_FILE_ATTR);
Throwable rootCause = StandardWrapper.getRootCause(e);
if (!(rootCause instanceof ClientAbortException)) {
container.getLogger().error(sm.getString(
exception(request, response, e);
} catch (Throwable e) {
ExceptionUtils.handleThrowable(e);
- request.removeAttribute(Globals.JSP_FILE_ATTR);
container.getLogger().error(sm.getString(
"standardWrapper.serviceException", wrapper.getName(),
context.getName()), e);
// Call the filter chain for this request
// NOTE: This also calls the servlet's event() method
try {
- String jspFile = wrapper.getJspFile();
- if (jspFile != null)
- request.setAttribute(Globals.JSP_FILE_ATTR, jspFile);
- else
- request.removeAttribute(Globals.JSP_FILE_ATTR);
if ((servlet != null) && (filterChain != null)) {
// Swallow output if needed
}
}
- request.removeAttribute(Globals.JSP_FILE_ATTR);
} catch (ClientAbortException e) {
- request.removeAttribute(Globals.JSP_FILE_ATTR);
throwable = e;
exception(request, response, e);
} catch (IOException e) {
- request.removeAttribute(Globals.JSP_FILE_ATTR);
container.getLogger().error(sm.getString(
"standardWrapper.serviceException", wrapper.getName(),
context.getName()), e);
throwable = e;
exception(request, response, e);
} catch (UnavailableException e) {
- request.removeAttribute(Globals.JSP_FILE_ATTR);
container.getLogger().error(sm.getString(
"standardWrapper.serviceException", wrapper.getName(),
context.getName()), e);
// Do not save exception in 'throwable', because we
// do not want to do exception(request, response, e) processing
} catch (ServletException e) {
- request.removeAttribute(Globals.JSP_FILE_ATTR);
Throwable rootCause = StandardWrapper.getRootCause(e);
if (!(rootCause instanceof ClientAbortException)) {
container.getLogger().error(sm.getString(
exception(request, response, e);
} catch (Throwable e) {
ExceptionUtils.handleThrowable(e);
- request.removeAttribute(Globals.JSP_FILE_ATTR);
container.getLogger().error(sm.getString(
"standardWrapper.serviceException", wrapper.getName(),
context.getName()), e);
// Description is ignored
// Display name is ignored
// Icons are ignored
- // Only set this if it is non-null else every servlet will get
- // marked as the JSP servlet
- String jspFile = servlet.getJspFile();
- if (jspFile != null) {
- wrapper.setJspFile(jspFile);
- }
+
+ // jsp-file gets passed to the JSP Servlet as an init-param
+
if (servlet.getLoadOnStartup() != null) {
wrapper.setLoadOnStartup(servlet.getLoadOnStartup().intValue());
}
ok = webXml.merge(orderedFragments);
}
+ // Step 6.5 Convert explicitly mentioned jsps to servlets
+ if (!false) {
+ convertJsps(webXml);
+ }
+
// Step 7. Apply merged web.xml to Context
if (ok) {
webXml.configureContext(context);
}
} else {
// Apply unmerged web.xml to Context
+ convertJsps(webXml);
webXml.configureContext(context);
}
}
+ private void convertJsps(WebXml webXml) {
+ ServletDef jspServlet = webXml.getServlets().get("jsp");
+ for (ServletDef servletDef: webXml.getServlets().values()) {
+ if (servletDef.getJspFile() != null) {
+ convertJsp(servletDef, jspServlet);
+ }
+ }
+ }
+
+ private void convertJsp(ServletDef servletDef, ServletDef jspServletDef) {
+ servletDef.setServletClass(org.apache.catalina.core.Constants.JSP_SERVLET_CLASS);
+ String jspFile = servletDef.getJspFile();
+ servletDef.getParameterMap().put("jspFile", jspFile);
+ if ((jspFile != null) && !jspFile.startsWith("/")) {
+ if (context.isServlet22()) {
+ if(log.isDebugEnabled())
+ log.debug(sm.getString("standardContext.wrapper.warning",
+ jspFile));
+ jspFile = "/" + jspFile;
+ } else {
+ throw new IllegalArgumentException
+ (sm.getString("standardContext.wrapper.error", jspFile));
+ }
+ }
+ servletDef.setJspFile(null);
+ for (Map.Entry<String, String> initParam: jspServletDef.getParameterMap().entrySet()) {
+ servletDef.addInitParameter(initParam.getKey(), initParam.getValue());
+ }
+ }
+
protected WebXml createWebXml() {
return new WebXml();
}
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.reflect.Constructor;
+import java.net.MalformedURLException;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
private ServletConfig config;
private Options options;
private JspRuntimeContext rctxt;
+ //jspFile for a jsp configured explicitly as a servlet, in environments where this configuration is
+ //translated into an init-param for this servlet.
+ private String jspFile;
/*
options = new EmbeddedServletOptions(config, context);
}
rctxt = new JspRuntimeContext(context, options);
-
+ if (config.getInitParameter("jspFile") != null) {
+ jspFile = config.getInitParameter("jspFile");
+ try {
+ if (null == context.getResource(jspFile)) {
+ throw new ServletException("missing jspFile");
+ }
+ } catch (MalformedURLException e) {
+ throw new ServletException("Can not locate jsp file", e);
+ }
+ try {
+ serviceJspFile(null, null, jspFile, null, true);
+ if (SecurityUtil.isPackageProtectionEnabled()){
+ AccessController.doPrivileged(new PrivilegedExceptionAction<Object>(){
+ public Object run() throws IOException, ServletException {
+ serviceJspFile(null, null, jspFile, null, true);
+ return null;
+ }
+ });
+ } else {
+ serviceJspFile(null, null, jspFile, null, true);
+ }
+ } catch (IOException e) {
+ throw new ServletException("Could not precompile jsp: " + jspFile, e);
+ } catch (PrivilegedActionException e) {
+ Throwable t = e.getCause();
+ if (t instanceof ServletException) throw (ServletException)t;
+ throw new ServletException("Could not precompile jsp: " + jspFile, e);
+ }
+ }
+
if (log.isDebugEnabled()) {
log.debug(Localizer.getMessage("jsp.message.scratch.dir.is",
options.getScratchDir().toString()));
public void service (HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
+ //jspFile may be configured as an init-param for this servlet instance
+ String jspUri = jspFile;
- 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 {
+ if (jspUri == null) {
+ // JSP specified via <jsp-file> in <servlet> declaration and supplied through
+ //custom servlet container code
+ jspUri = (String) request.getAttribute(Constants.JSP_FILE);
+ }
+ if (jspUri == null) {
/*
* Check to see if the requested JSP has been the target of a
* RequestDispatcher.include()
<code>jsp:attribute</code> elements now supports the use of expressions
and expression language. (markt)
</fix>
+ <fix>
+ <bug>49916</bug>: Switch to using an initialisation parameter to pass
+ JSP file information from Catalina to Jasper. This simplifies the
+ Catalina code as well as making it easier for Geronimo and others to
+ integrate Jasper. Patch provided by David Jencks. (markt)
+ </fix>
</changelog>
</subsection>
<subsection name="Cluster">