Hi all,
I'am absolutely new to Liferay and now want to create a user with liferay webservices not within portal but from a single java-application from within eclipse. Under Liferay:
Developer documentation I just found one general example of liferay webservices usage and tried to understand the fundamentals.
Within eclipse I created a new Webservice-client by giving it the name of the "Portal_UserService.wsdl", the "Portal_CompanyService.wsdl" and the Portal_OrganizationService.wsdl".
"Portal_UserService" offers me a method to addUser.
"Portal_CompanyService" is necessary to retrieve the company-id I have to pass to the addUser-method.
"Portal_OrganizationService" is not mandatory for this purpose.
The system generated the appropiate Stub classes.
I then created a new test-class to test the adding of a new user. The code in the class is as follows (using some parts of the above mentioned example in liferay developer docu)
1
2 .
3 .
4 .
5 try {
6 String remoteUser = "test";
7 String password = "Test";
8 virtualHost = "localhost";
9
10 String serviceCompanyName = "Portal_CompanyService";
11 String serviceUserName = "Portal_UserService";
12
13 // Locate the Company
14 CompanyServiceSoapServiceLocator locatorCompany = new CompanyServiceSoapServiceLocator();
15 CompanyServiceSoap soapCompany = locatorCompany.getPortal_CompanyService(_getURL(remoteUser, password, serviceCompanyName, true));
16 CompanySoap companySoap = soapCompany.getCompanyByVirtualHost(virtualHost);
17
18 // Locate the User service
19 UserServiceSoapServiceLocator locatorUser = new UserServiceSoapServiceLocator();
20 UserServiceSoap userSoap = locatorUser.getPortal_UserService(_getURL(remoteUser, password, serviceUserName, true));
21
22 ServiceContext context = new ServiceContext();
23 context.setPortalURL("http://localhost:8080");
24
25 userSoap.addUser(companySoap.getCompanyId(),
26 false, // autoPassword
27 "pass1", // String password1
28 "pass1", // String password2
29 false, // boolean autoScreenName
30 "Testuser", // String screenName
31 "Testuser@someplace.com", // String emailAddress
32 (long) -1, // long facebookId
33 "-1", // String openId
34 Locale.getDefault().toString(), // Locale locale
35 "Test", // String firstName
36 "", // String middleName
37 "User", // String lastName
38 -1, // int prefixId
39 -1, // int suffixId
40 true, // boolean male
41 1, // int birthdayMonth
42 1, // int birthdayDay
43 1985, // int birthdayYear
44 "", // String jobTitle
45 new long[0], // long[] groupIds
46 new long[0], // long[] organizationIds
47 new long[0], // long[] roleIds
48 new long[0], // long[] userGroupIds
49 false, // boolean sendEmail
50 context // ServiceContext serviceContext)
51 );
52
53 }
54 catch (Exception e) {
55 e.printStackTrace();
56 }
57 .
58 .
59 .
60
61 private static URL _getURL(String remoteUser, String password, String serviceName, boolean authenicate) throws Exception {
62 // Unauthenticated url
63 String url = "http://localhost:8080/api/axis/" + serviceName;
64
65 // Authenticated url
66 if (authenicate) {
67 url = "http://" + remoteUser + ":" + password + "@localhost:8080/api/secure/axis/" + serviceName;
68 }
69
70 return new URL(url);
71 }
Liferay is running on the local machine with the given port. The programm did run through without any errors but it did not create the user. I replaced the context parameter in
addUser with null. Then an exception was thrown.
As the documentation in the api is a bit poor, its like fishing in troubled waters.
Can anyone help?
I have some fundamental questions about this topic
1. I think I have to give the remote user to the UserServiceSoap-class because this user has permissions to add a new user, right?
2. I have no understanding of the service-context object. Its meaning is not explained in the liferay-api nor in its documentation. Somehow it seams to be the context to the portal,
but I think the connection to it is done when creating the userSoap-Object.
I would be very obliged for an (a detailed) answer, Clemens
Please sign in to flag this as inappropriate.