Creating your first Web Service provider and consumer in LotusScript and Java.

Creating your first Web Service provider and consumer in LotusScript and Java.
Added by  IBM contributor Simon O'Doherty  | Edited by  IBM contributor Simon O'Doherty  on  2012年4月30日  |  Version 36
This simple walkthrough will introduce you to create a LotusScript and Java Web Service provider and consumer. This tutorial assumes you have no knowledge of what web services are.

Initial Setup

You will need the following to complete this walkthrough. 

  • Domino server. 
  • Notes Designer + Admin client. 
  • Web Browser.

In the examples below the following refer to your Notes/Domino install location.

  • Domino:  C:\Domino 
  • Notes: C:\Notes 

Change these to match your server as required. 

Terminology

This walkthrough will not go into details of what Web Services are or the internals. Here are some terms that will be used that you should be aware of. 
  • Web Service - In its most simple definition. It is a method of two systems to communicate with each other through a common language. For a developer in LotusScript/Java you do not need to worry about how the Domino server communicates with the other system.
  • Provider - The service that is providing the web service. In a server-client relationship, this would be the server. 
  • Consumer - The service that is requesting the web service. In a server-client relationship, this would be the client. 
  • WSDL - Web Service Definition Language. This is an XML file that describes how a web service provider can be communicated with. Using the WSDL you can automatically create the script library that will handle all communication for you. 
  • SOAP - Simple Object Access Protocol. This is the XML messaging system between the consumer and the provider. 
  • Endpoint - This is the URL to the web service provider. 

Server setup

For this walkthrough we will be creating the provider and consumer in the same database. To avoid the Domino server from hanging, you will need to allow concurrent web services/agents. 
  1. Open Domino Administrator.
  2. Select the configuration tab and expand "Server" on the right hand side and click "All Server Documents". 
  3. Expand the list on the right and edit the server document you are working on. 
  4. Select the "Internet Protocols" tab. 
  5. Select the "Domino Web Engine" tab. 
  6. Scroll down to the bottom of the page to the "Web Agents and Web Services" section. 
  7. Set "Run web agents and web services concurrently?" to "Enabled"
  8. Save and close the server document. Close the administrator client. 

Make sure that the HTTP process is running. If it isn't you can start it from the Domino console by typing "load http". 

Also ensure that the signature you are creating the agents with has the rights to run agents on the server. 

Database Setup

1. Start the Designer client. 

2. From the menu select "File -> New -> Application". 

3. Fill out the dialog as follows. 

  • Server:  
  • Title: Web Services Hello World
  • Filename: WS.nsf
  • Template: -Blank-

4. Click OK. 

5. Modify the database ACL to allow default access as Editor. 

Creating the LotusScript provider

1. From your database outline double click the item "Code -> Web Service Providers".

2. Click "New Web Service Provider" button. 

3. Fill out the dialog box as follows (leave other fields as the default value)

  • Name: Hello World LS Web Service Provider
  • Alias: HWLSP
  • Type: LotusScript

4. Click OK. 

5. In the LotusScript view select "(Declarations)" and type in the following code. 

	Class hwProvider

	    Function Hello ( txt as String ) 

	        Hello = "Hello " + txt

	    End Function

	End Class

6. Right click anywhere in the code and select "Web Service Properties". 

7. Fill out the properties as follows. 

  • Tab 1: 
  • Port type class: hwProvider
     
  • Tab 3:
  • Encoding: RPC
  • SOAP message format: RPC/encoded

8. Press CTRL-S to save the web Service. On the third tab, it should automatically fill out the remaining fields. If this does not happen, then type it in yourself as follows. 

  • Port type name: hwProvider
  • Service element name: hwProviderService
  • Service port name: Domino

9. Close the web service provider window (and save if required). 

Testing the LotusScript provider

At this point your web service WSDL file should be accessible on the server. You can test this by opening a browser and pointing to the following URL. Replace SERVER_NAME with the name of your server (eg. localhost , testserver.lan )

http://SERVER_NAME/WS.nsf/HWLSP?WSDL

 

This will display the XML details of your web service provider. You do not need to worry about what is contained in this XML as the Designer client will do the work for you. 

Sample: 
Sample WSDL output

Creating the Java provider

1. In the Designer client, if you are not already at the Web Service Provider view then double click the item "Code -> Web Service Providers"

2. Click "New Web Service Provider" button. 

3. Fill out the dialog box as follows (leave other fields as the default values)

  • Name: Hello World Java Web Service Provider
  • Alias: HWJP
  • Type: Java

5. Click OK. 

6. Click "New Java Class" and fill out the dialog box as follows (leave other fields as the default values). 

  • Name: HwProvider

7. Click OK. 

8. Replace the code in the Java script window with the following. 

	public class HwProvider { 

	       public String hello (String txt) { 

	           return "Hello " + txt; 

	       }

	   }

9. Save and close the script window. 

10. From the Properties window / Basics tab, click on "Port type class" drop down and select "HwProvider". 

11. Click the Advanced Tab in the Properties window and change the following. 

  • Programming model: RPC
  • SOAP message format: RPC/encoded

12. Press CTRL-S to save. Click on the window to confirm that the following in the advanced tab is filled in (if not then manually fill in). 

  • Port type name: HwProvider
  • Service element name: HwProviderService
  • Service port name: Domino

13. Close the Java web service provider window. Save if required. 

Testing the Java provider

 

Like before you can check if your WSDL file is being generated by using the following URL. Again replace SERVER_NAME with the name of your server (eg. localhost , testserver.lan)

http://SERVER_NAME/WS.nsf/HWJP?WSDL

Creating consumers

 

To demonstrate the power of web services, the consumers will talk to the alternate language provider, as shown in the diagram below. 

Consumer and Provider layout

Creating the Java Consumer to connect to the LotusScript Provider

1. From the database outline in Designer double click "Code -> Web Service Consumers". 

2. Click "New Web Service Consumer". 

3. Fill out the dialog box as follows (leave the other options as the default). 

  • Name: HWJC
  • Type: Java
     
  • Get Web Service Description from: (Replace SERVER_NAME with your servers name). 
    http://SERVER_NAME/WS.nsf/HWLSP?WSDL

4. Click OK. 

5. Save and close the consumer window. 

Creating the LotusScript Consumer to connect to the Java Provider

 

1. From the database outline in Designer, double click "Code -> Web Service Consumers". 

2. Click "New Web Service Consumer". 

3. Fill out the dialog box as follows (leave the other options as the default). 

  • Name: HWLSC
  • Type: LotusScript
     
  • Get Web Service Description from: (Replace SERVER_NAME with your servers name). 
    http://SERVER_NAME/WS.nsf/HWJP?WSDL

4. Click OK

5. Save and close the consumer window. 

Creating the LotusScript agent to test the LotusScript Consumer

1. From the database outline in Designer double click "Code -> Agents". 

2. Click "New Agent" and fill out the dialog as follows (leave the rest as the default). 

  • Name: TestLS
  • Type: LotusScript

3. Click OK. 

4. In the Agent properties set the following. 

  • Trigger: On Event
  • Action Menu Selection
  • Target: None

5. In the script window replace with the following code.

	Option Public

	Option Declare

	 

	Use "HWLSC"

	 

	Sub Initialize

	    Dim stub As New HwProvider()

	    MessageBox stub.Hello("world")

	End Sub

6. Save and close the agent. 

7. From the Agent list window, right click the agent and select "Run". A message box will appear saying "Hello World". 

Creating the Java agent to test the Java Consumer

1. From the database outline in Designer, double click "Code -> Agents". 

2. Click "New Agent" and fill out the dialog as follows (leaving the rest as the default). 

  • Name: TestJava
  • Type: Java

3. In the Agent properties (Basics) set the following. 

  • Trigger: On Event
  • Action Menu Selection
     
  • Target: None

4. Click "Import" and select "Web Service Consumer". 

5. Select "HWJC" and click "Import". 

6. Double click "JavaAgent.java" and replace with the following code. 

	import lotus.domino.*; 

	public class JavaAgent extends AgentBase {   

	      public void NotesMain() { 

	        try { 

	            Session session = getSession();

	            AgentContext agentContext = session.getAgentContext();

	            HwProvider stub = new HwProviderServiceLocator().getDomino();

	 

	            String answer = "" + stub.HELLO("world"); 

	            System.out.println("The answer is : " + answer); 

	        } catch (Exception e) { 

	            e.printStackTrace();

	        }

	      }

	}

7. Save and close the script, then save and close the agent. 

8. From the agent list window, right click the agent and select "Run". 

9. From the tools menu select "Show Java Debug Console". There will be a message that says "The answer is : Hello World". 

点击打开链接

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值