Java WebService Provider/Consumer


 * Created: 2013.
 * SiteCategoriesWebServs |
 * WebServices data for Xpages
import lotus.domino.Database;
import lotus.domino.Document;
import lotus.domino.NotesException;
import lotus.domino.Session;
import lotus.domino.View;
import lotus.domino.WebServiceBase;
 * @author Dököll Solutions, Inc.
 * @version 2013.
public class SitesCategoryServiceAgent {
	private Session session;
	private Database database;
	private View view;
	private Document document;
	public SitesCategoryServiceAgent() throws NotesException {
		session = WebServiceBase.getCurrentSession();
		// grab database from session obtained
		database = session.getDatabase("", "sitefindermobile.nsf");	
		System.out.println("database loaded from session..." + database);
		// grab view from database	
		view = database.getView("SiteList");
		System.out.println("view obtained from database..." + view);
	//perform search
	public String getSiteCategory(String SiteName) {
		System.out.println("declare variable to load search results..");
		String SiteCategory = "";
		try {
			//search view based on first column (Key)
			System.out.println("view column search from database...");
			System.out.println("using getDocumentByKey...");
			document = view.getDocumentByKey(SiteName);
			if (document == null) {
				//alert user where no site are found
				SiteCategory = "Search results for specific site type  returned null";
				System.out.println("view obtained from database, but no sites..." + SiteCategory);
			} else {
				//load site to user where site are found
				SiteCategory = document.getItemValueString("Type");
				System.out.println("view obtained, site Found..." + SiteCategory);
				if (SiteCategory.equalsIgnoreCase("")) {
					//alert user where key retrieve null for Type
					SiteCategory = "check view column, Type is empty...";
					System.out.println("check view, column empty..." + SiteCategory);
		} catch (NotesException e) {
		} catch (Exception e) {
		return SiteCategory;

Copy and Paste JavaAgent to invoke WebService:
Create a new JavaAgent, copy and paste the following over the generated code.  You will be using this JavaAgent to invoke the WebService consumer and grab documents from your view.  You will also add the snippet you checked earlier from the class.

 * Created: 2013.
 * ConsumeSitesCategoryWebServsJavaAgent |
 * WebServices data for Xpages
import lotus.domino.*;

 * @author Dököll Solutions, Inc.
 * @version 2013.
public class JavaAgent extends AgentBase {
    public void NotesMain() {
      try {
    	  //Locate the WebService code to perform the search, aided by sitefindermobile.nsf WSDL
    	  //Note: below stub may be different than your version if you named your WebService Agent differently
    	  //grab below stub from the YourWebServiceAgentNameService (for this exercise ours is named 'SitesCategoryServiceAgentService'
    	  //code that can be found among the four Java classes generated when creating the WebService consumer
    	  SitesCategoryServiceAgent stub = new SitesCategoryServiceAgentServiceLocator().getDomino();
          //do something with the result of your search
    	  //example show the value of getSiteCategory method in an Xpages form
    	  System.out.println(stub.getSiteCategory("Dököll Solutions, Inc."));
      } catch(Exception e) {

Use JavaAgent code samples to create WebService provider and consumer using two different NSF files.   You will be creating the WebService provider on sitefindermobile.nsf and the consumer will connect to the WSDL on sitefindermobile.nsf using filebin.nsf.  Build a connection to these Lotus Notes Domino Database(s) located on C Drive to get started...

Copy and Paste WebService JavaAgent Code
Copy and paste below code sample to your environment over the above generated 'Untitled' class.  You might also want to make sure your code is making the proper connection to an existing view, and that your search criteria is solid and bound to the right key; it will save you a ton of work and time.

Configure WebService Agent/Create WSDL:
We hope you are connecting to an existing view and your search criteria is up to snuff at this point.  You want to check 'Warn if the WSDL Interface is modified' and select the Port Type class from the dropdown.  Please note, once you hit save, the WSDL will be created, thus no turning back.

Export or Read WebService via URL:
From here you can either export the WebService WSDL to a location to be picked up by other programs or you can simply call the WSDL via URL to create a consuming WebService.  For this example we are going to call the WebService provider.  We are using a different NSF file to call the WebService provider.  Create a new WebService consumer in Java, select the second option 'URL that points to a WSDL file'.  You will type the full URL to grab the WebService provider:

Locate generated snippet code to consume WebService:
You will be using a JavaAgent to invoke the WebService consumer and grab documents from your view.  To do this, open the Java class named 'SitesCategoryServiceAgentService':

* To instantiate a callable instance for invoking this service, copy and paste from the following:

   import *;

   // Refer to for service interface methods:
   SitesCategoryServiceAgent stub = new SitesCategoryServiceAgentServiceLocator().getDomino();

See code samples above, grab the JavaAgent consumer code to complete the process.

Köll S Cherizard
September 26, 2013 4:27 PM

All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.

2 comment(s)Login first to comment...
Köll S Cherizard
(at 20:55 on 09.08.2017)
It's a little fancier using an Xpage Michele, although I've not tried that- Thanks for posting:-)
Michele Malaguti
(at 05:41 on 01.10.2013)
This example uses a JavaAgent to invoke the WebService consumer; now i wonder what's the best way to invoke the WebService consumer from an Xpage instead from an agent. I did it calling a java agent from xpage and using a temporary notesdocument to pass data.
Thanks, Michele.