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");
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.