powered by Jive Software

AccountManager.createAccount() NoResponseException 4.1.0-aplha2

Hi,

Because of stream management support I wanted to test 4.1.0-aplha2 (currently using 4.0.0 with no problems). Everything seems to work fine by now (big applause for Stream Management!!!), except for creation of new accounts by AccountManager.

this is how I create new account:

AccountManager accountManager = AccountManager.getInstance(connection);

accountManager.createAccount(username, password);

But create account throws** NoResponseException** with no message.

In LogCat I can see this error:

09-29 08:46:10.009 3439-3513/package W/AbstractXMPPConnection﹕ Connection closed with error

** javax.net.ssl.SSLException: Connection closed by peer**

at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_do_handshake(Native Method)

at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLS ocketImpl.java:474)

at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl$SSLInputStream.(O penSSLSocketImpl.java:750)

at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.getInputStream(OpenSSLS ocketImpl.java:692)

at org.jivesoftware.smack.tcp.XMPPTCPConnection.initReaderAndWriter(XMPPTCPConnect ion.java:661)

at org.jivesoftware.smack.tcp.XMPPTCPConnection.proceedTLSReceived(XMPPTCPConnecti on.java:768)

at org.jivesoftware.smack.tcp.XMPPTCPConnection.access$1000(XMPPTCPConnection.java :132)

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

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

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

The only thing I did was change of import path of AccountManager as is in Upgrade Guide, except that I didn’t do any changes in account creation code…

If I try to login using some existing account, then everything works as great.

Appears to be a problem of your SSL/TLS configuration. Make sure the used SSLContext allows a connection to the XMPP server. Or disable security in Smack.

I am quite sure that used SSLContext allows connection to the XMPP server, because I can log in with existing account without any problems. Weird is that when I migrate back to asmack 4.0.0 and leave the code as it is (only comment few stream management parts) it starts to work!

Are there any changes in AccountManager API since 4.0.0? Are the any changes in api for creating secure connection since 4.0.0? I walked through smack 4.1 upgrade guide and it seems to be that there should not be any changes in that…

This is how I create XMPPTCPConnection:

ConnectionConfiguration conf;

if (ProviderManager.getStreamFeatureProvider(SM_FEATURE_ELEMENT_NAME, SM_FEATURE_NAMESPACE) == null) {

ProviderManager.addStreamFeatureProvider(SM_FEATURE_ELEMENT_NAME, SM_FEATURE_NAMESPACE, new StreamManagementStreamFeatureProvider());

}

conf = new ConnectionConfiguration(mProfileData.getDomain());

// disable the built-in ReconnectionManager since we handle this

conf.setReconnectionAllowed(false);

conf.setRosterLoadedAtLogin(false);

//set up stream management

XMPPTCPConnection connection = new XMPPTCPConnection(conf);

connection.setUseStreamManagement(true);

connection.addRequestAckPredicate(ForEveryMessage.INSTANCE);

Here is my logcat output with Smack init connection messages:

09-29 13:11:10.082 28905-29317/package D/SMACK﹕ SENT (12): <stream:stream xmlns=‘jabber:client’ to=‘server’ xmlns:stream=‘http://etherx.jabber.org/streams’ version=‘1.0’>

09-29 13:11:10.092 28905-29317/package D/SMACK﹕ SENT (12):

09-29 13:11:10.532 28905-29318/package D/SMACK﹕ RCV (12): <?xml version='1.0'?><stream:stream xmlns=‘jabber:client’ xmlns:stream=‘http://etherx.jabber.org/streams’ id=‘4280133582’ from=‘server’ version=‘1.0’ xml:lang=‘en’>stream:featuresPLAINDIGEST-MD5SCRAM-SHA-1<register xmlns='http://jabber.org/features/iq-register’/></stream:features>

09-29 13:11:10.552 28905-29317/package D/SMACK﹕ SENT (12):

09-29 13:11:10.732 28905-29318/package D/SMACK﹕ RCV (12): Choose a username and password to register with this server

09-29 13:11:10.822 28905-28967/package D/dalvikvm﹕ GC_FOR_ALLOC freed 1038K, 13% free 10928K/12552K, paused 81ms, total 81ms

09-29 13:11:10.842 28905-29317/package D/SMACK﹕ SENT (12): s0r73pgojeopmssjaairu6kcmk3v4l< username>nqcjloj4v6uk52bug16hrrhspfanlr

09-29 13:11:10.912 28905-29318/package D/SMACK﹕ RCV (12):

09-29 13:11:11.132 28905-29318/package W/AbstractXMPPConnection﹕ Connection closed with error

javax.net.ssl.SSLException: Connection closed by peer

at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)

at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.ja va:405)

at com.android.org.conscrypt.OpenSSLSocketImpl$SSLInputStream.(OpenSSLSocket Impl.java:661)

at com.android.org.conscrypt.OpenSSLSocketImpl.getInputStream(OpenSSLSocketImpl.ja va:632)

at org.jivesoftware.smack.tcp.XMPPTCPConnection.initReaderAndWriter(XMPPTCPConnect ion.java:661)

at org.jivesoftware.smack.tcp.XMPPTCPConnection.proceedTLSReceived(XMPPTCPConnecti on.java:768)

at org.jivesoftware.smack.tcp.XMPPTCPConnection.access$1000(XMPPTCPConnection.java :132)

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

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

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

09-29 13:11:15.842 28905-28967/package E/package.xmpp.XmppManager﹕ NoResponseException: org.jivesoftware.smack.SmackException$NoResponseException

The AccountManager is trying to perform the registration too soon, i.e., before the proceed was received.

Please show your code from the creation of connection instance up to the call to createAccount

here is main method :

XMPPTCPConnection mConnection;

// create a new connection if the connection is obsolete or if th

// old connection is still active

if (mConnection == null || mConnection.isConnected()) {

try {

connection = createNewConnection();

} catch (Exception e) {

// connection failure

Log.e(“Exception creating new XMPP Connection”, e.toString());

reconnect();

return;

}

if (needRegister) {

if (!connectAndRegisterAccount(connection)) {

// registration failure

return;

}

} else {

if (!connectAndAuth(connection)) {

// connection failure

return;

}

}

}

here is createNewConnection():

private XMPPTCPConnection createNewConnection() {

ConnectionConfiguration conf;

if (ProviderManager.getStreamFeatureProvider(SM_FEATURE_ELEMENT_NAME, SM_FEATURE_NAMESPACE) == null) {

ProviderManager.addStreamFeatureProvider(SM_FEATURE_ELEMENT_NAME, SM_FEATURE_NAMESPACE, new StreamManagementStreamFeatureProvider());

}

conf = new ConnectionConfiguration(mProfileData.getDomain());

// disable the built-in ReconnectionManager since we handle this

conf.setReconnectionAllowed(false);

conf.setRosterLoadedAtLogin(false);

//set up stream management

XMPPTCPConnection connection = new XMPPTCPConnection(conf);

connection.setUseStreamManagement(true);

connection.addRequestAckPredicate(ForEveryMessage.INSTANCE);

return connection;

}

here is connectAndRegisterAccount**():**

private boolean connectAndRegisterAccount(XMPPTCPConnection connection) {

try {

connection.connect();

} catch (IOException e) {

Log.w(“XMPP connection failed”, e);

reconnect();

return false;

} catch (XMPPException e) {

Log.w(“XMPP connection failed”, e);

reconnect();

return false;

} catch (SmackException e) {

Log.w(“XMPP connection failed”, e);

reconnect();

return false;

}

AccountManager accountManager = AccountManager.getInstance(connection);

** try {**

__ accountManager.createAccount(username, password);__

** } catch (SmackException.NoResponseException e) {**

** Log.e(TAG, " NoResponseException: " + e.toString());**

reconnect();

return false;

} catch (SmackException.NotConnectedException e) {

Log.e(TAG, "NotConnectedException: ", e);

reconnect();

return false;

} catch (XMPPException e) {

Log.e(TAG, “Registration unsuccessful”, e);

reconnect();

return false;

}

mProfileData.setRegistrationAccepted(true);

return connectAndAuth(connection);

}

There is a missing synchronization point within connect(), which results in the method returning before starttls is completed. I’m going to fix this, but it may take a while (as I’m very busy at the moment). Until it is fixed, you could workaround by introducing an artificial delay between connect() and createAccount().

You are right! Workaround you suggested works! Thanks a lot!

I’ve uploaded 4.1.0-alpha3-SNAPSHOT which contains the supposed fix (Move saslFeatureReceived check in connect() · a942863 · Flowdalic/Smack · GitHub ). Could you grab the snapshot, verify if it makes the workaround obsolete and report back?

Thanks

I have verified it and with 4.1.0-alpha3-SNAPSHOT creating new account work as it should. Workaround is now obsolete.

Good job! Thanks