Skip to end of metadata
Go to start of metadata

There are ofcourse multiple ways to create Webservices on the portal which are documented at help.sap.com. In this blog I am going to show the simplest way to create webservices using XML-RPC.

You can find the limitations of XML-RPC here:

http://weblog.masukomi.org/writings/xml-rpc_vs_soap.htm

Download the java implementation of XML-RPC from http://ws.apache.org/xmlrpc/

Copy the below libraries to \dist\PORTAL-INF\lib folder of your project:

commons-codec-1.3.jar

commons-logging-1.1.jar

ws-commons-java5-1.0.jar

ws-commons-util-1.0.2.jar

xmlrpc-common-3.1.1.jar

xmlrpc-server-3.1.1.jar

Implementing the webservice:

I will implement a very simple webservice which shows "Quote of the day" which is nothing but a string.

For this, I implement a MyQuotes class in src.api folder, this class should only have the business methods that can be called through remote procedure calls. In our case it is the getQuoteofTheDay method.






Here we are creating a servlet that extends the standard XmlRpcServlet, which contains the logic to handle XML-RPC.



Configuring the servlet as portal comonent in portalapp.xml:

<?xml version="1.0" encoding="UTF-8"?>
<application>
<application-config/>
<components>
<component name="XmlRpcWebservice">
<component-config>
<property name="ClassName" value="com.test.webservice.XmlRpcWebservice"/>
<property name="ComponentType" value="servlet"/>
</component-config>
<component-profile>
<property name="SupportedUserAgents" value="(,,*)"/>
<property name="SupportedUserAgents-validvalues" value="(,,*)"/>
<property name="AuthScheme" value="anonymous"/>
</component-profile>
</component>
</components>
<services/>
</application>

Now deploy the application on the portal and the webservice is ready for use. The XmlRpcWebservice portal component acts as an endpoint for the webservice calls.

Implementing a client to call the webservice:

Here you need the following libraries in your classpath:

commons-httpclient-3.1.jar

xmlrpc-client-3.1.1.jar

commons-codec-1.3.jar

commons-logging-1.1.jar

ws-commons-java5-1.0.jar

ws-commons-util-1.0.2.jar

xmlrpc-common-3.1.1.jar




Now when you run the client class, you should be able to see the Quote of the day.

Benefits of this approach in portal environment:

As the webservice will be implemented as a portal component all the security features of the portal component like AuthScheme and Security Zones can be used to protect the access of webservice from end users.

Debugging the request/response of the Webservice calls:

Using the TCP/IP Monitor plugin in Eclipse 3.3, it is very easy to check the request/response XML of the webservice calls. Ofcourse you cannot use this plugin in NWDS 7.0 but if you have NWDS 7.1 Composition Environment or Eclipse 3.1 installed you can use this wonderful goodie.

To open the TCP/IP Monitor goto:

Window -> Show View -> Debug --> TCP/IP Monitor

Goto TCP/IP Monitor window and right click with your mouse and choose properties menu item. Add a new monitor by clicking Add button and set a local monitoring port. I chose 80 as my portal runs on 50000. Now fill the Host name, which is the portal host name. Fill port, which is portal port, which is 50000 in my case. Now click ok to add the monitor. Now select the monitor in the table and click the start button to start the monitor.

From now all the requests that come to localhost on port 80 will be redirected to portal on port 50000. And we will have the opportunity to monitor the request/response XML.

Next step is to modify the host and port in the client class to point to the host and port on which the TCP/IP Monitor is hearing. (http://localhost/irj/servlet/prt/portal/prtroot/SimpleWebservice.XmlRpcWebservice)

Now once you run your client class you should be able to see request/response in the TCP/IP Monitor:
For further documentation and examples on Apache XML-RPC, check:

http://ws.apache.org/xmlrpc/

  • No labels