How to connect XMPP bosh server using java smack library?

落花浮王杯 提交于 2019-12-01 06:42:04

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.

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

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).

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!