In this post I will show how to call plugin webservice remotely. If we have wsdl file then we can generate the client or stub from wsdl file and invoke the operations/methods of the service.
Before reading this post I would suggest please go through Creating Liferay plugin webservice project
Requirements
Liferay Developer Studio 1.4, wsdl
1. Create a new java project “NewPluginTest” in Liferay Developer Studio 1.4.
2. Now we have wsdl file so we will generate client or stub from this wsdl file. Do right-click on the project and go to New->Other. Select Web Services->Web Service Client.
3. Click Next. Make sure Deploy Client is selected in the vertical bar as highlighted in the picture. Click on Browse to select wsdl file.
4. Click on Browse again to select the wsdl file from a particular location.
5. Now select the wsdl file and click “OK”. Then again click “OK”.
6. Now click Finish.
7. The necessary things will be generated as highlighted in the image.
8. Now create a main class for testing the service.
9. Write the logic for testing the service
import com.liferay.portal.model.UserGroupSoap; import in.sblog.service.service.http.NewEntityServiceSoap; import in.sblog.service.service.http.NewEntityServiceSoapService; import in.sblog.service.service.http.NewEntityServiceSoapServiceLocator; import java.net.URL; import javax.xml.rpc.ServiceException; public class TestClass { /** * @param args */ public static void main(String[] args) { NewEntityServiceSoapService newEntityServiceSoapService = new NewEntityServiceSoapServiceLocator(); try { NewEntityServiceSoap serviceSoap = newEntityServiceSoapService.getPlugin_sblogin_NewEntityService(_getServiceURL()); UserGroupSoap[] userGroups = serviceSoap.getAllUserGroups(); if (userGroups != null) { System.out.println("Total User Groups: " + userGroups.length); System.out.println(); } for (int i = 0; i < userGroups.length; i++) { System.out.println("User Group ID: " + userGroups[i].getUserGroupId()); System.out.println("User Group Name: " + userGroups[i].getName()); System.out.println("User Group Description: " + userGroups[i].getDescription()); // more } } catch (ServiceException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } private static URL _getServiceURL() throws Exception { String url = "http://portal.admin:test@localhost:8080/NewPlugin-portlet/secure/axis/Plugin_sblogin_NewEntityService"; return new URL(url); } }
Output
Total User Groups: 9 User Group ID: 10339 User Group Name: SHARED_EUROPE User Group Description: For all Europe based Shared Users User Group ID: 10327 User Group Name: SHARED_INDIA User Group Description: For all India based Shared Users User Group ID: 10331 User Group Name: SHARED_SA User Group Description: For all South Africa based Shared Users User Group ID: 10343 User Group Name: TP_EUROPE User Group Description: For all Europe based Third Party Users User Group ID: 10323 User Group Name: TP_INDIA User Group Description: For all India based Third Party Users User Group ID: 10335 User Group Name: TP_SA User Group Description: For all South Africa based Third Party Users User Group ID: 10319 User Group Name: USER_EUROPE User Group Description: For all Europe based General Users User Group ID: 10311 User Group Name: USER_INDIA User Group Description: For all India based General Users User Group ID: 10315 User Group Name: USER_SA User Group Description: For all South Africa based General Users
Thanks for your patience. Please do not forget to leave a comment.