0

I have this code to create a user, inspired by this.
After executing I have this error:

An error occurred when attempting to create a new user
Username field is required.
E-mail address field is required.
Password field is required.
Exception in thread "main" org.apache.xmlrpc.XmlRpcException: Username field is required.
E-mail address field is required.

Here is my code:

public boolean createUser(DrupalAccount account) throws Exception
{
    Vector<Object> params = generateDefaultParams(MethodUserCreate);
    // code can be re-factored to use ArrayList<Object>
    //ArrayList<Object> params = generateDefaultParams(MethodUserCreate);
    // must also re-factor generateDefaultParams method
    // currently objects don't work for submitting parameters to the
    // user.save service. Use an array instead

    params.add(account);
    try
    {
        Object o = xmlRpcClient.execute(MethodUserCreate, params);
        if (log.isLoggable(Level.FINEST))
        {
            log.finest(MethodUserCreate + " returned " + o.toString());
            System.out.println(o.toString());
        }
    }
    catch(Exception e)
    {
        System.err.println("An error occurred when attempting to create a user");
        System.err.println(e.getMessage());
        throw e;
    }

    //TODO add code to inform if user successfully created
    return true;
}

Edit: I tried MathRo's suggestion and it still gives the error:

Exception in thread "main" org.apache.xmlrpc.XmlRpcException:
Server error. Requested method user.create not specified.
    at org.apache.xmlrpc.client.XmlRpcStreamTransport.readResponse(XmlRpcStreamTransport.java:197)
    at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:156)
    at org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:143)
    at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.sendRequest(XmlRpcSunHttpTransport.java:69)
    at org.apache.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:56)
    at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:167)
    at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:137)
    at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:126)
    at DrupalService.userCreate(DrupalService.java:284)
    at Main.main(Main.java:29)

although I added in my Service class this:

public HashMap userCreate(String name, String mail, String pass)
        throws XmlRpcException {
    HashMap paramUser = new HashMap();
    paramUser.put("name", name);
    paramUser.put("mail",mail);
    paramUser.put("pass",pass);
    Object[] param = {paramUser};
    HashMap ret_createUser = (HashMap)xmlRpcClient.execute("user.create", param);
    return  ret_createUser;
}

and in my Main class this:

service.userCreate("myname", "[email protected]", "mypass");
2
  • Hi, I'm doing the same kind of work but not exactly like you. May I can help, but before can you tell more about your configuration ? using Drupal 7, Services 3, Apache XMLRPC for the JavaClient ? The main difference with my code, is that when I log to my Drupal site, I keep the session ID and the session Name, then I write it in the header to have the cookies session. With this I have the permission to create node (because the account logged have the permission...) P.S : Sorry if my english is bad Commented May 5, 2011 at 15:48
  • thank you drupal-6.20 services-6.x-2.4. apache-xmlrpc-3.1.3 my code is the same as the one in this I just made some changes. I put a username, password, email address but it gives me this error An error occurred when attempting to create a new user Username field is required. E-mail address field is required. Password field is required. Exception in thread "main" org.apache.xmlrpc.XmlRpcException: Username field is required. E-mail address field is required. Commented May 6, 2011 at 7:05

1 Answer 1

0

Ok, I'm not used to Drupal 6 and services-6 but I'll try to help (I'm working with D7).

Did you try to call the user.save method by creating the parameter yourself (without using the DruaplAccount Object)?

For example for my JavaClient (with services 3.x on D7), I made a function to create a user:

/**
 * Create a user 
 * @param name : 
 * @param mail
 * @param pass
 * @return
 * @throws XmlRpcException
 */
public HashMap userCreate(String name, String mail, String pass)
        throws XmlRpcException {
    HashMap paramUser = new HashMap();
    paramUser.put("name", name);
    paramUser.put("mail",mail);
    paramUser.put("pass",pass);
    Object[] param = {paramUser};
    HashMap ret_createUser =
            (HashMap) this.client.execute("user.create", param );
    return  ret_createUser;
}

I don't know if it's very helpful, but I posted in case it could.

Sign up to request clarification or add additional context in comments.

1 Comment

This suggestion is for the module services 7.x-3.x-dev. In your case your using services 6.x-2.4, so I looked in the code and the name of the method for the 6.x-2.4 version is "user.save", not "user.create". So you have to replace this.client.execute("user.create", param ) by this.client.execute("user.save", param );.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.