Include both the docbroker in the dfc.properties.
public static IDfSession connectToDocbase1(String docbaseName,
String username, String passwd, String domain,
String docBrokerHost, String docBrokerPort) throws DfException {
try {
IDfSession session = null;
IDfClientX clientX = new DfClientX();
IDfClient client = clientX.getLocalClient();
IDfLoginInfo loginInfo = new DfLoginInfo();
loginInfo.setUser(username);
loginInfo.setPassword(passwd);
loginInfo.setDomain(domain);
if (docBrokerHost != null && docBrokerHost.length() > 0) {
IDfTypedObject apiconfig = client.getClientConfig();
String primaryHost = apiconfig.getString("primary_host");
String primaryPort = apiconfig.getString("primary_port");
apiconfig.setString("primary_host", docBrokerHost);
apiconfig.setString("primary_port", docBrokerPort);
try {
IDfTypedObject serverMap = client.getServerMapEx(
docbaseName, null, docBrokerHost, docBrokerPort);
session = client.newSession(docbaseName + "@"
+ serverMap.getString("i_host_name"), loginInfo);
} catch (DfException e) {
if (primaryHost != null) {
apiconfig.setString("primary_host", primaryHost);
}
if (primaryPort != null) {
apiconfig.setString("primary_port", primaryPort);
}
throw e;
}
apiconfig.setString("primary_host", primaryHost);
apiconfig.setString("primary_port", primaryPort);
} else {
session = client.newSession(docbaseName, loginInfo);
}
return session;
} catch (DfException ex) {
System.out.println("failed to connect " + ex.getMessage());
throw ex;
}
}
Comments (0)
Post a Comment