private XmlRpcClient connect(String hostPort) throws XMLDBException {
synchronized (this) {
if (client == null) {
// Initialize XML-RPC static properties
XmlRpcClientConfigImpl cfg = new XmlRpcClientConfigImpl();
cfg.setEncoding("utf-8");
// FIXME Is XmlRpc.setKeepAlive(true); gone forever?
/*
* Determine the path in the web server to the XML-RPC service.
*
* In priority order:
* DatabaseImpl service-location property
* (passed in the serviceLocation parameter)
* System property "xindice.xmlrpc.service-location"
* Default value "/xindice/"
*/
String serviceLocation = getProperty(PROP_SERVICE_LOCATION);
if (serviceLocation == null) {
serviceLocation = System.getProperty(SYSPROP_SERVICE_LOCATION);
if (serviceLocation == null) {
serviceLocation = DEFAULT_SERVICE_LOCATION;
}
}
if (!serviceLocation.startsWith("/")) {
serviceLocation = "/" + serviceLocation;
}
if (!serviceLocation.endsWith("/")) {
serviceLocation = serviceLocation + "/";
}
String xmlRpcURL = "http://" + hostPort + serviceLocation;
if (log.isDebugEnabled()) {
log.debug("Using URL: '" + xmlRpcURL + "'");
}
try {
cfg.setServerURL(new URL(xmlRpcURL));
} catch (MalformedURLException e) {
throw new XMLDBException(ErrorCodes.INVALID_URI, e);
}
/*
* Determine basic authentication parameters
*/
String basicUser = getProperty(PROP_XMLRPC_USER);
if (basicUser == null) {
basicUser = System.getProperty(SYSPROP_XMLRPC_USER);
}
if (basicUser != null) {
String basicPassword = getProperty(PROP_XMLRPC_PASSWORD);
if (basicPassword == null) {
basicPassword = System.getProperty(SYSPROP_XMLRPC_PASSWORD);
}
if (log.isDebugEnabled()) {
log.debug("Using Basic authentication. User: '" + basicUser + "', password: '" + basicPassword + "'");
}
cfg.setBasicUserName(basicPassword);
cfg.setBasicPassword(basicPassword);
}
client = new XmlRpcClient();
client.setConfig(cfg);
}