final File serverXml = new File(catalinaBase, "conf/server.xml");
if (!serverXml.exists()) { // openejb
return;
}
final QuickServerXmlParser parser = QuickServerXmlParser.parse(serverXml);
String value = read(serverXml);
File keystoreFile = new File(parser.keystore());
if (!keystoreFile.exists()) {
keystoreFile = new File(System.getProperty("user.home"), ".keystore");
}
if (!keystoreFile.exists()) {
keystoreFile = new File("target", ".keystore");
}
final String keystoreFilePath = (keystoreFile.exists() ? keystoreFile.getAbsolutePath() : "");
if (tomeeHttpsPort != null && tomeeHttpsPort > 0 && parser.value("HTTPS", null) == null) {
// ensure connector is not commented
value = value.replace("<Service name=\"Catalina\">", "<Service name=\"Catalina\">\n"
+ " <Connector port=\"" + tomeeHttpsPort + "\" protocol=\"HTTP/1.1\" SSLEnabled=\"true\"\n" +
" scheme=\"https\" secure=\"true\"\n" +
" clientAuth=\"false\" sslProtocol=\"TLS\" keystoreFile=\"" + keystoreFilePath + "\" />\n");
}
if (tomeeHttpsPort == null) {
// avoid NPE
tomeeHttpsPort = 8443;
}
FileWriter writer = null;
try {
writer = new FileWriter(serverXml);
writer.write(value
.replace(parser.http(), Integer.toString(tomeeHttpPort))
.replace(parser.https(), Integer.toString(tomeeHttpsPort))
.replace(parser.ajp(), Integer.toString(tomeeAjpPort))
.replace(parser.stop(), Integer.toString(tomeeShutdownPort))
.replace(parser.host(), tomeeHost)
.replace(parser.appBase(), webappDir));
} catch (final IOException e) {
throw new TomEEException(e.getMessage(), e);
} finally {
close(writer);
}