Openfire Smack Connection issue

2.6k views Asked by At

This is my first time using Openfire & smack. These are the details :

  • Version: Openfire 3.10.0
  • Server Directory: /opt/openfire Server
  • Name: ubuntu

Environment

  • Java Version: 1.7.0_79 Oracle Corporation -- OpenJDK 64-Bit Server VM

  • Appserver: jetty/9.2.z-SNAPSHOT

  • Host Name: ubuntu

I am using the latest version of Smack 4.1

And this is the code :

    public XMPPManager() 
{   
    XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
            .setServiceName("ubuntu")
            //.setHost("127.0.0.1")
            .setPort(5222)
            .setSecurityMode(SecurityMode.disabled)
            .setDebuggerEnabled(true).build();

    AbstractXMPPConnection mConnection = new XMPPTCPConnection(config);

    try 
    {
        System.out.println("connecting");
        mConnection.setPacketReplyTimeout(10000);
        mConnection.connect();
        System.out.println("connected");
        mConnection.login("tuser1", "test1");

    } 
    catch (SmackException | IOException | XMPPException e) 
    {
        e.printStackTrace();
    }

}

Now when I am running this code I am getting following error :

    Java project working, Hello World !!
connecting
Jun 08, 2015 8:16:49 AM org.jivesoftware.smack.util.DNSUtil resolveDomain
WARNING: Exception while resovling SRV records for ubuntu. Consider adding '_xmpp-(server|client)._tcp' DNS SRV Records
javax.naming.NameNotFoundException: DNS name not found [response code 3]; remaining name '_xmpp-client._tcp.ubuntu'
    at com.sun.jndi.dns.DnsClient.checkResponseCode(DnsClient.java:654)
    at com.sun.jndi.dns.DnsClient.isMatchResponse(DnsClient.java:572)
    at com.sun.jndi.dns.DnsClient.doUdpQuery(DnsClient.java:421)
    at com.sun.jndi.dns.DnsClient.query(DnsClient.java:210)
    at com.sun.jndi.dns.Resolver.query(Resolver.java:81)
    at com.sun.jndi.dns.DnsContext.c_getAttributes(DnsContext.java:430)
    at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_getAttributes(ComponentDirContext.java:231)
    at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(PartialCompositeDirContext.java:139)
    at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(PartialCompositeDirContext.java:127)
    at javax.naming.directory.InitialDirContext.getAttributes(InitialDirContext.java:142)
    at org.jivesoftware.smack.util.dns.javax.JavaxResolver.lookupSRVRecords(JavaxResolver.java:78)
    at org.jivesoftware.smack.util.DNSUtil.resolveDomain(DNSUtil.java:171)
    at org.jivesoftware.smack.util.DNSUtil.resolveXMPPDomain(DNSUtil.java:120)
    at org.jivesoftware.smack.AbstractXMPPConnection.populateHostAddresses(AbstractXMPPConnection.java:569)
    at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectUsingConfiguration(XMPPTCPConnection.java:552)
    at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectInternal(XMPPTCPConnection.java:830)
    at org.jivesoftware.smack.AbstractXMPPConnection.connect(AbstractXMPPConnection.java:360)
    at XMPPManager.<init>(XMPPManager.java:29)
    at Main.main(Main.java:12)

08:16:49 AM SENT (0): <stream:stream xmlns='jabber:client' to='ubuntu' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' xml:lang='en'>
08:16:49 AM RECV (0): <?xml version='1.0' encoding='UTF-8'?><stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" from="ubuntu" id="3197fe6e" xml:lang="en" version="1.0"><stream:features><starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"></starttls><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>DIGEST-MD5</mechanism><mechanism>PLAIN</mechanism><mechanism>ANONYMOUS</mechanism><mechanism>CRAM-MD5</mechanism></mechanisms><compression xmlns="http://jabber.org/features/compress"><method>zlib</method></compression><auth xmlns="http://jabber.org/features/iq-auth"/><register xmlns="http://jabber.org/features/iq-register"/></stream:features>
connected
08:16:50 AM SENT (0): <auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='DIGEST-MD5'>=</auth>
08:16:50 AM RECV (0): <challenge xmlns="urn:ietf:params:xml:ns:xmpp-sasl">cmVhbG09InVidW50dSIsbm9uY2U9InFva3NTWFkveDZSQTh1bmJpb3FSQjZKY2NhSnhsd3JsNXBWZEVzakUiLHFvcD0iYXV0aCIsY2hhcnNldD11dGYtOCxhbGdvcml0aG09bWQ1LXNlc3M=</challenge>
08:16:50 AM SENT (0): <response xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>Y2hhcnNldD11dGYtOCx1c2VybmFtZT0idHVzZXIxIixyZWFsbT0idWJ1bnR1Iixub25jZT0icW9rc1NYWS94NlJBOHVuYmlvcVJCNkpjY2FKeGx3cmw1cFZkRXNqRSIsbmM9MDAwMDAwMDEsY25vbmNlPSJoanlFaTl4N1BZTCtZb1VCQmZXRDJWNjF6M2doSzlBOW43Tlh6RDgyIixkaWdlc3QtdXJpPSJ4bXBwL3VidW50dSIsbWF4YnVmPTY1NTM2LHJlc3BvbnNlPTliMGM5YzBiOGNmYjVlOTYzNmI1ZDUyOWFlOTgwNThkLHFvcD1hdXRo</response>
08:16:50 AM RECV (0): <success xmlns="urn:ietf:params:xml:ns:xmpp-sasl">cnNwYXV0aD02OGY5MTNhNDNmOWYyNzIxMTViM2I5YTc4ZDBhM2JlOA==</success>
08:16:50 AM SENT (0): <stream:stream xmlns='jabber:client' to='ubuntu' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' id='3197fe6e' xml:lang='en'>
08:16:50 AM RECV (0): <?xml version='1.0' encoding='UTF-8'?><stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" from="ubuntu" id="3197fe6e" xml:lang="en" version="1.0"><stream:features><compression xmlns="http://jabber.org/features/compress"><method>zlib</method></compression><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"/><session xmlns="urn:ietf:params:xml:ns:xmpp-session"><optional/></session></stream:features>
08:16:50 AM SENT (0): <iq id='hqopf-3' type='set'><bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'><resource>Smack</resource></bind></iq>
08:16:50 AM RECV (0): <iq type="result" id="hqopf-3" to="ubuntu/3197fe6e"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><jid>tuser1@ubuntu/Smack</jid></bind></iq>
08:16:50 AM User logged (0): tuser1@ubuntu:5222/Smack
08:16:50 AM SENT (0): <iq id='hqopf-5' type='get'><query xmlns='jabber:iq:roster'></query></iq>
08:16:50 AM RECV (0): <iq type="result" id="hqopf-5" to="tuser1@ubuntu/Smack"><query xmlns="jabber:iq:roster"/></iq>
08:16:50 AM XMPPConnection authenticated (0)
08:16:50 AM SENT (0): <presence id='hqopf-7'><c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='http://www.igniterealtime.org/projects/smack' ver='NfJ3flI83zSdUDzCEICtbypursw='/></presence>
08:16:50 AM RECV (0): <iq type="get" id="360-5" to="tuser1@ubuntu/Smack" from="ubuntu"><query xmlns="http://jabber.org/protocol/disco#info"/></iq>
08:16:50 AM SENT (0): <iq to='ubuntu' id='360-5' type='result'><query xmlns='http://jabber.org/protocol/disco#info'><identity category='client' name='Smack' type='pc'/><feature var='http://jabber.org/protocol/commands'/><feature var='http://jabber.org/protocol/xhtml-im'/><feature var='jabber:iq:privacy'/><feature var='http://jabber.org/protocol/disco#items'/><feature var='vcard-temp'/><feature var='urn:xmpp:time'/><feature var='jabber:iq:last'/><feature var='urn:xmpp:ping'/><feature var='jabber:x:data'/><feature var='http://jabber.org/protocol/bytestreams'/><feature var='http://jabber.org/protocol/muc'/><feature var='http://jabber.org/protocol/xdata-validate'/><feature var='jabber:iq:version'/><feature var='http://jabber.org/protocol/xdata-layout'/><feature var='urn:xmpp:receipts'/><feature var='http://jabber.org/protocol/caps'/><feature var='http://jabber.org/protocol/disco#info'/></query></iq>
08:16:50 AM RECV (0): <presence id="hqopf-7" from="tuser1@ubuntu/Smack" to="tuser1@ubuntu/Smack"><c xmlns="http://jabber.org/protocol/caps" hash="sha-1" node="http://www.igniterealtime.org/projects/smack" ver="NfJ3flI83zSdUDzCEICtbypursw="/></presence><presence from="testuser2@ubuntu" to="tuser1@ubuntu" type="subscribe"/>

What is going wrong. I cannot see any sessions on the openfire admin console. The server is setup on Ubuntu 12.04.3 (localhost)

1

There are 1 answers

0
OddDev On

Your connection settings are wrong, here use this :

XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
        .setServiceName("127.0.0.1")
        .setHost("127.0.0.1")
        .setPort(5222)
        .setSecurityMode(SecurityMode.disabled)
        .setDebuggerEnabled(true).build();