Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #279 from rhusar/MODCLUSTER-457
MODCLUSTER-457 Expose Tomcat configuration to explicitly specify a connector to register with the proxy
- Loading branch information
Showing
40 changed files
with
424 additions
and
256 deletions.
There are no files selected for viewing
59 changes: 0 additions & 59 deletions
59
...omcat/src/main/java/org/jboss/modcluster/container/tomcat/AutoProxyConnectorProvider.java
This file was deleted.
Oops, something went wrong.
98 changes: 98 additions & 0 deletions
98
...c/main/java/org/jboss/modcluster/container/tomcat/ConfigurableProxyConnectorProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright 2017, Red Hat Middleware LLC, and individual contributors | ||
* as indicated by the @author tags. See the copyright.txt file in the | ||
* distribution for a full listing of individual contributors. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package org.jboss.modcluster.container.tomcat; | ||
|
||
import java.net.InetAddress; | ||
import java.net.UnknownHostException; | ||
|
||
import org.apache.catalina.Engine; | ||
import org.jboss.modcluster.ModClusterLogger; | ||
import org.jboss.modcluster.container.Connector; | ||
|
||
/** | ||
* Connector provider implementation that picks a connector based on configured {@code connectorPort=".."} and/or {@code connectorAddress=".."}. | ||
* Should multiple or no connectors match the defined values a {@link RuntimeException} is thrown. | ||
* | ||
* @author Radoslav Husar | ||
*/ | ||
public class ConfigurableProxyConnectorProvider implements ProxyConnectorProvider { | ||
|
||
private final TomcatConnectorConfiguration connectorConfiguration; | ||
|
||
public ConfigurableProxyConnectorProvider(TomcatConnectorConfiguration connectorConfiguration) { | ||
this.connectorConfiguration = connectorConfiguration; | ||
} | ||
|
||
@Override | ||
public Connector createProxyConnector(ConnectorFactory factory, Engine engine) { | ||
// Resolve configuration parameters *after* it was set by Tomcat modeler | ||
String connectorAddress = connectorConfiguration.getConnectorAddress(); | ||
Integer connectorPort = connectorConfiguration.getConnectorPort(); | ||
|
||
// Iterate entire collection of connectors once, ensuring that exactly only *one* matches the given host:port configuration | ||
org.apache.catalina.connector.Connector candidate = null; | ||
|
||
for (org.apache.catalina.connector.Connector connector : engine.getService().findConnectors()) { | ||
if (connectorPort == null || connectorPort.equals(connector.getPort())) { | ||
|
||
String resolvedConfiguredAddress = null; | ||
String addressInTomcat = null; | ||
|
||
if (connector != null) { | ||
// Resolve the connector's address in use | ||
Object addressObj = connector.getProperty("address"); | ||
if (addressObj instanceof InetAddress) { | ||
addressInTomcat = ((InetAddress) addressObj).getHostAddress(); | ||
} else if (addressObj != null) { | ||
addressInTomcat = addressObj.toString(); | ||
} | ||
|
||
// Resolve configured address | ||
try { | ||
resolvedConfiguredAddress = InetAddress.getByName(connectorAddress).getHostAddress(); | ||
} catch (UnknownHostException e) { | ||
throw ModClusterLogger.LOGGER.connectorAddressUnknownHost(connectorAddress); | ||
} | ||
} | ||
|
||
if (connectorAddress == null || resolvedConfiguredAddress.equalsIgnoreCase(addressInTomcat)) { | ||
if (candidate == null) { | ||
candidate = connector; | ||
} else { | ||
throw ModClusterLogger.LOGGER.connectorMatchesMultiple(format(connectorAddress, connectorPort)); | ||
} | ||
} | ||
|
||
} | ||
} | ||
|
||
if (candidate == null) { | ||
throw ModClusterLogger.LOGGER.connectorNoMatch(format(connectorAddress, connectorPort)); | ||
} | ||
|
||
return factory.createConnector(candidate); | ||
} | ||
|
||
private static String format(String connectorAddress, Integer connectorPort) { | ||
return (connectorAddress == null ? "*" : connectorAddress) + ":" + (connectorPort == null ? "*" : connectorPort); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...cat/src/main/java/org/jboss/modcluster/container/tomcat/TomcatConnectorConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright 2017, Red Hat Middleware LLC, and individual contributors | ||
* as indicated by the @author tags. See the copyright.txt file in the | ||
* distribution for a full listing of individual contributors. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package org.jboss.modcluster.container.tomcat; | ||
|
||
/** | ||
* Tomcat-specific configuration for selecting a connector to register with the proxy. | ||
* | ||
* @author Radoslav Husar | ||
*/ | ||
public interface TomcatConnectorConfiguration { | ||
|
||
/** | ||
* Returns optional connector address. | ||
* | ||
* @return connector address | ||
*/ | ||
String getConnectorAddress(); | ||
|
||
/** | ||
* Returns optional connector port. | ||
* | ||
* @return connector port | ||
*/ | ||
Integer getConnectorPort(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.