367680 jsp-file with load-on-startup not precompiled
This commit is contained in:
parent
7d662360f1
commit
7db7620c36
|
@ -846,7 +846,7 @@ public class ServletHandler extends ScopedHandler
|
|||
{
|
||||
try
|
||||
{
|
||||
if (servlet.getClassName() == null && servlet.getForcedPath() != null)
|
||||
/* if (servlet.getClassName() == null && servlet.getForcedPath() != null)
|
||||
{
|
||||
ServletHolder forced_holder = _servletPathMap.match(servlet.getForcedPath());
|
||||
if (forced_holder == null || forced_holder.getClassName() == null)
|
||||
|
@ -854,8 +854,9 @@ public class ServletHandler extends ScopedHandler
|
|||
mx.add(new IllegalStateException("No forced path servlet for " + servlet.getForcedPath()));
|
||||
continue;
|
||||
}
|
||||
System.err.println("ServletHandler setting forced path classname to "+forced_holder.getClassName()+ " for "+servlet.getForcedPath());
|
||||
servlet.setClassName(forced_holder.getClassName());
|
||||
}
|
||||
}*/
|
||||
|
||||
servlet.start();
|
||||
servlet.initialize();
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package org.eclipse.jetty.servlet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
@ -86,6 +87,8 @@ public class ServletHolder extends Holder<Servlet> implements UserIdentity.Scope
|
|||
private transient long _unavailable;
|
||||
private transient boolean _enabled = true;
|
||||
private transient UnavailableException _unavailableEx;
|
||||
|
||||
public static final String JSP_GENERATED_PACKAGE_NAME = "org.eclipse.jetty.jspPackagePrefix";
|
||||
public static final Map<String,String> NO_MAPPED_ROLES = Collections.emptyMap();
|
||||
|
||||
/* ---------------------------------------------------------------- */
|
||||
|
@ -277,8 +280,6 @@ public class ServletHolder extends Holder<Servlet> implements UserIdentity.Scope
|
|||
public void doStart()
|
||||
throws Exception
|
||||
{
|
||||
|
||||
|
||||
_unavailable=0;
|
||||
if (!_enabled)
|
||||
return;
|
||||
|
@ -287,8 +288,8 @@ public class ServletHolder extends Holder<Servlet> implements UserIdentity.Scope
|
|||
if (_forcedPath != null)
|
||||
{
|
||||
// Look for a precompiled JSP Servlet
|
||||
String precompiled="org.apache.jsp"+_forcedPath.replace('.','_').replace('/','.');
|
||||
|
||||
String precompiled=getClassNameForJsp(_forcedPath);
|
||||
LOG.debug("Checking for precompiled servlet {} for jsp {}", precompiled, _forcedPath);
|
||||
ServletHolder jsp=getServletHandler().getServlet(precompiled);
|
||||
if (jsp!=null)
|
||||
{
|
||||
|
@ -297,13 +298,25 @@ public class ServletHolder extends Holder<Servlet> implements UserIdentity.Scope
|
|||
setClassName(jsp.getClassName());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Look for normal JSP servlet
|
||||
jsp=getServletHandler().getServlet("jsp");
|
||||
if (jsp!=null)
|
||||
{
|
||||
if (getClassName() == null)
|
||||
{
|
||||
LOG.debug("JSP file {} for {} mapped to Servlet {}",_forcedPath, getName(),jsp.getClassName());
|
||||
setClassName(jsp.getClassName());
|
||||
// Look for normal JSP servlet
|
||||
jsp=getServletHandler().getServlet("jsp");
|
||||
if (jsp!=null)
|
||||
{
|
||||
LOG.debug("JSP file {} for {} mapped to Servlet {}",_forcedPath, getName(),jsp.getClassName());
|
||||
setClassName(jsp.getClassName());
|
||||
//copy jsp init params that don't exist for this servlet
|
||||
for (Map.Entry<String, String> entry:jsp.getInitParameters().entrySet())
|
||||
{
|
||||
if (!_initParams.containsKey(entry.getKey()))
|
||||
setInitParameter(entry.getKey(), entry.getValue());
|
||||
}
|
||||
//jsp specific: set up the jsp-file on the JspServlet so it can precompile iff load-on-startup is >=0
|
||||
if (_initOnStartup)
|
||||
setInitParameter("jspFile", _forcedPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -784,6 +797,78 @@ public class ServletHolder extends Holder<Servlet> implements UserIdentity.Scope
|
|||
return false;
|
||||
return ("org.apache.jasper.servlet.JspServlet".equals(classname));
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
private String getNameOfJspClass (String jsp)
|
||||
{
|
||||
if (jsp == null)
|
||||
return "";
|
||||
|
||||
int i = jsp.lastIndexOf('/') + 1;
|
||||
jsp = jsp.substring(i);
|
||||
try
|
||||
{
|
||||
Class jspUtil = Loader.loadClass(Holder.class, "org.apache.jasper.compiler.JspUtil");
|
||||
Method makeJavaIdentifier = jspUtil.getMethod("makeJavaIdentifier", String.class);
|
||||
return (String)makeJavaIdentifier.invoke(null, jsp);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
String tmp = jsp.replace('.','_');
|
||||
LOG.warn("Unable to make identifier for jsp "+jsp +" trying "+tmp+" instead");
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.warn(e);
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
private String getPackageOfJspClass (String jsp)
|
||||
{
|
||||
if (jsp == null)
|
||||
return "";
|
||||
|
||||
int i = jsp.lastIndexOf('/');
|
||||
if (i <= 0)
|
||||
return "";
|
||||
try
|
||||
{
|
||||
Class jspUtil = Loader.loadClass(Holder.class, "org.apache.jasper.compiler.JspUtil");
|
||||
Method makeJavaPackage = jspUtil.getMethod("makeJavaPackage", String.class);
|
||||
return (String)makeJavaPackage.invoke(null, jsp.substring(0,i));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
String tmp = jsp.substring(1).replace('/','.');
|
||||
LOG.warn("Unable to make package for jsp "+jsp +" trying "+tmp+" instead");
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.warn(e);
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
private String getJspPackagePrefix ()
|
||||
{
|
||||
String jspPackageName = (String)getServletHandler().getServletContext().getAttribute(JSP_GENERATED_PACKAGE_NAME );
|
||||
if (jspPackageName == null)
|
||||
jspPackageName = "org.apache.jsp";
|
||||
|
||||
return jspPackageName;
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
private String getClassNameForJsp (String jsp)
|
||||
{
|
||||
if (jsp == null)
|
||||
return null;
|
||||
|
||||
return getJspPackagePrefix() + "." +getPackageOfJspClass(jsp) + "." + getNameOfJspClass(jsp);
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
|
Loading…
Reference in New Issue