Wednesday, 27 June 2012

Consuming web service in liferay

Following are the steps to Consume the web service in the liferay.

1) Now it's time to verify the web service which we have generated is working or not. For that we need to make a client which is going to consume the web service we have published.


Make a sample portlet called "web-service-Consuming-portlet ".  Hit the url "http://127.0.0.1:8080/web-service-publishing-portlet/api/axis/Plugin_WebServiceDemoSample_SampleService?wsdl" copy the wsdl file from the browser.


2) Copy that file into the WEB-INF folder.


3) Right click on the .wsdl file from eclipse and click on the new and make a web service client.then set assemble client and clisk on thegenerate the classes for accessing the service.

4) Write a class ConsumingWebService and write the follwoing code access the web service.

public void render(RenderRequest request,RenderResponse renderResponse){
        SampleServiceSoapServiceLocator serviceLocator = new SampleServiceSoapServiceLocator();
    //SampleServiceSoapService soapService = (SampleServiceSoapService) serviceLocator.getPlugin_WebServiceDemoSample_SampleService();
    SampleServiceSoap serviceSoap;
    try {
        serviceSoap = serviceLocator.getPlugin_WebServiceDemoSample_SampleService();
        SampleSoap[] sampleSoap =  serviceSoap.getUsers(10180);
        for(int i=0 ;i<sampleSoap.length;i++){
            System.out.println("User Id"+sampleSoap[i].getName());
        }
    } catch (ServiceException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (RemoteException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
   
    }


In the above code we have cnsumed the web service which are published in the previous example.Which is going to print print the resut on the concel. 

1 comment:

  1. I saw this post, i was trying to copy the wsdl to my portlet project but i couldn't copy inside web-inf folder.

    Can u send me this post sample portlet project.

    ReplyDelete