Browse Source
Previously, when a Tomcat connector failed to start it was assumed that the failure was due to the port being in use and a PortInUseException was thrown. Unfortunately, this assumption doesn’t always hold true. For example, a Tomcat connector will also fail to start when its using SSL and the key store password is wrong. This could lead to incorrect guidance from the PortInUseFailureAnalyzer indicating that a port clash had occurred when, in fact, it was the SSL configuration that needed to be corrected. Unfortunately, Tomcat only tells us that the connector failed to start. It doesn’t provide access to the exception that would allow us to determine why it failed to start. This commit updates the embedded Tomcat container to throw a ConnectorStartFailedException in the event of a connector failing to start. A new failure analyser, ConnectorStartFailureAnalyzer, has been introduced to analyse the new exception and offer some more general guidance. Closes gh-6896pull/6858/merge
8 changed files with 127 additions and 7 deletions
@ -0,0 +1,50 @@
@@ -0,0 +1,50 @@
|
||||
/* |
||||
* Copyright 2012-2016 the original author or authors. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package org.springframework.boot.context.embedded.tomcat; |
||||
|
||||
import org.apache.catalina.connector.Connector; |
||||
|
||||
import org.springframework.boot.context.embedded.EmbeddedServletContainerException; |
||||
|
||||
/** |
||||
* A {@code ConnectorStartFailedException} is thrown when a Tomcat {@link Connector} fails |
||||
* to start, for example due to a port clash or incorrect SSL configuration. |
||||
* |
||||
* @author Andy Wilkinson |
||||
* @since 1.4.1 |
||||
*/ |
||||
public class ConnectorStartFailedException extends EmbeddedServletContainerException { |
||||
|
||||
private final int port; |
||||
|
||||
/** |
||||
* Creates a new {@code ConnectorStartFailedException} for a connector that's |
||||
* configured to listen on the given {@code port}. |
||||
* |
||||
* @param port the port |
||||
*/ |
||||
public ConnectorStartFailedException(int port) { |
||||
super("Connector configured to listen on port " + port + " failed to start", |
||||
null); |
||||
this.port = port; |
||||
} |
||||
|
||||
public int getPort() { |
||||
return this.port; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,44 @@
@@ -0,0 +1,44 @@
|
||||
/* |
||||
* Copyright 2012-2016 the original author or authors. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package org.springframework.boot.diagnostics.analyzer; |
||||
|
||||
import org.springframework.boot.context.embedded.tomcat.ConnectorStartFailedException; |
||||
import org.springframework.boot.diagnostics.AbstractFailureAnalyzer; |
||||
import org.springframework.boot.diagnostics.FailureAnalysis; |
||||
|
||||
/** |
||||
* An {@link AbstractFailureAnalyzer} for {@link ConnectorStartFailedException}. |
||||
* |
||||
* @author Andy Wilkinson |
||||
*/ |
||||
class ConnectorStartFailureAnalyzer |
||||
extends AbstractFailureAnalyzer<ConnectorStartFailedException> { |
||||
|
||||
@Override |
||||
protected FailureAnalysis analyze(Throwable rootFailure, |
||||
ConnectorStartFailedException cause) { |
||||
return new FailureAnalysis( |
||||
"The Tomcat connector configured to listen on port " + cause.getPort() |
||||
+ " failed to start. The port may already be in use or the" |
||||
+ " connector may be misconfigured.", |
||||
"Verify the connector's configuration, identify and stop any process " |
||||
+ "that's listening on port " + cause.getPort() |
||||
+ ", or configure this application to listen on another port.", |
||||
cause); |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue