You are on page 1of 17

Liferay Web Services

Copyright © 2000 – 2007 Liferay, Inc.


All Rights Reserved.
October 29, 2007
Tested on Liferay 4.3.3
Valid for Liferay 4.2.2+

No material may be reproduced electronically or in print


without written permission from Liferay, Inc.
Objectives
 Learn how to generate an Axis web service
client
 Learn how to call web services via your
generated client
 Use your generated client to access web
services from the ext environment
Executive Overview
1.Get the WSDL for the web service you want to access
2.Run through the Web Services Client wizard in Eclipse
3.Test your Web Service Client
4.Copy the necessary classes into the ext environment
5.Call the web service from a portlet or from the services
layer
Getting the WSDL
 You can get the WSDL from a URL or a file
 We will be getting the WSDL from a URL
 We need to use Eclipse 3.2 for the Axis 1.x runtime, which is
what Liferay uses. Eclipse 3.3 uses Axis 2.x.
 Get a Tomcat runtime
 Connect that runtime to Eclipse
 Create new Dynamic Web Project
 Create new Web Service Client
 Generate Java code from the WSDL
 Run the Web Service Client
Get a Tomcat Runtime
 Download Tomcat from
http://tomcat.apache.org
 Unzip to a directory on
your machine
 Connect it to Eclipse
 Servers Tab -> New
Server...
 Pick Apache ->
Tomcat 5.5
Connect Runtime to Eclipse
 Browse to where you
unzipped Tomcat
 Click Finish
 Server Runtime
appears in the Servers
tab in the Java EE
Perspective
Create new Dynamic Web Project
 Click File -> New -> Project....
 Select Web -> Dynamic Web
Project
 Make sure your Tomcat
Runtime is selected
 Give your project a name and
select Finish
Create New Web Service Client
 Right-click on the
project, select New ->
Other
 Select Web Services -
> Web Service Client
 Click Next
Create a new Web Service Client
 In Service Definition,
click Browse, and then
paste in the url to your
WSDL
 Click OK
Generate Java Code from the
WSDL
 Slide the slider (on the
left) all the way to the
top and then click
Finish
 The Java code will be
generated, the project
will built, and then it
will be deployed and
run on your Tomcat
runtime
Run the Web Service Client
 The test client loads in a
browser window
 You can select methods
from the web service on the
left
 Once you've selected a
web service, you can pass
it parameters and invoke it
 You can see the result on
the bottom
Generated Code
 We just generated a web service client for the
stock quote web service at
http://www.webservicex.net
 This illustrates the power of web services, as
the services on this site are all .NET web
services
 We have not written a single line of code to do
this
Generated Code
 Java bean and proxy
code was generated
 JSPs were generated
to provide forms for
invoking the web
service with the
proper parameters
 The source of the
JSPs can be used for
your own code
Copy the Code to Ext Environment
 Because we used the same version of Axis
included in Liferay to generate the client, we
can copy the package (and all source) into the
ext environment and use it directly
 Copy the source package of the web service (in
this example, the whole directory tree starting
with the folder called NET) into the ext-impl/src
directory of your extension environment
Call the Web Service
 You can now call the web service anywhere in
the ext environment
Call the Web Service
 You could also do this in a standalone portlet
plugin by copying the .jars from your generated
project into your portlet project
Revision History
 Author: Rich Sezov

You might also like