4

I have working xmpp client on webapp using strophe.js ,as per my use case scenario i have to switch to different pages rapidly

Current approach is not secure as jid and password is visible in java script ,I was finding work around to implement security in strophe client an trying to make connection time(with bosh) more shorter ,while going through the book "XMPP Programming with JavaScript and jQuery"by jake moffitt i came across one solution which element both of my above problems is to implement session mechanism.which says that we can use strophe attach(jid,sid,rid) to connect to existing connection,so i need SID and RID ,which i can get from application server!!!

book has given an example of automated connection to bosh server when user logged in the web application,author has implement it using an Django project in python,As I am using java as server side language i tried to implement same example using java smcak-4.0.3 and smack-bosh-4.0.3 but unable to connect to bosh server(i am using ejabberd as xmpp server)

my code is as below

 BOSHConfiguration config = new BOSHConfiguration(false,"192.168.0.106",5280,"/http-bind/","192.168.0.106");
                XMPPBOSHConnection xbc=new XMPPBOSHConnection(config); 
                xbc.connect();
                xbc.login("admin", "admin");
                System.out.println(xbc.getConnectionID());

stack trace

java.lang.ClassNotFoundException: org.xmlpull.v1.XmlPullParserFactory
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
    at org.jivesoftware.smack.SmackConfiguration.processConfigFile(SmackConfiguration.java:352)
    at org.jivesoftware.smack.SmackConfiguration.processConfigFile(SmackConfiguration.java:347)
    at org.jivesoftware.smack.SmackConfiguration.<clinit>(SmackConfiguration.java:155)
    at org.jivesoftware.smack.ConnectionConfiguration.<init>(ConnectionConfiguration.java:67)

When i tried to login to bosh server it fails every time,i am not sure what is wrong here can some one explain me?

One more thing i have find is one can get session identifier(SID) using "xbc.getConnectionID()" but how to find request identifier?

Any help on above problem will be appriciable!!!!

thanks in advance!

Dev
  • 2,326
  • 24
  • 45

3 Answers3

4

I had a similar problem. I donwload all the smack github I import smack.jar from /lib/ and add the 3 java files from /src/main/java/org/jivesoftware/smack/

I tried to fix it by importing smack-bosh-3.2.2-jar-with-dependencies.jar from /target/. I don't know why this diddn't work.

Finally, I read here that you need to download all the dependencies libraries : jbosh-0.6.0.jar xlightweb-2.5.jar xSocket-2.4.6.jar xpp3-1.1.3.3.jar dom4j-1.6.1.jar

So I used smack.jar from /lib/ with all thoses libraries and this problem was solved.

As i said in comments, you need after to retreive RID. I used jbosh sources and add following lines :

In com.kenai.jbosh.BOSHClient class
//I introduced a new property
private Long rid;

//commented the following code
//long rid = requestIDSeq.getNextRID();
//and at that place added
this.rid = requestIDSeq.getNextRID();

//and finally added a new getter for rid
public Long getRid() {
    return rid;}

Then in smack-bosh :

In BOSHConnection.java
public Long getRid() {
    return client.getRid();}
public String getSid() {
    return sessionID;}

Now I'm blocked cause my session is disconected. According to my openFire logs, it's because of overactivity. So I'm looking for a solution to reduce the number of presence messages.

GuiguiDt
  • 263
  • 1
  • 11
  • thanks for your answer,can you please share your code with me,it would be so helpful for me!!!! – Dev Aug 20 '14 at 14:01
  • hey its working now,but one problem is still remaining is that i am able to get SID but no RID ,can you tell me how to get RID(request identifier)??? – Dev Aug 20 '14 at 15:20
  • Apparently you have direct access to Sid with BOSHConnection.getConnectionID. For Rid it's more complicated. I had to work on the source of jbosh library. I'm now able to retrieve an Rid. I haven't tested it yet. But the idea is to add a getter to the Rid in BOSHClient and one in BOSHConnection using the previous one. I let u know as soon I test it. Moreover importing directly .java to my project didn't work so I had to modified .java of bosh then recompiled them but the new .class in a new .jar that I imported. – GuiguiDt Aug 21 '14 at 08:13
  • Thanks for the code.have you monitor what is the actual sid and rid while you are establishing bosh connection using jbosh and smack,I observed that sid which we get using smack is totally different from which i observed in xml stanza using smack debugger,may be this would be causing problem!!!! – Dev Aug 22 '14 at 04:03
  • Me, I'm using openFire because of compatibility with other parts of my project. But with this new method getRid(), i retrieve the good one. I notice that getConnectionID some time give authentificationID instead off sessionID but each time those two variables are the same for me but just in case I also add a getSid() in BOSHConnection. – GuiguiDt Aug 22 '14 at 08:15
  • Thank you vary much for your help and example code above,i have also modify BOSHClient.java and placed getter method for exacting rid and sid,It seem i have one issue left , when to disconnect bosh connection from app server ,before passing sid and rid to strophe or after attach() is successful !!!do you have any idea!!! – Dev Aug 22 '14 at 14:33
  • one more thing i want to ask you ,right now i have added jbosh's source code (all java file )in order to perform modification ,but when i created a jar far for it and added in my project it after i tried to connect to bosh manager ,it is giving me error ...says no response from server!!!do you have any idea how can i create a .jar file in eclipse??? – Dev Aug 22 '14 at 14:37
  • 1
    Hi, in answer to "i have one issue left..." above (might be best as a separate question!). You need to be aware that SID is "Session ID" - so this connect from server then pass to attach() is a trick using same XMPP session across two http "sessions" - you can't close the connection on the server until after you have attached - otherwise the session gets cleaned up in XMPP server before you attach (I think). See http://stackoverflow.com/a/23287076/1265200 - I also had to change code to stop presence stanza being issued on server connection. – Dazed Aug 22 '14 at 15:46
  • 1
    For the .jar, I put jbosh sources in my project, then with the autocompilation I retrieve .class that i introduced in the original jbosh.jar with winrar. Agreed with Dazed for the "one issue left" or it gonna be a mess. Dazed, could you explicit your last sentence, please? – GuiguiDt Aug 22 '14 at 15:54
  • thansks @Dazed i have added a seprate question on this link http://stackoverflow.com/questions/25455638/when-to-disconnect-bosh-connection-establish-from-app-server-to-use-prebinding-i hope you will help me with it, and yes can share code for "how you had stop presence stanza being issued on server connection" – Dev Aug 22 '14 at 21:18
  • @ Deuteu thanks for your answer ,i have alredy perform this step,but it seem that new modify jar file fails to connect to bosh server!!!do you have any idea what will be the possible reason!!! – Dev Aug 22 '14 at 21:21
  • 1
    @user3523641 I don't know exaclty cause for me it worked well directly, tried to import only the .class modified (to keep the most part of the original code) and make sure to import all the part of .class modified : I noticed that there were 3 .class for the BOSHClient the raw one and 2 others with $1 and $2 at the end. But I don't see specific reason for now, I let you know if I find one. – GuiguiDt Aug 25 '14 at 07:22
  • @Deuteu thnaks for your answer,i have added only one class BOSHClien.class ,after adding BOSHClien$1.class and BOSHClien$2.class file in in .jar file using archive manager ,every thing is working link charm!!! – Dev Aug 26 '14 at 04:11
3

To get latest benefits in Android BOSH you need Smack Releases 4.1.1

SMACK --- smack-tcp smack-sasl-provided smack-resolver-minidns smack-resolver-dnsjava smack-extensions smack-core smack-bosh smack-android-extensions smack-android

You additionally Need

XPP3 1.1.4c delete the javax package from the JAR file for android because android already have javax....QName class

JXMMP, JXMMP CACHE, JBOSH, MINIDNS, DNSJAVA, JSTUN, XBILL DNS

No need for Apache HTTP Client which is already available in android

Unfortunately it comes around some 12 JAR files, better use Maven Android Project in Eclipse

Otherwise search the above keywords at Maven Central http://search.maven.org/#search and get the JAR files one by one

Dickens A S
  • 3,824
  • 2
  • 22
  • 45
  • 1
    I've removed the SaslException from smack-bosh. The next release should now work on Android without modifications. If you had reported this to the Smack community forums I would likely removed it earlier. Also note that jstun and xbilldns (dnsjava) is not required. – Flow Jan 25 '15 at 09:52
1

stack trace

java.lang.ClassNotFoundException: org.xmlpull.v1.XmlPullParserFactory
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
    at org.jivesoftware.smack.SmackConfiguration.processConfigFile(SmackConfiguration.java:352)
    at org.jivesoftware.smack.SmackConfiguration.processConfigFile(SmackConfiguration.java:347)
    at org.jivesoftware.smack.SmackConfiguration.<clinit>(SmackConfiguration.java:155)
    at org.jivesoftware.smack.ConnectionConfiguration.<init>(ConnectionConfiguration.java:67)

The exception here clearly states that Webapp cant find class org.xmlpull.v1.XmlPullParserFactory. That sounds like you are missing xml-apis library in your classpath, (or some other implementation of XmlPullParser interface).

dant3
  • 966
  • 9
  • 26
  • thanks for your answer,As mention by @Deuteu i haven't included xlightweb-2.5.jar so that i am getting above problem. – Dev Aug 20 '14 at 15:21