public static synchronized Session getSession(long syncAccountId) { Session session = _sessions.get(syncAccountId); if (session != null) { return session; } try { SyncAccount syncAccount = SyncAccountService.fetchSyncAccount(syncAccountId); URL url = new URL(syncAccount.getUrl()); session = new Session( url, syncAccount.getLogin(), Encryptor.decrypt(syncAccount.getPassword()), syncAccount.isTrustSelfSigned(), syncAccount.getMaxConnections()); _sessions.put(syncAccountId, session); return session; } catch (Exception e) { _logger.error(e.getMessage(), e); return null; } }