2017-09-09 6 views
-1

私は今までCloudant-syncアンドロイド最新リリースを使用しています:2.0.2、Android api 21+をターゲットにしています。
私のサーバーデータベースはCouchDB 2.1.0ですReplicator/ReplicatorBuilderはURI資格情報を無視します

私はアンドロイドアプリからレプリケーションプルをトリガーしてローカルデータベースを更新しようとしています。 "https:// user:password @ databaseurl/db_name" (ここではhttps://github.com/cloudant/sync-android/blob/master/doc/replication.mdとなります) のように、レプリケータのソースURIを指定していますが、生成されたレプリケータオブジェクトでは、 "replicator.strategy"を検査します。 sourceDb https」のデシベルのURIは単に である 『://からDatabaseUrl/DB_NAME』ので、私はunhautorized取得(私は、データベース・サーバー上のセキュリティチェックを無効にする場合、それは正常に動作します)

これは私のランニングコードです:

public ReplicationListener pullAllAsync(Databases db_name) { 
    try { 
     URI uri = db_name.getServerURI(); 
     DocumentStore ds = DocumentStore.getInstance(new File(db_name.getMobilePath(), db_name.toString())); 
     Replicator replicator = ReplicatorBuilder.pull().from(uri).to(ds).build(); 
     ReplicationListener listener = new ReplicationListener(replicator); 
     replicator.getEventBus().register(listener); 
     replicator.start(); 
     return listener; 
    } catch (Exception e) { 
     e.printStackTrace(); 
     LogRepository.getInstance().escribirLog(LogRepository.TipoLog.ERROR, null, e, true); 
     return null; 
    } 
} 

私は何か間違っていますか?

ありがとうございます!

+0

ここにコードを貼り付けてください。それのイメージではありません。 –

+0

申し訳ありませんが、私はすでに編集しています。ありがとう –

答えて

0

問題はCookieAuthentication(これは、CreditsがURIで渡されたときにReplicatorのデフォルトの認証方法です)であるようです。 CouchDBサーバーインスタンスが原因で失敗した理由はわかりませんCookieAuthenticationを受け入れるように設定されています。

とにかく、これは最善の解決策ではないかもしれませんが、十分な回避策です。私は次のようにBasicAuthenticationメソッドを強制してこの作業を行いました:

public ReplicationListener pullAllAsync(Databases db_name) { 
    try { 
     URI uri = db_name.getServerURI(); 

     DocumentStore ds = DocumentStore.getInstance(new File(db_name.getMobilePath(), db_name.toString())); 
     Replicator replicator = ReplicatorBuilder 
       .pull() 
       .from(uri) 
       .to(ds) 

       //WORKAROUND: forces BasicAuthentication method instead of CookieAuthentication 
       .addRequestInterceptors(new BasicAuthInterceptor(uri.getRawUserInfo())) 
       .build(); 

     ReplicationListener listener = new ReplicationListener(replicator); 
     replicator.getEventBus().register(listener); 
     replicator.start(); 
     return listener; 
    } catch (Exception e) { 
     e.printStackTrace(); 
     LogRepository.getInstance().escribirLog(LogRepository.TipoLog.ERROR, null, e, true); 
     return null; 
    } 
}