3
votes

i have been developing a chat application using smack client library 4.1.8 and xmpp server(openfire server) but while trying to create new user using Accountmanger class it raises and exception "XMPPError: bad-request - modify"

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

                AbstractXMPPConnection conn2 = new XMPPTCPConnection(conf);

                //conn2.login();
                conn2.connect();

                AccountManager accountManager = AccountManager.getInstance(conn2);
                if (accountManager.supportsAccountCreation()) {
                    accountManager.sensitiveOperationOverInsecureConnection(true);
                    accountManager.createAccount("qidus", "123456");
                    conn2.login("qidus", "123456");

                }

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

and the exception is this

04:01:41 AM SENT (0): <iq to='127.0.0.1' id='aYej1-3' type='get'><query xmlns='jabber:iq:register'></query></iq>

04:01:41 AM RECV (0):

org.jivesoftware.smack.XMPPException$XMPPErrorException: XMPPError: bad-request - modify
at org.jivesoftware.smack.XMPPException$XMPPErrorException.ifHasErrorThenThrow(XMPPException.java:135)
at org.jivesoftware.smack.PacketCollector.nextResultOrThrow(PacketCollector.java:232)
at org.jivesoftware.smack.PacketCollector.nextResultOrThrow(PacketCollector.java:213)
at org.jivesoftware.smackx.iqregister.AccountManager.getRegistrationInfo(AccountManager.java:332)
at org.jivesoftware.smackx.iqregister.AccountManager.supportsAccountCreation(AccountManager.java:144)
at chat.Chat$1.run(Chat.java:46)
2

2 Answers

5
votes

You need to set properly Service Name. You can chek your serviceName in Openfire through admin panel (127.0.0.1:9090) it's in first page in middle of the page, look for "Server Name" after login.

By default it's your machine name.

However your code will run just once: 2nd time AccountManger will throw an exception due to already registered user.

0
votes

You also get this error or exception when the username which you are passing for account creation has the null value.So check your username also.