Author: fmeschbe
Date: Tue Nov 25 13:43:14 2008
New Revision: 720611

URL: http://svn.apache.org/viewvc?rev=720611&view=rev
Log:
SLING-743 Set/Reset Thread context class loader for the evaluation (compile, 
execute) of JSP scripts

Modified:
    
incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java

Modified: 
incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
URL: 
http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java?rev=720611&r1=720610&r2=720611&view=diff
==============================================================================
--- 
incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
 (original)
+++ 
incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
 Tue Nov 25 13:43:14 2008
@@ -340,6 +340,12 @@
             Bindings props = context.getBindings(ScriptContext.ENGINE_SCOPE);
             SlingScriptHelper scriptHelper = (SlingScriptHelper) 
props.get(SLING);
             if (scriptHelper != null) {
+                
+                // set the current class loader as the thread context loader 
for
+                // the compilation and execution of the JSP script
+                ClassLoader old = 
Thread.currentThread().getContextClassLoader();
+                Thread.currentThread().setContextClassLoader(jspClassLoader);
+
                 try {
                     callJsp(props, scriptHelper);
                 } catch (SlingServletException e) {
@@ -359,10 +365,20 @@
                             }
                         }
                     }
+                    
                     // fallback to standard behaviour
                     throw new BetterScriptException(e.getMessage(), e);
+                    
                 } catch (Exception e) {
+                    
                     throw new BetterScriptException(e.getMessage(), e);
+                    
+                } finally {
+                    
+                    // make sure the context loader is reset after setting up 
the
+                    // JSP runtime context
+                    Thread.currentThread().setContextClassLoader(old);
+
                 }
             }
             return null;


Reply via email to