私は、サーバーのメッセージを聞くbayeuxクライアントを持つことを目指しています。しかし、私はまだbayeuxクライアントのサーバとの接続に苦労しています。サーバーにはログイン資格情報が必要です。しかし、私はログインの詳細なしで多くの例を発見した。いくつかの例を使用して、私は、BayeuxクライアントオブジェクトにLongPollingTransportオブジェクトが必要であることを発見しました。これにはhttpclientが含まれています。しかし、私は最初に接続をしていることを知っているので、私はチャネル/テスト/一時的にチャネルのサーバーを聞いて開始する必要があります。サーバーのURLは(URL = "https://manse.abcd.fi";)とクライアントBayuex http urlはログインが必要なので、どのように私は接続を確立するためにログイン(ユーザーとパスワード)を渡すことができます。私は、それがLongPollingTransportクラスのどこかに与えられるべきだと感じています。これまで私は接続に失敗しました。bayuexclientでサーバのログイン認証情報を渡すには?
import org.cometd.bayeux.Channel;
import org.cometd.bayeux.Message;
import org.cometd.bayeux.client.ClientSessionChannel;
import org.cometd.bayeux.client.ClientSessionChannel.MessageListener;
import org.cometd.client.BayeuxClient;
import org.cometd.client.transport.ClientTransport;
import org.cometd.client.transport.LongPollingTransport;
import org.eclipse.jetty.client.ContentExchange;
import org.eclipse.jetty.client.HttpClient;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
public class Test {
public static void main(String[] args) {
HttpClient httpClient = new HttpClient();
// LongPollingTransport transport = new LongPollingTransport(options, httpClient);
String url = "https://manse.soneraiox.fi";
//LongPollingTransport transport = new LongPollingTransport(url, null, httpClient);
// String url = "https://manse.soneraiox.fi";
BayeuxClient client = new BayeuxClient(url, LongPollingTransport.create(null));
//System.out.println(client.isHandshook);
// Handshake
client.handshake();
Boolean a=client.isHandshook();
System.out.println(a);
System.out.println(client.isConnected());
このコードはまだfalseを返します。 LongPollingTransport.create(null)が動作しているかどうかはまだわかりません。あなたが提案したのと同じ名前空間を使用しました。それは沖です。
import org.cometd.bayeux.Channel;
import org.cometd.bayeux.Message;
import org.cometd.bayeux.client.ClientSessionChannel;
import org.cometd.bayeux.client.ClientSessionChannel.MessageListener;
import org.cometd.client.BayeuxClient;
import org.cometd.client.transport.ClientTransport;
import org.cometd.client.transport.LongPollingTransport;
import org.eclipse.jetty.client.ContentExchange;
import org.eclipse.jetty.client.HttpClient;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
public class Stest {
public static void main(String[] args) {
HttpClient httpClient = new HttpClient();
// LongPollingTransport transport = new LongPollingTransport(options, httpClient);
String url = "https://manse.soneraiox.fi";
//LongPollingTransport transport = new LongPollingTransport(url, null, httpClient);
// String url = "https://manse.soneraiox.fi";
BayeuxClient client = new BayeuxClient(url, LongPollingTransport.create(null));
//System.out.println(client.isHandshook);
// Handshake
Map<String, Object> extra = new HashMap<>();
Map<String, Object> ext = new HashMap<>();
extra.put(Message.EXT_FIELD, ext);
Map<String, Object> authn = new HashMap<>();
ext.put("com.acme.authn", authn);
authn.put("username", "[email protected]");
authn.put("password", "xxxxx");
client.handshake(extra);
//client.handshake();
Boolean a=client.isHandshook();
System.out.println(a);
System.out.println(client.isConnected());
}
}
Sbordet、私はあなたが提案した方法を試しました。しかし、握手はうまくいかなかった。ネームスペースとクラスLongPollingTransportを正しく使用したかどうか教えてください。 –
あなたはどのバージョンのCometDを使用していますか? 'LongPollingTransport.create()'はCometD 3.xには存在しません。 CometD 3.1.xとスティックハンドシェイクは非同期操作であるため、 'handshake()'を呼び出した直後に 'BayeuxClient'のステータスをコンソールに出力することはできません。 [documentation](https://docs.cometd.org/current/reference/#_java_client_handshake)をお読みください。サーバーに資格情報を正しく渡したら、[認証のドキュメント](https://docs.cometd.org/current/reference/#_java_server_authentication)で説明されているように、資格情報を検証する必要があります。 – sbordet
http://stackoverflow.com/questions/41830883/how-the-java-client-in-cumulosity-listens-to-events –