Unable to use smack-bosh out of the box

I had a few issues getting going with smack-bosh 3.4.1:

(1) First when I added all the appropriate jars to my classpath and when running my BOSH client, I get the error:

IllegalStateException: Could not load org.igniterealtime.jbosh.HTTPSender implementation

Turns out the XLightWebSender.java was in the test src, so when I copied that and XLightWebResponse.java into the src main directory I was able to get past this issue.

(2) When I created the BOSHConnection, I was unable to connect to OF because the host and port were ‘null’ and 0 respectively. Turns out host and port aren’t being set when you pass these values in the BOSHConfiguration constructor. I had to manually call the following in order to finally get it to connect:

config.setUsedHostAddress(new HostAddress(_host, _port));

Basically, I had to hack around a little bit in order to get the smack-bosh jar to work. Is this the way it’s suppose to work or am I doing something wrong?

IllegalStateException: Could not load org.igniterealtime.jbosh.HTTPSender implementation
Could you show us the stacktrace of this ISE?

Turns out host and port aren’t being set when you pass these values in the BOSHConfiguration constructor.
This was caused by API changes. Thanks for reporting!

Basically, I had to hack around a little bit in order to get the smack-bosh jar to work. Is this the way it’s suppose to work or am I doing something wrong?
No, BOSH code is beta. This is also stated in the sub-projects description. We are looking for someone who is willing to maintain that part. But I’m happy about every good quality bug report I get and will do my best to fix the issues.

I’ve had this issue, too, when I upgraded from 3.2.1 to 3.3.1.

Here was my fix: In the BOSHConfiguration constructors, I added:

setUsedHostAddress(getHostAddresses().get(0));

(not sure, if this is the best solution, because it only uses the first address).

Flow, here’s another modification, I made. Maybe you can review it and modify the code:

BOSHConnection.java, at the very end (around line 608) I modified this (luckily with a comment):

else {

// Only notify, if we were connected.

// Sometimes a connection event is fired (with connEvent.isConnected == false), although we were already disconnected by a previous event.

// I had this problem when logging in with the same resource twice. The first exception contains the stream:conflict and the second exception is a strange exception containing HTML and “invalid SID”.

if (connected && connEvent.isError() && connEvent.getCause() instanceof Exception) {

notifyConnectionError((Exception) connEvent.getCause());

}

connected = false;

}

The current code, doesn’t make sense at all (because getCause() doesn’t throw an exception):

try {

connEvent.getCause();

}

catch (Exception e) {

notifyConnectionError(e);

}

The problem with the current code is that connection errors aren’t reported at all to the listeners.

There were others in the getRoster method, but I saw, that you already moved it to the parent class.

The second issue should be fixed.

Could you checkout the code, build Smack and report back if it solves the issue for you?

That is indeed nonsense. Thanks for reporting.

Fixed.

Maybe also consider to change

if (connEvent.isError())

to

if (connected && connEvent.isError())

I can’t recall the exact problem here, but connEvent is sometimes fired twice and then the second event also calls the listeners.

I had the problem with Openfire, when User A logs in with resource “test” and then the same User A logs in with another JVM/device, but with the same resource “test”. Openfire will then send a “conflict” stream error to the first connection, causing it to disconnect and reconnect.

And the BOSH logic also throws another connection event, which I think caused some trouble, e.g. duplicate reconnection trials.

Now that I think about it, I think the problem was, that it connected and didn’t stop retrying, but it always failed with “Invalid SID”.

Thanks, I’ll try it out. I realized the 1st issue I reported is from using https://github.com/igniterealtime/jbosh.git

Is this the right jbosh library to use with smack-bosh?

The second issue is fixed, however with the latest code from master, I’m seeing the following whenever it tries to call PubSubManager.getNode()

org.jivesoftware.smack.SmackException$NoResponseException

at org.jivesoftware.smack.PacketCollector.nextResultOrThrow(PacketCollector.java:177)

at org.jivesoftware.smack.PacketCollector.nextResultOrThrow(PacketCollector.java:161)

at org.jivesoftware.smackx.pubsub.PubSubManager.getNode(PubSubManager.java:167)

The stacktrace for the first issue is below:

org.jivesoftware.smack.SmackException$ConnectionException: java.lang.IllegalStateException: Could not load org.igniterealtime.jbosh.HTTPSender implementation

at org.jivesoftware.smack.BOSHConnection.connect(BOSHConnection.java:182)

at com.cisco.ccbu.finesse.event.test.BOSHAgent.login(BOSHAgent.java:73)

at com.cisco.ccbu.finesse.event.test.EventTestClient.login(EventTestClient.java:216)

at com.cisco.ccbu.finesse.event.test.EventTestClient.main(EventTestClient.java:880)

Caused by: java.lang.IllegalStateException: Could not load org.igniterealtime.jbosh.HTTPSender implementation

at org.igniterealtime.jbosh.ServiceLib.loadService(ServiceLib.java:83)

at org.igniterealtime.jbosh.BOSHClient.(BOSHClient.java:235)

at org.igniterealtime.jbosh.BOSHClient.create(BOSHClient.java:368)

at org.jivesoftware.smack.BOSHConnection.connect(BOSHConnection.java:158)

… 3 more

I’ve made some (untested) changes to Smack BOSH/jbosh.

Could you try Smack from my branch and report back?

I tried it out and aside from some unit test errors, it was the same result, same exception being thrown

If you are talking about the jbosh unit-tests, then please ignore any errors. jbosh’s unit-tests are in a terrible shape and simply non-deterministic.

I’ve just clicked together a sample gradle project the uses the latest snapshots of Smack (and jbosh) and was able to establish a BOSH connection and to send and receive messages.

Are you sure that you are using the latest version of the code?

So I’ve gotten a chance to try this out again. I’m suck on commit 18d0dbdc5f6633ceb2996a7ac06eba687f8020df because I don’t have Java 1.7

Anyway, I am able to login but anytime I try to make a request such as add an event listener which implicitly tries to get the node it seems to get queued up and while it waits an exception is thrown as follows:

org.jivesoftware.smack.SmackException$NoResponseException
          at org.jivesoftware.smack.PacketCollector.nextResultOrThrow(PacketCollector.java:177)
          at org.jivesoftware.smack.PacketCollector.nextResultOrThrow(PacketCollector.java:161)
          at org.jivesoftware.smackx.pubsub.PubSubManager.getNode(PubSubManager.java:172)

After the next BOSH longpoll request returns after timing out on the OF end, it looks like the request to get the node finally goes out, so it seems like the BOSH Client is somehow single threaded?

Have you seen this in your testing?

I’m using the following dependencies:

jbosh 0.8.0-SNAPSHOT

xpp3 1.1.4c

httpcore 4.3.2

httpclient 4.3.3

I don’t have Java 1.7
You are aware that it’s higly dangerous to use anything older then Java 1.7? Especially in network environments!

Have you seen this in your testing?
No, but I didnt’ test pubsub.