jmp 105 – xml and web services jumpstart paul t. calhoun | chief technology officer

132
JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Upload: molly-cooper

Post on 30-Jan-2016

232 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

JMP 105 – XML and Web Services JumpstartPaul T. Calhoun | Chief Technology Officer

Page 2: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

2

Obligatory Introduction SlidePaul T. Calhoun

Chief Technology OfficerNetNotes Solutions [email protected]

I'm a Speaker, Trainer and Consultant who provides customer-focused knowledge transfer and consulting to businesses worldwide. I currently develop solutions using Domino, Xpages, Web Services, Java, and XML for customers using Domino, Portlet Factory, WebSphere and Eclipse.

I am administration and developer certified on all releases since 3.0. I co-authored the IBM Redbook “XML Powered by Domino,” and have developed several online courses for both Application Development as well as System Administration. I have spoke at technical conferences world wide and published over a dozen articles in leading publications. I contribute frequently to the XPages Blog.

Page 3: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

3

Evaluations● Please make sure you fill out your evaluations from the pages at the

back of you notepad.

● THANKS !!!!!!!!

Page 4: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

4

Please Put you Phone/PDA On Silent Mode

Page 5: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

5

Agenda● XML Overview

● XML Development in IBM Lotus Domino

● Web Services Overview

● Developing Web Service Providers

● Developing Web Service Consumers

● Q & A

Page 6: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

6

XML Overview● Current State of XML

● XML Technologies YOU need to know▬ XML Syntax▬ XSD Schema▬ XSL

▬ XSLT▬ XPATH▬ XSL-FO

Page 7: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Current Stateof XML

XML = eXensible MarkupLanguage

XML is 13 Years Old(That's like 91 technology years)

Developed by W3committee headed bySun's Jon Bosak

Standard is stillmaintained by the W3 todayhttp://www.w3.org

Still @ version 1.0(Fifth revision)http://www.w3.org/tr/xml

Page 8: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

XML is NOT...

A newer, different, better, coolerHTML

XHTML(XHTML is DEFINED using XML)

Any specifically defined markup languageor tag definition like WML, DXL XHMLT, MathML

Page 9: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

XML is...

All about the DATA !!

All about the DATA !!

All about the DATA !!

All about the DATA !!

All about the DATA !!

All about the DATA !!

All about the DATA !!

All about the DATA !!All about the DATA !!

All about the DATA !!

All about the DATA !!All about the DATA !!

Page 10: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

With XML you can ...● Create/Define your own Markup Language

▬ Using Syntax Rules defined in the XML standard (defined at www.w3.org)▬ Set of tags that describe specific DATA structures

▬ Books▬ Documents▬ Cars▬ Business Processes▬ Messages▬ Pizza▬ <insert YOUR markup language here>

Page 11: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

With XML you can ...● Exchange DATA with ANYONE

▬ Ubiquitous data transfer from system “A” to system “B” regardless of▬ Platform▬ Operating System▬ Programming Language▬ Protocol▬ Connectivity

● Define▬ Software/Hardware configuration▬ Tool set properties▬ Industry Standard Markup Languages▬ Web Services Transactions

▬ SOAP▬ WSDL▬ UDDI▬ REST

At the end of the day XML is what YOU make it to be !

BestPractice

Page 12: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

XML SyntaxRules

Comments start with

<!-- and end with -->

Starts with a correct XML declaration

<?xml version = “1.0” ?>

All tags are enclosed with angle brackets "< >"

A root tag encompasses all other tags<books>

..xml content...

</books>Each opening tag must have

a corresponding closing tag

Tags can be nested but cannot overlapTag names are case sensitive

All attribute values must be enclosed in quotes(single quotes OR double quotes but be contestant)

Page 13: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

XML Declaration● First line of an XML document

● All the following are valid XML declarations

<?xml version="1.0" ?>

<?xml version="1.0" encoding="UTF-8" ?>

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>

Page 14: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

XML Tags● All tags are enclosed with angle brackets "< >"

● A root tag encompasses all other tags

● Each opening tag must have a corresponding closing tag

● Tags can be nested but cannot overlap

<?xml version="1.0" encoding="UTF-8" ?><Pizza>

<Type>Supreme</Type></Pizza>

Page 15: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Tag Names are Case Sensitive● Valid Tag Combinations

● <Pizza></Pizza>

● <pizza></pizza>

● <PIZZA></PIZZA>

● Invalid Tag combinations

● <Pizza></PIZZA>

● <pizza></Pizza>

● <Pizza><pizza>

Page 16: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Attributes must be enclosed in quotes● Single ( ' ' )

● Double ( “” )

● Be consistent

<?xml version="1.0" encoding="UTF-8" ?><Pizza attrib1=”value1”>

<Type attrib2=”value2”>supreme</Type></Pizza>

Page 17: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Processing Instructions and Comments● Processing instructions start with <? and end with ?>

▬ Processing Instructions are used to provide additional information to the parser▬ Schema Definitions▬ Stylesheet locations

● Comments start with <!-- and end with -->▬ Comments are ignored by the parser

<?xml version="1.0" encoding="UTF-8" ?><?xml-stylesheet type="text/xsl" href="style.xsl"?><!-- This is an XML Comment --><Pizza attrib1=”value1”>

<Type attrib2=”value2”>supreme</Type></Pizza>

Page 18: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

XML “Documents” must beWELL FORMED

Well Formed:XML followed allSyntax Rules

Not Well-Formed:XML did not followall Syntax Rules

An XML “document” can be a ...Physical file on diskStream of data on same systemStream of data from remote systemIn memory resource

Page 19: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Checking for well-formedness● XML documents are processed by “parsers”

● Parsers are software built into many▬ Applications▬ Application Servers▬ Web Browsers▬ Development Software

▬ Trivia:There has been an XML parser in Domino since Release 5

● The Parser determines if the XML document is well-formed▬ If the XML document is NOT well-formed then processing stops and the parser throws an error▬ If the XML document is well-formed the processing continues

● Parsers can optionally determine if an XML document is “Valid” according to an existing schema

▬ More on this later

Page 20: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

XML Parser API's● DOM - Document Object Model

▬ XML documents are parsed into anin-memory Node Tree

▬ Good for smaller XML documents▬ Most common▬ http://www.w3.org/DOM/

● SAX - Simple API for XML▬ XML document is processed from

beginning to end ▬ Each element of the XML document is

processed in real time▬ Not as common▬ http://www.saxproject.org/

● Both DOM and SAX parsers are available in all the common programming languages

▬ Java▬ .NET▬ C▬ C++▬ C sharp▬ Javascript▬ Lotuscript▬ Fortran

Page 21: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Demo - Testing XML for Well-Formedness

Page 22: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

XML “Documents” canoptionally beVALID

Valid:After parser verifies the document is well-formedwill optionally validateagainst a referenced schema

Schema API's:Document Type Definition (DTD)XML Schema (XSD)

Schemas are generally a “1” to many relationship

Page 23: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Validating API's● Document Type Definition – DTD

▬ Original XML validation mechanism▬ Issues

▬ Does not allow for data typing● (Everything is a string)

▬ Does not Support Namespaces▬ Not written in XML syntax

● XML Schema - XSD▬ Replacement for DTD's▬ Addresses all of the DTD issues▬ More complex▬ More verbose▬ Not easily created

Page 24: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Validation Best Practices● DTD's were XML's original validation mechanism

● Primary con is lack of data typing

● Although DTD's are still supported (primarily for backwards compatibility) developers should standardize and implement XML validation via XSD as a best practice

Page 25: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

What to develop first?

● What do you develop first? The XML data or the XSD that defines the data ?

▬ Either approach is valid▬ Tools available to generate XML sample from XSD as well as tool to generate XSD from sample

XML▬ For Domino development most XML is going to be generated via an agent from document data

▬ During development this is generally a dynamic ongoing process with many changes

● Best practice is to finalize the XML stream and then use tools to generate the XSD schema

Page 26: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Generating XSD Schemas● XSD schema documents can be written manually with any XML editor

▬ But you don't want to (remember the verbose part?)

● The problem is tools to generate XSD files from XML are ▬ Not Free

▬ Rational application Developer▬ Altova XML Spy▬ Style Studio

▬ Not easily available/configurable

● So I wrote you one and put it in the download !▬ Based upon Apache XMLBeans ▬ Creates XSD Schema Documents from generated or static XML▬ Allows developers to set schema format

Page 27: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

XSD Schema Formats● There are three generally used XSD schema formats

▬ Russian Doll▬ Follows a cascading tree structure

▬ Salami Slice (Seriously. This is not a typo)▬ Based upon layers

▬ Venetian Blind▬ Combination of the first two

● Using our well formed Pizza XML document as the XML source

<?xml version="1.0" encoding="UTF-8" ?><!-- This is an XML Comment --><pizza attrib1="value1">

<pizzaStyle attrib2="value2">supreme</pizzaStyle></pizza>

Page 28: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

XSD – Russian Doll<?xml version="1.0" encoding="UTF-8"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="pizza"><xs:annotation>

<xs:documentation>This is an XML Comment</xs:documentation></xs:annotation><xs:complexType>

<xs:sequence><xs:element name="pizzaStyle">

<xs:complexType><xs:simpleContent>

<xs:extension base="xs:string"><xs:attribute type="xs:string" name="attrib2" />

</xs:extension></xs:simpleContent>

</xs:complexType></xs:element>

</xs:sequence><xs:attribute type="xs:string" name="attrib1" />

</xs:complexType></xs:element>

</xs:schema>

Page 29: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

XSD – Salami Slice<?xml version="1.0" encoding="UTF-8"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="pizza"><xs:annotation>

<xs:documentation>This is an XML Comment</xs:documentation></xs:annotation><xs:complexType>

<xs:sequence><xs:element ref="pizzaStyle" />

</xs:sequence><xs:attribute type="xs:string" name="attrib1" />

</xs:complexType></xs:element><xs:element name="pizzaStyle">

<xs:complexType><xs:simpleContent>

<xs:extension base="xs:string"><xs:attribute type="xs:string" name="attrib2" />

</xs:extension></xs:simpleContent>

</xs:complexType></xs:element>

</xs:schema>

Page 30: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

XSD – Venetian Blind<?xml version="1.0" encoding="UTF-8"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="pizza" type="pizzaType"><xs:annotation>

<xs:documentation>This is an XML Comment</xs:documentation></xs:annotation>

</xs:element><xs:complexType name="pizzaType">

<xs:sequence><xs:element type="pizzaStyleType" name="pizzaStyle" />

</xs:sequence><xs:attribute type="xs:string" name="attrib1" />

</xs:complexType><xs:complexType name="pizzaStyleType">

<xs:simpleContent><xs:extension base="xs:string">

<xs:attribute type="xs:string" name="attrib2" /></xs:extension>

</xs:simpleContent></xs:complexType>

</xs:schema>

Page 31: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

NameSpaces● Did you notice something different about the Schema XML?

● XML tags in an XML document can be combined from more than one vocabulary or Markup Language

● Namespaces prefixes are typically defined in the root tag of an XML document

▬ Tags defined in that markup language or vocabulary are then prefixed with that “Namespace”

● This is what allows tags from multiple markup languages to exist in the same XML document

<?xml version="1.0" encoding="UTF-8"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="pizza" type="pizzaType"><xs:annotation>

<xs:documentation>This is an XML Comment</xs:documentation></xs:annotation>

</xs:element>

Page 32: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Demo – Validating XML

Page 33: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

XML Stylesheet Language - XSL● What if I need an XML document in a different format than the one it is

currently in ?

● XSL – XML Stylesheet Language▬ XSLT – XSL Transformations▬ XPATH – Expressions used to traverse an XML document▬ XSL-FO – XSL Formatted Objects

Page 34: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Transforming XML

XMLDocument

XSLStylesheet

XSLTProcessing

Engine

TextDocument

XMLDocument

HTMLDocument

WMLDocument

?????Document

Page 35: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

XSLT Stylesheets● XSLT Stylesheets are

▬ Well-formed XML documents▬ A list of instructions (templates) that use XPATH notations that read the xml and output the

results

● Most systems that include an XML Parser also include XSL processing capabilities

● Transformation requires▬ XML Source Document▬ XSL Source Document▬ Output Document

Page 36: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

ExampleStylesheet● Transforms Pizza XML

into alternate XML

<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output indent="yes" /><xsl:template match="/">

<xsl:apply-templates select="pizza" /></xsl:template>

<xsl:template match="pizza"><xsl:element name="pizzaPie">

<xsl:apply-templates select="pizzaStyle" /><xsl:apply-templates select="toppings" />

</xsl:element></xsl:template>

<xsl:template match="pizzaStyle"><xsl:element name="typeOfPizza">

<xsl:value-of select="."></xsl:value-of></xsl:element>

</xsl:template>

<xsl:template match="toppings"><xsl:element name="ingredients">

<xsl:apply-templates select="topping" /></xsl:element>

</xsl:template>

<xsl:template match="topping"> <xsl:element name="ingredient">

<xsl:value-of select="." /> </xsl:element></xsl:template>

</xsl:stylesheet>

Page 37: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Transformations In Domino● There is a bug in 8.5.0 that throws a security error whenever any XSLT

transformation is done

● This Bug is Fixed in 8.5.1 !!!!!

Page 38: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Demo – Transforming XML

Page 39: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

39

Agenda● XML Overview

● XML Development in IBM Lotus Domino

● Web Services Overview

● Developing Web Service Providers

● Developing Web Service Consumers

● Q & A

Page 40: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

XML and Domino● XML capabilities of Notes/Domino ?

▬ Notes/Domino contains an XML Parser (Since Release 5.0.3)▬ Notes/Domino contains an XSLT processing engine

● Design Elements that can produce XML▬ Forms▬ Views▬ Pages▬ Agents

▬ LotusScript and Java▬ Servlets

▬ Java only

● Design Elements that can consume XML▬ Agents▬ Servlets

Page 41: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

XML and Domino● XPages

▬ XPages source code is formatted as a well-formed XML document▬ This source code is then used to compile the XPage that is then

served to the browser and Notes clients

Page 42: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

DXL – The Domino Markup Language● Domino design elements and data represented as XML

▬ Documents▬ Database▬ Forms▬ Views▬ Items▬ Agents

● DXL can be exported▬ From the Designer Client▬ By using code

▬ LotusScript and Java

● DXL can be imported▬ Only by using code

▬ LotusScript and Java

Page 43: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

LotusScript XML Classes● NotesXMLProcessor

▬ A base class that contains properties and methods common to all XML classes.

● NotesDOMParser▬ A class that parses XML into a standard DOM (Document Object Model) tree. Additional

NotesDOM classes allow you to work with DOM trees.

● NotesSAXParser▬ A class that processes XML as events using a SAX (Simple API for XML) parser.

● NotesXSLTransformer▬ A class that transforms XML through XSLT.

● NotesStream▬ A class for streaming XML to or from a memory buffer or file.

Page 44: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

LotusScript XML Classes (cont)● NotesDXLImporter

▬ A class that enables the import of domino data and design elements as DXL (Domino XML Language).

● NotesDXLExporter▬ A class that enables the export of domino data and design elements as DXL (Domino XML

Language).

● NotesNoteCollection▬ A class that builds subsets of Domino design and data elements for DXL exporting

Page 45: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Java XML Classes● There are not corresponding XML processing classes in the Domino

Java implementation

● There are XML parsers and XSLT transformation capabilities included in the SUN J2SE implementation that is part of the Core Notes/Domino Java API

▬ javax.xml.parsers▬ javax.xml.transform▬ javax.xml.transform.dom▬ javax.xml.transform.sax▬ javax.xml.transform.stream

Page 46: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Java XML Classes (cont)● There are two native Domino Classes

▬ DxlExporter▬ DxlImporter

● XML processing capabilities exist in some of the Domino core classes as properties and methods

▬ Document▬ EmbeddedObject▬ Item▬ MIMEEntity▬ RichTextItem

Page 47: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Demo – Producing XML from Domino

Page 48: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Demo – Consuming XML from Domino

Page 49: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

49

Agenda● XML Overview

● XML Development in IBM Lotus Domino

● Web Services Overview

● Developing Web Service Providers

● Developing Web Service Consumers

● Q & A

Page 50: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Web Services Overview● What are Web Services ?

▬ Request – Response architecture for communicating between two Systems▬ Should be “Loosely Coupled”

▬ Client and Server (Requestor / Responder) should not rely on one another

● Standards based▬ Any client on any platform should be able to access a Web service on any server

▬ Linux → Windows▬ Java → .NET▬ English → Russian

● No operating system or language dependencies

● No need for proprietary drivers

Page 51: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Web Services components ● XML

▬ Lingua Franca of Web Services▬ Web Service Requests and Responses all formatted using XML

● SOAP – Simple Object Access Protocol▬ Specific Format of Web Service Requests and Responses

● WSDL – Web Services Description Language▬ XML documents that describe a web services functionality

● UDDI – Universal Description, Discovery and Integration

Page 52: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

SOAP● Simple Object Access Protocol

▬ An XML based protocol for information exchange in decentralized and distributed environments▬ Co-developed by

▬ IBM and Microsoft (now that’s collaboration!)

● Send XML data formatted as a SOAP message TO the Web service▬ Message is “parsed” to read the request

▬ Data for one of the defined service methods

● Receive XML data formatted as a SOAP message FROM the Web service

▬ Message is “parsed” to read the response▬ Data that provides the information that fulfills the service request▬ Or an error message

Page 53: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

SOAP Versions● You need to send and receive messages based upon a common SOAP

version▬ Version 1.1▬ Version 1.2

● Specification maintained at the W3C▬ http://www.w3.org/TR/soap

Page 54: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

SOAP – Version 1.1 Request

<SOAP-ENV:Envelope  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"  SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>   <SOAP-ENV:Body>       <m:GetLastTradePriceDetailed         xmlns:m="Some-URI">           <Symbol>DEF</Symbol>           <Company>DEF Corp</Company>           <Price>34.1</Price>       </m:GetLastTradePriceDetailed>   </SOAP-ENV:Body></SOAP-ENV:Envelope>

Page 55: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

SOAP – Version 1.1 Response <SOAP-ENV:Envelope … same ns as request> <SOAP-ENV:Body> <m:GetLastTradePriceResponse xmlns:m="Some-URI"> <PriceAndVolume> <LastTradePrice>34.5 </LastTradePrice> <DayVolume>10000 </DayVolume> </PriceAndVolume> </m:GetLastTradePriceResponse> </SOAP-ENV:Body></SOAP-ENV:Envelope>

Page 56: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

SOAP – Version 1.2 Request

<?xml version='1.0' ?><env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"> <env:Header> <test:echoOk xmlns:test=http://example.org/ts-tests

env:role="http://www.w3.org/2003/05/soap-envelope/role/next"> foo </test:echoOk> </env:Header> <env:Body> </env:Body></env:Envelope>

Page 57: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

SOAP – Version 1.2 Response

<?xml version='1.0' ?><env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"> <env:Header> <test:responseOk xmlns:test="http://example.org/ts-tests"> foo </test:responseOk> </env:Header> <env:Body> </env:Body></env:Envelope>

Page 58: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Is it necessary to know all that syntax?● Yes !

▬ If you don’t know the syntax (or at least how to read the reference) then you can’t▬ Troubleshoot ill-formed SOAP envelopes▬ Parse the SOAP packet to get to the data easily

● And no▬ Most Web services development platforms / toolkits produce the SOAP envelopes for you▬ The SOAP request envelopes are produced dynamically by your code▬ SOAP responses can be parsed with any XML parser

Page 59: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Web Services Description / Definition language● An XML-formatted language used to

▬ Describe a Web service's capabilities as collections of communication endpoints capable of exchanging messages

▬ WSDL describes the public interface to the Web service▬ These are the methods that get invoked

▬ This is an XML-based service description on how to communicate using the Web service▬ A description of the services provided by a Web service

▬ Method names, Return data types▬ Written in XML syntax as an XML document

● Seems to be some confusion about what the “D” stands for▬ Description/Definition▬ Don’t worry about it, it's all the same thing

Page 60: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Example WSDL Document<?xml version="1.0"?><definitions name="StockQuote"

targetNamespace="http://example.com/stockquote/definitions" xmlns:tns="http://example.com/stockquote/definitions" xmlns:xsd1="http://example.com/stockquote/schemas" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns="http://schemas.xmlsoap.org/wsdl/"> <import namespace="http://example.com/stockquote/schemas" location="http://example.com/stockquote/stockquote.xsd"/> <message name="GetLastTradePriceInput"> <part name="body" element="xsd1:TradePriceRequest"/> </message> <message name="GetLastTradePriceOutput"> <part name="body" element="xsd1:TradePrice"/> </message> <portType name="StockQuotePortType"> <operation name="GetLastTradePrice"> <input message="tns:GetLastTradePriceInput"/> <output message="tns:GetLastTradePriceOutput"/> </operation> </portType></definitions>

Page 61: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

UDDI● Universal description, discovery, and integration

▬ A platform-independent, XML-based registry for businesses worldwide to list themselves on the Internet

▬ UDDI is an open industry initiative (sponsored by OASIS) enabling businesses to discover each other and define how they interact over the Internet

● The UDDI authors had a vision of a world in which consumers of Web Services would be linked up with providers through a dynamic brokerage system

▬ Anyone needing a service would go to a broker and select one ▬ This vision has not come to pass

▬ Instead, services write custom service endpoints with custom WSDL descriptions▬ Consumers then hard-code the URLs to their SOAP endpoints, working only with specific

systems ▬ The most common place that a UDDI system can be found is inside a company where it is used

to dynamically bind client systems to implementations

Page 62: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Web Service Architecture

Page 63: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

63

Agenda● XML Overview

● XML Development in IBM Lotus Domino

● Web Services Overview

● Developing Web Service Providers

● Developing Web Service Consumers

● Q & A

Page 64: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Web Service Provider Support● Server based Web Services were introduced in Domino 7

▬ Enhanced in Domino 8

● WSDL▬ Version 1.1

● SOAP▬ Version 1.1

● The Apache Axis engine is used for web service processing▬ AXIS 1 (Version 1.4)

● The Web service design element is similar to an agent

● Can be coded in ▬ Java▬ LotusScript

Page 65: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Compatibility● Web Services created on a Domino 7 server can be ported AS-IS to a

Domino 8.x Server▬ In other words, copy the database from Server A (Dom Version 7.x) to Server B(Dom Version 8.x)

and don't open it in the designer client

● These services will continue to execute on the Domino 7.x AND 8.x environments

▬ For example during a conversion from 7.x to 8.x and you are replicating between 7 and 8 servers

● As soon as the Web Service is opened AND saved in a version 8 designer client

▬ The Web Service will no longer execute on a Domino 7.x server only Domino 8.x▬ A HUGE warning will be displayed and you will have to accept it

▬ Don't say we didn't tell you !!

Page 66: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Creating Web Service Providers● In the Domino Designer Client

▬ Expand Code | Web Service Providers▬ Click the New Web Service Provider Action in the Action bar▬ Provide a Name / Alias / Comment and choose the Programming Language Type

▬ This can not be changed to a different type after the Web Service is Created

Page 67: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

The editor that loads is based upon the language type selected● LotusScript

Page 68: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

The editor that loads is based upon the language type selected (cont)● Java

Page 69: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Web Service Properties - Basics● Name

▬ Required

● Alias and Comment

● Warn if the WSDL interface is modified▬ Will not let you save a Web service if you add code that changes the WSDL

● Port Type class▬ Class in Declarations that contains the publicly “exposed” methods

● Any other classes will not be available (unless they are complex types)

Page 70: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Web Service Properties - Security● These are identical to the agent security properties

● Web service security respects normal Notes ACL security including:

● Basic or session-based authentication

● Run-time privileges

● Allow public access use

● HTTP error 401 is returned requestor is not authorized to use the Web Service

Page 71: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Web Service Properties - Advanced● Programming model

▬ Almost always RPC▬ “Message” is XML document based

● SOAP Message format▬ More information in the next slide

● Include operation name in SOAP action▬ Usually optional▬ Checked by default

● Port type and service names▬ Generated automatically on Web Service Save

Page 72: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

SOAP message format● Affects WSDL format, which affects SOAP message format

▬ Doesn’t affect your how you write your code in either language▬ Some clients (Like .NET) are pickier about the format▬ RPC - Document/literal is emerging as the defacto standard

● Notes 8.x default is ▬ RPC – Document/Literal

● Notes 7 default is▬ RPC – Encoded

● See the following URL for a detailed discussion▬ http://www.ibm.com/developerworks/webservices/library/ws-whichwsdl/

Page 73: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Coding a LotusScript WS Provider● STOP !!!!!!!

● This is an excellent time to consider adding Java to your programming toolbox

● Unless you are calling existing libraries that contain LotusScript Code then start your Web Services adventure using Java

Page 74: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Coding LotusScript Web Service Provider● For those I didn't convince to try Java, here are the LotusScript

procedures

● LotusScript Web Service Provider Editor is still “old” LotusScript Editor

● All code should go in the Declarations Event▬ All code should be in a single class definition▬ Declare variables to be used ▬ Create a SUB to instantiate the variables▬ Create 1 to “N” public functions

▬ Functions can optionally take an input▬ Majority return a value

Page 75: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Skeleton LotusScript Web Service code

Class WSClassNameREM Declare Variables here

Sub NewREM Instantiate Variables hereREM At least the Session object

End Sub

Public Function functionName(varName As String) As String

REM Code logic goes here

End Function

End Class

Page 76: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Simple LotusScript Web ServiceClass WSDemo6WebService

session As NotesSessiondb As Notesdatabaseview As NotesView

Sub NewSet session = New NotesSessionSet db = session.GetDatabase("","Names.nsf")Dim doc As NotesDocumentIf db.IsOpen Then

Set view = db.GetView("($NamesFieldLookup)")End If

End Sub

Public Function getEmailAddress(UserName As String) As StringDim EmailAddress As String

Set doc = view.getDocumentByKey(UserName)If doc Is Nothing Then

EmailAddress = "No Name Found"Else

EmailAddress = doc.InternetAddress(0)End If

getEmailAddress = EmailAddress

End Function

End Class

Page 77: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

More Complex Web Services● Web Service input parameters can be

▬ Nothing▬ Strings▬ Arrays▬ Classes

● Web Services can return▬ Nothing (Although you should at least check the return code)▬ Strings▬ Arrays▬ Classes

Page 78: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Demo – LotusScript WS Providers

Page 79: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Coding Java Web Service Providers● Code Editor uses new Eclipse Java Editor Interface

● All code should be in a single class definition▬ Declare variables to be used ▬ Use the class constructor to instantiate the variables

● Create 1 to “N” public methods▬ Methods can optionally take input▬ Majority return a value

Page 80: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Skeleton Code – Java WS Providerimport lotus.domino.*;public class WSClassName {

//Declare Variables here

public WSClassName() throws NotesException {//Instantiate Variables here

}

public String methodName(String varName) {try {

//Method Logic Here

} catch (NotesException e) {e.printStackTrace();

} catch (Exception e){e.printStackTrace();

}return DataTypeValue;

}}

Page 81: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Simple Java Web Servicepublic class mywcjavaws {

private Session session;private Database db;private View vw;private Document doc;

public mywcjavaws() throws NotesException {session = WebServiceBase.getCurrentSession();// ac = session.getAgentContext();db = session.getDatabase("", "Names.nsf");vw = db.getView("($NamesFieldLookup)"); }

public String getEmailAddress(String UserName) {String EmailAddress = "";try {

doc = vw.getDocumentByKey(UserName);if (doc == null) {

EmailAddress = "No Name Found";} else {

EmailAddress = doc.getItemValueString("InternetAddress");if(EmailAddress.equalsIgnoreCase("")){

EmailAddress = "Email Address Field is Blank";} }

} catch (NotesException e) {e.printStackTrace();

} catch (Exception e){e.printStackTrace();

}return EmailAddress; } }

Page 82: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

More Complex Web Services● Web Service input parameters can be

▬ Nothing▬ Strings▬ Arrays▬ Classes

● Web Services can return▬ Nothing (Although you should at least check the return code)▬ Strings▬ Arrays▬ Classes

Page 83: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Demo – Java WS Providers

Page 84: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Testing Web Services● Web Services can be tested without manually creating client code

● Why test the Web Service before creating the client consumer?▬ Ensures the Web Service is working properly▬ Allows for providing input to the Web Service without writing any test code▬ Allows you to see the results returned by the Web Service▬ Allows you to focus on your client code

● If coding your own Web Service client (for example, if you are still using Domino 6.x or 7.x) testing allows you to

▬ Examine the exact SOAP that needs to be sent to the service▬ Examine the exact SOAP that will be returned from the service

Page 85: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Web Service Testing Tools● There are several tools available that will test Web Services without

creating any client code

● Free tools▬ Eclipse

▬ Any 3.x version with the Web Tools Plug-in (WTP) loaded▬ Latest version is part of the Galileo project (ver 3.5)

▬ soapUI▬ Not as feature rich as Eclipse

● Not so free tools▬ Rational Application Developer▬ Visual Studio .NET

● You can also Google “Web Service Test Client” to search for available test clients

Page 86: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Eclipse Web Service Explorer● Includes a Web Service Test client

▬ Built on the fly from the referenced WSDL

● You can test any accessible Web Service, not just Domino Web Services

▬ Via URL or local project file

● It does not require you to create any project code

● Includes wizards to generate Java based Web Service Client code▬ In non 8.5.1 environments this is an excellent time saver for generating and testing web service

clients prior to incorporating them into Domino

Page 87: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Using the Eclipse Web Service Explorer● We’ll use the Eclipse Web Services Explorer test client

● From either the Web or JavaEE perspective

● From the “Run” menu ▬ Launch the Web Services Explorer

Page 88: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Using the Eclipse Web Service Explorer● The Web Services Explorer simply needs the URI of a Web Service

Definition Language (WSDL) document

● The WSDL will be parsed and a test client created “on-the-fly”

Page 89: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Using the Eclipse Web Service Explorer● Once the WSDL file is parsed, the Public methods of the Web Service

are available as links▬ Click a link in the “Navigator” view ▬ The Actions view will open where

inputs can be provided if required▬ Click the “GO” button to

invoke the Web ▬ Service Results will be displayed

in the Status View at the bottom of the WS Explorer

Page 90: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Using the Eclipse Web Service Explorer● In the Status View source you can review the SOAP Request/Response

envelopes

● Click the “Source” link in the Status View to display the Soap Envelops

● Click the “Form” link to return to the previous view

Page 91: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Demo – Testing Domino Web Services

Page 92: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

92

Agenda● XML Overview

● XML Development in IBM Lotus Domino

● Web Services Overview

● Developing Web Service Providers

● Developing Web Service Consumers

● Q & A

Page 93: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Consuming Web Services● The ability to consume Web Services in Domino is new to release 8.0

● In 8.0.x▬ Web Service clients are implemented as script libraries

▬ Can be coded in either LotusScript or Java▬ Script libraries can then be called from agents or events

● In 8.5▬ Web Service clients are implemented via the Web Service Consumer interface

▬ Can be coded in either LotusScript or Java▬ Can be called from agents or events

● Only resource required to create web service client code is the Web Services WSDL

▬ In File format▬ Via URI

● There is no “out of the box” solution for consuming Web Services in any prior release

Page 94: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Consuming Web Services in ND 6.x and 7.x● The Web Service must be created using regular agents

● There is no “Native” or out-of-the-box solution for creating LotusScript Web Service clients

▬ Although there are third-party COM objects available

● The core Java packages contain all the needed classes to implement a Web Services client

▬ Client code is most easily created using a Java IDE (like Eclipse)▬ In the Web Service Explorer there is a built-in wizard for creating Web Service client code▬ See resources at end for example locations

Page 95: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Consuming Web Services in ND 8.0.x● In ND 8.0.x Web Service clients are created as script libraries

▬ LotusScript▬ Java

● Create a new Script Library▬ Click the WSDL button at the bottom

of the designer

Page 96: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Consuming Web Services in ND 8.5.x● In Domino Designer

▬ Expand Code▬ Select Web Service Consumers▬ Click New Web Service Consumer

Page 97: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Consuming Web Services in ND 8.5.x● Name

▬ Provide a descriptive name for what this web service consumes/returns

● Comment▬ More descriptive info on what is being consumed

● Get Web service description from▬ Local WSDL File

▬ File stored on file system▬ URL that points to WSDL file

▬ A valid URL that returns the WSDL

● In 8.5.0 reading a WSDL from URL does not work

BestPractice

Page 98: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Consuming Web Services● If the WSDL file is imported from a file that has been exported from a

Domino Web Service▬ The “Service End Point” will need to be edited to the actual URI BEFORE referencing it from the

Web Service Consumer▬ Domino Defaults the Service End Point to “LocalHost”

<wsdl:service name="WSDemo1Service"> <wsdl:port binding="intf:DominoSoapBinding" name="Domino">

<wsdlsoap:address location="http://localhost"/></wsdl:port>

</wsdl:service>

<wsdl:service name="WSDemo1Service"> <wsdl:port binding="intf:DominoSoapBinding" name="Domino">

<wsdlsoap:address location="http://host/path/wsdlurl"/></wsdl:port>

</wsdl:service>

Page 99: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Consuming Web Services● If the WSDL file was imported from a URI

▬ Either Domino or Non-Domino▬ Then no changes should need to be made to the imported code as the correct Service End Point

is already included

Page 100: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

LotusScript Imported Code Structure ● If importing into a LotusScript WS consumer, a class will be created in

the Declarations Event

● The class will have: ▬ A SUB that implements Web Service using the Service End Point▬ One to “N” defined functions that will be called in your agent code

Page 101: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Java Imported Code Structure● If importing into a Java WS Consumer, several classes will be created

● The Service End Point is located in the WSNAMEServiceLocator.java source file

● Sample code on how to implement the Web Service is located in the WSNAMEService class

Page 102: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Web Service Consumers● Once the Web Service is saved, it will be listed in the Web Service

Consumers designer view

● Actions▬ The Sign Action can be used to sign the Web Service without opening it and saving it.▬ Export WSDL – Export the WSDL to the local file structure▬ Show WSDL – Display WSDL in browser

Page 103: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Consuming Domino Web Services● If consuming external Web Services

▬ Web Services not being hosted on the same Domino server as the Web Service client▬ No changes will need to be made to the Notes/Domino configuration

● If consuming local Domino Web Service (Web Service is hosted on the same Domino Server as the Web Service Consumer and client)

▬ Changes will need to be made to the Domino Configuration Server Document▬ Internet Protocols > Domino Web Engine

▬ Web Agents and Web Services▬ Enable to run concurrently

▬ In Version 7.x and 8.0.x, If this is not done then the HTTP task will lock up in a race condition that will never terminate causing the server to have to be shut down by killing the Server process at the O/S level

Page 104: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Creating Web Service Consumers● The process for creating Web Service Consumers is always the same

● Create the Web Service Consumer

● – LotusScript

● – Java

● Use that Web Service Consumer in an Agent or supported event▬ Agents

▬ LotusScript▬ Java

▬ Supported Events▬ LotusScript

Page 105: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Demo – Creating Web Service Consumers

Page 106: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Including Web Service Consumers in LotusScript Agents and Events● Once the Web Service Consumer code has been created, Agents or

supported events can be created that use that code

● The steps to implement the Web Service are:▬ USE the Web Service Library Name in the “Options” event

▬ Use “WebServiceLibraryName”▬ In the action event, initialize an instance of the class defined in the Web Service Library

▬ Dim WSVar As New WSLibraryName▬ Call the methods of the Web Service

▬ WSVar.FunctionName(OptionalParameter)▬ Use the returned value in your code

Page 107: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

LotusScript Agent calling WS Consumer

Option PublicOption DeclareUse "LSReturnEmailAddress"

Sub Initialize()Dim ws As New SlswsDim emailaddress As String, username As String, msgtext As Stringusername = "Mary"emailaddress = ws.Getemailaddress(username)msgtext = msgtext +username +"'s Mail address is - " + emailaddress MsgBox msgtext,0,"Email Address"Exit Sub

End Sub

Page 108: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Calling Multiple Methods with Error Handling

Option PublicOption DeclareUse "LSImplementTwoMethods"

Sub Initialize()

On Error 4746 GoTo errhandleDim ws As New SlswstwomethodsDim emailaddress As String, mailserver As String, username As StringDim msgtext As String, CRLF As Stringusername = "Mary"CRLF = Chr(10) & Chr(13)emailaddress = ws.getEmailAddress(username)mailserver = ws.getMailServer(username)msgtext = msgtext +username +"'s Mail address is - " + emailaddress + CRLFmsgtext = msgtext +username +"'s Mail Server is - " + mailserver + CRLFMsgBox msgtext,0,"Directory Information"Exit Sub

errhandle:MsgBox "The Web Services host can not be found."Exit Sub

End Sub

Page 109: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Consuming Complex Web Services● Web Services are not limited to returning single text or numeric values

● Web Services can return complex data types, such as:▬ Classes▬ Arrays▬ Vectors▬ XML data

Page 110: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Consuming Complex Web Services● The following is the generated Web Service Consumer code generated

when consuming a web service that uses a classClass DIRINFO As XSD_ANYTYPE

Public INTERNETADDRESS As StringPublic MAILSERVER As StringPublic MAILFILE As StringPublic MAILDOMAIN As String

Sub NEWEnd Sub

End Class

Class Clswsusingclass As PortTypeBase

Sub NEWCall Service.Initialize ("UrnDefaultNamespaceclswsusingclassService", _"clswsusingclassService.Domino", "http://nnsuportal:80/JMP105.nsf/clswsusingclass?OpenWebService", _"Clswsusingclass")

End Sub

Function GETDIRINFO(USERNAME As String) As DIRINFOSet GETDIRINFO = Service.Invoke("GETDIRINFO", USERNAME)

End Function

End Class

Page 111: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Consuming Complex Web Services● The following Web Service client implements the Web Service and a

corresponding class object “DirInfo”Option PublicOption DeclareUse "LSDirInfoViaClass"

Sub Initialize()

On Error 4746 GoTo errhandleDim ws As New ClswsusingclassDim DirectoryInfo As DirInfoDim username As String, msgtext As String, CRLF As Stringusername = "Mary"Set DirectoryInfo = ws.getDirInfo(username)CRLF = Chr(10) & Chr(13)msgtext = msgtext +username +"'s Mail address is - " + DirectoryInfo.INTERNETADDRESS + CRLFmsgtext = msgtext +username +"'s Mail Server is - " + DirectoryInfo.MAILSERVER + CRLFmsgtext = msgtext +username +"'s Mail File is - " + DirectoryInfo.MAILFILE + CRLFmsgtext = msgtext +username +"'s Mail Domain is - " + DirectoryInfo.MAILDOMAIN + CRLFMsgBox msgtext,0,"Directory Information"Exit Sub

errhandle:MsgBox "The Web Services host can not be found."Exit Sub

End Sub

Page 112: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Web Query Save using Web Services● The Agent code that implements the Web Service client can be

incorporated into a form’s WebQuerySave event to provide Web Service parameters and process the Web Service results

Option PublicUse "LSReturnEmailAddress"

Sub InitializeOn Error 4746 Goto errhandleDim s As New NotesSessionDim ws As New SlswsDim emailaddress As String, username As StringDim doc As NotesDocumentSet doc=s.DocumentContext

username = doc.UserName(0)emailaddress = ws.getEmailAddress(username)

Print | <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'> |Print | <html><head><meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-1'> |Print | <title>Web Query Save Example</title></head><body> |Print | <h1>Web Query Save Example</h1> |Print | <br /><br /> |Print | <h2>The users email address is : | emailaddress | </h2> |

Exit Suberrhandle:

Msgbox "The Web Services host can not be found."Exit Sub

End Sub

Page 113: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Error Handling in LotusScript● There are specific errors defined in the LSXBEERR.LSS file that are

specific to Web Services▬ Public Const lsERR_NOTES_WSENGINE_UNINIT_METHOD_ARG = 4743 ▬ Public Const lsERR_NOTES_WSENGINE_NOTINIT = 4744 ▬ Public Const lsERR_NOTES_WSENGINE_ERROR = 4745 ▬ Public Const lsERR_NOTES_WSENGINE_METHOD_ERROR = 4746 ▬ Public Const lsERR_NOTES_WSENGINE_METHOD_FAULT = 4747

● By using a class defined in the LSXSD.LSS, these errors can be trapped

● Use the wsfault class to trap for errorserrhandle:

Set wsfault = ws.getlastfault()If wsfault.getfault() Then

Msgbox "There was a fault in the web service, error message is: " & Chr(13) & wsfault.getFaultString()

ElseMsgbox Error$Msgbox Err

End If

Exit Sub

Page 114: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Passing Credentials to Web Services in LotusScript● Call the “setcredentials” method of the Web Service class

● Pass User ID and Password Values as parameters

Option PublicOption DeclareUse "LSReturnEmailAddress"

Sub Initialize()Dim ws As New Slsws

Call ws.setcredentials("Paul Calhoun", "password")

Dim emailaddress As String, username As String, msgtext As Stringusername = "Mary"emailaddress = ws.Getemailaddress(username)msgtext = msgtext +username +"'s Mail address is - " + emailaddress MsgBox msgtext,0,"Email Address"Exit Sub

End Sub

Page 115: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Demo – LotusScript Web Service Clients

Page 116: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Including Web Service Consumers in Java Agents● The steps to implement the Web Service Consumer in a Java Agent are:

▬ Click the “Import” button in the Java Agent Project Manager and choose “Web Service Consumer”▬ In the opened Dialog Box choose Web Service to include in Agent and click “Import”

Page 117: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Java Agent Calling Web Service Consumer● In the Code editor:

▬ Instantiate an Instance of the Service Locator class using the code sample from the Web Service Script Library

▬ Call the public methods of the class that returns the Web Service content

import lotus.domino.*;

public class JavaAgent extends AgentBase {

public void NotesMain() {

try {

SimpleJavaWebService stub = new SimpleJavaWebServiceServiceLocator().getDomino();

System.out.println(stub.getEmailAddress("Mary"));

} catch(Exception e) { e.printStackTrace(); } }}

Page 118: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Consuming Web Services● Java Agents can consume the same complex Web Services that

LotusScript can

● Java Agents that consume web services can also be called from a forms web query save agent

Page 119: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Error Handling in Java WS Agents● In Java Web Service clients, the Error handling is taken care of by the

default behavior of using the Try-Catch-Finally block structure

import lotus.domino.*;

public class JavaAgent extends AgentBase {

public void NotesMain() {

try {

SimpleJavaWebService stub = new SimpleJavaWebServiceServiceLocator().getDomino();

System.out.println(stub.getEmailAddress("Mary"));

} catch(Exception e) { e.printStackTrace(); } }}

Page 120: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Passing Credentials to Web Services in Java● In the generated DominoSoapBindingStub class in the Web Service

Consumer▬ Add two lines to the public method that implements _call▬ Pass in the User ID and Password ▬ Works in 8.0.x and 8.5.x

public class DominoSoapBindingStub extends lotus.domino.websvc.client.Stub implements SimpleJavaWebService {

public DominoSoapBindingStub(java.net.URL endpointURL, javax.xml.rpc.Service service) throws lotus.domino.types.Fault { super(endpointURL, service); }

public java.lang.String getEmailAddress(java.lang.String in0) throws java.rmi.RemoteException { lotus.domino.websvc.client.Call _call = createCall("getEmailAddress"); //The following two lines were added to implement authentication _call.setUsername("Paul"); _call.setPassword("password"); //End of additional code java.lang.Object _resp = _call.invoke(new java.lang.Object[] {in0}); return (java.lang.String) _call.convert(_resp, java.lang.String.class); }

}

Page 121: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Passing Credentials to Web Services in Java● In the Agent that consumes the Web Service

▬ Call the “setCredentials” method of the stub class▬ Pass in the User ID and Password ▬ Works in Version 8.5.1

SimpleJavaWebServiceRPC stub = new SimpleJavaWebServiceRPCServiceLocator().getDomino(); stub.setCredentials("Mary Smith","password");

Page 122: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Capturing SOAP Request and Response● In the generated DominoSoapBindingStub class in the Web Service

Consumer▬ Add the following code to the public method that implements _call▬ Write the output to the console or capture in a Log file▬ Use this procedure during DEVELOPMENT only. Disable once Web Service goes in production

import java.io.ByteArrayOutputStream;import java.io.IOException;

import javax.xml.soap.SOAPException;import javax.xml.soap.SOAPMessage;

try {SOAPMessage soapReq = _call.getMessageContext().getRequestMessage();SOAPMessage soapRes = _call.getMessageContext().getResponseMessage();ByteArrayOutputStream reqOut = new ByteArrayOutputStream();ByteArrayOutputStream resOut = new ByteArrayOutputStream();

soapReq.writeTo(reqOut);soapRes.writeTo(resOut);System.out.println("****SOAP Request Envelope*****");System.out.println(reqOut.toString());System.out.println();System.out.println("****SOAP Response Envelope*****");System.out.println(resOut.toString());

} catch (SOAPException e) {e.printStackTrace();

} catch (IOException e) {e.printStackTrace();}}}

BestPractice

Page 123: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Demo – Java Web Service Clients

Page 124: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Calling Web Services from an XPage● Web Services can be called from an XPage by adding code that

implements an Apache Axis client

● The following code in the value property of a computed control will invoke the Simple Java Web Service

● This code does NOT work when calling Document/Literal based web services

var nameval = getComponent("PerName").getValue();var wsc = new org.apache.axis.client.Service; var call = wsc.createCall(); call.setTargetEndpointAddress("http://localhost/jmp207.nsf/sjws?WSDL"); call.setOperationName("getEmailAddress"); var xmlType = new javax.xml.rpc.encoding.XMLType(); call.addParameter("INPUT1", xmlType.XSD_STRING, javax.xml.rpc.ParameterMode.IN); call.setReturnType(xmlType.XSD_STRING); var a = new java.lang.Object[1]; a[0] = nameval; var retname = call.invoke(a); return retname;

Page 125: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

What you learned !!!● XML is ALL ABOUT THE DATA !!!!!!

● Remember to stay well-formed and optionally valid

● If you don't like the format your XML is in TRANSFORM it

● Serving up Domino content via Web Services increases the visibility of Domino in your world and others

● Domino can consume any Web Service accessible on the wire▬ As a Web Service Consumer▬ As an Agent

Page 126: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Resources● Learn XML and Web Services in your Notes Client

▬ http://www.tlcc.com▬ Go by their booth number 626 in the exhibit hall and get a demo▬ Courses available for versions 7 and 8▬ The 8.5.1 course will be available in the 1st Quarter

● For information on creating Web Service Clients in all pre 8 releases go to my web site

▬ http://www.nnsu.com▬ In the downloads area, download the slides from Lotusphere 2007 and 2008

● SOAP message format technical reference on IBM developerWorks▬ Russel Butek, “Which style of WSDL should I use?”▬ www.ibm.com/developerworks/webservices/library/ws-whichwsdl/=

● Testing tools▬ Eclipse — www.eclipse.org▬ SoapUI — www.soapui.org

Page 127: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Resources● All of the following can be downloaded at my website

▬ Slides▬ JMP105.nsf (XML Test harness and XSD Schema Generator)▬ XSLT to transform Domino Forms to Xpages

● Click on the downloads link

● All items will be available the Monday AFTER Lotusphere

http://www.nnsu.com

Page 128: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

Resources● W3 Schools – Tutorials on XML and Web Services

▬ http://www.w3schools.com/

● W3 Organization – All specification Documents▬ http://www.w3.org

● Developer Works – XML and Web Services Zones▬ http://www.ibm.com/developerworks/webservices/▬ http://www.ibm.com/developerworks/xml/

● ZVON Organization – XSLT and XPath Testing tools▬ http://www.zvon.org/

● Eclipse Organization – Web Service Explorer▬ http://www.eclipse.org

● XMethods Organization – Sample Web Services for Testing▬ http://www.xmethods.org/

Page 129: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

129

Agenda● XML Overview

● XML Development in IBM Lotus Domino

● Web Services Overview

● Developing Web Service Providers

● Developing Web Service Consumers

● Q & A

Page 130: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

130

Friendly Reminder● Please remember to fill out you evaluations and drop at the back of the

room

● THANKS !!!!!!

Page 131: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

131

Questions and Answers

Contact me at:

Email: [email protected]

I am available for Consulting and Mentoring on Domino,Java, Web Services and XPages !!!!!

Page 132: JMP 105 – XML and Web Services Jumpstart Paul T. Calhoun | Chief Technology Officer

132

Legal Disclaimer© IBM Corporation 2009. All Rights Reserved.

The information contained in this publication is provided for informational purposes only. While efforts were made to verify the completeness and accuracy of the information contained in this publication, it is provided AS IS without warranty of any kind, express or implied. In addition, this information is based on IBM’s current product plans and strategy, which are subject to change by IBM without notice. IBM shall not be responsible for any damages arising out of the use of, or otherwise related to, this publication or any other materials. Nothing contained in this publication is intended to, nor shall have the effect of, creating any warranties or representations from IBM or its suppliers or licensors, or altering the terms and conditions of the applicable license agreement governing the use of IBM software.

References in this presentation to IBM products, programs, or services do not imply that they will be available in all countries in which IBM operates. Product release dates and/or capabilities referenced in this presentation may change at any time at IBM’s sole discretion based on market opportunities or other factors, and are not intended to be a commitment to future product or feature availability in any way. Nothing contained in these materials is intended to, nor shall have the effect of, stating or implying that any activities undertaken by you will result in any specific sales, revenue growth or other results.

If the text contains performance statistics or references to benchmarks, insert the following language; otherwise delete:

Performance is based on measurements and projections using standard IBM benchmarks in a controlled environment. The actual throughput or performance that any user will experience will vary depending upon many factors, including considerations such as the amount of multiprogramming in the user's job stream, the I/O configuration, the storage configuration, and the workload processed. Therefore, no assurance can be given that an individual user will achieve results similar to those stated here.

If the text includes any customer examples, please confirm we have prior written approval from such customer and insert the following language; otherwise delete:

All customer examples described are presented as illustrations of how those customers have used IBM products and the results they may have achieved. Actual environmental costs and performance characteristics may vary by customer.

Please review text for proper trademark attribution of IBM products. At first use, each product name must be the full name and include appropriate trademark symbols (e.g., IBM Lotus® Sametime® Unyte™). Subsequent references can drop “IBM” but should include the proper branding (e.g., Lotus Sametime Gateway, or WebSphere Application Server). Please refer to http://www.ibm.com/legal/copytrade.shtml for guidance on which trademarks require the ® or ™ symbol. Do not use abbreviations for IBM product names in your presentation. All product names must be used as adjectives rather than nouns. Please list all of the trademarks that you use in your presentation as follows; delete any not included in your presentation.

IBM, the IBM logo, Lotus, Lotus Notes, Notes, Domino, Quickr, Sametime, WebSphere, UC2, PartnerWorld and Lotusphere are trademarks of International Business Machines Corporation in the United States, other countries, or both. Unyte is a trademark of WebDialogs, Inc., in the United States, other countries, or both.

If you reference Adobe® in the text, please mark the first use and include the following; otherwise delete:

Adobe, the Adobe logo, PostScript, and the PostScript logo are either registered trademarks or trademarks of Adobe Systems Incorporated in the United States, and/or other countries.

If you reference Java™ in the text, please mark the first use and include the following; otherwise delete:

Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. in the United States, other countries, or both.

If you reference Microsoft® and/or Windows® in the text, please mark the first use and include the following, as applicable; otherwise delete:

Microsoft and Windows are trademarks of Microsoft Corporation in the United States, other countries, or both.

If you reference Intel® and/or any of the following Intel products in the text, please mark the first use and include those that you use as follows; otherwise delete:

Intel, Intel Centrino, Celeron, Intel Xeon, Intel SpeedStep, Itanium, and Pentium are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

If you reference UNIX® in the text, please mark the first use and include the following; otherwise delete:

UNIX is a registered trademark of The Open Group in the United States and other countries.

If you reference Linux® in your presentation, please mark the first use and include the following; otherwise delete:

Linux is a registered trademark of Linus Torvalds in the United States, other countries, or both.

Other company, product, or service names may be trademarks or service marks of others.

If the text/graphics include screenshots, no actual IBM employee names may be used (even your own), if your screenshots include fictitious company names (e.g., Renovations, Zeta Bank, Acme) please update and insert the following; otherwise delete:

All references to [insert fictitious company name] refer to a fictitious company and are used for illustration purposes only.