Author: markt
Date: Tue Mar  7 10:51:55 2017
New Revision: 1785823

URL: http://svn.apache.org/viewvc?rev=1785823&view=rev
Log:
Follow up to the fix for bug 58178. When creating the ELContext for a tag file, 
ensure that any registered ELContextListeners are fired.

Added:
    tomcat/trunk/test/webapp/bug5nnnn/bug58178c.jsp
Modified:
    tomcat/trunk/java/org/apache/jasper/runtime/JspApplicationContextImpl.java
    tomcat/trunk/java/org/apache/jasper/runtime/JspContextWrapper.java
    tomcat/trunk/test/org/apache/jasper/runtime/TestJspContextWrapper.java
    tomcat/trunk/webapps/docs/changelog.xml

Modified: 
tomcat/trunk/java/org/apache/jasper/runtime/JspApplicationContextImpl.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/runtime/JspApplicationContextImpl.java?rev=1785823&r1=1785822&r2=1785823&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/jasper/runtime/JspApplicationContextImpl.java 
(original)
+++ tomcat/trunk/java/org/apache/jasper/runtime/JspApplicationContextImpl.java 
Tue Mar  7 10:51:55 2017
@@ -22,6 +22,7 @@ import java.util.ArrayList;
 import java.util.List;
 
 import javax.el.CompositeELResolver;
+import javax.el.ELContext;
 import javax.el.ELContextEvent;
 import javax.el.ELContextListener;
 import javax.el.ELResolver;
@@ -101,12 +102,16 @@ public class JspApplicationContextImpl i
         ctx.putContext(JspContext.class, context);
 
         // alert all ELContextListeners
-        ELContextEvent event = new ELContextEvent(ctx);
+        fireListeners(ctx);
+
+        return ctx;
+    }
+
+    protected void fireListeners(ELContext elContext) {
+        ELContextEvent event = new ELContextEvent(elContext);
         for (int i = 0; i < this.contextListeners.size(); i++) {
             this.contextListeners.get(i).contextCreated(event);
         }
-
-        return ctx;
     }
 
     private ELResolver createELResolver() {

Modified: tomcat/trunk/java/org/apache/jasper/runtime/JspContextWrapper.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/runtime/JspContextWrapper.java?rev=1785823&r1=1785822&r2=1785823&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/jasper/runtime/JspContextWrapper.java 
(original)
+++ tomcat/trunk/java/org/apache/jasper/runtime/JspContextWrapper.java Tue Mar  
7 10:51:55 2017
@@ -41,7 +41,9 @@ import javax.servlet.ServletException;
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpSession;
+import javax.servlet.jsp.JspApplicationContext;
 import javax.servlet.jsp.JspContext;
+import javax.servlet.jsp.JspFactory;
 import javax.servlet.jsp.JspWriter;
 import javax.servlet.jsp.PageContext;
 import javax.servlet.jsp.el.ELException;
@@ -508,6 +510,11 @@ public class JspContextWrapper extends P
     public ELContext getELContext() {
         if (elContext == null) {
             elContext = new ELContextWrapper(rootJspCtxt.getELContext(), 
jspTag, this);
+            JspFactory factory = JspFactory.getDefaultFactory();
+            JspApplicationContext jspAppCtxt = 
factory.getJspApplicationContext(servletContext);
+            if (jspAppCtxt instanceof JspApplicationContextImpl) {
+                ((JspApplicationContextImpl) 
jspAppCtxt).fireListeners(elContext);
+            }
         }
         return elContext;
     }

Modified: tomcat/trunk/test/org/apache/jasper/runtime/TestJspContextWrapper.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/jasper/runtime/TestJspContextWrapper.java?rev=1785823&r1=1785822&r2=1785823&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/jasper/runtime/TestJspContextWrapper.java 
(original)
+++ tomcat/trunk/test/org/apache/jasper/runtime/TestJspContextWrapper.java Tue 
Mar  7 10:51:55 2017
@@ -66,4 +66,20 @@ public class TestJspContextWrapper exten
         // Class import
         Assert.assertTrue(result, result.contains("02-" + 
Collections.EMPTY_LIST.size()));
     }
+
+    @Test
+    public void testELTagFileELContextListener() throws Exception {
+        getTomcatInstanceTestWebapp(false, true);
+
+        ByteChunk out = new ByteChunk();
+
+        int rc = getUrl("http://localhost:"; + getPort() + 
"/test/bug5nnnn/bug58178c.jsp", out, null);
+
+        Assert.assertEquals(HttpServletResponse.SC_OK, rc);
+
+        String result = out.toString();
+
+        Assert.assertTrue(result, result.contains("JSP count: 1"));
+        Assert.assertTrue(result, result.contains("Tag count: 1"));
+    }
 }

Added: tomcat/trunk/test/webapp/bug5nnnn/bug58178c.jsp
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/webapp/bug5nnnn/bug58178c.jsp?rev=1785823&view=auto
==============================================================================
--- tomcat/trunk/test/webapp/bug5nnnn/bug58178c.jsp (added)
+++ tomcat/trunk/test/webapp/bug5nnnn/bug58178c.jsp Tue Mar  7 10:51:55 2017
@@ -0,0 +1,65 @@
+<%--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+--%>
+<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
+<%!
+static class TestListener implements javax.el.ELContextListener {
+
+    private int jspCount = 0;
+    private int tagCount = 0;
+
+    @Override
+    public void contextCreated(javax.el.ELContextEvent event) {
+        javax.el.ELContext elContext = event.getELContext();
+        if (elContext instanceof org.apache.jasper.el.ELContextImpl) {
+            jspCount++;
+        } else {
+            tagCount++;
+        }
+        (new Exception()).printStackTrace();
+    }
+
+    public int getJspCount() {
+        return jspCount;
+    }
+
+    public int getTagCount() {
+        return tagCount;
+    }
+}
+
+static TestListener listener = new TestListener();
+
+private boolean listenerAdded;
+%>
+<%
+synchronized(this) {
+    if (!listenerAdded) {
+        JspFactory factory = JspFactory.getDefaultFactory();
+        JspApplicationContext jspApplicationContext = 
factory.getJspApplicationContext(application);
+        jspApplicationContext.addELContextListener(listener);
+        listenerAdded = true;
+    }
+}
+%>
+<html>
+<body>
+<p>JSP count: <%= listener.getJspCount() %></p>
+<p>Tag count: <%= listener.getTagCount() %></p>
+<tags:bug58178b />
+<p>JSP count: <%= listener.getJspCount() %></p>
+<p>Tag count: <%= listener.getTagCount() %></p>
+</html>
\ No newline at end of file

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1785823&r1=1785822&r2=1785823&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Tue Mar  7 10:51:55 2017
@@ -240,6 +240,11 @@
   <subsection name="Jasper">
     <changelog>
       <fix>
+        Follow up to the fix for <bug>58178</bug>. When creating the
+        <code>ELContext</code> for a tag file, ensure that any registered
+        <code>ELContextListener</code>s are fired. (markt)
+      </fix>
+      <fix>
         Refactor code generated for JSPs to reduce the size of the code 
required
         for tags. (markt)
       </fix>



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to