Author: markt Date: Tue Jun 26 22:02:04 2012 New Revision: 1354255 URL: http://svn.apache.org/viewvc?rev=1354255&view=rev Log: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=53465 Populate mapped-name property for resources defined in web.xml Based on a patch by Violeta Georgieva
Modified: tomcat/trunk/java/org/apache/catalina/startup/WebRuleSet.java tomcat/trunk/test/org/apache/naming/resources/TestNamingContext.java tomcat/trunk/test/webapp-3.0/WEB-INF/web.xml Modified: tomcat/trunk/java/org/apache/catalina/startup/WebRuleSet.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/WebRuleSet.java?rev=1354255&r1=1354254&r2=1354255&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/startup/WebRuleSet.java (original) +++ tomcat/trunk/java/org/apache/catalina/startup/WebRuleSet.java Tue Jun 26 22:02:04 2012 @@ -24,6 +24,7 @@ import java.util.ArrayList; import org.apache.catalina.deploy.ContextHandler; import org.apache.catalina.deploy.ContextService; +import org.apache.catalina.deploy.ResourceBase; import org.apache.catalina.deploy.SecurityConstraint; import org.apache.catalina.deploy.ServletDef; import org.apache.catalina.deploy.WebXml; @@ -493,6 +494,8 @@ public class WebRuleSet extends RuleSetB "setLocal", 0); digester.addCallMethod(fullPrefix + "/ejb-local-ref/local-home", "setHome", 0); + digester.addRule(fullPrefix + "/ejb-local-ref/mapped-name", + new MappedNameRule()); configureInjectionRules(digester, "web-app/ejb-local-ref/"); //ejb-ref @@ -513,6 +516,8 @@ public class WebRuleSet extends RuleSetB "setHome", 0); digester.addCallMethod(fullPrefix + "/ejb-ref/remote", "setRemote", 0); + digester.addRule(fullPrefix + "/ejb-ref/mapped-name", + new MappedNameRule()); configureInjectionRules(digester, "web-app/ejb-ref/"); //env-entry @@ -529,6 +534,8 @@ public class WebRuleSet extends RuleSetB "setType", 0); digester.addCallMethod(fullPrefix + "/env-entry/env-entry-value", "setValue", 0); + digester.addRule(fullPrefix + "/env-entry/mapped-name", + new MappedNameRule()); configureInjectionRules(digester, "web-app/env-entry/"); //resource-env-ref @@ -541,6 +548,8 @@ public class WebRuleSet extends RuleSetB "setName", 0); digester.addCallMethod(fullPrefix + "/resource-env-ref/resource-env-ref-type", "setType", 0); + digester.addRule(fullPrefix + "/resource-env-ref/mapped-name", + new MappedNameRule()); configureInjectionRules(digester, "web-app/resource-env-ref/"); //message-destination @@ -559,6 +568,8 @@ public class WebRuleSet extends RuleSetB "setSmallIcon", 0); digester.addCallMethod(fullPrefix + "/message-destination/message-destination-name", "setName", 0); + digester.addRule(fullPrefix + "/message-destination/mapped-name", + new MappedNameRule()); //message-destination-ref digester.addObjectCreate(fullPrefix + "/message-destination-ref", @@ -576,7 +587,8 @@ public class WebRuleSet extends RuleSetB "setType", 0); digester.addCallMethod(fullPrefix + "/message-destination-ref/message-destination-usage", "setUsage", 0); - + digester.addRule(fullPrefix + "/message-destination-ref/mapped-name", + new MappedNameRule()); configureInjectionRules(digester, "web-app/message-destination-ref/"); //resource-ref @@ -595,6 +607,8 @@ public class WebRuleSet extends RuleSetB "setScope", 0); digester.addCallMethod(fullPrefix + "/resource-ref/res-type", "setType", 0); + digester.addRule(fullPrefix + "/resource-ref/mapped-name", + new MappedNameRule()); configureInjectionRules(digester, "web-app/resource-ref/"); //service-ref @@ -652,9 +666,9 @@ public class WebRuleSet extends RuleSetB "addSoapRole", 0); digester.addCallMethod(fullPrefix + "/service-ref/handler/port-name", "addPortName", 0); + digester.addRule(fullPrefix + "/service-ref/mapped-name", + new MappedNameRule()); configureInjectionRules(digester, "web-app/service-ref/"); - - } protected void configureInjectionRules(Digester digester, String base) { @@ -1246,6 +1260,31 @@ final class TaglibLocationRule extends R "taglib definition not consistent with specification version"); } } +} + +/** + * A Rule that sets mapped name on the ResourceBase. + */ +final class MappedNameRule extends Rule { + public MappedNameRule() { + // NO-OP + } + /** + * Process the body text of this element. + * + * @param namespace the namespace URI of the matching element, or an + * empty string if the parser is not namespace aware or the element has + * no namespace + * @param name the local name if the parser is namespace aware, or just + * the element name otherwise + * @param text The body text of this element + */ + @Override + public void body(String namespace, String name, String text) + throws Exception { + ResourceBase resourceBase = (ResourceBase) digester.peek(); + resourceBase.setProperty("mappedName", text.trim()); + } } \ No newline at end of file Modified: tomcat/trunk/test/org/apache/naming/resources/TestNamingContext.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/naming/resources/TestNamingContext.java?rev=1354255&r1=1354254&r2=1354255&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/naming/resources/TestNamingContext.java (original) +++ tomcat/trunk/test/org/apache/naming/resources/TestNamingContext.java Tue Jun 26 22:02:04 2012 @@ -480,4 +480,29 @@ public class TestNamingContext extends T } } } + + @Test + public void testBug53465() throws Exception { + Tomcat tomcat = getTomcatInstance(); + tomcat.enableNaming(); + + File appDir = + new File("test/webapp-3.0"); + // app dir is relative to server home + org.apache.catalina.Context ctxt = + tomcat.addWebapp(null, "/test", appDir.getAbsolutePath()); + + tomcat.start(); + + ByteChunk bc = new ByteChunk(); + int rc = getUrl("http://localhost:" + getPort() + + "/test/bug53465.jsp", bc, null); + + Assert.assertEquals(HttpServletResponse.SC_OK, rc); + Assert.assertTrue(bc.toString().contains("<p>10</p>")); + + ContextEnvironment ce = + ctxt.getNamingResources().findEnvironment("bug53465"); + Assert.assertEquals("Bug53465MappedName", ce.getProperty("mappedName")); + } } Modified: tomcat/trunk/test/webapp-3.0/WEB-INF/web.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/test/webapp-3.0/WEB-INF/web.xml?rev=1354255&r1=1354254&r2=1354255&view=diff ============================================================================== --- tomcat/trunk/test/webapp-3.0/WEB-INF/web.xml (original) +++ tomcat/trunk/test/webapp-3.0/WEB-INF/web.xml Tue Jun 26 22:02:04 2012 @@ -116,4 +116,13 @@ <login-config> <auth-method>BASIC</auth-method> </login-config> + + <env-entry> + <description>Resource for testing bug 53465</description> + <env-entry-name>bug53465</env-entry-name> + <env-entry-value>10</env-entry-value> + <env-entry-type>java.lang.Integer</env-entry-type> + <mapped-name>Bug53465MappedName</mapped-name> + </env-entry> + </web-app> \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org