ID 352 An XML / Power B uilder Messaging System

69
ID 352 An XML / PowerBuilder Messaging System Paul Donohue Technical Architect JP Morgan (London) [email protected]

description

ID 352 An XML / Power B uilder Messaging System. Paul Donohue Technical Architect JP Morgan (London) [email protected]. Overview. Topics we will cover. The AutoTrade System Overview of XML PowerBuilder and XML PowerBuilder and NT Services Summary Questions. - PowerPoint PPT Presentation

Transcript of ID 352 An XML / Power B uilder Messaging System

Page 1: ID 352 An  XML / Power B uilder Messaging System

ID 352An XML / PowerBuilder Messaging System

• Paul Donohue• Technical Architect• JP Morgan (London)• [email protected]

Page 2: ID 352 An  XML / Power B uilder Messaging System

Overview

• The AutoTrade System

• Overview of XML

• PowerBuilder and XML

• PowerBuilder and NT Services

• Summary

• Questions

Topics we will cover

Page 3: ID 352 An  XML / Power B uilder Messaging System

The AutoTrade System

Page 4: ID 352 An  XML / Power B uilder Messaging System

The AutoTrade System

• Deals were sent by phone or fax

• Systems did not communicate

• Data was entered many times

• Delays were common

Bond trading in England was old fashioned

Page 5: ID 352 An  XML / Power B uilder Messaging System

The AutoTrade System

A multi-bank working group investigated possible

solutions and chose IssueLink from a vendor called

CapitalNET.

JP Morgan developed the AutoTrade suite of programs to interface with IssueLink.

Something had to be done

Page 6: ID 352 An  XML / Power B uilder Messaging System

The AutoTrade System

• Browser based

• Automates workflow

• Interfaces with back office systems

• XML messaging

IssueLink is a B2B bond trading system

Page 7: ID 352 An  XML / Power B uilder Messaging System

The AutoTrade System

The participants

ClearingSystems

IssueLink

JP MorganDealers

OtherBanks

Page 8: ID 352 An  XML / Power B uilder Messaging System

The AutoTrade System

The technology

CNTrade(C++)

IssueLink(C++)

AutoTrade(PB)

Browseror

In-house

Browseror

In-house

HTTPor

XML

XMLHTTP

orXML

XML

Page 9: ID 352 An  XML / Power B uilder Messaging System

The AutoTrade System

• All developed with PowerBuilder

• AutoTrade Server

• AutoTrade Console

• AutoTrade Administrator

• AutoTrade Support

There are four AutoTrade components

Page 10: ID 352 An  XML / Power B uilder Messaging System

The AutoTrade System

• An NT Service

• Receives XML messages

• Parses XML messages

• Processes XML messages

• Sends XML messages

What is AutoTrade Server?

Page 11: ID 352 An  XML / Power B uilder Messaging System

The AutoTrade System

• 6 weeks development

• Runs 24 x 7

• Processed $20,000,000,000 USD in 9 months

• Quickest trade was 1 minute 8 seconds

• 25% of trades in less than 15 minutes

A success story

Page 12: ID 352 An  XML / Power B uilder Messaging System

Overview of XML

Page 13: ID 352 An  XML / Power B uilder Messaging System

Overview of XML

• XML = Extensible Markup Language

• Uses tags like in HTML

• A format for describing structured data

• Describes data structure and content

• Separates data from its presentation

What is XML?

Page 14: ID 352 An  XML / Power B uilder Messaging System

Overview of XML

• Industry standard

• Platform & vendor independent

• Self describing

• Flexible

• Caters for nested & repeating data

Why use XML?

Page 15: ID 352 An  XML / Power B uilder Messaging System

Overview of XML

<?xml version="1.0"?> <!--Example XML file--><presentation code="ID352"><title>A PB / XML Messaging System</title><presenter>Paul Donohue</presenter><audience>PowerBuilder Developers</audience><time>13:30</time><date>2001-08-13</date></presentation>

An example

Page 16: ID 352 An  XML / Power B uilder Messaging System

Overview of XML

Parts of an XML document

• XML Declaration

• Prolog

• Elements

• Attributes

• Comments

• Other Parts

<?xml version="1.0"?> <!DOCTYPE presentation SYSTEM “DEMO.DTD"><!--Example XML file--><presentation code="ID352" ><title>A PB / XML Messaging System</title><presenter>Paul Donohue</presenter><audience>PowerBuilder Developers</audience><time>13:30</time><date>2001-08-13</date></presentation>

Page 17: ID 352 An  XML / Power B uilder Messaging System

Overview of XML

• Document Type Definitions (DTDs) define rules about XML data

• DTDs are optional

• Well formed XML follows the basic rules of XML

• Valid XML follows the rules of the DTD

• Get your DTD correct before you code

Valid and well formed

Page 18: ID 352 An  XML / Power B uilder Messaging System

Overview of XML

• Two XML interfaces

• DOM = Document Object Model

• SAX = Simple API for XML

• AutoTrade uses DOM

SAX vs DOM

Page 19: ID 352 An  XML / Power B uilder Messaging System

Overview of XML

Demonstration

Page 20: ID 352 An  XML / Power B uilder Messaging System

PowerBuilder and XML

Page 21: ID 352 An  XML / Power B uilder Messaging System

PowerBuilder and XML

• Why not?

• PB can access OLE objects

• PB is good at data manipulation

• PB is good at database access

Why use PowerBuilder?

Page 22: ID 352 An  XML / Power B uilder Messaging System

PowerBuilder and XML

• There are many XML parsers

• Internet Explorer includes a parser

• An OLE object

• Can be distributed royalty free

• Current version is 3

• Easy to use

The Microsoft Redistributable XML Parser

Page 23: ID 352 An  XML / Power B uilder Messaging System

PowerBuilder and XML

• Connect to the parser

• Load the XML file

• Walk the tree

• Process the results

• Disconnect

How to parse an XML file

Page 24: ID 352 An  XML / Power B uilder Messaging System

PowerBuilder and XML

• Declare an OLE object variable oleobject iole_xml

• Connect to the XML parser iole_xml .ConnectToNewObject("Microsoft.XMLDOM")

• Set parser attributes iole_xml.async = FALSE iole_xml.validateOnParse = TRUE iole_xml.preserveWhiteSpace = FALSE

Parsing XML - Connecting

Page 25: ID 352 An  XML / Power B uilder Messaging System

PowerBuilder and XML

• Load the XML file iole_xml.load(filename)

• Any errors will be in the parseerror property iole_xml.parseerror.errorCode iole_xml.parseerror.reason iole_xml.parseerror.filepos iole_xml.parseerror.line iole_xml.parseerror.linepos iole_xml.parseerror.srcText

Parsing XML - Loading

Page 26: ID 352 An  XML / Power B uilder Messaging System

PowerBuilder and XML

• Find the root element lole_root = iole_xml.documentElement

• Use a recursive function to walk the tree

• Arguments for the function are; The node to process (start with the root) This node’s level (start with 1) A “stack” to hold node details

Parsing XML - Walking

Page 27: ID 352 An  XML / Power B uilder Messaging System

PowerBuilder and XML

• Find the node’s name, type and value ls_node_name = aole_node.nodename ls_node_type = aole_node.nodetypestring ls_node_value = String(aole_node.nodevalue)

• Add this node’s details to the “stack” ll_max_nodes = UpperBound(ai_level) + 1 ai_xml_node_level[ll_max_nodes]= ai_node_level as_xml_node_name[ll_max_nodes] = ls_node_name as_xml_node_type[ll_max_nodes] = ls_node_type as_xml_node_value[ll_max_nodes = ls_node_value

Parsing XML - Walking (in circles)

Page 28: ID 352 An  XML / Power B uilder Messaging System

PowerBuilder and XML

• Process this node’s attributes ll_max_nodes = 0 lole_node_list = aole_node.attributes IF IsValid(lole_node_list) THEN ll_max_nodes = lole_node_list.length END IF

FOR ll_idx = 0 TO ll_max_nodes – 1 lole_node = lole_node_list.Item(ll_idx) of_process_node (ai_level + 1, lole_node, stack) NEXT

Parsing XML - Walking (in circles)

Page 29: ID 352 An  XML / Power B uilder Messaging System

PowerBuilder and XML

• Repeat the recursion for the child elements lole_node_list = aole_node.childNodes

• There is a hasChildNodes property lb_any_children = aole_node.hasChildNodes

• But there is no hasAttributeNodes property

Parsing XML - Walking (in circles)

Page 30: ID 352 An  XML / Power B uilder Messaging System

PowerBuilder and XML

• After parsing the XML data can be processed

• Examples; Update the database Call a business rule object Write to a file Send an email

Parsing XML - Processing

Page 31: ID 352 An  XML / Power B uilder Messaging System

PowerBuilder and XML

• Disconnect from the XML parser iole_xml.DisConnectObject()

• Destroy the OLE object variable DESTROY iole_xml

Parsing XML - Disconnecting

Page 32: ID 352 An  XML / Power B uilder Messaging System

PowerBuilder and XML

The XML DOM tree

#text (ID352)

#comment (Example XML file)

#text (A PB/XML Messaging System)

#text (Paul Donohue)

Presenter (NULL)

Title (NULL)

Code (ID352)

Presentation

Page 33: ID 352 An  XML / Power B uilder Messaging System

PowerBuilder and XML

• Record macros

• Generating XML files

Handy hints

Page 34: ID 352 An  XML / Power B uilder Messaging System

PowerBuilder and XML

Demonstration

Page 35: ID 352 An  XML / Power B uilder Messaging System

PowerBuilder and NT Services

Page 36: ID 352 An  XML / Power B uilder Messaging System

PowerBuilder and NT Services

• Why not?

• PB can generate an EXE

• PB is fairly reliable

Why use PowerBuilder?

Page 37: ID 352 An  XML / Power B uilder Messaging System

PowerBuilder and NT Services

• Create a timer object

• Use the NT event log

• Run the EXE as a service

How to write an NT service

Page 38: ID 352 An  XML / Power B uilder Messaging System

PowerBuilder and NT Services

• Standard class inherited from timing

• Add a function to initialise the service

• Add a function to finalise the service

• Add code to the timer event

Creating the timer object

Page 39: ID 352 An  XML / Power B uilder Messaging System

PowerBuilder and NT Services

• Open an invisible window Open (w_service) ll_app_handle = Handle(xml_service) IF ll_app_handle = 0 THEN w_service.Visible = True END IF

• Record the start in the NT event log

• Start the timer running This.Start(5)

The initialise function

Page 40: ID 352 An  XML / Power B uilder Messaging System

PowerBuilder and NT Services

• Perform any housekeeping

• Record the stop in the NT event log

The finalise function

Page 41: ID 352 An  XML / Power B uilder Messaging System

PowerBuilder and NT Services

• Stop the timer This.Stop()

• Perform one cycle of work This.of_process_a_cycle()

• Force garbage collection GarbageCollect()

• Restart the timer This.Start(5)

The timer event

Page 42: ID 352 An  XML / Power B uilder Messaging System

PowerBuilder and NT Services

• A discrete unit of work

• Should be stateless

• For an XML messaging service this might be; Check for incoming XML files Parse the XML files Process the XML Generate any outgoing XML files

A cycle of work

Page 43: ID 352 An  XML / Power B uilder Messaging System

PowerBuilder and NT Services

• Services can not access network drives

• Services can not interact with the user

• Connect to database each cycle?

• Maintain connection between cycles?

A cycle of work

Page 44: ID 352 An  XML / Power B uilder Messaging System

PowerBuilder and NT Services

• Use Win32 API calls to write to the event log

• RegisterEventSource() – Retrieves a handle to the event log

• ReportEvent() – Writes an entry to the event log

• DeregisterEventSource() – Closes the event log handle

The NT event log

Page 45: ID 352 An  XML / Power B uilder Messaging System

PowerBuilder and NT Services

• All messages are prefixed by a nasty warning

• This is because we don’t have a message file

The nasty event log warning

Page 46: ID 352 An  XML / Power B uilder Messaging System

PowerBuilder and NT Services

• The wording of events is stored in message files

• Each has a unique ID

• Messages can have placeholders

• Message files are compiled into DLLs

• PowerBuilder can’t create message file DLLs

• Make a generic message file

Message files

Page 47: ID 352 An  XML / Power B uilder Messaging System

PowerBuilder and NT Services

• Declare a global variable n_cst_service gnv_service

• Instantiate the object in Application Open event gnv_service = CREATE n_cst_service gnv_service.of_initialise()

• Destroy the object in Application Close event gnv_service.of_finalise() DESTROY gnv_service

Using the timer object

Page 48: ID 352 An  XML / Power B uilder Messaging System

PowerBuilder and NT Services

• Compile your application into an EXE.

• Windows NT4 Resource Kit utilities

• SRVANY run any EXE as an NT service

• SRVINSTW install an NT service

Running as a service

Page 49: ID 352 An  XML / Power B uilder Messaging System

PowerBuilder and NT Services

• An easy to follow wizard interface

Using SRVINSTW – Step 1

Page 50: ID 352 An  XML / Power B uilder Messaging System

PowerBuilder and NT Services

• Select local machine

Using SRVINSTW – Step 2

Page 51: ID 352 An  XML / Power B uilder Messaging System

PowerBuilder and NT Services

• Give your service a name

Using SRVINSTW – Step 3

Page 52: ID 352 An  XML / Power B uilder Messaging System

PowerBuilder and NT Services

• The executable is SRVANY.EXE

• Not your Power Builder executable

Using SRVINSTW – Step 4

Page 53: ID 352 An  XML / Power B uilder Messaging System

PowerBuilder and NT Services

• The service should be its own process

Using SRVINSTW – Step 5

Page 54: ID 352 An  XML / Power B uilder Messaging System

PowerBuilder and NT Services

• The system account does not require a user id or password

• SRVANY needs to interact with the desktop

Using SRVINSTW – Step 6

Page 55: ID 352 An  XML / Power B uilder Messaging System

PowerBuilder and NT Services

• Set the startup option to automatic

• NT will start the service when the machine boots

• With no need for a user to log on

Using SRVINSTW – Step 7

Page 56: ID 352 An  XML / Power B uilder Messaging System

PowerBuilder and NT Services

• Press Finish to create the service

Using SRVINSTW – Step 8

Page 57: ID 352 An  XML / Power B uilder Messaging System

PowerBuilder and NT Services

• SRVINSTW will create an registry entry for your service under the key HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services

• Add two new keys called “Parameters” and “Enum” under your service

Configuring SRVANY

Page 58: ID 352 An  XML / Power B uilder Messaging System

PowerBuilder and NT Services

• Add three string values under the “Parameters” key; Application = Your service’s path & EXE AppDirectory = Your service’s working directory AppParameters = Any command line parameters

• Do not add any values under the “Enum” key

• These will be added when the service is first run

Configuring SRVANY

Page 59: ID 352 An  XML / Power B uilder Messaging System

PowerBuilder and NT Services

• SRVANY uses TerminateProcess() to stop your EXE

• No application or window Close events

• Use a registry entry to request a shut down

• Check the registry each cycle

• Close the invisible window to stop your EXE

Controlling your service

Page 60: ID 352 An  XML / Power B uilder Messaging System

PowerBuilder and NT Services

• Make your app bullet proof

• Test for memory leaks

• Reconnect lost database connections

• Write an administration utility

Handy hints

Page 61: ID 352 An  XML / Power B uilder Messaging System

PowerBuilder and NT Services

Demonstration

Page 62: ID 352 An  XML / Power B uilder Messaging System

Summary

Page 63: ID 352 An  XML / Power B uilder Messaging System

Summary

• A little about XML

• How XML can be used in a B2B system

• How to process XML with PowerBuilder

• How to write an NT Service with PowerBuilder

What have we learnt?

Page 64: ID 352 An  XML / Power B uilder Messaging System

Summary

Recommended reading

Title : Professional XMLAuthor : Mark Birbeck et alPublisher : Wrox Press IncISBN: 1861003110

Page 65: ID 352 An  XML / Power B uilder Messaging System

Summary

Recommended reading

Title : Professional NT ServicesAuthor : Kevin MillerPublisher : Wrox Press IncISBN: 1861001304

Page 66: ID 352 An  XML / Power B uilder Messaging System

Summary

• http://www.xml.com

• http://www.xml.org

• http://www.w3.org/xml

• http://msdn.microsoft.com/xml/default.asp

XML resources on the internet

Page 67: ID 352 An  XML / Power B uilder Messaging System

Summary

• The Microsoft Parser & other tools http://msdn.microsoft.com/downloads

• XML Notepad http://msdn.microsoft.com/xml/notepad/intro.asp

• Windows NT4 Resource Kit utilities ftp://ftp.microsoft.com /bussys/winnt/winnt-public/reskit/nt40/i386/

Free downloads from Microsoft

Page 68: ID 352 An  XML / Power B uilder Messaging System

Questions

If you have any questions about this presentation or you would like a copy of the PB objects please email me or visit my web site.

Email : [email protected]

Web : http://www.pauldonohue.com/techwave

Page 69: ID 352 An  XML / Power B uilder Messaging System

About The Author

Paul has 15 years experience as a solution provider.

He has worked with PowerBuilder since version 2 and is a Certified PowerBuilder Developer.

He now concentrates on XML, Java, EJB, JSP and other distributed technologies.

Paul Donohue