add config value for ssl/https port (default=8443)

adjust server routines to use config
pull/1/head
reger 11 years ago
parent 91d79c1ac4
commit a71718a459

@ -10,6 +10,9 @@
# port number where the server should bind to # port number where the server should bind to
port = 8090 port = 8090
# optinal ssl port (https port) the server should bind to
port.ssl = 8443
# prefix for new default peer names # prefix for new default peer names
peernameprefix=_anon peernameprefix=_anon
@ -31,7 +34,7 @@ bindPort =
# #
# English speaking user read below: # English speaking user read below:
# #
# With this you can access your peer using https://localhost:8090 # With this you can access your peer using https://localhost:8443
# #
# There are two possibilities to specify which certificate should # There are two possibilities to specify which certificate should
# be used by YaCy. # be used by YaCy.
@ -65,7 +68,7 @@ pkcs12ImportPwd =
# the keyStore is only used, if server.https is set to true # the keyStore is only used, if server.https is set to true
# if server.https=true, then the YaCy web interface is available at # if server.https=true, then the YaCy web interface is available at
# https://localhost:<port>/ and not at http://localhost:<port>/ # https://localhost:<port.ssl>/ and at http://localhost:<port>/
server.https=false server.https=false
# property that collects the names of all servlets that had been used so far # property that collects the names of all servlets that had been used so far

@ -70,7 +70,6 @@ import org.eclipse.jetty.webapp.WebAppContext;
public class Jetty8HttpServerImpl implements YaCyHttpServer { public class Jetty8HttpServerImpl implements YaCyHttpServer {
private final Server server; private final Server server;
private final int sslport = 8443; // the port to use for https
/** /**
* @param port TCP Port to listen for http requests * @param port TCP Port to listen for http requests
@ -90,6 +89,7 @@ public class Jetty8HttpServerImpl implements YaCyHttpServer {
final SslContextFactory sslContextFactory = new SslContextFactory(); final SslContextFactory sslContextFactory = new SslContextFactory();
final SSLContext sslContext = initSslContext(sb); final SSLContext sslContext = initSslContext(sb);
if (sslContext != null) { if (sslContext != null) {
int sslport = sb.getConfigInt("port.ssl", 8443);
sslContextFactory.setSslContext(sslContext); sslContextFactory.setSslContext(sslContext);
SslSelectChannelConnector sslconnector = new SslSelectChannelConnector(sslContextFactory); SslSelectChannelConnector sslconnector = new SslSelectChannelConnector(sslContextFactory);
@ -234,6 +234,9 @@ public class Jetty8HttpServerImpl implements YaCyHttpServer {
// TODO: // TODO:
} }
/**
* @return true if ssl/https connector is available
*/
@Override @Override
public boolean withSSL() { public boolean withSSL() {
Connector[] clist = server.getConnectors(); Connector[] clist = server.getConnectors();
@ -242,16 +245,24 @@ public class Jetty8HttpServerImpl implements YaCyHttpServer {
} }
return false; return false;
} }
/**
* The port of actual running ssl connector
* @return the ssl/https port or -1 if not active
*/
@Override @Override
public int getSslPort() { public int getSslPort() {
return sslport; Connector[] clist = server.getConnectors();
for (Connector c:clist) {
if (c.getName().startsWith("ssl")) return c.getPort();
}
return -1;
} }
/** /**
* reconnect with new port settings (after waiting milsec) - routine returns * reconnect with new port settings (after waiting milsec) - routine returns
* immediately * immediately
* * checks http and ssl connector for new port settings
* @param milsec wait time * @param milsec wait time
*/ */
@Override @Override
@ -271,7 +282,9 @@ public class Jetty8HttpServerImpl implements YaCyHttpServer {
try { // reconnect with new settings (instead to stop/start server, just manipulate connectors try { // reconnect with new settings (instead to stop/start server, just manipulate connectors
final Connector[] cons = server.getConnectors(); final Connector[] cons = server.getConnectors();
final int port = Switchboard.getSwitchboard().getConfigInt("port", 8090); final int port = Switchboard.getSwitchboard().getConfigInt("port", 8090);
final int sslport = Switchboard.getSwitchboard().getConfigInt("port.ssl", 8443);
for (Connector con : cons) { for (Connector con : cons) {
// check http connector
if (con.getName().startsWith("httpd") && con.getPort() != port) { if (con.getName().startsWith("httpd") && con.getPort() != port) {
con.close(); con.close();
con.stop(); con.stop();
@ -280,7 +293,19 @@ public class Jetty8HttpServerImpl implements YaCyHttpServer {
} }
con.setPort(port); con.setPort(port);
con.start(); con.start();
ConcurrentLog.fine("SERVER", "set new port for Jetty connector " + con.getName()); ConcurrentLog.info("SERVER", "set new port for Jetty connector " + con.getName());
continue;
}
// check https connector
if (con.getName().startsWith("ssl") && con.getPort() != sslport) {
con.close();
con.stop();
if (!con.isStopped()) {
ConcurrentLog.warn("SERVER", "Reconnect: Jetty Connector failed to stop");
}
con.setPort(sslport);
con.start();
ConcurrentLog.info("SERVER", "set new port for Jetty connector " + con.getName());
} }
} }
} catch (Exception ex) { } catch (Exception ex) {

Loading…
Cancel
Save