You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2012/11/09 20:33:44 UTC
svn commit: r1407596 - in /tomcat/tc7.0.x/trunk: ./
java/org/apache/catalina/core/NamingContextListener.java
test/org/apache/catalina/core/TestNamingContextListener.java
webapps/docs/changelog.xml
Author: markt
Date: Fri Nov 9 19:33:44 2012
New Revision: 1407596
URL: http://svn.apache.org/viewvc?rev=1407596&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=54096
env-entry can use any type that has a String or char constructor
Modified:
tomcat/tc7.0.x/trunk/ (props changed)
tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/NamingContextListener.java
tomcat/tc7.0.x/trunk/test/org/apache/catalina/core/TestNamingContextListener.java
tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
Merged /tomcat/trunk:r1407595
Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/NamingContextListener.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/NamingContextListener.java?rev=1407596&r1=1407595&r2=1407596&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/NamingContextListener.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/NamingContextListener.java Fri Nov 9 19:33:44 2012
@@ -21,6 +21,7 @@ package org.apache.catalina.core;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
+import java.lang.reflect.Constructor;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collection;
@@ -863,7 +864,11 @@ public class NamingContextListener
}
}
} else {
- logger.error(sm.getString("naming.invalidEnvEntryType", env.getName()));
+ value = constructEnvEntry(env.getType(), env.getValue());
+ if (value == null) {
+ logger.error(sm.getString(
+ "naming.invalidEnvEntryType", env.getName()));
+ }
}
} catch (NumberFormatException e) {
logger.error(sm.getString("naming.invalidEnvEntryValue", env.getName()));
@@ -886,6 +891,33 @@ public class NamingContextListener
}
+ private Object constructEnvEntry(String type, String value) {
+ try {
+ Class<?> clazz = Class.forName(type);
+ Constructor<?> c = null;
+ try {
+ c = clazz.getConstructor(String.class);
+ return c.newInstance(value);
+ } catch (NoSuchMethodException e) {
+ // Ignore
+ }
+
+ if (value.length() != 1) {
+ return null;
+ }
+
+ try {
+ c = clazz.getConstructor(char.class);
+ return c.newInstance(Character.valueOf(value.charAt(0)));
+ } catch (NoSuchMethodException e) {
+ // Ignore
+ }
+ } catch (Exception e) {
+ // Ignore
+ }
+ return null;
+ }
+
/**
* Set the specified local EJBs in the naming context.
*/
Modified: tomcat/tc7.0.x/trunk/test/org/apache/catalina/core/TestNamingContextListener.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/catalina/core/TestNamingContextListener.java?rev=1407596&r1=1407595&r2=1407596&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/test/org/apache/catalina/core/TestNamingContextListener.java (original)
+++ tomcat/tc7.0.x/trunk/test/org/apache/catalina/core/TestNamingContextListener.java Fri Nov 9 19:33:44 2012
@@ -33,8 +33,13 @@ import org.apache.catalina.startup.Tomca
public class TestNamingContextListener extends TomcatBaseTest {
- private static final String JNDI_NAME = "TestName";
- private static final String JNDI_VALUE= "Test Value";
+ private static final String BUG49132_NAME = "TestName";
+ private static final String BUG49132_VALUE = "Test Value";
+
+ private static final String BUG54096_NameA = "envA";
+ private static final String BUG54096_ValueA = "valueA";
+ private static final String BUG54096_NameB = "envB";
+ private static final String BUG54096_ValueB = "B";
/**
* Test JNDI is available to ServletContextListeners.
@@ -51,9 +56,9 @@ public class TestNamingContextListener e
tomcat.enableNaming();
ContextEnvironment environment = new ContextEnvironment();
- environment.setType(JNDI_VALUE.getClass().getName());
- environment.setName(JNDI_NAME);
- environment.setValue(JNDI_VALUE);
+ environment.setType(BUG49132_VALUE.getClass().getName());
+ environment.setName(BUG49132_NAME);
+ environment.setValue(BUG49132_VALUE);
ctx.getNamingResources().addEnvironment(environment);
ctx.addApplicationListener(Bug49132Listener.class.getName());
@@ -77,8 +82,8 @@ public class TestNamingContextListener e
initCtx = new InitialContext();
javax.naming.Context envCtx =
(javax.naming.Context) initCtx.lookup("java:comp/env");
- String value = (String) envCtx.lookup(JNDI_NAME);
- if (!JNDI_VALUE.equals(value)) {
+ String value = (String) envCtx.lookup(BUG49132_NAME);
+ if (!BUG49132_VALUE.equals(value)) {
throw new RuntimeException();
}
} catch (NamingException e) {
@@ -87,4 +92,95 @@ public class TestNamingContextListener e
}
}
+ @Test
+ public void testBug54096() throws Exception {
+ Tomcat tomcat = getTomcatInstance();
+
+ // Must have a real docBase - just use temp
+ org.apache.catalina.Context ctx =
+ tomcat.addContext("", System.getProperty("java.io.tmpdir"));
+
+ // Enable JNDI - it is disabled by default
+ tomcat.enableNaming();
+
+ ContextEnvironment environmentA = new ContextEnvironment();
+ environmentA.setType(Bug54096EnvA.class.getName());
+ environmentA.setName(BUG54096_NameA);
+ environmentA.setValue(BUG54096_ValueA);
+ ctx.getNamingResources().addEnvironment(environmentA);
+
+ ContextEnvironment environmentB = new ContextEnvironment();
+ environmentB.setType(Bug54096EnvB.class.getName());
+ environmentB.setName(BUG54096_NameB);
+ environmentB.setValue(BUG54096_ValueB);
+ ctx.getNamingResources().addEnvironment(environmentB);
+
+ ctx.addApplicationListener(Bug54096Listener.class.getName());
+
+ tomcat.start();
+
+ assertEquals(LifecycleState.STARTED, ctx.getState());
+ }
+
+ public static class Bug54096EnvA {
+
+ private final String value;
+
+ public Bug54096EnvA(String value) {
+ this.value = value;
+ }
+
+ public String getValue() {
+ return value;
+ }
+ }
+
+ public static class Bug54096EnvB {
+
+ private final char value;
+
+ public Bug54096EnvB(char value) {
+ this.value = value;
+ }
+
+ public char getValue() {
+ return value;
+ }
+ }
+
+ public static final class Bug54096Listener implements
+ ServletContextListener {
+
+ @Override
+ public void contextDestroyed(ServletContextEvent sce) {
+ // NOOP
+ }
+
+ @Override
+ public void contextInitialized(ServletContextEvent sce) {
+ javax.naming.Context initCtx;
+ try {
+ initCtx = new InitialContext();
+ javax.naming.Context envCtx =
+ (javax.naming.Context) initCtx.lookup("java:comp/env");
+
+ // Validate entry A
+ Bug54096EnvA valueA =
+ (Bug54096EnvA) envCtx.lookup(BUG54096_NameA);
+ if (!BUG54096_ValueA.equals(valueA.getValue())) {
+ throw new RuntimeException();
+ }
+
+ // Validate entry B
+ Bug54096EnvB valueB =
+ (Bug54096EnvB) envCtx.lookup(BUG54096_NameB);
+ if (BUG54096_ValueB.charAt(0) != valueB.getValue()) {
+ throw new RuntimeException();
+ }
+
+ } catch (NamingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
}
Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1407596&r1=1407595&r2=1407596&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Fri Nov 9 19:33:44 2012
@@ -106,6 +106,10 @@
per connection (Tomcat only does this if an HTTP session is available).
(markt)
</fix>
+ <fix>
+ <bug>54096</bug>: In web.xml, <env-entry> should accept any type
+ that has a constructor that takes a single String or char. (markt)
+ </fix>
</changelog>
</subsection>
<subsection name="Coyote">
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
Re: svn commit: r1407596 - in /tomcat/tc7.0.x/trunk: ./ java/org/apache/catalina/core/NamingContextListener.java
test/org/apache/catalina/core/TestNamingContextListener.java webapps/docs/changelog.xml
Posted by Mark Thomas <ma...@apache.org>.
On 10/11/2012 09:31, Konstantin Kolinko wrote:
> 2012/11/9 <ma...@apache.org>:
>> Author: markt
>> Date: Fri Nov 9 19:33:44 2012
>> New Revision: 1407596
>>
>> URL: http://svn.apache.org/viewvc?rev=1407596&view=rev
>> Log:
>> Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=54096
>> env-entry can use any type that has a String or char constructor
>>
>
> Does it change what types are allowed for the <Environment> element in
> Context or in GlobalResources?
>
> I mean the following documentation:
> http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Environment_Entries
> http://tomcat.apache.org/tomcat-7.0-doc/config/globalresources.html#Environment_Entries
It does. Those limitations were removed in Servlet 2.4 (Tomcat 5.x).
I'll update the docs.
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
Re: svn commit: r1407596 - in /tomcat/tc7.0.x/trunk: ./
java/org/apache/catalina/core/NamingContextListener.java test/org/apache/catalina/core/TestNamingContextListener.java
webapps/docs/changelog.xml
Posted by Konstantin Kolinko <kn...@gmail.com>.
2012/11/9 <ma...@apache.org>:
> Author: markt
> Date: Fri Nov 9 19:33:44 2012
> New Revision: 1407596
>
> URL: http://svn.apache.org/viewvc?rev=1407596&view=rev
> Log:
> Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=54096
> env-entry can use any type that has a String or char constructor
>
Does it change what types are allowed for the <Environment> element in
Context or in GlobalResources?
I mean the following documentation:
http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Environment_Entries
http://tomcat.apache.org/tomcat-7.0-doc/config/globalresources.html#Environment_Entries
Best regards,
Konstantin Kolinko
> Modified:
> tomcat/tc7.0.x/trunk/ (props changed)
> tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/NamingContextListener.java
> tomcat/tc7.0.x/trunk/test/org/apache/catalina/core/TestNamingContextListener.java
> tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
>
> Propchange: tomcat/tc7.0.x/trunk/
> ------------------------------------------------------------------------------
> Merged /tomcat/trunk:r1407595
>
> Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/NamingContextListener.java
> URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/NamingContextListener.java?rev=1407596&r1=1407595&r2=1407596&view=diff
> ==============================================================================
> --- tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/NamingContextListener.java (original)
> +++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/NamingContextListener.java Fri Nov 9 19:33:44 2012
> @@ -21,6 +21,7 @@ package org.apache.catalina.core;
>
> import java.beans.PropertyChangeEvent;
> import java.beans.PropertyChangeListener;
> +import java.lang.reflect.Constructor;
> import java.net.MalformedURLException;
> import java.net.URL;
> import java.util.Collection;
> @@ -863,7 +864,11 @@ public class NamingContextListener
> }
> }
> } else {
> - logger.error(sm.getString("naming.invalidEnvEntryType", env.getName()));
> + value = constructEnvEntry(env.getType(), env.getValue());
> + if (value == null) {
> + logger.error(sm.getString(
> + "naming.invalidEnvEntryType", env.getName()));
> + }
> }
> } catch (NumberFormatException e) {
> logger.error(sm.getString("naming.invalidEnvEntryValue", env.getName()));
> @@ -886,6 +891,33 @@ public class NamingContextListener
> }
>
>
> + private Object constructEnvEntry(String type, String value) {
> + try {
> + Class<?> clazz = Class.forName(type);
> + Constructor<?> c = null;
> + try {
> + c = clazz.getConstructor(String.class);
> + return c.newInstance(value);
> + } catch (NoSuchMethodException e) {
> + // Ignore
> + }
> +
> + if (value.length() != 1) {
> + return null;
> + }
> +
> + try {
> + c = clazz.getConstructor(char.class);
> + return c.newInstance(Character.valueOf(value.charAt(0)));
> + } catch (NoSuchMethodException e) {
> + // Ignore
> + }
> + } catch (Exception e) {
> + // Ignore
> + }
> + return null;
> + }
> +
> /**
> * Set the specified local EJBs in the naming context.
> */
>
> Modified: tomcat/tc7.0.x/trunk/test/org/apache/catalina/core/TestNamingContextListener.java
> (...)
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org