2016-04-07 15 views
0

localhostで実行中のopenfireサーバーがあり、登録ユーザーにメッセージを送受信できました。しかし私はサーバーからすべてのユーザーを取得することができませんでした。私は管理アクセス権を持たないユーザーでログインしています。私はサーバー側で任意の許可を与える必要がありますか?smackを使ってopenfireサーバーからすべてのユーザーを取得する

私はすべてのユーザーを取得するために使用していたコードがあるが...

if (xmpp.getConnection()== null || !xmpp.getConnection().isConnected()) 
     return; 

    try { 
     UserSearchManager usm = new UserSearchManager(xmpp.getConnection()); 
     Form searchForm = usm.getSearchForm("search." + xmpp.getConnection().getServiceName()); 
     Form answerForm = searchForm.createAnswerForm(); 
     UserSearch userSearch = new UserSearch(); 
     answerForm.setAnswer("Username", true); 
     answerForm.setAnswer("search", userName); 
     ReportedData data = userSearch.sendSearchForm(xmpp.getConnection(), answerForm, "search." + xmpp.getConnection().getServiceName()); 

     for (ReportedData.Row row : data.getRows()) 
     { 
      arrayList.add(row.getValues("Username").toString()); 
     } 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 

は、しかし私は、それはまた、私を助けていない、選手クラスを使用することを示し、いくつかの解決策を試してみました。誰かが私が間違ってやっていることを示すことができますか、私は管理者としてログインしていないので、私は任意の許可を与える必要がある場合?私は取得しています エラーが..

org.jivesoftware.smack.XMPPException$XMPPErrorException: XMPPError: remote-server-not-found 

感謝:)

答えて

0

このコードを試してみてくださいです。私はこのコードを微調整しますthis answer

UserSearchManager usm= new UserSearchManager(xmpp.getConnection()); 
Form searchForm = usm.getSearchForm("search." +xmpp.getConnection().getServiceName()); 
Form answerForm = searchForm.createAnswerForm(); 
answerForm.setAnswer("Username", true); 
answerForm.setAnswer("search", userName); 
ReportedData data = usm 
    .getSearchResults(answerForm, "search." + xmpp.getConnection().getServiceName()); 

if (data.getRows() != null) { 
    for (ReportedData.Row row: data.getRows()) { 
     for (String jid:row.getValues("jid")) { 
     System.out.println(jid); 
     } 
    } 
} 
0

スマックはクライアントの作成に使用されます。クライアントは1人のユーザーによって使用されます。通常、ユーザーはサーバーのすべてのユーザーにアクセスできません。ユーザーには連絡先リスト、またはロスターがありますが、他のユーザーを追加する場所です。

+0

どのように私の連絡先がサーバーに登録されているか知ることができますか?私はそれを使用しようとしたコードを投稿することができます。しかし、それは私を助けていない – Newbiee

+0

基本的に何を言っている私は連絡先の番号を渡す必要がありますし、私はサーバー上の番号を探す必要がありますか? – Newbiee

+0

登録されているすべてのユーザーのリストをサーバー上に取得することはできません。登録者を使用して特定のユーザーを追加することができます –

2

これは私がopenfire

からすべてのユーザーを取得していますどのようにあなたが実際にユーザ名

にワイルドカード(*)を渡す必要があります。ここで動作するコード

Utils.getConnectionは()です - 私のxmpp接続

public static void getAllXmppUsers() 
{ 
    try { 
    UserSearchManager manager = new UserSearchManager(Utils.getConnection()); 
    String searchFormString = "search." + Utils.getConnection().getServiceName(); 
    Log.d("***", "SearchForm: " + searchFormString); 
    Form searchForm = null; 

     searchForm = manager.getSearchForm(searchFormString); 

    Form answerForm = searchForm.createAnswerForm(); 

    UserSearch userSearch = new UserSearch(); 
    answerForm.setAnswer("Username", true); 
    answerForm.setAnswer("search", "*"); 

    ReportedData results = userSearch.sendSearchForm(Utils.getConnection(), answerForm, searchFormString); 
    if (results != null) { 
     List<ReportedData.Row> rows = results.getRows(); 
     for (ReportedData.Row row : rows) { 
      Log.d("***", "row: " + row.getValues("Username").toString()); 
     } 
    } else { 
     Log.d("***", "No result found"); 
    } 

    } catch (SmackException.NoResponseException e) { 
     e.printStackTrace(); 
    } catch (XMPPException.XMPPErrorException e) { 
     e.printStackTrace(); 
    } catch (SmackException.NotConnectedException e) { 
     e.printStackTrace(); 
    } 
} 
+0

こんにちは、ユーザーがオンラインかオフラインかを確認するにはどうすればいいですか? –

関連する問題