again unable to create an user via Webservices. [solved]

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2007 09:51 AM
first my sample code:
and few things to check the homefolder already exist and check if the users already exists.
the createpersonprop function
and finally the error on client side.
and at least the server version 2.1 RC1
after all this problem the alfresco server working well.
vincent
ps : great Jobs …
AdministrationServiceSoapBindingStub administrationService = WebServiceFactory.getAdministrationService(); RepositoryServiceSoapBindingStub repositoryService= WebServiceFactory.getRepositoryService();
and few things to check the homefolder already exist and check if the users already exists.
// Create the new users NewUserDetails[] newUsers = new NewUserDetails[1] ; NewUserDetails newUser = new NewUserDetails( userLogin, userPassword, createPersonProperties(homeFolder, userName, userMiddlename, userSurname, userMail, userOrg)); UserDetails[] userDetails = administrationService.createUsers(new NewUserDetails[]{newUser});
the createpersonprop function
private static NamedValue[] createPersonProperties( String homeFolder, String firstName, String middleName, String lastName, String email, String orgId) { // Create the new user objects return new NamedValue[] { new NamedValue(Constants.PROP_USER_HOMEFOLDER, false, homeFolder, null), new NamedValue(Constants.PROP_USER_FIRSTNAME, false, firstName, null), new NamedValue(Constants.PROP_USER_MIDDLENAME, false, middleName, null), new NamedValue(Constants.PROP_USER_LASTNAME, false, lastName, null), new NamedValue(Constants.PROP_USER_EMAIL, false, email, null), new NamedValue(Constants.PROP_USER_ORGID, false, orgId, null)}; }
and finally the error on client side.
AxisFault faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException faultSubcode: faultString: org.xml.sax.SAXParseException: Premature end of file.
i have found the sample code in org.alfresco.webservice.test.AdministrationServiceSystemTest/** * Administration service system test * * @author Roy Wetherall */public class AdministrationServiceSystemTest extends BaseWebServiceSystemTest{ private static Log logger = LogFactory.getLog(AdministrationServiceSystemTest.class); public void testGetUsersBatching() throws Exception { int batchSize = 5; QueryConfiguration queryCfg = new QueryConfiguration(); queryCfg.setFetchSize(batchSize); WebServiceFactory.getAdministrationService().setHeader( new RepositoryServiceLocator().getServiceName().getNamespaceURI(), "QueryHeader", queryCfg); // Get the details of the new users String homeFolder = store.getScheme() + "://" + store.getAddress() + "/" + folderReference.getUuid(); String one = Long.toString(System.currentTimeMillis()); String two = one + "2"; NewUserDetails[] newUsers = new NewUserDetails[] { new NewUserDetails( "user" + one, "password" + one, createPersonProperties(homeFolder, "first" + one, "middle" + one, "last" + one, "email" + one, "org" + one)), new NewUserDetails( "user" + two, "password2" + two, createPersonProperties(homeFolder, "first" + two, "middle" + two, "last" + two, "email" + two, "org" + two)) }; // Create the new users WebServiceFactory.getAdministrationService().createUsers(newUsers); UserQueryResults results = WebServiceFactory.getAdministrationService().queryUsers(null); assertNotNull(results);
and at least the server version 2.1 RC1
after all this problem the alfresco server working well.
vincent
ps : great Jobs …
Labels:
- Labels:
-
Archive
1 REPLY 1

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2007 04:02 PM
ok a little sample code to create:
and if you want a little code to delete..
have a nice day!
:lol:
public static void userAdd( String userLogin, String userPassword, String userName,String userMiddlename, String userSurname, String userMail, String userOrg) throws Exception { repositoryService = WebServiceFactory.getRepositoryService(); contentService = WebServiceFactory.getContentService(); administrationService = WebServiceFactory.getAdministrationService(); int batchSize = 5; QueryConfiguration queryCfg = new QueryConfiguration(); queryCfg.setFetchSize(batchSize); WebServiceFactory.getAdministrationService().setHeader( new RepositoryServiceLocator().getServiceName().getNamespaceURI(), "QueryHeader", queryCfg); // check the user boolean existUser=false; try { // test before the user administrationService.getUser(userLogin); existUser=true; } catch (Exception e){ existUser=false; } if (existUser) { throw new Exception("User " + userLogin + " Already exists."); } Store store = new Store(Constants.WORKSPACE_STORE,"SpacesStore"); Reference folderReference = new Reference(store,null,"/app:company_home/app:user_homes/cm:"+userLogin); Node[] nodes=null; // try to create the folder try{ nodes = repositoryService.get(new Predicate(new Reference[]{folderReference},store,null)); } catch (Exception e) { // Create parent reference to company home ParentReference parentReference = new ParentReference( store, null, "/app:company_home/app:user_homes", Constants.ASSOC_CONTAINS, Constants.createQNameString(Constants.NAMESPACE_CONTENT_MODEL, userLogin)); // Create folder NamedValue[] properties = new NamedValue[]{Utils.createNamedValue(Constants.PROP_NAME, userLogin)}; CMLCreate create = new CMLCreate("1", parentReference, null, null, null, Constants.TYPE_FOLDER, properties); CML cml = new CML(); cml.setCreate(new CMLCreate[]{create}); UpdateResult[] results = WebServiceFactory.getRepositoryService().update(cml); // Create parent reference to sample folder Reference userFolder = results[0].getDestination(); ParentReference parentReference2 = new ParentReference( store, userFolder.getUuid(), null, Constants.ASSOC_CONTAINS, Constants.createQNameString(Constants.NAMESPACE_CONTENT_MODEL, userLogin)); } // get the reference for the folder Reference userFolder =null; try { nodes = repositoryService.get(new Predicate(new Reference[]{folderReference},store,null)); if (nodes.length == 1) { userFolder = nodes[0].getReference(); } } catch (Exception e) { e.printStackTrace(); throw new Exception("Unable to create the new folder for user "+userLogin+"."); } try { String homeFolder = store.getScheme() + "://" + store.getAddress() + "/" + userFolder.getUuid(); // Create the new users NewUserDetails[] newUsers = new NewUserDetails[1] ; NewUserDetails newUser = new NewUserDetails( userLogin, userPassword, createPersonProperties(homeFolder, userName, userMiddlename, userSurname, userMail, userOrg)); UserDetails[] userDetails = administrationService.createUsers(new NewUserDetails[]{newUser}); } catch ( Exception e) { e.printStackTrace(); throw new Exception("Unable to create the new user."); } System.out.println("the user "+userLogin+" has been created and her folder too."); }/* * create the property's */ private static NamedValue[] createPersonProperties( String homeFolder, String firstName, String middleName, String lastName, String email, String orgId) { // Create the new user objects return new NamedValue[] { new NamedValue(Constants.PROP_USER_HOMEFOLDER, false, homeFolder, null), new NamedValue(Constants.PROP_USER_FIRSTNAME, false, firstName, null), new NamedValue(Constants.PROP_USER_MIDDLENAME, false, middleName, null), new NamedValue(Constants.PROP_USER_LASTNAME, false, lastName, null), new NamedValue(Constants.PROP_USER_EMAIL, false, email, null), new NamedValue(Constants.PROP_USER_ORGID, false, orgId, null)}; }
and if you want a little code to delete..
public static void userDel( String userLogin, boolean userDeleteRepo ) throws Exception { repositoryService = WebServiceFactory.getRepositoryService(); contentService = WebServiceFactory.getContentService(); administrationService = WebServiceFactory.getAdministrationService(); // check the user try { // test before the user administrationService.getUser(userLogin); } catch (Exception e){ throw new Exception("User " + userLogin + " does not exists."); } administrationService.deleteUsers(new String[]{userLogin}); System.out.println("The user "+userLogin+" has been deleted."); if (userDeleteRepo){ Store store = new Store(Constants.WORKSPACE_STORE,"SpacesStore"); Reference folderReference = new Reference(store,null,"/app:company_home/app:user_homes/cm:"+userLogin); // get the reference for the folder try { repositoryService.get(new Predicate(new Reference[]{folderReference},store,null)); } catch (Exception e) { e.printStackTrace(); throw new Exception("Unable to get the folder for user "+userLogin+"."); } try { CML cml = new CML(); CMLDelete cmlDelete = new CMLDelete(); cmlDelete.setWhere(new Predicate(new Reference[]{folderReference},store,null)); cml.setDelete(new CMLDelete[]{cmlDelete}); UpdateResult[] results = repositoryService.update(cml); } catch (Exception e) { e.printStackTrace(); } System.out.println("the folder "+userLogin+" has been deleted."); } }
have a nice day!
:lol:
