Quantcast
Channel: Ignite Realtime : Unanswered Discussions - Support
Viewing all articles
Browse latest Browse all 4979

Connection fails when trying to connect to openfire

$
0
0

openfire 3.9.3

smack 4.1.0

 

I have the following code that is trying to make a connection to our xmpp openfire, and not sure if my code is correct for creating a connection and logging in.

 

domain   = xmpp2.sun-system.com

username = steve

 

    public boolean createConnection(String domain, String username, String password) {

        boolean isConnected = false;

 

        XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder();

        configBuilder.setUsernameAndPassword(username, password);

        configBuilder.setResource("Smack");

        configBuilder.setServiceName(domain);

        configBuilder.setPort(5222);

        configBuilder.setDebuggerEnabled(true);

        configBuilder.setConnectTimeout(10000);

        configBuilder.setSecurityMode(ConnectionConfiguration.SecurityMode.required);      

     

        AbstractXMPPConnection clientConnection = new XMPPTCPConnection(configBuilder.build());

        if(clientConnection == null) {

            log.log(Level.SEVERE, "Failed to create XMPPTCPConnection object");

            return false;

        }

    

        try {         

            if(!clientConnection.isConnected()) {

                clientConnection.connect();

            }

            else {

                clientConnection.login(username, password);

            }

            isConnected = true;

        }

        catch(XMPPException ex) {

            log.log(Level.SEVERE, "XMPPException: " + ex.getMessage());

            isConnected = false;

        }

        catch(SmackException.ConnectionException ex) {

            log.log(Level.SEVERE, "SmackConnection.ConnectionException: " + ex.getMessage());

            isConnected = false;

        }

        catch(SmackException ex) {

            log.log(Level.SEVERE, "SmackException: " + ex.getMessage());

            isConnected = false;

        }

        catch(IOException ex) {

            log.log(Level.SEVERE, "IOException: " + ex.getMessage());

            isConnected = false;

        }     

        catch(Exception ex) {

            log.log(Level.SEVERE, "Exception: " + ex.getMessage());

            isConnected = false;

        }

     

        return isConnected;

    }

 

01:59:13 PM SENT (0): <stream:stream xmlns='jabber:client' to='xmpp2.sun-system.com' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' from='steve@xmpp2.sun-system.com' xml:lang='en'>

01:59:13 PM RECV (0): <?xml version='1.0' encoding='UTF-8'?><stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" from="nagios-office" id="7c391983" xml:lang="en" version="1.0">

 

    Exception in thread "Smack Packet Reader (0)" java.lang.AssertionError

    at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPC onnection.java:992)

    at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$200(XMPPTCPCon nection.java:937)

    at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnecti on.java:952)

    at java.lang.Thread.run(Thread.java:744)

    Apr 10, 2015 2:13:34 PM com.sunsystems.smackclient.SmackClient createConnection

    SEVERE: SmackException: No response received within reply timeout. Timeout was 5000ms (~5s). Used filter: No filter used or filter was 'null'.

 

The line that throws the assertion is this line of code:

                                                    String reportedServiceName = parser.getAttributeValue("", "from");

(XMPPTCPConnection.java:992) assert(reportedServiceName.equals(config.getServiceName()));

 

I am not sure about this getServiceName and what it should equal? Or it has something to do with the timeout. Can anyone confirm that my code to create a connection and login is correct?

I can connect to this openfire using swift 2.0 client without any problem.

 

My dependencies are these:

    compile "org.igniterealtime.smack:smack-java7:4.1.0"

    compile "org.igniterealtime.smack:smack-tcp:4.1.0"

    compile "org.igniterealtime.smack:smack-im:4.1.0"

    compile "org.igniterealtime.smack:smack-extensions:4.1.0"

    compile "org.igniterealtime.smack:smack-resolver-dnsjava:4.1.0"

 

Many thank for any suggestions,


Viewing all articles
Browse latest Browse all 4979

Trending Articles