- Replace custom Server.InetEndpoint class with java.net.InetSocketAddress
- Remove code in Server.checkPort() that calls InetAddress.getLocalHost() in case no interface is defined. This should help fixing bogus error message when default interface is not up.
This commit is contained in:
parent
3f6010377e
commit
ea2d20c55f
3 changed files with 50 additions and 78 deletions
|
@ -25,6 +25,7 @@ import org.mortbay.util.InetAddrPort;
|
||||||
|
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class JettyServer {
|
public class JettyServer {
|
||||||
|
@ -49,19 +50,19 @@ public class JettyServer {
|
||||||
openListeners();
|
openListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
private JettyServer(InetEndpoint webPort, InetEndpoint ajpPort, Server server)
|
private JettyServer(InetSocketAddress webPort, InetSocketAddress ajpPort, Server server)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
http = new HttpServer();
|
http = new HttpServer();
|
||||||
|
|
||||||
// create embedded web server if port is specified
|
// create embedded web server if port is specified
|
||||||
if (webPort != null) {
|
if (webPort != null) {
|
||||||
http.addListener(new InetAddrPort(webPort.getInetAddress(), webPort.getPort()));
|
http.addListener(new InetAddrPort(webPort.getAddress(), webPort.getPort()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// activate the ajp13-listener
|
// activate the ajp13-listener
|
||||||
if (ajpPort != null) {
|
if (ajpPort != null) {
|
||||||
// create AJP13Listener
|
// create AJP13Listener
|
||||||
ajp13 = new AJP13Listener(new InetAddrPort(ajpPort.getInetAddress(), ajpPort.getPort()));
|
ajp13 = new AJP13Listener(new InetAddrPort(ajpPort.getAddress(), ajpPort.getPort()));
|
||||||
ajp13.setHttpServer(http);
|
ajp13.setHttpServer(http);
|
||||||
|
|
||||||
String jkallow = server.sysProps.getProperty("allowAJP13");
|
String jkallow = server.sysProps.getProperty("allowAJP13");
|
||||||
|
|
|
@ -29,9 +29,7 @@ import java.io.*;
|
||||||
import java.rmi.registry.*;
|
import java.rmi.registry.*;
|
||||||
import java.rmi.server.*;
|
import java.rmi.server.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.net.UnknownHostException;
|
import java.net.*;
|
||||||
import java.net.ServerSocket;
|
|
||||||
import java.net.InetAddress;
|
|
||||||
|
|
||||||
import helma.util.ResourceProperties;
|
import helma.util.ResourceProperties;
|
||||||
|
|
||||||
|
@ -69,10 +67,10 @@ public class Server implements Runnable {
|
||||||
private Thread mainThread;
|
private Thread mainThread;
|
||||||
|
|
||||||
// server ports
|
// server ports
|
||||||
InetEndpoint rmiPort = null;
|
InetSocketAddress rmiPort = null;
|
||||||
InetEndpoint xmlrpcPort = null;
|
InetSocketAddress xmlrpcPort = null;
|
||||||
InetEndpoint websrvPort = null;
|
InetSocketAddress websrvPort = null;
|
||||||
InetEndpoint ajp13Port = null;
|
InetSocketAddress ajp13Port = null;
|
||||||
|
|
||||||
// Jetty configuration file
|
// Jetty configuration file
|
||||||
File configFile = null;
|
File configFile = null;
|
||||||
|
@ -200,7 +198,7 @@ public class Server implements Runnable {
|
||||||
// check if there's a property setting for those ports not specified via command line
|
// check if there's a property setting for those ports not specified via command line
|
||||||
if (!config.hasWebsrvPort() && sysProps.getProperty("webPort") != null) {
|
if (!config.hasWebsrvPort() && sysProps.getProperty("webPort") != null) {
|
||||||
try {
|
try {
|
||||||
config.setWebsrvPort(new InetEndpoint(sysProps.getProperty("webPort")));
|
config.setWebsrvPort(getInetSocketAddress(sysProps.getProperty("webPort")));
|
||||||
} catch (Exception portx) {
|
} catch (Exception portx) {
|
||||||
throw new Exception("Error parsing web server port property from server.properties: " + portx);
|
throw new Exception("Error parsing web server port property from server.properties: " + portx);
|
||||||
}
|
}
|
||||||
|
@ -208,7 +206,7 @@ public class Server implements Runnable {
|
||||||
|
|
||||||
if (!config.hasAjp13Port() && sysProps.getProperty("ajp13Port") != null) {
|
if (!config.hasAjp13Port() && sysProps.getProperty("ajp13Port") != null) {
|
||||||
try {
|
try {
|
||||||
config.setAjp13Port(new InetEndpoint(sysProps.getProperty("ajp13Port")));
|
config.setAjp13Port(getInetSocketAddress(sysProps.getProperty("ajp13Port")));
|
||||||
} catch (Exception portx) {
|
} catch (Exception portx) {
|
||||||
throw new Exception("Error parsing AJP1.3 server port property from server.properties: " + portx);
|
throw new Exception("Error parsing AJP1.3 server port property from server.properties: " + portx);
|
||||||
}
|
}
|
||||||
|
@ -216,7 +214,7 @@ public class Server implements Runnable {
|
||||||
|
|
||||||
if (!config.hasRmiPort() && sysProps.getProperty("rmiPort") != null) {
|
if (!config.hasRmiPort() && sysProps.getProperty("rmiPort") != null) {
|
||||||
try {
|
try {
|
||||||
config.setRmiPort(new InetEndpoint(sysProps.getProperty("rmiPort")));
|
config.setRmiPort(getInetSocketAddress(sysProps.getProperty("rmiPort")));
|
||||||
} catch (Exception portx) {
|
} catch (Exception portx) {
|
||||||
throw new Exception("Error parsing RMI server port property from server.properties: " + portx);
|
throw new Exception("Error parsing RMI server port property from server.properties: " + portx);
|
||||||
}
|
}
|
||||||
|
@ -224,7 +222,7 @@ public class Server implements Runnable {
|
||||||
|
|
||||||
if (!config.hasXmlrpcPort() && sysProps.getProperty("xmlrpcPort") != null) {
|
if (!config.hasXmlrpcPort() && sysProps.getProperty("xmlrpcPort") != null) {
|
||||||
try {
|
try {
|
||||||
config.setXmlrpcPort(new InetEndpoint(sysProps.getProperty("xmlrpcPort")));
|
config.setXmlrpcPort(getInetSocketAddress(sysProps.getProperty("xmlrpcPort")));
|
||||||
} catch (Exception portx) {
|
} catch (Exception portx) {
|
||||||
throw new Exception("Error parsing XML-RPC server port property from server.properties: " + portx);
|
throw new Exception("Error parsing XML-RPC server port property from server.properties: " + portx);
|
||||||
}
|
}
|
||||||
|
@ -247,25 +245,25 @@ public class Server implements Runnable {
|
||||||
config.setPropFile(new File(args[++i]));
|
config.setPropFile(new File(args[++i]));
|
||||||
} else if (args[i].equals("-p") && ((i + 1) < args.length)) {
|
} else if (args[i].equals("-p") && ((i + 1) < args.length)) {
|
||||||
try {
|
try {
|
||||||
config.setRmiPort(new InetEndpoint(args[++i]));
|
config.setRmiPort(getInetSocketAddress(args[++i]));
|
||||||
} catch (Exception portx) {
|
} catch (Exception portx) {
|
||||||
throw new Exception("Error parsing RMI server port property: " + portx);
|
throw new Exception("Error parsing RMI server port property: " + portx);
|
||||||
}
|
}
|
||||||
} else if (args[i].equals("-x") && ((i + 1) < args.length)) {
|
} else if (args[i].equals("-x") && ((i + 1) < args.length)) {
|
||||||
try {
|
try {
|
||||||
config.setXmlrpcPort(new InetEndpoint(args[++i]));
|
config.setXmlrpcPort(getInetSocketAddress(args[++i]));
|
||||||
} catch (Exception portx) {
|
} catch (Exception portx) {
|
||||||
throw new Exception("Error parsing XML-RPC server port property: " + portx);
|
throw new Exception("Error parsing XML-RPC server port property: " + portx);
|
||||||
}
|
}
|
||||||
} else if (args[i].equals("-w") && ((i + 1) < args.length)) {
|
} else if (args[i].equals("-w") && ((i + 1) < args.length)) {
|
||||||
try {
|
try {
|
||||||
config.setWebsrvPort(new InetEndpoint(args[++i]));
|
config.setWebsrvPort(getInetSocketAddress(args[++i]));
|
||||||
} catch (Exception portx) {
|
} catch (Exception portx) {
|
||||||
throw new Exception("Error parsing web server port property: " + portx);
|
throw new Exception("Error parsing web server port property: " + portx);
|
||||||
}
|
}
|
||||||
} else if (args[i].equals("-jk") && ((i + 1) < args.length)) {
|
} else if (args[i].equals("-jk") && ((i + 1) < args.length)) {
|
||||||
try {
|
try {
|
||||||
config.setAjp13Port(new InetEndpoint(args[++i]));
|
config.setAjp13Port(getInetSocketAddress(args[++i]));
|
||||||
} catch (Exception portx) {
|
} catch (Exception portx) {
|
||||||
throw new Exception("Error parsing AJP1.3 server port property: " + portx);
|
throw new Exception("Error parsing AJP1.3 server port property: " + portx);
|
||||||
}
|
}
|
||||||
|
@ -387,24 +385,14 @@ public class Server implements Runnable {
|
||||||
/**
|
/**
|
||||||
* Check whether a server port is available by trying to open a server socket
|
* Check whether a server port is available by trying to open a server socket
|
||||||
*/
|
*/
|
||||||
private static void checkPort(InetEndpoint addrPort) throws Exception {
|
private static void checkPort(InetSocketAddress endpoint) throws IOException {
|
||||||
InetAddress addr = addrPort.getInetAddress();
|
|
||||||
int port = addrPort.getPort();
|
|
||||||
if (addr == null) {
|
|
||||||
try {
|
|
||||||
addr = InetAddress.getLocalHost();
|
|
||||||
} catch (UnknownHostException unknown) {
|
|
||||||
System.err.println("Error checking running server: localhost is unknown.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
ServerSocket sock = new ServerSocket(port, 1, addr);
|
ServerSocket sock = new ServerSocket();
|
||||||
|
sock.bind(endpoint);
|
||||||
sock.close();
|
sock.close();
|
||||||
} catch (Exception x) {
|
} catch (IOException x) {
|
||||||
throw new Exception("Error: Server already running on this port: " + addrPort);
|
throw new IOException("Error binding to " + endpoint + ": " + x.getMessage());
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -581,8 +569,8 @@ public class Server implements Runnable {
|
||||||
XmlRpc.setDriver(xmlparser);
|
XmlRpc.setDriver(xmlparser);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xmlrpcPort.getInetAddress() != null) {
|
if (xmlrpcPort.getAddress() != null) {
|
||||||
xmlrpc = new WebServer(xmlrpcPort.getPort(), xmlrpcPort.getInetAddress());
|
xmlrpc = new WebServer(xmlrpcPort.getPort(), xmlrpcPort.getAddress());
|
||||||
} else {
|
} else {
|
||||||
xmlrpc = new WebServer(xmlrpcPort.getPort());
|
xmlrpc = new WebServer(xmlrpcPort.getPort());
|
||||||
}
|
}
|
||||||
|
@ -854,42 +842,24 @@ public class Server implements Runnable {
|
||||||
public void stopApplication(String name) {
|
public void stopApplication(String name) {
|
||||||
appManager.stop(name);
|
appManager.stop(name);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
class InetEndpoint {
|
private static InetSocketAddress getInetSocketAddress(String inetAddrPort)
|
||||||
|
throws UnknownHostException {
|
||||||
InetAddress addr;
|
InetAddress addr = null;
|
||||||
int port;
|
|
||||||
|
|
||||||
public InetEndpoint(String inetAddrPort)
|
|
||||||
throws java.net.UnknownHostException {
|
|
||||||
int c = inetAddrPort.indexOf(':');
|
int c = inetAddrPort.indexOf(':');
|
||||||
if (c >= 0) {
|
if (c >= 0) {
|
||||||
String addr = inetAddrPort.substring(0, c);
|
String a = inetAddrPort.substring(0, c);
|
||||||
if (addr.indexOf('/') > 0)
|
if (a.indexOf('/') > 0)
|
||||||
addr = addr.substring(addr.indexOf('/') + 1);
|
a = a.substring(a.indexOf('/') + 1);
|
||||||
inetAddrPort = inetAddrPort.substring(c + 1);
|
inetAddrPort = inetAddrPort.substring(c + 1);
|
||||||
|
|
||||||
if (addr.length() > 0 && !"0.0.0.0".equals(addr)) {
|
if (a.length() > 0 && !"0.0.0.0".equals(a)) {
|
||||||
this.addr = InetAddress.getByName(addr);
|
addr = InetAddress.getByName(a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
int port = Integer.parseInt(inetAddrPort);
|
||||||
this.port = Integer.parseInt(inetAddrPort);
|
return new InetSocketAddress(addr, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
public InetAddress getInetAddress() {
|
|
||||||
return addr;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPort() {
|
|
||||||
return port;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
return addr == null ? "0.0.0.0:" + port : addr + ":" + port;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package helma.main;
|
package helma.main;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility class for server config
|
* Utility class for server config
|
||||||
|
@ -24,13 +25,13 @@ import java.io.File;
|
||||||
|
|
||||||
public class ServerConfig {
|
public class ServerConfig {
|
||||||
|
|
||||||
private InetEndpoint rmiPort = null;
|
private InetSocketAddress rmiPort = null;
|
||||||
private InetEndpoint xmlrpcPort = null;
|
private InetSocketAddress xmlrpcPort = null;
|
||||||
private InetEndpoint websrvPort = null;
|
private InetSocketAddress websrvPort = null;
|
||||||
private InetEndpoint ajp13Port = null;
|
private InetSocketAddress ajp13Port = null;
|
||||||
private File propFile = null;
|
private File propFile = null;
|
||||||
private File homeDir = null;
|
private File homeDir = null;
|
||||||
private File configFile = null;
|
private File configFile = null;
|
||||||
|
|
||||||
public boolean hasPropFile() {
|
public boolean hasPropFile() {
|
||||||
return (propFile != null);
|
return (propFile != null);
|
||||||
|
@ -56,35 +57,35 @@ public class ServerConfig {
|
||||||
return (ajp13Port != null);
|
return (ajp13Port != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public InetEndpoint getRmiPort() {
|
public InetSocketAddress getRmiPort() {
|
||||||
return rmiPort;
|
return rmiPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRmiPort(InetEndpoint rmiPort) {
|
public void setRmiPort(InetSocketAddress rmiPort) {
|
||||||
this.rmiPort = rmiPort;
|
this.rmiPort = rmiPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
public InetEndpoint getXmlrpcPort() {
|
public InetSocketAddress getXmlrpcPort() {
|
||||||
return xmlrpcPort;
|
return xmlrpcPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setXmlrpcPort(InetEndpoint xmlrpcPort) {
|
public void setXmlrpcPort(InetSocketAddress xmlrpcPort) {
|
||||||
this.xmlrpcPort = xmlrpcPort;
|
this.xmlrpcPort = xmlrpcPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
public InetEndpoint getWebsrvPort() {
|
public InetSocketAddress getWebsrvPort() {
|
||||||
return websrvPort;
|
return websrvPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setWebsrvPort(InetEndpoint websrvPort) {
|
public void setWebsrvPort(InetSocketAddress websrvPort) {
|
||||||
this.websrvPort = websrvPort;
|
this.websrvPort = websrvPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
public InetEndpoint getAjp13Port() {
|
public InetSocketAddress getAjp13Port() {
|
||||||
return ajp13Port;
|
return ajp13Port;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAjp13Port(InetEndpoint ajp13Port) {
|
public void setAjp13Port(InetSocketAddress ajp13Port) {
|
||||||
this.ajp13Port = ajp13Port;
|
this.ajp13Port = ajp13Port;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue