« Zurück zu Web Services

Web Service samples

Introduction #

When initially installing Liferay in an environment without a LDAP, it often takes time to enter master data such as user and organization from Liferay's Control Panel page. In such a circumstance, it is often easier to upload a csv file in bulk from a command line. Liferay offers a web service interface to make this possible. This page will try to present an actually working program to add users and organization to Liferay v6.0.5 from a batch file. Note, that this is just a sample program written so that it would be easier to read. In actual production environment, it is recommended to modify the sample source code to make it more effiecient.

Obtaining the Sample Web Service Tools #

Sample tool to add users may be downloaded from the attachment to this page. Just download the file and extract it to some folder to use it.

Caution: The tool will not work with Liferay v5.x because it has a different web service interface

Using the tool #

First, the tool is written is Java so it requires Java to be installed. Second, the tool requires Liferay to be running and requires Liferay's administrative credentials (aka admin user/password).

Open up the ws-settings.properties from using a text editor and edit the username, password, host, and port fields with values from your Liferay installation. Example:

username=test
password=test
host=http://localhost
port=8080

Retrieving User Information #

If you are using Liferay's bundled download with the demo pages, try retrieving user data using the sample batch command (Linux users would have to create a .sh script): Edit the userGetSample.bat file and comment out row 3 and uncomment row 9.

echo off
rem get user information by screen name
rem userGet.bat -output users.csv -type screen -value "10131,test"

rem get user information by userid
rem userGet.bat -output users.csv -type userid -value 10134

rem get user information by email
userGet.bat -output users.csv -type email -value "10131,test@liferay.com"

Executing this script will create a csv file users.csv in the local folder. This file should contain user data for the test user if the program was able to connect properly to Liferay. If there was an error, it should display in the console.

Adding User Information #

To bulk add users, create a csv file with user information. The tools uses format matching Liferay's web service interface which unfortunately has different interface format for getting user information and adding user information. The format used to add users is provided in the data\Template folder - usersTemplate.xls. A sample of a csv file is provided in the \data folder. Fill out the necessary information for each user to add. Edit the usersImport.bat file to point to the csv file.

java jp.co.ogis.liferay.util.UsersImport data\users.csv

Execute this batch file and users will be added with information provided in the csv file with other default settings provided in the portal.properties and portal-ext.properties files. Login as an administrator to check if users have been added.

3 Anhänge
56070 Angesehen
Durchschnitt (3 Stimmen)
Die durchschnittliche Bewertung ist 5.0 von max. 5 Sternen.
Kommentare
Antworten im Thread Autor Datum
Thank you for great information and sample... Tetsuya Zama 19. Juli 2011 23:16
hi , I am trying to add bulk users in liferay... Shripad Bharde 4. Oktober 2011 02:07
Hi, The link to the sample code under... Ivano Carrara 24. Oktober 2011 14:35
The sample code is also available as an... Ken Barron 20. Dezember 2011 05:05
Thanks very much for making this available! ... Ken Barron 20. Dezember 2011 06:48
help.... it doesn't work in my laptop. I've... Iseng Dong 25. April 2012 03:27
did you finally get the answers to your... austen xia 5. Juli 2013 01:35
Hi i do get the same error ... sandeep tripathi 28. Mai 2012 02:23
I want to create similar web service to... urman parikh 8. August 2012 02:05
Hi.. Thanks for this useful tool.. I have tried... Jo Cern 14. Oktober 2013 16:01
Hi, Some time ago I wrote an article for import... Antonio Musarra 16. April 2014 15:01

Thank you for great information and sample codes!
This is that I've been looking for.
Gepostet am 19.07.11 23:16.
hi ,

I am trying to add bulk users in liferay using web service 'liferay-wstools_20110119' (http://www.liferay.com/community/wiki/-/wiki/Main/Web+Service+samples)
but when I try to load users with already present users.csv I get exception


Caused by: org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateCo­nverter.java:140)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)­
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:179)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(Abstract­FlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListe­ner.java:51)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1206)
at com.liferay.portal.dao.orm.hibernate.SessionImpl.flush(SessionImpl.java:108)
... 92 more
Caused by: java.sql.BatchUpdateException: Incorrect string value: '\xE3\x82\x88\xE3\x81\x86...' for column 'greeting' at row 1
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:125­7)
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:943)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeBatch(NewProxyPrepared­Statement.java:1723)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
... 98 more


is there any problem in given sample user.csv or do you have sample user.csv which can add users using web service .



Thanks & Regards ,

Shripad Bharde
Gepostet am 04.10.11 02:07.
Hi,

The link to the sample code under "Obtaining the Sample Web Service Tool" is broken ...
Gepostet am 24.10.11 14:35.
The sample code is also available as an attachment to this article.
Gepostet am 20.12.11 05:05 als Antwort auf Ivano Carrara.
Thanks very much for making this available! Saved me a day of coding, exactly what I need.
P.S. one tip, make sure you have tunnel-web installed as a webapp otherwise the servcice calls will not work.
Gepostet am 20.12.11 06:48.
help.... it doesn't work in my laptop.

I've tried at Liferay 6.1. I could see the process that the datas are being moved. But, when I took a look at user and organization menu and also in my mysql, there was nothing. It is still the default data.

and, I also have tried in Liferay 6.0. In the process, it says "skipped". The system skipped all of the row.

what should I do? thanks in advance emoticon
Gepostet am 25.04.12 03:27.
Hi
i do get the same error
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
is there any other setting which we need to do .
thanks and regards
Sandeep
Gepostet am 28.05.12 02:23.
I want to create similar web service to associate site template to public/private pages to an organization when organization is added.

So when i add organization it's site should be created and its public/private page should have site templete.

can any one help.
Gepostet am 08.08.12 02:05.
did you finally get the answers to your question? I got the same error
Gepostet am 05.07.13 01:35 als Antwort auf Iseng Dong.
Hi..
Thanks for this useful tool..
I have tried to get it to work (user import) with the 6.2s interface by editing the UserInfo.java and UserImport. java accordingly.. no luck so far get the user table updated but with a message unknown element when running the BAT file.. in the logs on the server I have this error
17:48:31,744 ERROR [http-bio-8080-exec-4][UserServiceSoap:92] com.liferay.portal.DuplicateUserEmailAddressException
edited userimport.java with >> UserSoap usoap= soap.addUser(userInfo.getcompanyId(),userInfo.getAutoPassword(),userInfo.getPass­word1(),userInfo.getPassword2(),userInfo.getAutoScreenName(),userInfo.getScreenN­ame(),userInfo.getEmailAddress(),userInfo.getFacebookId(),userInfo.getOpenId(),u­serInfo.getLocale(),userInfo.getFirstName(),userInfo.getMiddleName(),userInfo.ge­tLastName(),userInfo.getPrefixId(),userInfo.getSuffixId(),userInfo.getMale(),use­rInfo.getBirthdayMonth(),userInfo.getBirthdayDay(),userInfo.getBirthdayYear(),us­erInfo.getJobTitle(),userInfo.getGroupIds(),userInfo.getOrganizationIds(),userIn­fo.getRoleIds(),userInfo.getUserGroupIds(),userInfo.getSendEmail(),serviceContex­t);

And also the UserInfo.java with the corresponding values... I am obviously missing something... a little help or hint in the right direction would be much appreciated..
Cheers
Gepostet am 14.10.13 16:01.
Hi,
Some time ago I wrote an article for import users from an excel sheet using web services liferay. http://www.dontesta.it/blog/blog-2/cms/liferay/liferay-web-services-come-importa­re-utenti/ The source repository at https://github.com/amusarra/ImportUsersLiferayViaWS

Bye,
Antonio.
Gepostet am 16.04.14 15:01.