public Integer run()
{
MailWriter mailWriter;
UserFolderSyncStateStorage syncStateStorage;
HBaseManager hbaseManager = null;
if (useHBase)
{
hbaseManager = new HBaseManager(hbaseQuorum, hbaseclientPort);
mailWriter = HBaseMailWriter.create(hbaseManager, hbaseTableName, hbaseKeyHeader,
hbaseColumnFamily);
syncStateStorage = new HBaseUserFolderSyncStateStorage(hbaseManager, hbaseMetadataTableName);
}
else
{
mailWriter = new ConsoleMailWriter();
syncStateStorage = new InMemoryUserFolderSyncStateStorage();
}
ExchangeMailStore mailStore = new ExchangeMailStore(exchangeUrl);
try
{
PrincipalFetcher userLister = new LdapFetcher(domain);
Iterable<String> users = userLister.getPrincipals();
mailWriter.write(mailStore.getMail(users, syncStateStorage));
return 0;
}
catch (ExchangeRuntimeException e)
{
Throwable inner = e.getCause();
if (inner instanceof HttpErrorException)
{
HttpErrorException httpError = (HttpErrorException) inner;
if (httpError.getErrorCode() == HttpURLConnection.HTTP_UNAUTHORIZED)
{
System.out.println("There was an authentication error connecting to Exchange or HBase. "
+ "See the log for more details.");
}
else
{
System.out.println("There was an HTTP " + httpError.getErrorCode()
+ " error connection to either Exchange or HBase. "
+ "See the log for more details.");
}
}
else if (inner instanceof ServiceCallException)
{
ServiceCallException serviceError = (ServiceCallException) inner;
if (serviceError.getReason() == ServiceCallException.Reason.AUTHENTICATION)
{
System.out.println("There was an authentication error connecting to Exchange or HBase. "
+ "See the log for more details.");
}
else if (serviceError.getReason() == ServiceCallException.Reason.SOAP)
{
System.out.println("There was a SOAP error connecting to Exchange: "
+ serviceError.getSoapError().toString() + " See the log for more details.");
}
else
{
System.out.println("There was an unknown error connecting to Exchange or HBase. "
+ "See the log for more details.");
}
}
else
{
System.out.println("There was an unknown error connection to Exchange or HBase. "
+ "See the log for more details.");
}
}
catch (PrincipalFetchException e)
{
System.out.println("There was a problem fetching a list of users from Active Directory. "
+ e.getMessage() + "See the log for more details.");
}
finally
{
if (hbaseManager != null)
{
hbaseManager.close();
}
}
return 1;
}