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 2016/10/07 14:39:48 UTC
svn commit: r1763769 - in /tomcat/trunk: java/org/apache/catalina/connector/
java/org/apache/catalina/core/ test/org/apache/catalina/connector/
webapps/docs/ webapps/docs/config/
Author: markt
Date: Fri Oct 7 14:39:47 2016
New Revision: 1763769
URL: http://svn.apache.org/viewvc?rev=1763769&view=rev
Log:
Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=60152
Provide an option for Connector Lifecycle exceptions to be re-thrown rather than logged. This is controlled by the new throwOnFailure attribute of the Connector.
Modified:
tomcat/trunk/java/org/apache/catalina/connector/Connector.java
tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties
tomcat/trunk/java/org/apache/catalina/core/LocalStrings_es.properties
tomcat/trunk/java/org/apache/catalina/core/StandardService.java
tomcat/trunk/test/org/apache/catalina/connector/TestConnector.java
tomcat/trunk/webapps/docs/changelog.xml
tomcat/trunk/webapps/docs/config/ajp.xml
tomcat/trunk/webapps/docs/config/http.xml
tomcat/trunk/webapps/docs/config/systemprops.xml
Modified: tomcat/trunk/java/org/apache/catalina/connector/Connector.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/Connector.java?rev=1763769&r1=1763768&r2=1763769&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/Connector.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/Connector.java Fri Oct 7 14:39:47 2016
@@ -106,6 +106,9 @@ public class Connector extends Lifecycle
URIEncoding = "UTF-8";
URIEncodingLower = URIEncoding.toLowerCase(Locale.ENGLISH);
}
+
+ // Default for Connector depends on this system property
+ setThrowOnFailure(Boolean.getBoolean("org.apache.catalina.startup.EXIT_ON_INIT_FAILURE"));
}
Modified: tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties?rev=1763769&r1=1763768&r2=1763769&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties (original)
+++ tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties Fri Oct 7 14:39:47 2016
@@ -190,10 +190,6 @@ standardHostValue.customStatusFailed=Cus
standardServer.accept.timeout=The socket listening for the shutdown command experienced an unexpected timeout [{0}] milliseconds after the call to accept(). Is this an instance of bug 56684?
standardServer.shutdownViaPort=A valid shutdown command was received via the shutdown port. Stopping the Server instance.
standardServer.storeConfig.notAvailable=No StoreConfig implementation was registered as an MBean named [{0}] so no configuration could be saved. A suitable MBean is normally registered via the StoreConfigLifecyleListener.
-standardService.connector.destroyFailed=Failed to destroy connector [{0}]
-standardService.connector.initFailed=Failed to initialize connector [{0}]
-standardService.connector.startFailed=Failed to start connector [{0}]
-standardService.connector.stopFailed=Failed to stop connector [{0}]
standardService.engine.startFailed=Failed to start associated Engine
standardService.engine.stopFailed=Failed to stop associated Engine
standardService.mapperListener.startFailed=Failed to start associated MapperListener
Modified: tomcat/trunk/java/org/apache/catalina/core/LocalStrings_es.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/LocalStrings_es.properties?rev=1763769&r1=1763768&r2=1763769&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/LocalStrings_es.properties (original)
+++ tomcat/trunk/java/org/apache/catalina/core/LocalStrings_es.properties Fri Oct 7 14:39:47 2016
@@ -127,9 +127,6 @@ standardHost.noContext = No se ha config
standardHost.notContext = El Hijo de una M\u00E1quina debe de ser un Contexto
standardHost.nullName = Es necesario poner el nombre de M\u00E1quina
standardServer.shutdownViaPort = Se ha recibido un comando de apagado a trav\u00E9s del puerto de apagado. Parando la instancia del Servidor.
-standardService.connector.initFailed = No pude inicializar el conector [{0}]
-standardService.connector.startFailed = No pude arrancar el conector [{0}]
-standardService.connector.stopFailed = No pude parar el conector [{0}]
standardService.start.name = Arrancando servicio {0}
standardService.stop.name = Parando servicio {0}
standardWrapper.allocate = Error reservando espacio para una instancia de servlet
Modified: tomcat/trunk/java/org/apache/catalina/core/StandardService.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardService.java?rev=1763769&r1=1763768&r2=1763769&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/StandardService.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/StandardService.java Fri Oct 7 14:39:47 2016
@@ -434,15 +434,9 @@ public class StandardService extends Lif
// Start our defined Connectors second
synchronized (connectorsLock) {
for (Connector connector: connectors) {
- try {
- // If it has already failed, don't try and start it
- if (connector.getState() != LifecycleState.FAILED) {
- connector.start();
- }
- } catch (Exception e) {
- log.error(sm.getString(
- "standardService.connector.startFailed",
- connector), e);
+ // If it has already failed, don't try and start it
+ if (connector.getState() != LifecycleState.FAILED) {
+ connector.start();
}
}
}
@@ -488,13 +482,7 @@ public class StandardService extends Lif
// stopped (e.g. via a JMX call)
continue;
}
- try {
- connector.stop();
- } catch (Exception e) {
- log.error(sm.getString(
- "standardService.connector.stopFailed",
- connector), e);
- }
+ connector.stop();
}
}
@@ -539,16 +527,7 @@ public class StandardService extends Lif
// Initialize our defined Connectors
synchronized (connectorsLock) {
for (Connector connector : connectors) {
- try {
- connector.init();
- } catch (Exception e) {
- String message = sm.getString(
- "standardService.connector.initFailed", connector);
- log.error(message, e);
-
- if (Boolean.getBoolean("org.apache.catalina.startup.EXIT_ON_INIT_FAILURE"))
- throw new LifecycleException(message);
- }
+ connector.init();
}
}
}
@@ -561,12 +540,7 @@ public class StandardService extends Lif
// Destroy our defined Connectors
synchronized (connectorsLock) {
for (Connector connector : connectors) {
- try {
- connector.destroy();
- } catch (Exception e) {
- log.error(sm.getString(
- "standardService.connector.destroyFailed", connector), e);
- }
+ connector.destroy();
}
}
Modified: tomcat/trunk/test/org/apache/catalina/connector/TestConnector.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/connector/TestConnector.java?rev=1763769&r1=1763768&r2=1763769&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/connector/TestConnector.java (original)
+++ tomcat/trunk/test/org/apache/catalina/connector/TestConnector.java Fri Oct 7 14:39:47 2016
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertTru
import org.junit.Test;
import org.apache.catalina.Context;
+import org.apache.catalina.LifecycleException;
import org.apache.catalina.Wrapper;
import org.apache.catalina.startup.TesterServlet;
import org.apache.catalina.startup.Tomcat;
@@ -92,4 +93,50 @@ public class TestConnector extends Tomca
assertTrue(localPort1 > 0);
assertTrue(localPort2 > 0);
}
+
+
+ @Test(expected=LifecycleException.class)
+ public void testInvalidProtocolThrows() throws Exception {
+ doTestInvalidProtocol(true);
+ }
+
+
+ @Test
+ public void testInvalidProtocolNoThrows() throws Exception {
+ doTestInvalidProtocol(false);
+ }
+
+
+ private void doTestInvalidProtocol(boolean throwOnFailure) throws Exception {
+ Connector c = new Connector("foo.Bar");
+ c.setThrowOnFailure(throwOnFailure);
+
+ c.start();
+ }
+
+
+ @Test(expected=LifecycleException.class)
+ public void testDuplicatePortThrows() throws Exception {
+ doTestDuplicatePort(true);
+ }
+
+
+ @Test
+ public void testDuplicatePortNoThrows() throws Exception {
+ doTestDuplicatePort(false);
+ }
+
+
+ private void doTestDuplicatePort(boolean throwOnFailure) throws Exception {
+ Connector c1 = new Connector();
+ c1.setThrowOnFailure(throwOnFailure);
+ c1.setPort(0);
+ c1.start();
+
+ Connector c2 = new Connector();
+ c2.setThrowOnFailure(throwOnFailure);
+ c2.setPort(c1.getLocalPort());
+
+ c2.start();
+ }
}
Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1763769&r1=1763768&r2=1763769&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Fri Oct 7 14:39:47 2016
@@ -55,6 +55,11 @@
Reduce multiple error messages when Connector fails to instantiate the
associated ProtocolHandler. (markt)
</fix>
+ <fix>
+ <bug>60152</bug>: Provide an option for Connector Lifecycle exceptions
+ to be re-thrown rather than logged. This is controlled by the new
+ <code>throwOnFailure</code> attribute of the Connector. (markt)
+ </fix>
</changelog>
</subsection>
</section>
Modified: tomcat/trunk/webapps/docs/config/ajp.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/config/ajp.xml?rev=1763769&r1=1763768&r2=1763769&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/config/ajp.xml (original)
+++ tomcat/trunk/webapps/docs/config/ajp.xml Fri Oct 7 14:39:47 2016
@@ -446,6 +446,14 @@
</p>
</attribute>
+ <attribute name="throwOnFailure" required="false">
+ <p>If the Connector expereinces an Exception during a Lifecycle transition
+ should the Exception be rethrown or logged? If not specified, the default
+ of <code>false</code> will be used. Note that the default can be changed
+ by the <code>org.apache.catalina.startup.EXIT_ON_INIT_FAILURE</code>
+ system property.</p>
+ </attribute>
+
<attribute name="tomcatAuthentication" required="false">
<p>If set to <code>true</code>, the authentication will be done in Tomcat.
Otherwise, the authenticated principal will be propagated from the native
Modified: tomcat/trunk/webapps/docs/config/http.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/config/http.xml?rev=1763769&r1=1763768&r2=1763769&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/config/http.xml (original)
+++ tomcat/trunk/webapps/docs/config/http.xml Fri Oct 7 14:39:47 2016
@@ -578,6 +578,15 @@
this priority means.
</p>
</attribute>
+
+ <attribute name="throwOnFailure" required="false">
+ <p>If the Connector expereinces an Exception during a Lifecycle transition
+ should the Exception be rethrown or logged? If not specified, the default
+ of <code>false</code> will be used. Note that the default can be changed
+ by the <code>org.apache.catalina.startup.EXIT_ON_INIT_FAILURE</code>
+ system property.</p>
+ </attribute>
+
</attributes>
</subsection>
Modified: tomcat/trunk/webapps/docs/config/systemprops.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/config/systemprops.xml?rev=1763769&r1=1763768&r2=1763769&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/config/systemprops.xml (original)
+++ tomcat/trunk/webapps/docs/config/systemprops.xml Fri Oct 7 14:39:47 2016
@@ -623,8 +623,11 @@
<property name="org.apache.catalina.startup. EXIT_ON_INIT_FAILURE">
<p>If <code>true</code>, the server will exit if an exception happens
- during the server initialization phase.</p>
- <p>If not specified, the default value of <code>false</code> will be used.</p>
+ during the server initialization phase. To support this feature, this
+ system property is used as the default for the
+ <strong>throwOnFailure</strong> attribute of a Connector.</p>
+ <p>If not specified, the default value of <code>false</code> will be
+ used.</p>
</property>
<property name="org.apache.catalina.startup. RealmRuleSet.MAX_NESTED_REALM_LEVELS">
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org