@Override public CouchContext createSession(String userName, String password) throws Exception { Map<String,String> form = new HashMap<String,String>(); form.put("name", userName); form.put("password", password); // Create a context to receive the cookie for authentication CouchContextCookie context = new CouchContextCookie(); // POST _session JSONObject jsonUserCtx = ConnectionUtils.postForm(context, url, form); ConnectionUtils.captureReponseErrors(jsonUserCtx, "Error while creating session context: "); // Parse response CouchUtils.authenticationContextFromDocument(jsonUserCtx); return context; }
static public String computeEffectiveDatabaseUrl( String serverUrl ,String userName ,String password ,String databaseName ) throws Exception { if( null == databaseName ) { throw new Exception("Can not specify a db URL without a database name"); } String effectiveServerUrl = computeEffectiveServerUrl(serverUrl, userName, password); if( "".equals(effectiveServerUrl) ) { return databaseName; } if( effectiveServerUrl.endsWith("/") ) { return effectiveServerUrl + databaseName; } return effectiveServerUrl + "/" + databaseName; }
String source = CouchUtils.computeEffectiveDatabaseUrl( replicationRequest.getSourceServerUrl() ,replicationRequest.getSourceUserName() ,replicationRequest.getSourceDbName() ); String target = CouchUtils.computeEffectiveDatabaseUrl( replicationRequest.getTargetServerUrl() ,replicationRequest.getTargetUserName()
private void performReplication(ReplicationRequest replication) { try { // Check if active String source = CouchUtils.computeEffectiveDatabaseUrl( replication.getSourceServerUrl() ,replication.getSourceUserName() ,replication.getSourcePassword() ,replication.getSourceDbName() ); String target = CouchUtils.computeEffectiveDatabaseUrl( replication.getTargetServerUrl() ,replication.getTargetUserName() ,replication.getTargetPassword() ,replication.getTargetDbName() ); JSONArray activeTasks = couchClient.activeTasks(); ReplicationStatus status = ReplicationStatus.findReplicationTask(activeTasks, source, target); if( null == status ) { logger.info("Start replication: "+replication); // Replication not running, start it couchClient.replicate(replication); } } catch(Exception e) { logger.error("Problem performing replication: "+replication, e); } }