Creating your first Web Service provider and consumer in LotusScript and Java.
Added by
Simon O'Doherty
| Edited by
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.
|
Hide
Table of Contents
Initial SetupYou will need the following to complete this walkthrough.
In the examples below the following refer to your Notes/Domino install location.
Change these to match your server as required.
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.
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.
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 Setup1. Start the Designer client. 2. From the menu select "File -> New -> Application". 3. Fill out the dialog as follows.
4. Click OK. 5. Modify the database ACL to allow default access as Editor. Creating the LotusScript provider1. 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)
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.
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.
9. Close the web service provider window (and save if required). Testing the LotusScript providerAt 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: Creating the Java provider1. 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)
5. Click OK. 6. Click "New Java Class" and fill out the dialog box as follows (leave other fields as the default values).
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.
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).
13. Close the Java web service provider window. Save if required. Testing the Java providerLike 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 consumersTo demonstrate the power of web services, the consumers will talk to the alternate language provider, as shown in the diagram below.
Creating the Java Consumer to connect to the LotusScript Provider1. 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).
4. Click OK. 5. Save and close the consumer window. Creating the LotusScript Consumer to connect to the Java Provider1. 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).
4. Click OK 5. Save and close the consumer window. Creating the LotusScript agent to test the LotusScript Consumer1. 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).
3. Click OK. 4. In the Agent properties set the following.
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 Consumer1. 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).
3. In the Agent properties (Basics) set the following.
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". |