Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Bartel2014-05-06 15:20:41 -0400
committerJan Bartel2014-05-06 15:22:00 -0400
commit7db7620c3656c89b70868e584445248838795233 (patch)
treeeceffa2848b74ba31d65189007c5c2a71a9ed6ae /jetty-servlet
parent7d662360f1ec4ab79b17f7b21f9efb7aa27871ec (diff)
downloadorg.eclipse.jetty.project-7db7620c3656c89b70868e584445248838795233.tar.gz
org.eclipse.jetty.project-7db7620c3656c89b70868e584445248838795233.tar.xz
org.eclipse.jetty.project-7db7620c3656c89b70868e584445248838795233.zip
367680 jsp-file with load-on-startup not precompiled
Diffstat (limited to 'jetty-servlet')
-rw-r--r--jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java5
-rw-r--r--jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHolder.java105
2 files changed, 98 insertions, 12 deletions
diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java
index f19bcd9eb0..81243e01e7 100644
--- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java
+++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java
@@ -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();
diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHolder.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHolder.java
index 3ae2bc5022..c5f6e8a3af 100644
--- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHolder.java
+++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHolder.java
@@ -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);
+ }
/* ------------------------------------------------------------ */

Back to the top