powered by Jive Software

Create Account asmack throws error 400 bad request

Hello,

I am trying to make an appli on android which have to connect to a server ejabberd to first, whether it is needed, create en account or log into the server.

I am using smack here is my code:

try {
               /**
                * The abstract Connection class provides an interface for
                * connections to a XMPP server and implements shared methods which
                * are used by the different types of connections (e.g.
                * XMPPConnection or BoshConnection).
                *                 * To create a connection to a XMPP server a simple usage of this
                * API might look like the following:
                */                // Connect to the server                con.connect();
                                     // Create a connection to the igniterealtime.org XMPP server.
                 ConnectionConfiguration connectionConfiguration = null;
                 connectionConfiguration = new ConnectionConfiguration("server.com", 5222);
                //connectionConfiguration.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
                con = new XMPPConnection(connectionConfiguration);                                              con.getAccountManager().createAccount("log@server.com", "azer");
//               Log.i(TAG, "support account creation : "
//                         + am.supportsAccountCreation() + "\n"
//                         + am.getAccountInstructions());
//               am.createAccount("thomas", "azer");
          } catch (Exception e) {
               Log.e(TAG, e.getMessage());
          }

The supportsAccountCreation() method return true and when I am creating an account from empathy it works fine.

However this code always return a 400 bas request error.

there is also a warning keystoreException: Keystore jks implementation not found.

If any one have any idea.

After studying the exchange between the client and the server, I saw that the login and pasword were null.

In, fact you have to make a change in the source code of AccountManager.java:

public void createAccount(String username, String password, Map<String, String> attributes)
            throws XMPPException
    {
        if (!supportsAccountCreation()) {
            throw new XMPPException("Server does not support account creation.");
        }         Log.v("test", "attribute : username : " + username + " pw : " + password);
        Registration reg = new Registration();
        reg.setType(IQ.Type.SET);
        reg.setTo(connection.getServiceName());         for(String s : attributes.keySet()){              reg.addAttribute(s, attributes.get(s));
             Log.v("test", reg.getAttributes().get(s));
        }
        reg.setUsername(username);
        reg.setPassword(password);         PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()),
                new PacketTypeFilter(IQ.class));
        PacketCollector collector = connection.createPacketCollector(filter);
        connection.sendPacket(reg);
        IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
        // Stop queuing results
        collector.cancel();
        if (result == null) {
            throw new XMPPException("No response from server.");
        }
        else if (result.getType() == IQ.Type.ERROR) {
            throw new XMPPException(result.getError());
        }
    }