私のプロジェクトでは、pubsubとcometDサブスクライバを使用する必要があります。 私は2つのapplciationsのOracle Weblogicアプリケーションサーバーを使用します。 1人はpubsubsチャンネルにいくつかのメッセージを公開し、もう1人はチャンネルを購読してメッセージを表示します。 私のpubsubサーバもweblogicアプリケーションサーバ上にあり、xmlファイル(weblogic.xmlとweblogic-pubsub.xml)で構成されています。ここ は私のpubsubサーバが(のweblogic-pubsub.xml)設定されている方法です。CometDクライアントJava APIの使い方は?
<wlps:channel>
<wlps:channel-pattern>/gip/**</wlps:channel-pattern>
</wlps:channel>
<wlps:channel-constraint>
<wlps:channel-resource-collection>
<wlps:channel-resource-name>all-permissions</wlps:channel-resource-name>
<wlps:description>Grant all permissions for everything by everyone</wlps:description>
<wlps:channel-pattern>/gip/*</wlps:channel-pattern>
</wlps:channel-resource-collection>
</wlps:channel-constraint>
そして、私の第二のアプリケーションがcometDのsubscirber JavaScriptのAPIとDojoツールキットでチャンネルにsusbscribeことができますので、それがうまく動作します。 これで、このJavascript APIのおかげで、サブスクリプションは私のWebアプリケーションのクライアント側で実行されます。ここで
は、サブスクリプションは、Dojoツールキットを使用してクライアント側(JavascriptのAPIを)どのように行われるかである。
//Initialize Dojo (CometD) for pubsub events
dojo.require("dojo.io.script");
dojo.require("dojox.cometd");
dojo.require("dojox.cometd.callbackPollTransport");
dojo.addOnLoad(function()
{
console.log("on load dojo");
dojox.cometd.init("/WebInterface/cometd", {
});
dojox.cometd.subscribe("/gip/**", onEvent);
initMap();
});
このクライアント側実装がうまく機能したメッセージが到達したとき、のonEvent()関数はよく発射されますpubsubチャネル。
今、サブスクリプションとメッセージ処理が行われましたサーバー側です。このため、私はCometDにpubsubチャンネルを購読してメッセージを処理できるクライアントJava APIも持っていることを理解しました。 しかし、私はそれをすることに成功していません。ここで
私はCometD 3ドキュメント(https://docs.cometd.org/current/reference/#_java_client)次のサーバー側のために行うことを試みたものを以下のようになります。
import com.vaadin.ui.CustomComponent;
import java.util.HashMap;
import java.util.Map;
import org.cometd.bayeux.Channel;
import org.cometd.bayeux.Message;
import org.cometd.bayeux.client.ClientSession;
import org.cometd.bayeux.client.ClientSessionChannel;
import org.cometd.client.BayeuxClient;
import org.cometd.client.transport.ClientTransport;
import org.cometd.client.transport.LongPollingTransport;
import org.eclipse.jetty.client.HttpClient;
public class WireServerCometD extends CustomComponent {
private static final String CHANNEL = "/gip";
private final ClientSessionChannel.MessageListener gipListener = new GIPListener();
public WireServerCometD() {
System.out.println("Wire CometD constructor");
setSizeFull();
setWidth(50, Unit.PERCENTAGE);
setHeight(300, Unit.PIXELS);
addStyleName("customBackground");
try {
// Create (and eventually set up) Jetty's HttpClient:
HttpClient httpClient = new HttpClient();
// Here set up Jetty's HttpClient, for example:
// Prepare the transport
Map<String, Object> options = new HashMap<String, Object>();
ClientTransport transport = new LongPollingTransport(options, httpClient);
// Create the BayeuxClient
ClientSession client = new BayeuxClient("http://localhost:8080/WebInterface/cometd", transport);
client.getChannel(CHANNEL).addListener(new ClientSessionChannel.MessageListener() {
public void onMessage(ClientSessionChannel channel, Message message) {
if (message.isSuccessful()) {
// Here handshake is successful
System.out.println("Handshake is successfull");
}
}
});
client.handshake();
} catch (Exception ex) {
ex.printStackTrace();
}
}
private static class GIPListener implements ClientSessionChannel.MessageListener {
public void onMessage(ClientSessionChannel channel, Message message) {
System.out.println("message received");
}
}
}
これは、Vaadinフレームワークのコンポーネントである、チャネルサブスクリプションおよびメッセージリスナを試しに実行されますブロック。 コード行に次のエラーがあります。HttpClient httpClient = new HttpClient(); : SEVERE: java.lang.IncompatibleClassChangeError:ORG /日食/桟橋/クライアント/ HttpClientを
とのonMessage機能が解雇されることはありません...
あなたは私にいくつかの助けをもたらすことができますしてください?は、すべての
@sbordetに感謝します。私のプロジェクトで使用したCometD APIは、mavenに付属しています。私はWebLogicで出荷されたものを使用しません。 dojox.cometd.callbackPollTransportは、メッセージを購読して処理するためのJavascriptクライアントの実装ですが、動作します。 JDKのバージョンを確認し、JDK 8で再試行して、例外が再び表示されるかどうかを確認します。 私はVaadinにコンポーネントをJavascriptに変換させたくありません。逆に、私はそれをサーバー側で管理し、クライアント側では管理しません。 –