Skip navigation
5922 Views 22 Replies Latest reply: Oct 28, 2011 7:05 AM by Kristam269 RSS
soban Bronze 2 posts since
Jan 11, 2010
Currently Being Moderated

Jan 11, 2010 10:48 PM

Smack over http

Hi,

 

I am new to XMPP, started to use ejabberd and Smack API last week. I want to connect to the ejabberd on port 80 using Smack API. I am not sure how to proceed. Any help will be greatly appreciated. Thanks.

  • Guenther Niess KeyContributor 305 posts since
    Jun 19, 2008
    Currently Being Moderated
    Jan 12, 2010 7:39 AM (in response to soban)
    Re: Smack over http

    Hi Soban,

    do you mean BOSH (Bidirectional-streams Over Synchronous HTTP or formerly HTTP-Bind) and configured ejabberd with the http_poll module to port 80?

    There is currently no such support in the official release, but I've started a branch to implement this. You can download it via subversion

    svn co http://svn.igniterealtime.org/svn/repos/smack/branches/bosh/ smack-bosh
    

    But this is still in development and have some major issues, like there is currently no support for proxies and SSL/TLS. But I like to invite you to use it and report issues and problems to this forum, then I will try to fix them.

     

    You can build the sources using Ant:

    ant -f build/build.xml
    

    or Maven (but here you have to install some libraries to your local repository, since we don't have a maven repository here on ignite yet).

    The compiled libraries are located on the subproject directories (smack, smack-bosh, smackx, etc.) in the target folder. If you use the packages with the jar-with-dependencies suffix you don't need to care about other necessary libraries.

     

    Start to use smack with:

    BOSHConfiguration config = new BOSHConfiguration(false, "hostname", 80, "/http-poll/", "yourdomain.lt");
    Connection con = new BOSHConnection(config);
    con.connect();
    con.login(user, pass);
    

     

    Good Luck!

    • vibhu Bronze 3 posts since
      Jan 30, 2010
      Currently Being Moderated
      Feb 2, 2010 6:14 AM (in response to Guenther Niess)
      Re: Smack over http

      Hi Guenther,

       


      Thanx for the info. I have been able to connect to Openfire using the development build using BOSH.

       

      I am trying to pass the connection RID and SessionID after creation to the Browser, so that Strophe can reattach itself to the already created connection.

       

      I modified the com.kenai.jbosh and your library and added a function to return back the RID from the connection.

       


      My problem is that Strophe is not been able to bind itself to the created connection.

       

      While searching I came across this which uses Mod-Http-Pre-Bind

       

      for ejabbered. My question now is "Does Openfire supports Http-pre-binding". If yes how may I use it?

       


      Thanx in advance for your help.

       


      regards

       

      Vibhu

      • mlux Bronze 1 posts since
        Feb 16, 2010
        Currently Being Moderated
        Feb 16, 2010 2:24 AM (in response to vibhu)
        Re: Smack over http

        Hi vibhu,

         

        Openfire officially supports attaching to existing sessions (so it should also work with prebinding). Some time ago, I tried to use openfire with StropheJS, too but it just won't work. I figured out that it sometimes helped to increase the rid when attaching to a session but somehow that spawned new problems and I never got this working 100% with openfire. I guess that the BOSH implementation of openfire is a bit buggy or at least very strict when it comes to managing rid's.

        In the end my solution was switching to ejabberd which works like a charm.

      • Jordan Bronze 10 posts since
        Mar 12, 2010
        Currently Being Moderated
        Mar 15, 2010 3:09 PM (in response to vibhu)
        Re: Smack over http

        would you be so kind as to post the details on how you modified the code to return the RID? I am facing the same situation at the moment and I would like to try my hand at getting Strophe to successfully attach to a session. Thanks!

         

        Big thanks to Guenther for sharing the smack-bosh code. Its working well for me so far. I just need that RID now!

        • vibhu Bronze 3 posts since
          Jan 30, 2010
          Currently Being Moderated
          Mar 17, 2010 4:12 AM (in response to Jordan)
          Re: Smack over http

          Hi Jordan,

           

          I just added a getter for RID in org.jivesoftware.smack.BOSHConnection as follows

           

          public long getRid()
              {
                  return client.getRid();
              }

           

          and in your code you will have to cast the Connection object into BOSHConnection to use the method.

           

          Hope this may be of some help to you.

           

          regards

          Vibhu

          • Jordan Bronze 10 posts since
            Mar 12, 2010
            Currently Being Moderated
            Mar 17, 2010 9:48 AM (in response to vibhu)
            Re: Smack over http

            Thanks for the reply Vibhu,

             

            I must be missing something. I don't see a function called getRid() anywhere in the smack-bosh or jbosh source, and my build expectedly fails when I add the function suggested above. You mentioned making a modification to jbosh as well - were you talking about the referenced getRid() function? That's the part that would be most useful to me, I would greatly appreciate it if you could share that too

            • vibhu Bronze 3 posts since
              Jan 30, 2010
              Currently Being Moderated
              Mar 17, 2010 11:07 AM (in response to Jordan)
              Re: Smack over http

              Pardon me for the incomplete info. Here are the changes which I have done 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;

              }

               

               

               

              • Jordan Bronze 10 posts since
                Mar 12, 2010
                Currently Being Moderated
                Mar 17, 2010 11:10 AM (in response to vibhu)
                Re: Smack over http

                thanks vibhu, i'll try out your changes later today!

              • Jordan Bronze 10 posts since
                Mar 12, 2010
                Currently Being Moderated
                Mar 18, 2010 12:07 PM (in response to vibhu)
                Re: Smack over http

                i had some time yesterday to make those edits and rebuild the .jars. thanks again vibhu - your edits worked nicely. i was able to start a BOSH connection with smack with no problems. now i'm having an odd issue attaching the connection with strophe - it always works in firefox, sometimes in safari, and never in chrome. weird! i guess i'm to find some strophe support for that one now.

    • Protected Bronze 8 posts since
      Dec 8, 2010
      Currently Being Moderated
      Feb 8, 2011 12:38 AM (in response to Guenther Niess)
      Re: Smack over http

      Thanks for the good work. I have successfully used bosh with smack using this branch. Hopefully it will be included in the next version of smack. 

    • public@thorhauer.com Bronze 1 posts since
      Oct 10, 2011
      Currently Being Moderated
      Oct 10, 2011 10:23 AM (in response to Guenther Niess)
      Smack over http

      Hi Guenther,

       

      I was looking into your work in the bosh branch.  Can you tell me which version of smack the BOSH version is built against?   I noticed that when I built the library from source in shows 'smack-bosh-3.2.0'.  Does this mean that it is built against the 3.2.0 release of smack? Also, is there any idea if this branch will become part of the release so that bugs will be fixed against it?

  • ap_nat Bronze 1 posts since
    May 25, 2010
    Currently Being Moderated
    May 25, 2010 8:29 AM (in response to soban)
    Re: Smack over http

    have done a backport of the bosh client to smack 310, attaching as a zip file. The main part was to make BoshConnection extend XMPPConnection, handle IQ s in a better way. The only non BOSH class I needed was org.jivesoftware.smack.sasl.SASLMechanism from the latest branch.

    Attachments:
    • RAJ Bronze 1 posts since
      Oct 11, 2011
      Currently Being Moderated
      Oct 11, 2011 3:02 PM (in response to ap_nat)
      Smack over http

      Hi All,

       

      I am kind of stuck on build issue now!! I have been trying pubsub over XMPP which is supported in version SMACK 3.2.1 (Not in 3.2.0-Snapshot version).

       

      Now, I am trying to build Branch bosh against Tag (3.2.1) because I wanna use pubsub with bash over XMPP.

       

      But, there are few dependecy jars under "http://svn.igniterealtime.org/svn/repos/smack/branches/bosh/build/merge/smack-bo sh/jbosh.jar"

       

      This jar is having BOSHClient.java which calls "XmlPullParserFactory,java" at runtime which doesn't exist in latest 3.2.1 smack release. So, I end up with following exception:

       

      Exception in thread "BOSHClient[1762502123]: Receive thread" java.lang.NoClassDefFoundError: org/xmlpull/v1/XmlPullParserFactory

       

      Can someone please help me in understanding the build structure becuase structure of BOSH branch is different than TAG/Trunk.

       

      Thanks in advance! I really need this

      • Protected Bronze 8 posts since
        Dec 8, 2010
        Currently Being Moderated
        Oct 11, 2011 3:40 PM (in response to RAJ)
        Re: Smack over http

        You need the xpp3.jar library. (attached)

         

        It is available in the whack distribution.

         

        I remember I had to include other jars to get it to work.

         

        I needed following (google for them):

         

        1. xlightweb-2.13.2-jar-with-dependencies.jar

        2. xpp3.jar (attached)

        3. dom4j.jar (in whack distro)

        4. some code from com.kenai.jbosh branch

        5. some code from org.jivesoftware.smack branch

         

        I am attaching modified smack jar with the class files from 4 and 5 included. For the others you can download the regular jars.

        This is from 3.1.0 (one of the nightly builds).

        Attachments:
        • Kristam269 Bronze 35 posts since
          Oct 14, 2011
          Currently Being Moderated
          Oct 27, 2011 5:21 AM (in response to Protected)
          Re: Smack over http

          Hi,

           

          Version : Openfire 3.7.1 , Smack- 3.2.1 and jbosh-0.6.0.jar
          XMPP default port: 5222 and my connection manager port: 5333 and HttpBinding – 7070(Enabled in Admin console)
          BOSHConfiguration config = new BOSHConfiguration(false, "myipaddress",
              5222, "/http-bind", "myservicename");

          As per this thread to introduce a new rid property in BOSCHClient.java I have downloaded the jbosh-0.6.0 source code from this URL (http://grepcode.com/snapshot/repo1.maven.org/maven2/com.kenai.jbosh/jbosh/0.6.0)

          I made those changes in BOSHClient.java and after that also I am getting the same errors.

          If I use the port number as 5222 / 5333 I am getting Timeout reaches Exception
          And for 7070 port I am getting NullPointerException

          Exception in thread "BOSHClient[18378667]: Receive thread" java.lang.NullPointerException
          at com.kenai.jbosh.XLightWebResponse.awaitResponse(XLightWebResponse.java:187)
          at com.kenai.jbosh.XLightWebResponse.getBody(XLightWebResponse.java:166)
          at com.kenai.jbosh.BOSHClient.processExchange(BOSHClient.java:1031)
          at com.kenai.jbosh.BOSHClient.processMessages(BOSHClient.java:976)
          at com.kenai.jbosh.BOSHClient.access$000(BOSHClient.java:97)
          at com.kenai.jbosh.BOSHClient$1.run(BOSHClient.java:215)
          at java.lang.Thread.run(Unknown Source)       

          I am bit confusing with these port number. Actually which port number do I need to use here.

          I am using these jars [ smack.jar,smackx-debug.jar,smackx-jingle.jar, smackx.jar, xlightweb-2.5.jar, xmlpull_1_1_3_4c.jar, xpp3-1.1.4c.jar, xSocket-2.6.6.jar and dom4j-1.6.1.jar]

          Can someone please help me whatelse jars do need to include or post here the modified jars…

          Thanks

          • Protected Bronze 8 posts since
            Dec 8, 2010
            Currently Being Moderated
            Oct 27, 2011 6:38 AM (in response to Kristam269)
            Re: Smack over http

            I think you need the jar "xlightweb-2.13.2-jar-with-dependencies.jar". You can find it via Google.

            I am also attaching the same. Please let us know if you got it to work.

            • Kristam269 Bronze 35 posts since
              Oct 14, 2011
              Currently Being Moderated
              Oct 27, 2011 11:13 PM (in response to Protected)
              Re: Smack over http

              Thanks for the reply.

               

              BOSHConfiguration config = new BOSHConfiguration(false,"myipaddress", 5222, "/http-bind", "myservicename");

               

              Connection manger port : 5333 or Httpbind port : 7070 or default port : 5222 here which port number do I need to use

               

              Thanks

              • Protected Bronze 8 posts since
                Dec 8, 2010
                Currently Being Moderated
                Oct 27, 2011 11:59 PM (in response to Kristam269)
                Re: Smack over http

                You need to use the BOSH port (http-bind): 7070 or whatever your server is configured for

                 

                ejabberd default one is 5280, openfire 7070.

                • Kristam269 Bronze 35 posts since
                  Oct 14, 2011
                  Currently Being Moderated
                  Oct 28, 2011 12:43 AM (in response to Protected)
                  Re: Smack over http

                  I am using default openfire HTTP Binding port 7070 and enabled in Admin Console.

                   

                  Getting NullPointerException in XLightWebResponse.java (line number :188)

                  httpResp = future.getResponse();

                  System.out.println("httpResp:"+httpResp);

                  byte[] data = httpResp.getBlockingBody().readBytes();  ------> getting error here

                  and after that getting Timeout Reached Exception.

                   

                   

                  Output in java console

                   

                  httpResp:HTTP/1.1 302 Found
                  Server: Jetty(7.0.2-SNAPSHOT)
                  Content-Length: 0
                  Location: http://myipaddress:7070/http-bind/


                  Exception in thread "BOSHClient[32389396]: Receive thread" java.lang.NullPointerException
                  at com.kenai.jbosh.XLightWebResponse.awaitResponse(XLightWebResponse.java:188)
                  at com.kenai.jbosh.XLightWebResponse.getBody(XLightWebResponse.java:166)
                  at com.kenai.jbosh.BOSHClient.processExchange(BOSHClient.java:1056)
                  at com.kenai.jbosh.BOSHClient.processMessages(BOSHClient.java:1000)
                  at com.kenai.jbosh.BOSHClient.access$0(BOSHClient.java:970)
                  at com.kenai.jbosh.BOSHClient$1.run(BOSHClient.java:211)
                  at java.lang.Thread.run(Unknown Source)

                  

                  Thanks

              • Kristam269 Bronze 35 posts since
                Oct 14, 2011
                Currently Being Moderated
                Oct 28, 2011 12:11 AM (in response to Kristam269)
                Re: Smack over http

                Just I have downloaded the following jars from this thread

                 

                smack.jar, xlightweb.jar, xlightweb-2.13.2-jar-with-dependencies.jar, xpp3.jar, xSocket.jar, smack-bosh-backport.jar

                 

                and the remaining jars from Google(Smack 3.2.1)

                 

                smackx.jar, smackx-debug.jar, smackx-jingle.jar, dom4j-1.6.1.jar

                 

                Added all these jars to Build path and after that I have tried with 5222 / 5333 / 7070 still getting the same error.

                 

                Can you please let me know is there any code changes are required other than BOSHClient.java

                 

                Thanks

                • Kristam269 Bronze 35 posts since
                  Oct 14, 2011
                  Currently Being Moderated
                  Oct 28, 2011 7:05 AM (in response to Kristam269)
                  Smack over http

                  Thank you so much  for your help.

                   

                  Finally I am able to connect with Openfire using BOSH after I added the trailing slash.

                   

                  BOSHConfiguration config = new BOSHConfiguration(false,

                      "myipaddress", 7070, "/http-bind/", "myservicename");

                   

                  Without trailing slash I was getting Null pointer exception.

                   

                  Thanks,

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points