Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
Clemens Schaab
Adding new users programmatically from a single java application
February 7, 2013 7:29 AM
Answer

Clemens Schaab

Rank: New Member

Posts: 12

Join Date: February 7, 2013

Recent Posts

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
Hitoshi Ozawa
RE: Adding new users programmatically from a single java application
February 7, 2013 3:22 PM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7990

Join Date: March 23, 2010

Recent Posts

I've written a wiki page with sample code attached on calling liferay's web service to add users.

http://www.liferay.com/community/wiki/-/wiki/Main/Web+Service+samples
Clemens Schaab
RE: Adding new users programmatically from a single java application
February 7, 2013 11:43 PM
Answer

Clemens Schaab

Rank: New Member

Posts: 12

Join Date: February 7, 2013

Recent Posts

Hi Hitoshi,

I have read your article before writing my thread. But it doesn't help for answering my questions!

Best regards, Clemens
Olaf Kock
RE: Adding new users programmatically from a single java application
February 8, 2013 12:08 AM
Answer

Olaf Kock

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1892

Join Date: September 23, 2008

Recent Posts

Then an exception was thrown

well, it would help to get some more detailed information as the actual exception might give away the root cause of your problem

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?

Yes - and by default you have the user id (e.g. it's numeric) to authenticate with the webservice, unless you configure otherwise (see your _getURL method)

2. I have no understanding of the service-context object

You're right - it contains a lot of portal context that it carries into the method. The easiest way to see what is actually used from this bucket, is to go through the sourcecode of UserLocalServiceImpl.addUser. Just briefly looking at this code looks like it's optional as there are lots of checks for null - check the source to see the parts that you'll be missing
Clemens Schaab
RE: Adding new users programmatically from a single java application
February 8, 2013 1:45 AM
Answer

Clemens Schaab

Rank: New Member

Posts: 12

Join Date: February 7, 2013

Recent Posts

Hi Olaf, thanks for your answer!

This is the text of the exception: Has something to do with authentication

 1
 2AxisFault
 3 faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
 4 faultSubcode:
 5 faultString: java.rmi.RemoteException
 6 faultActor:
 7 faultNode:
 8 faultDetail:
 9    {http://xml.apache.org/axis/}hostname:CSC-Laptop
10
11java.rmi.RemoteException
12    at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:222)
13    at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:129)
14    at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087)
15    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:601)
16    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1782)
17    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2938)
18    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
19    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
20    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
21    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
22    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
23    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
24    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
25    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
26    at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
27    at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
28    at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
29    at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
30    at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)
31    at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
32    at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
33    at org.apache.axis.client.Call.invoke(Call.java:2767)
34    at org.apache.axis.client.Call.invoke(Call.java:2443)
35    at org.apache.axis.client.Call.invoke(Call.java:2366)
36    at org.apache.axis.client.Call.invoke(Call.java:1812)
37    at com.liferay.portal.service.http.Portal_UserServiceSoapBindingStub.addUser(Portal_UserServiceSoapBindingStub.java:1622)
38    at Test_Portal_TeamService.main(Test_Portal_TeamService.java:53)



The easiest way to see what is actually used from this bucket, is to go through the sourcecode of UserLocalServiceImpl.addUser.

My Code does not use UserLocalServiceImpl, it uses UserServiceSoap.addUser. Stepping through this code leads into the following code-fragment
 1
 2    public com.liferay.portal.model.UserSoap addUser(long companyId, boolean autoPassword, java.lang.String password1, java.lang.String password2, boolean autoScreenName, java.lang.String screenName, java.lang.String emailAddress, long facebookId, java.lang.String openId, java.lang.String locale, java.lang.String firstName, java.lang.String middleName, java.lang.String lastName, int prefixId, int suffixId, boolean male, int birthdayMonth, int birthdayDay, int birthdayYear, java.lang.String jobTitle, long[] groupIds, long[] organizationIds, long[] roleIds, long[] userGroupIds, boolean sendEmail, com.liferay.portal.service.ServiceContext serviceContext) throws java.rmi.RemoteException {
 3        if (super.cachedEndpoint == null) {
 4            throw new org.apache.axis.NoEndPointException();
 5        }
 6        org.apache.axis.client.Call _call = createCall();
 7        _call.setOperation(_operations[9]);
 8        _call.setUseSOAPAction(true);
 9        _call.setSOAPActionURI("");
10        _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
11        _call.setOperationName(new javax.xml.namespace.QName("urn:http.service.portal.liferay.com", "addUser"));
12
13        setRequestHeaders(_call);
14        setAttachments(_call);
15 try {    java.lang.Object _resp = _call.invoke(new java.lang.Object[] {new java.lang.Long(companyId), new java.lang.Boolean(autoPassword), password1, password2, new java.lang.Boolean(autoScreenName), screenName, emailAddress, new java.lang.Long(facebookId), openId, locale, firstName, middleName, lastName, new java.lang.Integer(prefixId), new java.lang.Integer(suffixId), new java.lang.Boolean(male), new java.lang.Integer(birthdayMonth), new java.lang.Integer(birthdayDay), new java.lang.Integer(birthdayYear), jobTitle, groupIds, organizationIds, roleIds, userGroupIds, new java.lang.Boolean(sendEmail), serviceContext});
16
17        if (_resp instanceof java.rmi.RemoteException) {
18            throw (java.rmi.RemoteException)_resp;
19        }
20        else {
21            extractAttachments(_call);
22            try {
23                return (com.liferay.portal.model.UserSoap) _resp;
24            } catch (java.lang.Exception _exception) {
25                return (com.liferay.portal.model.UserSoap) org.apache.axis.utils.JavaUtils.convert(_resp, com.liferay.portal.model.UserSoap.class);
26            }
27        }
28  } catch (org.apache.axis.AxisFault axisFaultException) {
29  throw axisFaultException;
30}

the line
try { java.lang.Object _resp = _call.invoke (...)
throws the exception.

Besides for that I copied the liferay-sources and was looking for the class you mentioned. Windows could not find it.

So my questions still remain alive.
Would be nice if you had any further help for me! Thank you very much, Clemens
Olaf Kock
RE: Adding new users programmatically from a single java application
February 9, 2013 4:11 AM
Answer

Olaf Kock

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1892

Join Date: September 23, 2008

Recent Posts

Sorry, looks like I read too quickly and missed the "webservice" part - I assumed you used the java API directly, e.g. from another webapp/plugin. This way it would have been easy to step into the implementation as it would have been running in the same process. Liferay's API usually is built along some conventions: UserService is implemented in UserServiceImpl and remotely available - of course, if you access it through Webservices, you don't get UserServiceImpl but the Webservice-Endpoint that just delegates to the webservice (UserServiceSoap). The implementation for UserService typically checks for permissions, then delegates to UserLocalService, which is typically implemented by UserLocalServiceImpl - this class implements all the heavy lifting, e.g. the real functionality. (Note the various *Service, *LocalService variations)

Typically *Service and *LocalService have very similar interfaces, and they're both available from Java applications running in the same container (e.g. tomcat) that Liferay is running in. The code for the implementations lives in portal-impl.jar, it definitely is contained in the sourcecode for Liferay, just not in portal-service.jar which is typically available to plugins and just contains (e.g.) UserLocalServiceClp which delegates to the actual implementation.

You can read about this in ServiceBuilder documentation - Servicebuilder is the component that is used in Liferay to build all the API-level interfaces.

So - coming back to your question (and without debugging the code myself, it'd take some time to reproduce), here's what you can quickly do: Just package your code as webapplication or portlet, deploy it in tomcat and don't go for the Soap-Interface but either through UserService (e.g. call the all-static UserServiceUtil.addUser()) or omit the permission checks and just use UserLocalServiceUtil.addUser(...)) - run all of this in the debugger and single step to see what's required in the implementation of that method.
Clemens Schaab
RE: Adding new users programmatically from a single java application
February 10, 2013 11:57 PM
Answer

Clemens Schaab

Rank: New Member

Posts: 12

Join Date: February 7, 2013

Recent Posts

Hi Olaf,
thank you very much for your detailed answer. I develop under Liferay 6.1, some functionallities have changed there to version 6.0.
Olaf Kock:

You can read about this in ServiceBuilder documentation - Servicebuilder is the component that is used in Liferay to build all the API-level interfaces.

ServiceBuilder is one of these objects that no longer exists in Version 6.1!

Besides I have now seen that the user was created. It just isn't displayed in the Liferay-GUI for some reason (not if I go under portal -> users and organisations) but I can access it programmatically.
I don't know why, but if you do so, I would be glad to hear the reason!

And another short question is if you know what "virtual-host" means in the context of liferay. The next line was part of the example I found at liferay but the meaning of virtual-host isn't clear to me!
1 CompanySoap companySoap = soapCompany.getCompanyByVirtualHost(virtualHost);

Thanks so much, Clemens
Olaf Kock
RE: Adding new users programmatically from a single java application
February 11, 2013 9:04 AM
Answer

Olaf Kock

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1892

Join Date: September 23, 2008

Recent Posts

Clemens Schaab:
ServiceBuilder is one of these objects that no longer exists in Version 6.1!

ServiceBuilder is well alive - it's not a class or interface but a build-time tool that generates the API level of Liferay.
Clemens Schaab:
Besides I have now seen that the user was created. It just isn't displayed in the Liferay-GUI for some reason (not if I go under portal -> users and organisations) but I can access it programmatically.
I don't know why, but if you do so, I would be glad to hear the reason!

if you can't see the user despite the data being there, the reason typically is in the full-text-index (aka lucene). Go to ControlPanel/Server/Server Administration and click "Reindex search index" - this will show the user in the user list. Why creating a user through the API doesn't add it to the index is beyond me, sorry - this should be automatic.
Clemens Schaab:
And another short question is if you know what "virtual-host" means in the context of liferay. The next line was part of the example I found at liferay but the meaning of virtual-host isn't clear to me!
1 CompanySoap companySoap = soapCompany.getCompanyByVirtualHost(virtualHost);

This would be worth a separate question, but as you already have my attention: You can have many different instances in Liferay. The technical name for an instance is "company". In order for Liferay to know which instance you want to access, it uses the virtual host name - e.g. depending on the host name you use, you can display different content. This in mandatory on the company/instance level and optional on a site/organization level.
Clemens Schaab
RE: Adding new users programmatically from a single java application
February 11, 2013 11:13 PM
Answer

Clemens Schaab

Rank: New Member

Posts: 12

Join Date: February 7, 2013

Recent Posts

Hi Olaf,
thank you very much again for your detailed answer. I do not want to "abuse" you any more but a small question still remains:
Olaf Kock:

ServiceBuilder is well alive - it's not a class or interface but a build-time tool that generates the API level of Liferay.

I thought it is a class in version 6.0 as I found it in the API there, but could not find it in the 6.1 API! I will have a look as soon as possible at the ServiceBuilder you meant!


if you can't see the user despite the data being there, the reason typically is in the full-text-index (aka lucene). Go to ControlPanel/Server/Server Administration and click "Reindex search index" - this will show the user in the user list. Why creating a user through the API doesn't add it to the index is beyond me, sorry - this should be automatic.

Olaf, I did as you mentioned, but the user is not displayed. It is the only user created programmatically and it is the only user with a different email-adress. All other users (those that are coming from Liferay itself and the ones that I created via GUI are there and have the same email-adresses! Programmatically I list all the users within a loop and if this "strange" user is in turn, I change his email adress and right afterwards let it display. Everything works well. But if I comment out the line by which I change his email and just list all the users again this "strange" user still has his old email-adress???


This would be worth a separate question, but as you already have my attention: You can have many different instances in Liferay. The technical name for an instance is "company". In order for Liferay to know which instance you want to access, it uses the virtual host name - e.g. depending on the host name you use, you can display different content. This in mandatory on the company/instance level and optional on a site/organization level.

Thank you very much for this pretty good explanation. It helps me much for understanding emoticon
Olaf Kock
RE: Adding new users programmatically from a single java application
February 12, 2013 12:23 AM
Answer

Olaf Kock

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1892

Join Date: September 23, 2008

Recent Posts

Clemens Schaab:
Olaf, I did as you mentioned, but the user is not displayed. It is the only user created programmatically and it is the only user with a different email-adress. All other users (those that are coming from Liferay itself and the ones that I created via GUI are there and have the same email-adresses! Programmatically I list all the users within a loop and if this "strange" user is in turn, I change his email adress and right afterwards let it display. Everything works well. But if I comment out the line by which I change his email and just list all the users again this "strange" user still has his old email-adress???


Sounds strange. Can you post code?
Clemens Schaab
RE: Adding new users programmatically from a single java application
February 12, 2013 12:47 AM
Answer

Clemens Schaab

Rank: New Member

Posts: 12

Join Date: February 7, 2013

Recent Posts

Olaf Kock:

Sounds strange. Can you post code?

No problem!
 1
 2public class Test_Portal_TeamService {
 3    public static void main(String[] args) {
 4
 5        try {
 6            String remoteUser = "Test";
 7            String password = "Test";
 8            String virtualHost = "localhost";
 9
10            String serviceCompanyName = "Portal_CompanyService";
11            String serviceOrganization = "Portal_OrganizationService";
12            String serviceUserName = "Portal_UserService";
13
14            // Locate the Company
15            CompanyServiceSoapServiceLocator locatorCompany = new CompanyServiceSoapServiceLocator();
16            CompanyServiceSoap soapCompany = locatorCompany.getPortal_CompanyService(_getURL(remoteUser, password, serviceCompanyName, true));
17            CompanySoap companySoap = soapCompany.getCompanyByVirtualHost(virtualHost);
18
19            // Locate the User service
20            UserServiceSoapServiceLocator locatorUser = new UserServiceSoapServiceLocator();
21            UserServiceSoap userSoap = locatorUser.getPortal_UserService(_getURL(remoteUser, password, serviceUserName, true));
22
23            UserSoap[] allUsers = userSoap.getCompanyUsers(companySoap.getCompanyId(), 0, userSoap.getCompanyUsersCount(companySoap.getCompanyId())-1);
24            for (UserSoap user : allUsers) {
25                System.out.println("Firstname: " + user.getFirstName() + " Lastname: " + user.getLastName() + " Login-name: " + user.getScreenName() + " password: " + user.getPassword() + " user_id: " + user.getUserId() + " Email: " + user.getEmailAddress());
26               
27                if (user.getLastName().equals("NewUser")) {
28                    user.setEmailAddress("newuser@liferay.com");
29                    System.out.println("User email-adress again: " + user.getEmailAddress() + " CompanyId: " + user.getCompanyId() + " UserID: " + user.getUserId() + " Screenname: " + user.getScreenName());
30                }
31            }
32        } catch (Exception e) {
33            e.printStackTrace();
34        }
35    }
36
37    private static URL _getURL(String remoteUser, String password, String serviceName, boolean authenicate) throws Exception {
38        // Unauthenticated url
39        String url = "http://localhost:8080/api/axis/" + serviceName;
40
41        // Authenticated url
42        if (authenicate) {
43            url = "http://" + remoteUser + ":" + password + "@localhost:8080/api/secure/axis/" + serviceName;
44        }
45        return new URL(url);
46    }
47}


That's all. Nothing really spectacular.

TestUser "Test" belongs to the userGroup "Administrators"!
Clemens Schaab
RE: Adding new users programmatically from a single java application
February 12, 2013 2:42 AM
Answer

Clemens Schaab

Rank: New Member

Posts: 12

Join Date: February 7, 2013

Recent Posts

Hi Olaf,

I went on a bit with coding but whatever I try, it has no effect on the GUI. Last attempt was to add a given regular organization as parent to another given regular organization. Programatically it worked but it had no effect in the GUI as well.
Doing the same things in the GUI works without any problems.
I think I am doing something basically wrong in using the webservices, don't I?
Olaf Kock
RE: Adding new users programmatically from a single java application
February 12, 2013 7:07 AM
Answer

Olaf Kock

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1892

Join Date: September 23, 2008

Recent Posts

In this code you're not creating any user - and you're only changing the user email address locally instead of publishing it back to the server. UserSoap will be changed locally but not on the server. See the UserService which is the interface for the actual business logic, particularly the update* methods. You'll also find them in your code generated from WSDL.

The main difference is that the interface "User" as well as its WS-counterpart UserSoap are just containers for the data, while UserService is used to persist this data.
Clemens Schaab
RE: Adding new users programmatically from a single java application
February 12, 2013 11:58 PM
Answer

Clemens Schaab

Rank: New Member

Posts: 12

Join Date: February 7, 2013

Recent Posts

Hi Olaf,
with this explanation I am sure we are shortly before solving the problem. Excellent!

Olaf Kock:
In this code you're not creating any user

thats right, because I thought I had created the user before. I give you the code by which I thought I would have created it (the code refers to the one I gave you in my last note).

 1       
 2            ServiceContext context = new ServiceContext();
 3            context.setPortalURL("http://localhost:8080");
 4            
 5             userSoap.addUser(companySoap.getCompanyId(),
 6             false, // autoPassword
 7             "newUser", // String password1
 8             "newUser", // String password2
 9             false, // boolean autoScreenName
10             "NewUser", // String screenName
11             "newuser@abashh.de", // String emailAddress
12             (long) -1, // long facebookId
13             "-1", // String openId
14             Locale.getDefault().toString(), // Locale locale               
15             "New", // String firstName
16             "", // String middleName
17             "User", // String lastName
18             -1, // int prefixId
19             -1, // int suffixId
20             true, // boolean male
21             1, // int birthdayMonth
22             1, // int birthdayDay
23             1985, // int birthdayYear
24             "", // String jobTitle
25             new long[0], // long[] groupIds
26             new long[0], // long[] organizationIds
27             new long[0], // long[] roleIds
28             new long[0], // long[] userGroupIds
29             false, // boolean sendEmail
30             context // ServiceContext serviceContext)
31             );

Olaf Kock:

- and you're only changing the user email address locally instead of publishing it back to the server. UserSoap will be changed locally but not on the server. See the UserService which is the interface for the actual business logic, particularly the update* methods. You'll also find them in your code generated from WSDL.

With this explanation I understand, why the changed email adress would not have an effect in the GUI, because I changed it just locally and not on the server.
But I do not understand, why the user is not created on the server. I use userSoap, and userSoap is of type UserServiceSoap so following your explanation it should have been inserted on the server.
I then replaced userSoap.addUser(...) with UserServiceUtil.addUser (...) (replacing parameter Locale.getDefault().toString with Locale.getDefault()) and hoped that would work. But
first: I am not sure about the difference between the two objects and
second: I got an error then

1
213.02.2013 08:19:06 com.liferay.portal.kernel.log.Jdk14LogImpl error
3SCHWERWIEGEND: BeanLocator is null
4com.liferay.portal.kernel.bean.BeanLocatorException: BeanLocator has not been set
5    at com.liferay.portal.kernel.bean.PortalBeanLocatorUtil.locate(PortalBeanLocatorUtil.java:72)
6    at com.liferay.portal.service.UserServiceUtil.getService(UserServiceUtil.java:1338)
7    at com.liferay.portal.service.UserServiceUtil.addUser(UserServiceUtil.java:203)
8    at Test_Portal_TeamService.main(Test_Portal_TeamService.java:207)


If I had understood you correctly the method userSoap.addUser(...) should have worked. I am now pretty excited because I am convinced that the solution is in the air!!!
Do you have any idea, why it did not work?

Olaf Kock:

The main difference is that the interface "User" as well as its WS-counterpart UserSoap are just containers for the data, while UserService is used to persist this data.

Thank you very much for that!

Clemens
Clemens Schaab
RE: Adding new users programmatically from a single java application
February 14, 2013 3:11 AM
Answer

Clemens Schaab

Rank: New Member

Posts: 12

Join Date: February 7, 2013

Recent Posts

Hi Olaf,
I tried the given liveray-soap-example again and I cound create a new UserGroup that was also visible in liferay that means updated on the server. The code doing this is

1            
2    UserGroupSoap newUserGroup = usergroupsoap.getUserGroup("NewGroup");
3    System.out.println("Added user group named " + groupName);
4    long users[] = { 12206 };
5    userSoap.addUserGroupUsers(newUserGroup.getUserGroupId(), users);

12206 is the id of a user I created over the GUI of liferay, not programmatically! userSoap is the object as always!
That means, that creating new stuff on the server basically works. It must be the method addUser I am using that fails somehow. Maybe the given context needs some more information - or proper ones?

Best regards, Clemens
Clemens Schaab
RE: Adding new users programmatically from a single java application
February 21, 2013 3:17 AM
Answer

Clemens Schaab

Rank: New Member

Posts: 12

Join Date: February 7, 2013

Recent Posts

Hi Olaf,

would be good for me to know, if I stil can expect an answer from you or not.
If not, okay, than we have to find another solution for our problem here.

It just helps me with our ongoing plannings. Thanks in advance for your answer!
Olaf Kock
RE: Adding new users programmatically from a single java application
February 25, 2013 8:12 AM
Answer

Olaf Kock

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1892

Join Date: September 23, 2008

Recent Posts

...vacation is over, I'm back - sorry for the delay. Did you solve your problems? As usual after vacation, I'm quite swamped - maybe someone else could step in if your problem still persists.
Clemens Schaab
RE: Adding new users programmatically from a single java application
February 26, 2013 12:51 AM
Answer

Clemens Schaab

Rank: New Member

Posts: 12

Join Date: February 7, 2013

Recent Posts

Hi Olaf,
hope you had some relaxing days off. Unfortunatelly no one else stepped in. So my problem still exists.
My post from 12. February 2013 describes what I have been trying after your last explanations.

Best regards, Clemens
Clemens Schaab
RE: Adding new users programmatically from a single java application
March 4, 2013 7:38 AM
Answer

Clemens Schaab

Rank: New Member

Posts: 12

Join Date: February 7, 2013

Recent Posts

Hi Olaf,

could you, please, answer my post from february, the 7th 2013. Thanks for that!