Exporting DXL for databases with Java web services

Today I needed to export a database application containing a web service written in Java as DXL. How stupid of me to think that I could do this with only Notes.jar on my build path… Doing such an export will make your code throw java.lang.ClassNotFoundExceptions unless you have the following libraries on your build path:

  • jvm/lib/ext/notes.jar (not much surprise there)
  • jvm/lib/ext/websvc.jar (due to missing lotus.domino.websvc.client.Service)
  • jvm/lib/ext/mail.jar (due to missing java.mail.Multipart from lotus.domino.ws.ServiceContext)
  • jvm/lib/ext/jsdk.jar (due to missing javax.servlet.http.HttpServlet)
  • jvm/lib/xml.jar (due to missing org.apache.xerces.parsers.SAXParser)

The above was found by diagnosing and reading ClassNotFoundExceptions in Eclipse at runtime since ClassNotFoundException is a runtime exception.

Now back to exporting…

Discovering Notes 8: Web service enabled script libraries


In a recent edition of the LotusUsergroup.org newsletter Julian listed some of the new AppDev features of Notes 8. Among them were the new web service enabled script libraries.

Basically what you do is simply pointing a script library to a WSDL file and some stub code is automatically generated for you. Then when you use the script library from agents etc. the methods you call will automatically be forwarded to the actual web service without you worrying about SOAP, HTTP etc. It actually is that easy!

To test it out I found an example of a public stock quote web service (http://www.webservicex.net/stockquote.asmx?WSDL) and used that for an example.

Start by creating a new empty LotusScript script library. Now click the “WSDL…” button at the bottom of Domino Designer and simply select “Import WSDL”. Now paste the above URL into the filename field and click Open (it’s really nice that you can actually simply paste the WSDL URL into the dialog instead of first saving the WSDL to a local file). Now your script library should look like this:

%INCLUDE "lsxsd.lss"
Const n4 = "http://www.webserviceX.NET/"
Class StockQuoteSoap_n4 As PortTypeBase

  Sub NEW
    Call Service.Initialize ("HttpWwwWebserviceXNETStockQuote", _
    "StockQuote.StockQuoteSoap", _
    "http://www.webservicex.net/stockquote.asmx", _
    "StockQuoteSoap_n4")

  End Sub

  Function GetQuote(symbol As XSD_STRING) As XSD_STRING
    Set GetQuote = Service.Invoke("GetQuote", symbol)
  End Function

End Class

Now save the script library and call it “Stock quote”.

Create a LotusScript agent and in Options import the script library (Use “Stock quote”). Now we want to call the script library which is done using code like this:

Sub Initialize
  Dim ws As New NotesUIWorkspace
  Dim sq As New StockQuoteSoap_n4()
  Dim symbol As String
  Dim symbols(2) As String
  symbols(0) = "IBM"
  symbols(1) = "JAVA"
  symbols(2) = "AAPL"
  symbol = ws.Prompt(4, "Stock symbol", _
    "Select stock for quote...", "", symbols)
  If symbol = "" Then
    Exit Sub
  Else
    Print "Using symbol: " + symbol
  End If

  Dim sh As New XSD_STRING()
  Call sh.setValueFromString(symbol)
  Set sh = sq.GetQuote(sh)
  Msgbox sh.getValueAsString()
End Sub

Now when you run the agent and you select a stock symbol it will actually automatically go out to the web service, get the quote and return it to the caller. All this with the code I just showed you. Nice!

Stand by for a post on the nitty, gritty details…

Regarding the Domino 7 freetime webservice

On 24 September 2005 I blogged about a freetime web service for Domino 7 (Freetime WebService) which was available for download from Passport Advantage. Now (17 April 2007) there is an article on developerWorks (Using and modifying the IBM Lotus Domino V7 Free Time Web service) on how to use it. It appears you have to install a server task as well.

And guess what – the article uses Stubby by Julian