3

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)
btinsae
  • 503
  • 2
  • 5
  • 13

2 Answers2

5

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.

MrPk
  • 2,862
  • 2
  • 20
  • 26
  • 1
    Thanks @MrPk, your answer has saved me after many days of research. – mut tony Jun 11 '20 at 11:30
  • I was getting `XMPPError: bad-request - modify` error with existing user. It works fine with new user. Why is it so and how can we fix it for existing user? – Manish Kumar Oct 04 '20 at 02:22
  • Hi @ManishKumar , please post a question and feel free to send me by private message the link: i need to read your code due to the lack of it I'm unable to help you sorry – MrPk Oct 05 '20 at 07:40
0

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.

BMM
  • 161
  • 1
  • 1
  • 12