Producing Custom Webservices


Steps:
1. Create a plugin portlet (ex: ProducerPortlet-portlet)
2. Create service-builder for it.

Service.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.0.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_0_0.dtd">
<service-builder package-path="com.liferay.producer">
      <author>abc</author>
      <namespace>producer</namespace>

      <entity name="Producer" local-service="true" remote-service="true">

            <!-- PK fields -->

            <column name="pid" type="long" primary="true" />

            <!-- Audit fields -->

            <column name="companyId" type="long" />
            <column name="userId" type="long" />
            <column name="userName" type="String" />
           
      </entity>
</service-builder>

3.  Then run the service builder(build-service command)
4. Write your webservice i.e your own methos in EntityServiceImpl.java(Ex: com.liferay.producer.service.impl. ProducerServiceImpl.java)

ProducerServiceImpl.java

package com.liferay.producer.service.impl;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.producer.model.Producer;
import com.liferay.producer.service.ProducerLocalServiceUtil;
import com.liferay.producer.service.base.ProducerServiceBaseImpl;

public class ProducerServiceImpl extends ProducerServiceBaseImpl {
           
            public Producer getProducerWebservice(long pid) throws SystemException{
                          try {
                                    return ProducerLocalServiceUtil.getProducer(pid);
                        } catch (PortalException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                        }
                       
                        return null;
                        }
}
5. After that run the service builder once again( ant build-service)
6. Check your webservice method code is placed in the
ProducerServiceSoap.java, ProducerServiceUtil.java, ProducerService.java
7. After that run ant build-wsdd command
Make sure that the build is successfull
8. Now deploy the plugin (ant deploy)
9. Configure localhost name in hosts file(C:\Windows\System32\drivers\etc\hosts)
Copy paste the following line:
            127.0.0.1       localhost
9. Check whether the web service is generated or not by using the following url
localhost:7070/plugin-project-name/axis
Ex: localhost:7070/ProducerPortlet-portlet/axis
10. You will see the web service in browser.
11. If you able to see the web service proceed to next step. Otherwise repeat above steps also refer errors list.
12. Run ant build-client. Make sure that the build is successful.
Note: Don’t run ant build-service after ant build-client. It will cause lot of errors. Also after running ant build-client, You no need to deploy application
13. Check whether Plugin_project_name_client.jar file(Ex: ProducerPortlet-portlet-client.jar) is generated or not in docroot/WEB-INF/client folder. It is generated means, you are successfully generated webservice.

Errors List:
1. You HTTP Status 403 - Access denied for 0:0:0:0:0:0:0:1
 Make sure that localhost is configured in hosts file. Otherwise use 127.0.0.1:7070/plugin-project-name/axis
2. toSoapModel() method is not there in EntityServiceSoap.java
That is because you run the ant build-service after ant buid-client. We cannot solve this issue, please creat new plugin.
3. ant build-client is failed.
Please remember whether you checked webservice after running ant build-wsdd.




Search This Blog

All the rights are reserved to this blog is belongs to me only.. Powered by Blogger.