Reputation: 61
For my project I have to use pubsub and cometD subscriber. I use Oracle Weblogic application server for two applciations. One of them publish some messages to pubsubs channels and the other one subscribe to channels to display the messages. My pubsub server is on the weblogic application server too and configured with some xml files (weblogic.xml and weblogic-pubsub.xml). Here is how my pubsub server is configured (weblogic-pubsub.xml):
<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>
And it works well because my second application can susbscribe to channel with the cometD subscirber javascript API and dojo toolkit. So now the subscription is done client side of my web application thanks to this Javascript API.
Here is how the subscription is done client side (Javascript API) with the dojo toolkit:
//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();
});
This client side implementation works well, the onEvent() function is well fired when messages reach the pubsub channel.
Now, I would like the subscription and the message handling are done server side. For this, I understood that CometD has also a client Java API allowing to subscribe to pubsub channel and to handle the messages. But I have not succeeded to do that.
Here is now what I tried to do for the server side following the CometD 3 documentation (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");
}
}
}
This is a Vaadin framework component, the channel subscription and message listener are done in the try block. I have the following error at the code line HttpClient httpClient = new HttpClient(); : SEVERE: java.lang.IncompatibleClassChangeError: org/eclipse/jetty/client/HttpClient
And the onMessage function is never fired ...
Can you bring me some help please ?
Thank you,
Upvotes: 0
Views: 471
Reputation: 18477
First of all, I think WebLogic may ship a very old version of CometD, or a very customized one that does not match the official one from the CometD project.
The dojox.cometd.callbackPollTransport
was not something that ever existed in the CometD project, it was probably a draft attempt when CometD was 0.x, or something that was not officially released, or something created by WebLogic.
Your chances to have an official CometD 3.x client work with the "CometD" shipped by WebLogic are very slim. I doubt they are compatible.
Furthermore, I don't think Vaadin will be able to translate the component you wrote above in JavaScript. A while back, people wrote bindings for CometD in JavaScript, but those never entered officially the CometD project (lack of traction, see https://github.com/cometd/cometd/issues/63), so I am not sure in what state they are now.
The IncompatibleClassChangeError
is probably due to the fact that you are using a JDK older than JDK 7, and CometD 3.x only works with JDK 7+.
I'm afraid you will have to rethink the whole system.
I would suggest to stick with the official CometD on the server (not the one shipped by WebLogic), and if you really have to use Vaadin/GWT have a look at how people wrote those bindings in the past, and perhaps replicate them if you can't use those libraries.
Once you have the Vaadin/GWT bindings in place, and the official CometD in the server, and JDK 7+, you should be good.
Upvotes: 0