« 返回到 Web Services

Creating Liferay 6 plugin web service

Today I tried to create a service in a plugin portlet of liferay. Since this is not very straight forward, it took me the whole day to get my simple service running. As a matter of fact, I decided to publish this on the web.

I used Liferay6.0.5 source and plugin sdk, along with eclipse 3.6, with WTP and Liferay IDE 1.0.1. The base platform was Java1.6.0_21 and MySQL5.1.46, both running on openSuse11.3. The deployment server was tomcat6.0.26.

Step 1: Setup liferay source project and tomcat

  1. Unzip the liferay source in your eclipse workspace. In eclipse, create a new project with the name liferay-portal-src-6.0.5. Eclipse will automatically detect the project type and configure it accordingly.

  2. Open the app.server.properties and edit the app.server.parent.dir to point to the folder containing the tomcat installation. Note that this is the parent folder of CATALINA_HOME. For me it was: app.server.parent.dir=/home/swoosh/installations

  3. Un-comment: app.server.type=tomcat

  4. Scroll down and change the app.server.tomcat.dir, so that it points to the CATALINA_HOME. For me it was: app.server.tomcat.dir=${app.server.parent.dir}/liferay-tomcat-6.0.26

  5. Save and close the app.server.properties

  6. Create a DB schema and user using any tool (I used MySQL Administrator)

  7. Open the portal.properties and comment out the HSQL (Hypersonic) DB settings.

  8. Un-comment the MySQL DB settings and change the host, schema name, username and password. For me the settings were:
    jdbc.default.driverClassName=com.mysql.jdbc.Driver
    jdbc.default.url=jdbc:mysql://localhost/lportal?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
    jdbc.default.username=liferay
    jdbc.default.password=test

  9. Save and close the portal.properties file.

  10. Now open the ant view in eclipse and drag liferay-portal-src-6.0.5/portal-web/build.xml and liferay-portal-src-6.0.5/build.xml file to the ant view. Wait for some time as ant loads the set of build files.

  11. Run the build-themes task under portal-web (from liferay-portal-src-6.0.5/portal-web/build.xml). Make sure that you get Build Successful message everytime you fire an ant task. (There is a bug in liferay's builder due to which it doesn't create the themes when you compile the source. If you directly deploy the source, you wont be able to access the home page).

  12. Now run the compile task under portal (from liferay-portal-src-6.0.5/build.xml).

  13. Then run the deploy task under the same file. Watch the log to verify that ant is copying the files to the right folder. If not, then double check the settings specified in the app.server.properties file.

  14. Now you have tomcat bundled up with the liferay portal. To start it you need to set up the runtime in eclipse. Go to Window->Preferences->Server->Runtime Environments. Click Add. Select the srever type as Liferay v6.0 (Tomcat 6). Click next. Give a name to your runtime - Liferay v6 (Tomcat 6). Browse and select the tomcat folder that you specified in app.server.properties' app.server.tomcat.dir property. Select runtime as java 1.6 and click Finish.

  15. If you don't have a server project in your workspace, then create a new one. Right click on the server project and Create a new server. Select the server type as Liferay v6.0 (Tomcat 6) and runtime as Liferay v6 (Tomcat 6). Server's host name should be localhost. Click next and click Finish.

  16. Now the server should appear under your server view (Add the view from Window->Show View->Servers)

  17. Double click on the server and change the Timeouts to 300 seconds. This will give enough time to the server to create and populate the DB schema for the first time.

  18. Right click on the server and select start.

  19. The liferay server should start. For the first time, it will create all the tables and populate them with the seed data.

  20. Once you get the server started message, open the web browser and open the http://localhost:8080. You should get the liferay's default home page. Enter test@liferay.com as email address and test as password.

  21. If you are not able to see the liferay's page even though the source was compiled and deployed successfully, then please check your app.server.properties file.

Step 2: Setup plugin SDK.

  1. Download and unzip the plugins sdk.

  2. Open the liferay-plugins-sdk-6.0.5/build.properties file and change the server settings:
    app.server.type=tomcat app.server.dir=/home/swoosh/installations/liferay-tomcat-6.0.26 app.server.deploy.dir=${app.server.dir}/webapps app.server.lib.global.dir=${app.server.dir}/lib/ext app.server.portal.dir=${app.server.dir}/webapps/ROOT

  3. Go to Window->Preferences->Liferay->Installed SDKs.

  4. Click on Add. In the pop-up window browse to the unzipped sdk folder and click Ok.

Step 3: Create the service project

  1. Now create a new Liferay plug-in project. Enter the details as in the screenshot below:

  2. Click Next and select Dynamic Web module version 2.5 and Default configuration for Liferay v6.0 (Tomcat 6).

  3. Click Finish and Click Yes on the Switch Perspective dialog box.

  4. A new TestPlugin-Portlet Project will appear in the navigator.

  5. Now right click on the plugin project and select New->Liferay Service.

  6. Enter the detail as in the screenshot below:

  7. You can enter a different package and Namespace. In that case you will have to follow the next steps accordingly.

  8. Click Finish. The service.xml file will be created and will be opened in the service editor.

  9. The service.xml is similar to the service definition files in the ext environment of older liferay versions. Here we can define as many entities along with their functions.

  10. We will create an Employee entity with id (long) and name (String) attributes. The service definition looks like:

  11. Save the service.xml file.

  12. Drag the TestPlugin-portlet/build.xml to the Ant view.

  13. In the ant view, expand the TestPlugin-portlet and run the build-service task.

  14. If the build fails, please check if you have followed the point number 2 in Step 2. On successful build, the ant task creates the files related to Employee entity.

  15. Refresh your project (F5) to see the files.

  16. Right click on the project go to Properties->Java Build Path->Source tab. Add the TestPlugin-portlet/docroot/WEB-INF/service and TestPlugin-portlet/docroot/WEB-INF/src folders, and click Ok.

  17. Implement the service by editing com.liferay.test.service.impl.EmployeeLocalServiceImpl. Add the implementations for CRUD and finder methods. They look like the following listing:
    public Employee create(Employee model) throws SystemException{
      long id = CounterLocalServiceUtil.increment(Employee.class.getName());
      model.setId(id);
      Employee newModel = EmployeeUtil.create(model.getId());

      newModel.setName(model.getName());
      EmployeeUtil.update(newModel, true);
      return newModel;
    }

    public Employee update(Employee model) throws NoSuchEmployeeException, SystemException{
      Employee newModel = EmployeeUtil.findByPrimaryKey(model.getId());

      newModel.setName(model.getName());

      EmployeeUtil.update(newModel, true);

      return newModel;
    }

    public List<Employee>
    findByName(String name) throws SystemException{
      return EmployeeUtil.findByName(name);
    }

    public Employee remove(long id) throws NoSuchEmployeeException, SystemException{
      return EmployeeUtil.remove(id);
    }

  18. Run the TestPlugin-portlet/build-service task and make sure that build is successful.

  19. Similarly edit the com.liferay.test.service.impl.EmployeeServiceImpl Add the CRUD and finder methods as listed below:
    public Employee create(Employee model) throws SystemException{
      return EmployeeLocalServiceUtil.create(model);
    }

    public Employee update(Employee model) throws NoSuchEmployeeException, SystemException{
      return EmployeeLocalServiceUtil.update(model);
    }

    public List<Employee> findByName(String name) throws SystemException{
      return EmployeeLocalServiceUtil.findByName(name);
    }

    public Employee remove(long id) throws NoSuchEmployeeException, SystemException{
      return EmployeeLocalServiceUtil.remove(id);
    }

  20. Run the TestPlugin-portlet/build-service task again and make sure that build is successful.

  21. There is a bug in liferay's service builder due to which it doesn't generate the ServiceSoap class correctly. It is not able convert the parameters to their corresponding soap type. See http://issues.liferay.com/browse/LPS-12629 for details. To get around this issue open the EmployeeServiceSoap and change the generated create and update methods as:

     
    publicstatic com.liferay.test.model.EmployeeSoap create(
       com.liferay.test.model.EmployeeSoap model) throws RemoteException {
     try {
      com.liferay.test.model.Employee returnValue = EmployeeServiceUtil.create(com.liferay.test.model.impl.EmployeeModelImpl.toModel(model));
     
      return com.liferay.test.model.EmployeeSoap.toSoapModel(returnValue);
      }
      catch (Exception e) {
      _log.error(e, e);
     
      throw new RemoteException(e.getMessage());
      }
    }
     
    publicstatic com.liferay.test.model.EmployeeSoap update(
       com.liferay.test.model.EmployeeSoap model) throws RemoteException {
     try {
      com.liferay.test.model.Employee returnValue = EmployeeServiceUtil.update(com.liferay.test.model.impl.EmployeeModelImpl.toModel(model));
     
      return com.liferay.test.model.EmployeeSoap.toSoapModel(returnValue);
      }
      catch (Exception e) {
      _log.error(e, e);
     
      thrownew RemoteException(e.getMessage());
      }
    }

  22.  Now run the TestPlugin-Portlet/build-wsdd task to generate the webservices.

  23. Once this is complete, start the server if not already started.
  24. Then run TestPlugin-Portlet/compile and TestPlugin-Portlet/deploy.
  25. Check the logs for "1 portlet for TestPlugin-portlet is available for use" message.
  26. If that appears, open the http://localhost:8080 in your browser.
  27. Login as test@liferay.com and password test.
  28. Go to Add -> More->Samples. Add the TestPlugin to you page. Make sure that the default page for the plugin appears. This confirms that the plugin was deployed properly.
  29. Now open http://127.0.0.1:8080/TestPlugin-portlet/axis/Plugin_Test_EmployeeService?wsdl in your browser and confirm that the wsdl opens up.
  30. This completes the plugin service creation.

Step 4: Create Web service client

  1. Now we need to test our webservice. For that we need to have another tomcat runtime as our Liferay tomcat 6 runtime eclipse plugin doesn't support building webservices. Also we need to make sure that the tomcat runtime and liferay runtime run on different ports. I used the ports 9005, 9080 and 9009 for my tomcat runtime.

  2. In eclipse go to New->Webservice Client and enter the details as in the screenshot below:

  3. Click Next on this and next screen. Then click on "Start server" to start the tomcat runtime. Then click Finish.

  4. Select all the methods and click Finish

  5. Eclipse will then deploy the client and open up a screen to test your webservice.

  6. Click on the methods to test them.

  7. We will test create method first. We will provide the primaryKey=0, name=Liferay and id=0 and click invoke.

  8. In the results section we can see that the employee entity has been created with the id=1.

  9. Now invoke findByName and provide name=Liferay. The result will show the reference of the entity object returned by the webservice.

That completes the tutorial. The complete plugin and the webservice client can be downloaded from the attachments of this post. Hope that was helpful. Do write your comments.


2 附件
108372 查看
平均 (12 票)
满分为 5,平均得分为 4.583333333333333。
评论
讨论主题回复 作者 日期
Nice article. Thanks! Juan Fernández 2010年9月14日 上午1:28
Thanks for the feedback :) Kapil Dev Verma 2010年9月14日 上午2:24
Some picture of this article can't display,I... XinYang Zhang 2010年9月14日 上午2:29
I have updated the article, hope you can see... Kapil Dev Verma 2010年9月14日 上午4:25
Please, I need your help:) Everything compiles,... Marius Marius 2010年9月14日 上午5:50
If everything goes fine, then you should get... Kapil Dev Verma 2010年9月14日 上午9:50
Hi Kapil Thanks for the excellent article. I... Liferay Developer 2010年9月17日 上午8:41
Hi.. Please provide me the zip of your plugin... Kapil Dev Verma 2010年9月19日 上午11:56
Kapil, what is the best way to send you the... Liferay Developer 2010年9月23日 下午12:23
You can mail me that at kapildverma@gmail.com Kapil Dev Verma 2010年9月26日 下午10:15
In this tutorial you advice to edit... Andrius Kurtinaitis 2010年9月14日 上午6:06
Thanks for the suggestion :) Kapil Dev Verma 2010年9月14日 上午9:48
Hi Kapil, Really very nice description to... sasi Kanth 2010年9月16日 下午11:12
Thanks Sasi for the feedback! Kapil Dev Verma 2010年9月17日 上午1:37
Very Nice Article. Thanks!! Harish Kumar 2010年9月27日 下午9:34
I need some help. Everything compiles, the wsdd... Andreea Tabacariu 2010年10月27日 上午2:53
Can you try running the samples attached with... Kapil Dev Verma 2010年11月10日 下午11:59
anybody know this error, help me.... DO Hung Thuan 2010年11月14日 下午11:55
Is there a way to expose REST based services... Seshendra Nalla 2010年11月24日 上午8:29
Hi there, at the end of your tutorial when I... Jack Bauer 2010年11月25日 上午11:55
Ok so I noticed what I was doing wrong, stupid... Jack Bauer 2010年11月26日 上午10:17
Result exception: java.rmi.RemoteException:... Sreeraj AV 2010年12月26日 下午11:37
@Raju - The issue seems to somewhere in... Kapil Dev Verma 2010年12月28日 下午9:22
Very nice article. Thanks!!! Dien NH 2011年1月20日 下午6:38
When I was executing the build-service task ant... Luca Andreatta 2011年1月25日 上午3:09
Hi Kapil, I have a requirement, where instead... Venkat Sankar Rao 2011年2月7日 下午2:27
Hi Venkat, From the stacktrace, we can see... Kapil Dev Verma 2011年2月9日 下午9:54
First thank you for a great guide, works great... Andrew Tillinghast 2011年2月28日 上午11:52
Hi Andrew, Thanks for your comments. I am not... Kapil Dev Verma 2011年3月4日 上午10:24
Nice article.Thank Kapil! Nguyen Trung Kien 2011年3月11日 上午7:23
Hi Kapil, I want add new method in existing... Nguyen Trung Kien 2011年3月12日 下午5:55
Hi Nguyen, You might have to create a new... Kapil Dev Verma 2011年3月21日 上午12:20
Nice article. Thank you Tom Mahy 2011年8月22日 上午5:31
Concerning Error:... Martin Wiegand 2011年9月9日 下午3:46
Sorry, it was a mistake. Removing axis.jar is... Martin Wiegand 2011年9月12日 上午5:38
Venkat S, dont forget to run a new tomcat... Tamás Barabás 2011年11月28日 上午3:53
Hi Kapli, Nice Article But i have an... Raghu teja 2011年12月14日 下午9:58
I'm getting exception:... Shantanu Puranik 2012年2月1日 上午1:13
This worked perfect on 6.0.6 but on 6.1 i cant... Tom Mahy 2012年2月17日 上午6:03
You can find service under /api/axis on liferay... Sy Do 2012年3月5日 下午8:10
in step 3 -> 29 i cannot seem to get the WSDL... Patrick Momin 2012年3月15日 上午7:50
I found the Solution by comparing the entries... Patrick Momin 2012年3月16日 上午2:37
Hi, I'm experiencing a problem since few days.... Giuseppe Pantaleo 2012年6月19日 上午2:17
I have same problem. Can you tell me solution? ... Petr Vasek 2012年7月12日 上午2:53
For all , problem is in implement of... Petr Vasek 2012年7月14日 上午2:36
Try this URL... Onkar Sutar 2013年2月5日 上午1:35
Thanks , Its was very helpful. Atif Hussain 2013年1月7日 上午4:08
Nice..For Beginners..Its really nice... sheela mk 2013年2月18日 下午10:57
Nice Article kapil Thanks for sharing...:) jaid shaik 2013年5月15日 上午2:29
Hi Kapil, I have take your sample portlet and... Abdulbasit Shaikh 2013年6月7日 上午4:54
Hi Kapil, Thanks for such a nice doucment.I... Abdulbasit Shaikh 2013年6月11日 上午1:55
I am using Liferay 6.1.1 I need some help.... Syed Mujeeb 2014年3月21日 下午1:18
In Liferay 6.1+ they have changed some URLs. ... Luca Andreatta 2014年9月4日 上午3:00
For documentation you can look here:... Luca Andreatta 2014年9月4日 上午3:01

在 10-9-14 上午1:28 发帖。
在 10-9-14 上午2:24 发帖以回复 Juan Fernández
Some picture of this article can't display,I can't see them.Could you fix it
在 10-9-14 上午2:29 发帖。
I have updated the article, hope you can see the images now. Please do a ctrl+F5.
在 10-9-14 上午4:25 发帖以回复 XinYang Zhang
Please, I need your helpemoticon
Everything compiles, deploys etc. but I am stuck at this point: http://127.0.0.1:8080/TestPlugin-portlet/axis/Plugin_Test_EmployeeService?wsd I get axis error because "Could not generate WSDL"
of cource and there: http://127.0.0.1:8080/tunnel-web/axis I don't see my plugin.
在 10-9-14 上午5:50 发帖以回复 Kapil Dev Verma
In this tutorial you advice to edit portal.properties file. This is oficially not recommended. This file does not even exist in a zipped bundle. Wouldn't it be better to change this filename to portal-ext.properties?
在 10-9-14 上午6:06 发帖。
在 10-9-14 上午9:48 发帖以回复 Andrius Kurtinaitis
If everything goes fine, then you should get docroot/WEB-INF/server-config.wsdd file generated. Verify if it is getting generated. Also, it would be helpful if you attach your plugin project.
在 10-9-14 上午9:50 发帖以回复 Marius Marius
Hi Kapil,

Really very nice description to generate service and web serivces in a portlet.

Thank you.
在 10-9-16 下午11:12 发帖。
Thanks Sasi for the feedback!
在 10-9-17 上午1:37 发帖以回复 sasi Kanth
Hi Kapil

Thanks for the excellent article.
I am having the same problem as Marius. There is an error when I try to generate the wsdl and I checked for the server-config.wsdd and was not able to find it.
在 10-9-17 上午8:41 发帖以回复 Kapil Dev Verma
Hi.. Please provide me the zip of your plugin project. Thanks!
在 10-9-19 上午11:56 发帖以回复 Liferay Developer
Kapil,
what is the best way to send you the zip?
Thanks..
在 10-9-23 下午12:23 发帖以回复 Kapil Dev Verma
You can mail me that at kapildverma@gmail.com
在 10-9-26 下午10:15 发帖以回复 Liferay Developer
Very Nice Article. Thanks!!
在 10-9-27 下午9:34 发帖。
I need some help. Everything compiles, the wsdd is created, the deploy works with no error, the portlet page loads but when I try to see the wsdl: http://127.0.0.1:8080/TestPlugin-portlet/axis/Plugin_Test_EmployeeService?wsd I am redirected to the portal home page and my service does not appear in http://127.0.0.1:8080/tunnel-web/axis
在 10-10-27 上午2:53 发帖。
Can you try running the samples attached with the post? If you still face the problem, please feel free to mail me your plugin.
在 10-11-10 下午11:59 发帖以回复 Andreea Tabacariu
anybody know this error, help me.
http://www.liferay.com/community/forums/-/message_boards/message/6414062
在 10-11-14 下午11:55 发帖。
Is there a way to expose REST based services instead of SOAP using Liferay Service builder?
在 10-11-24 上午8:29 发帖。
Hi there, at the end of your tutorial when I try to test by adding a Webservice Client I get the following error:

"The Apache Axis Web service runtime in Tomcat v6.0 Server does not support the client project TestPlugin-portlet."

I set it up exactly as you have it laid out in the picture as well so hopefully someone knows how to solve this problem because I find nothing when googling.
在 10-11-25 上午11:55 发帖。
Ok so I noticed what I was doing wrong, stupid mistake trying to setup the WebService Client to point to the TestPlugin instead of the WebServiceProject attached.

I'll just list some problems and solutions I had here for anyone else that runs into the same stuff I did. You need to import that WebServiceProject attached and do the WebServices Client on that.

After installing another version of Tomcat on your system you have to go into the tomcat/conf/server.xml to modify the ports like Kapil mentioned.

I also had to copy all the jars inside the WEB-INF/lib folder of WebServiceProject into the alternate Tomcat/lib folder.
在 10-11-26 上午10:17 发帖以回复 Clayton Jarczewski
Result
exception: java.rmi.RemoteException: com.liferay.portal.kernel.dao.orm.ORMException: org.hibernate.exception.SQLGrammarException: could not load an entity: [com.liferay.test.model.impl.EmployeeImpl#2]


how can i solve this issue?
在 10-12-26 下午11:37 发帖。
@Raju - The issue seems to somewhere in database. Are you sure that the tables are created as required? See portlet-hbm.xml and portlet-orm.xml in /TestPlugin-portlet/docroot/WEB-INF/classes/META-INF/. Use sql files in /TestPlugin-portlet/docroot/WEB-INF/sql/ to create the tables.
在 10-12-28 下午9:22 发帖以回复 Raju OO7
Very nice article. Thanks!!!
在 11-1-20 下午6:38 发帖。
When I was executing the build-service task ant was waiting in the java-compile ant task. I setted fork to "no" and all goes ok. Is there any controindication?
在 11-1-25 上午3:09 发帖。
Hi Kapil,

I have a requirement, where instead of accessing db i want a webservice which does action on cache, so i tried to follow the same steps except one change,
(ie)
<entity name="Employee" local-service="true" remote-service="true"></entity>

I was able to deploy, but i get the below classcastexception, can u please help,

"AXIS error
Sorry, something seems to have gone wrong... here are the details:

Fault - ; nested exception is:
org.apache.axis.ConfigurationException: java.lang.ClassCastException: org.apache.axis.handlers.http.URLMapper cannot be cast to org.apache.axis.Handler
java.lang.ClassCastException: org.apache.axis.handlers.http.URLMapper cannot be cast to org.apache.axis.Handler
at org.apache.axis.deployment.wsdd.WSDDDeployableItem.makeNewInstance(WSDDDeployabl­eItem.java:302)
at org.apache.axis.deployment.wsdd.WSDDDeployableItem.getNewInstance(WSDDDeployable­Item.java:274)
at org.apache.axis.deployment.wsdd.WSDDDeployableItem.getInstance(WSDDDeployableIte­m.java:260)
at org.apache.axis.deployment.wsdd.WSDDDeployment.getHandler(WSDDDeployment.java:39­4)
at org.apache.axis.deployment.wsdd.WSDDDeployableItem.getNewInstance(WSDDDeployable­Item.java:276)
at org.apache.axis.deployment.wsdd.WSDDDeployableItem.getInstance(WSDDDeployableIte­m.java:260)
at org.apache.axis.deployment.wsdd.WSDDChain.makeNewInstance(WSDDChain.java:125)
at­ org.apache.axis.deployment.wsdd.WSDDDeployableItem.getNewInstance(WSDDDeployable­Item.java:274)...."
在 11-2-7 下午2:27 发帖以回复 Luca Andreatta
Hi Venkat,

From the stacktrace, we can see that the makeNewInstance method in WSDDDeployableItem.java is expecting org.apache.axis.Handler, however, org.apache.axis.handlers.http.URLMapper is being passed.

It seems to be some configuration problem or it can even be version miss match. This has nothing to do with accessing DB or calling action on cache. The error is purely on axis side.

Please send me your project zip at kapildverma@gmail.com so that i can debug it.

Regards,
Kapil
在 11-2-9 下午9:54 发帖以回复 Venkat S
First thank you for a great guide, works great for 6.0.5

Now I have a Axis security question:

Is there any way to make /TestPlugin-Portlet/axis available to external IPs and still leave /tunnel-web/axis local IP only?

I know I can set axis.servlet.hosts.allowed= and leave the value blank to open the axis service to the world, but that opens the liferay wsdd as well, I just want to expose my custom SOAP services.

It looks to me that I could change the <init-param> values in my web.xml but would be over written every time I deploy.
<init-param>
<param-name>portal_property_prefix</param-name>
<param-value>axis.servlet.</param-value>
</init-param>


-Andrew
在 11-2-28 上午11:52 发帖以回复 Kapil Dev Verma
Hi Andrew,

Thanks for your comments. I am not an expert with axis. However, you can have a look at apache webserver's mod_proxy to achieve this....

http://httpd.apache.org/docs/trunk/mod/mod_proxy.html

Regards,
Kapil
在 11-3-4 上午10:24 发帖以回复 Andrew Tillinghast
在 11-3-11 上午7:23 发帖。
Hi Kapil,
I want add new method in existing Liferay webservice as add new addGroupEXT to GroupServiceSOAP. What should I do?
I'm using Liferay CE 6.05.
Thanks.
在 11-3-12 下午5:55 发帖。
Hi Nguyen,

You might have to create a new webservice for your extended class. The problem is that the webservice definition for GroupServiceSoap is embedded in liferay code and it can't be modified (without changing liferay code). So you will have to create a new webservice, with your custom addGroupEXT() method, which internally uses the liferay APIs to accomplish the tasks.

You can create your new class something like GroupEXTServiceImpl, import com.liferay.portal.service.GroupServiceUtil and write a method addGroupEXT() in it. From that method, you can call the GroupServiceUtil.addGroup().

Then you can expose your new class as webservice.

You can also try this by changing the plugin project attached with this post. It will be a lot easier if you are using Liferay's Eclipse plugin.

--
Kapil
在 11-3-21 上午12:20 发帖以回复 Nguyen Trung Kien
在 11-8-22 上午5:31 发帖。
Concerning Error: "org.apache.axis.handlers.http.URLMapper cannot be cast to org.apache.axis.Handler"

There are some classloading issues. axis.jar is deployed in ROOT.war and in your Plugin WAR.

Solution: Remove the axis.jar in your Plugin WAR (WEB-INF/lib). It works fine for me.
在 11-9-9 下午3:46 发帖以回复 Tom Mahy
Sorry, it was a mistake. Removing axis.jar is not jet the solution. One ERROR has been gone, but NoClassDefError occurs on other location.

Does anybody have a solution for the Problem?
在 11-9-12 上午5:38 发帖以回复 Martin Schwietzke
Venkat S,

dont forget to run a new tomcat server, so you have the liferay's tomcat boundled, and a clear tomcat for the client
在 11-11-28 上午3:53 发帖。
Hi Kapli,

Nice Article

But i have an issue with this ,when i am trying to bulid client (as per you article URL)as below its working fine ,methods are invoking and getting results

http://127.0.0.1:8080/TestPlugin-portlet/axis/Plugin_Test_EmployeeService?wsdl

Bu­t when i am trying to bulit webservice client as below URL ,

http://127.0.0.1:8080/TestPlugin-portlet/secure/axis/Plugin_Test_EmployeeService­?wsdl

methods are invoked but when iam trying to get results shows as
RE:404 unauthroized

Is Anything wrong in the URL???
在 11-12-14 下午9:58 发帖以回复 Tamás Barabás
I'm getting exception: java.rmi.RemoteException: BeanLocator has not been set
在 12-2-1 上午1:13 发帖以回复 Raghu teja
This worked perfect on 6.0.6 but on 6.1 i cant find the service under /tunnel-web/axis
Has anything changed ?
在 12-2-17 上午6:03 发帖以回复 Shantanu Puranik
You can find service under /api/axis on liferay 6.1
在 12-3-5 下午8:10 发帖以回复 Tom Mahy
in step 3 -> 29 i cannot seem to get the WSDL to show i get following error:

HTTP Status 404 - /TestPlugin-portlet/axis/Plugin_Test_EmployeeService

type Status report

message /TestPlugin-portlet/axis/Plugin_Test_EmployeeService

description The requested resource (/TestPlugin-portlet/axis/Plugin_Test_EmployeeService) is not available.
Apache Tomcat/7.0.23
在 12-3-15 上午7:50 发帖。
I found the Solution by comparing the entries in the corresponding web.xml files:

in liferay 6.1 the url to call is "/TestPlugin-portlet/api/axis" instead of "/TestPlugin-portlet/axis"

I hope this saved some people's time.
在 12-3-16 上午2:37 发帖以回复 Patrick Momin
Hi, I'm experiencing a problem since few days.
My development environment is the following: I'm using Liferay6.1.0 CE GA1 source and plugin sdk, along with Eclipse Indigo Service Release 2, with WTP and Liferay IDE 1.5.2. The base platform is Java1.6.0_32 and the deployment server is Tomcat 7.0.23 (the one bundled with Liferay).
While executing the step 3 -22 (running TestPlugin-Portlet/build-wsdd) I'm getting the following error:
build-wsdd:
Loading jar:file:/D:/liferay-portal-6.1.0-ce-ga1/tomcat-7.0.23/webapps/ROOT/WEB-INF/lib/­portal-impl.jar!/system.properties
19-giu-2012 9.05.48 com.liferay.portal.kernel.log.Jdk14LogImpl info
INFO: Global lib directory /D:/liferay-portal-6.1.0-ce-ga1/tomcat-7.0.23/lib/ext/
19-giu-2012 9.05.48 com.liferay.portal.kernel.log.Jdk14LogImpl info
INFO: Portal lib directory /D:/liferay-portal-6.1.0-ce-ga1/tomcat-7.0.23/webapps/ROOT/WEB-INF/lib/
09:05:48,470 INFO [EasyConf:122] Refreshed the configuration of all components
09:05:48,770 INFO [ConfigurationLoader:56] Properties for jar:file:/D:/liferay-portal-6.1.0-ce-ga1/tomcat-7.0.23/webapps/ROOT/WEB-INF/lib/­portal-impl.jar!/portal loaded from [jar:file:/D:/liferay-portal-6.1.0-ce-ga1/tomcat-7.0.23/webapps/ROOT/WEB-INF/lib­/portal-impl.jar!/com/liferay/portal/tools/dependencies/portal-tools.properties,­ file:/D:/liferay-portal-6.1.0-ce-ga1/tomcat-7.0.23/webapps/ROOT/WEB-INF/classes/­portal-ext.properties, jar:file:/D:/liferay-portal-6.1.0-ce-ga1/tomcat-7.0.23/webapps/ROOT/WEB-INF/lib/­portal-impl.jar!/portal.properties]
Loading jar:file:/D:/liferay-portal-6.1.0-ce-ga1/tomcat-7.0.23/webapps/ROOT/WEB-INF/lib/­portal-impl.jar!/portal.properties
Loading file:/D:/liferay-portal-6.1.0-ce-ga1/tomcat-7.0.23/webapps/ROOT/WEB-INF/classes/­portal-ext.properties
Loading jar:file:/D:/liferay-portal-6.1.0-ce-ga1/tomcat-7.0.23/webapps/ROOT/WEB-INF/lib/­portal-impl.jar!/com/liferay/portal/tools/dependencies/portal-tools.properties
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/D:/liferay-portal-6.1.0-ce-ga1/tomcat-7.0.23/webapps/ROOT/WEB-INF/lib­/util-java.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/D:/liferay-plugins-sdk-6.1.0-ce-ga1/portlets/TestPlugin-portlet/docro­ot/WEB-INF/lib/util-java.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
Java2WSDL com.liferay.test.service.http.EmployeeServiceSoap
09:05:52,085 WARN [Types:1704] The class com.liferay.test.model.Employee does not contain a default constructor, which is a requirement for a bean class. The class cannot be converted into an xml schema type. An xml schema anyType will be used to define this class in the wsdl file.
WSDL2Java D:\liferay-plugins-sdk-6.1.0-ce-ga1\portlets\TestPlugin-portlet\2012061909055154­0\service.wsdl
Running Wsdl2javaAntTask with parameters:
verbose:false
debug:false
quiet:false
server-side:true
skeletonDeploy:false
helperGen:false
factory:null
nsIncludes:[]
nsExcludes:[]
factoryProps:[]
testCase:false
noImports:false
NStoPkg:{}
outputemoticon:\liferay-plugins-sdk-6.1.0-ce-ga1\portlets\TestPlugin-portlet\2012061909­0551540
protocolHandlerPkgs:
deployScope:
URLemoticon:\liferay-plugins-sdk-6.1.0-ce-ga1\portlets\TestPlugin-portlet\2012061909055­1540\service.wsdl
all:false
typeMappingVersion:1.2
timeout:45000
failOnNetworkErrors:false
printStackTraceOnFailure:true
namespaceMappingFile:null
username:null
:passwordnull
:noWrappedfalse
:allowInvalidURLfalse
:implementationClassNamenull
:classpathnull
http.proxyHost=null
http.proxyPort=null
http.proxyUser=null
http.proxyPassword=null
socks.proxyHost=null
socks.proxyPort=null
java.io.IOException: Type {http://model.test.liferay.com}Employee is referenced but not defined.
at org.apache.axis.wsdl.symbolTable.SymbolTable.checkForUndefined(SymbolTable.java:­665)
at org.apache.axis.wsdl.symbolTable.SymbolTable.add(SymbolTable.java:545)
at org.apache.axis.wsdl.symbolTable.SymbolTable.populate(SymbolTable.java:518)
at org.apache.axis.wsdl.symbolTable.SymbolTable.populate(SymbolTable.java:495)
at org.apache.axis.wsdl.gen.Parser$WSDLRunnable.run(Parser.java:361)
at java.lang.Thread.run(Thread.java:619)
Exception in thread "main" WSDL processing error for D:\liferay-plugins-sdk-6.1.0-ce-ga1\portlets\TestPlugin-portlet\2012061909055154­0\service.wsdl :
Type {http://model.test.liferay.com}Employee is referenced but not defined.
at org.apache.axis.tools.ant.wsdl.Wsdl2javaAntTask.execute(Wsdl2javaAntTask.java:30­4)
at com.liferay.util.ant.Java2WsddTask.generateWsdd(Java2WsddTask.java:108)
at com.liferay.portal.tools.WSDDBuilder._createServiceWSDD(WSDDBuilder.java:130)
at com.liferay.portal.tools.WSDDBuilder.build(WSDDBuilder.java:93)
at com.liferay.portal.tools.WSDDBuilder.main(WSDDBuilder.java:49)
Caused by: java.io.IOException: Type {http://model.test.liferay.com}Employee is referenced but not defined.
at org.apache.axis.wsdl.symbolTable.SymbolTable.checkForUndefined(SymbolTable.java:­665)
at org.apache.axis.wsdl.symbolTable.SymbolTable.add(SymbolTable.java:545)
at org.apache.axis.wsdl.symbolTable.SymbolTable.populate(SymbolTable.java:518)
at org.apache.axis.wsdl.symbolTable.SymbolTable.populate(SymbolTable.java:495)
at org.apache.axis.wsdl.gen.Parser$WSDLRunnable.run(Parser.java:361)
at java.lang.Thread.run(Thread.java:619)
Java Result: 1


Have you any suggestions to solve the problem?
在 12-6-19 上午2:17 发帖以回复 Patrick Momin
I have same problem. Can you tell me solution?

Thak you
在 12-7-12 上午2:53 发帖以回复 Giuseppe Pantaleo
For all , problem is in implement of XXXLocalServicesImp class. IN version liferay 6.1 dont necesarry correct methods in XXXServiceSoap.

->
http://www.liferay.com/community/forums/-/message_boards/message/14855175
在 12-7-14 上午2:36 发帖以回复 Petr Vašek
Thanks , Its was very helpful.
在 13-1-7 上午4:08 发帖。
Try this URL
http://127.0.0.1:8080/TestPlugin-portlet/api/axis/Plugin_Test_EmployeeService­?wsdl
在 13-2-5 上午1:35 发帖以回复 Patrick Momin
Nice..For Beginners..Its really nice article..Thanks for your Good work emoticon
在 13-2-18 下午10:57 发帖。
Nice Article kapil Thanks for sharing...emoticon
在 13-5-15 上午2:29 发帖。
Hi Kapil,

I have take your sample portlet and deploy it.But I am getting an error like this,

AXIS error

Could not generate WSDL!

There is no SOAP service at this location

I am accessing this url : http://127.0.0.1:8080/TestPlugin-portlet/api/axis/Plugin_Test_EmployeeService?ws­dl

Any help would be appreciated.Thankx in advance.

Thanks And Regards,
Abdulbasit F Shaikh
在 13-6-7 上午4:54 发帖。
Hi Kapil,

Thanks for such a nice doucment.I finally did this succesfully.

For Others,

If you are using Liferay 6.1.0 GA1(I don't know about others),then you need to follow the step number 21.The main culprit is the finder method.So first try to remove finder method and try this example.Make sure that you will not add any code of finder method in XXXLocalServiceImpl and XXXServiceimpl.And one more thing is that, if you are hitting an url and not getting output, then first try this http://127.0.0.1:8080/TestPlugin-portlet/api/axis, you will get the list of methods and one "wsdl" link, click on that, you will get your wsdl.cheers emoticon.

And for webservice client,first you need to create one dynamic web project.Then follow the steps of creating webservice client.Make sure that in step number 2,your newly created project(Dynamic web project) should be selected in client project.For E.G. in this case WebService project is selected.Make sure you tomcat is your normal tomcat not your liferay tomcat.And make sure that you dragged scroll to the top.You will find scroll on extreme left of window.

Thanks And Regards,
Abdulbasit F Shaikh.
在 13-6-11 上午1:55 发帖。
I am using Liferay 6.1.1
I need some help. Everything compiles, the wsdd is created, the deploy works with no error, the portlet page loads but when I try to see the wsdl:
http://127.0.0.1:8080/TestPlugin-portlet/axis/Plugin_Test_EmployeeService?wsd I am gettting error HTTP Status 404 - /TestPlugin-portlet/axis/Plugin_Test_EmployeeService,
and also I can not see service
http://127.0.0.1:8080/tunnel-web/axis
在 14-3-21 下午1:18 发帖。
In Liferay 6.1+ they have changed some URLs.

You have to type this URL:
http://127.0.0.1:8080/TestPlugin-portlet/api/axis/Plugin_Test_EmployeeServic­e?wsd
在 14-9-4 上午3:00 发帖以回复 Syed Mujeeb
For documentation you can look here:
http://www.liferay.com/it/community/wiki/-/wiki/1071674/Liferay+Web+Service­s+Listing
在 14-9-4 上午3:01 发帖以回复 Luca Andreatta