ID 352 An XML Power Builder Messaging System
ID 352 An XML / Power. Builder Messaging System • • Paul Donohue Technical Architect JP Morgan (London) techwave@pauldonohue. com
Overview Topics we will cover • The Auto. Trade System • Overview of XML • Power. Builder and NT Services • Summary • Questions
The Auto. Trade System
The Auto. Trade System Bond trading in England was old fashioned • Deals were sent by phone or fax • Systems did not communicate • Data was entered many times • Delays were common
The Auto. Trade System Something had to be done A multi-bank working group investigated possible solutions and chose Issue. Link from a vendor called Capital. NET. JP Morgan developed the Auto. Trade suite of programs to interface with Issue. Link.
The Auto. Trade System Issue. Link is a B 2 B bond trading system • Browser based • Automates workflow • Interfaces with back office systems • XML messaging
The Auto. Trade System The participants Dealers JP Morgan Issue. Link Clearing Systems Other Banks
The Auto. Trade System The technology Browser or In-house CNTrade (C++) HTTP or XML Auto. Trade (PB) XML Issue. Link (C++) HTTP or XML Browser or In-house
The Auto. Trade System There are four Auto. Trade components • All developed with Power. Builder • Auto. Trade Server • Auto. Trade Console • Auto. Trade Administrator • Auto. Trade Support
The Auto. Trade System What is Auto. Trade Server? • An NT Service • Receives XML messages • Parses XML messages • Processes XML messages • Sends XML messages
The Auto. Trade System A success story • 6 weeks development • Runs 24 x 7 • Processed $20, 000, 000 USD in 9 months • Quickest trade was 1 minute 8 seconds • 25% of trades in less than 15 minutes
Overview of XML
Overview of XML What is 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
Overview of XML Why use XML? • Industry standard • Platform & vendor independent • Self describing • Flexible • Caters for nested & repeating data
Overview of XML An example <? xml version="1. 0"? > <!--Example XML file--> <presentation code="ID 352"> <title>A PB / XML Messaging System</title> <presenter>Paul Donohue</presenter> <audience>Power. Builder Developers</audience> <time>13: 30</time> <date>2001 -08 -13</date> </presentation>
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="ID 352" > <title>A PB / XML Messaging System</title> <presenter>Paul Donohue</presenter> <audience>Power. Builder Developers</audience> <time>13: 30</time> <date>2001 -08 -13</date> </presentation>
Overview of XML Valid and well formed • 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
Overview of XML SAX vs DOM • Two XML interfaces • DOM = Document Object Model • SAX = Simple API for XML • Auto. Trade uses DOM
Overview of XML Demonstration
Power. Builder and XML
Power. Builder and XML Why use Power. Builder? • Why not? • PB can access OLE objects • PB is good at data manipulation • PB is good at database access
Power. Builder and XML The Microsoft Redistributable XML Parser • 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
Power. Builder and XML How to parse an XML file • Connect to the parser • Load the XML file • Walk the tree • Process the results • Disconnect
Power. Builder and XML Parsing XML - Connecting • Declare an OLE object variable oleobject iole_xml • Connect to the XML parser iole_xml. Connect. To. New. Object("Microsoft. XMLDOM") • Set parser attributes iole_xml. async = FALSE iole_xml. validate. On. Parse = TRUE iole_xml. preserve. White. Space = FALSE
Power. Builder and XML Parsing XML - Loading • Load the XML file iole_xml. load(filename) • Any errors will be in the parseerror property iole_xml. parseerror. Code iole_xml. parseerror. reason iole_xml. parseerror. filepos iole_xml. parseerror. linepos iole_xml. parseerror. src. Text
Power. Builder and XML Parsing XML - Walking • Find the root element lole_root = iole_xml. document. Element • 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
Power. Builder and XML Parsing XML - Walking (in circles) • Find the node’s name, type and value ls_node_name = aole_nodename ls_node_type = aole_nodetypestring ls_node_value = String(aole_nodevalue) • Add this node’s details to the “stack” ll_max_nodes = Upper. Bound(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
Power. Builder and XML Parsing XML - Walking (in circles) • Process this node’s attributes ll_max_nodes = 0 lole_node_list = aole_node. attributes IF Is. Valid(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
Power. Builder and XML Parsing XML - Walking (in circles) • Repeat the recursion for the child elements lole_node_list = aole_node. child. Nodes • There is a has. Child. Nodes property lb_any_children = aole_node. has. Child. Nodes • But there is no has. Attribute. Nodes property
Power. Builder and XML Parsing XML - Processing • After parsing the XML data can be processed • Examples; § Update the database § Call a business rule object § Write to a file § Send an email
Power. Builder and XML Parsing XML - Disconnecting • Disconnect from the XML parser iole_xml. Dis. Connect. Object() • Destroy the OLE object variable DESTROY iole_xml
Power. Builder and XML The XML DOM tree Presentation Code (ID 352) #text (ID 352) #comment (Example XML file) Title (NULL) #text (A PB/XML Messaging System) Presenter (NULL) #text (Paul Donohue)
Power. Builder and XML Handy hints • Record macros • Generating XML files
Power. Builder and XML Demonstration
Power. Builder and NT Services
Power. Builder and NT Services Why use Power. Builder? • Why not? • PB can generate an EXE • PB is fairly reliable
Power. Builder and NT Services How to write an NT service • Create a timer object • Use the NT event log • Run the EXE as a service
Power. Builder and NT Services Creating the timer object • 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
Power. Builder and NT Services The initialise function • 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)
Power. Builder and NT Services The finalise function • Perform any housekeeping • Record the stop in the NT event log
Power. Builder and NT Services The timer event • Stop the timer This. Stop() • Perform one cycle of work This. of_process_a_cycle() • Force garbage collection Garbage. Collect() • Restart the timer This. Start(5)
Power. Builder and NT Services A cycle of work • 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
Power. Builder and NT Services A cycle of work • Services can not access network drives • Services can not interact with the user • Connect to database each cycle? • Maintain connection between cycles?
Power. Builder and NT Services The NT event log • Use Win 32 API calls to write to the event log • Register. Event. Source() – Retrieves a handle to the event log • Report. Event() – Writes an entry to the event log • Deregister. Event. Source() – Closes the event log handle
Power. Builder and NT Services The nasty event log warning • All messages are prefixed by a nasty warning • This is because we don’t have a message file
Power. Builder and NT Services Message files • The wording of events is stored in message files • Each has a unique ID • Messages can have placeholders • Message files are compiled into DLLs • Power. Builder can’t create message file DLLs • Make a generic message file
Power. Builder and NT Services Using the timer object • 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
Power. Builder and NT Services Running as a service • Compile your application into an EXE. • Windows NT 4 Resource Kit utilities • SRVANY run any EXE as an NT service • SRVINSTW install an NT service
Power. Builder and NT Services Using SRVINSTW – Step 1 • An easy to follow wizard interface
Power. Builder and NT Services Using SRVINSTW – Step 2 • Select local machine
Power. Builder and NT Services Using SRVINSTW – Step 3 • Give your service a name
Power. Builder and NT Services Using SRVINSTW – Step 4 • The executable is SRVANY. EXE • Not your Power Builder executable
Power. Builder and NT Services Using SRVINSTW – Step 5 • The service should be its own process
Power. Builder and NT Services Using SRVINSTW – Step 6 • The system account does not require a user id or password • SRVANY needs to interact with the desktop
Power. Builder and NT Services Using SRVINSTW – Step 7 • Set the startup option to automatic • NT will start the service when the machine boots • With no need for a user to log on
Power. Builder and NT Services Using SRVINSTW – Step 8 • Press Finish to create the service
Power. Builder and NT Services Configuring SRVANY • SRVINSTW will create an registry entry for your service under the key HKEY_LOCAL_MACHINESYSTEMControl. Set 001Services • Add two new keys called “Parameters” and “Enum” under your service
Power. Builder and NT Services Configuring SRVANY • Add three string values under the “Parameters” key; § Application = Your service’s path & EXE § App. Directory = Your service’s working directory § App. Parameters = Any command line parameters • Do not add any values under the “Enum” key • These will be added when the service is first run
Power. Builder and NT Services Controlling your service • SRVANY uses Terminate. Process() 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
Power. Builder and NT Services Handy hints • Make your app bullet proof • Test for memory leaks • Reconnect lost database connections • Write an administration utility
Power. Builder and NT Services Demonstration
Summary
Summary What have we learnt? • A little about XML • How XML can be used in a B 2 B system • How to process XML with Power. Builder • How to write an NT Service with Power. Builder
Summary Recommended reading Title : Professional XML Author : Mark Birbeck et al Publisher : Wrox Press Inc ISBN: 1861003110
Summary Recommended reading Title : Professional NT Services Author : Kevin Miller Publisher : Wrox Press Inc ISBN: 1861001304
Summary XML resources on the internet • http: //www. xml. com • http: //www. xml. org • http: //www. w 3. org/xml • http: //msdn. microsoft. com/xml/default. asp
Summary Free downloads from Microsoft • The Microsoft Parser & other tools http: //msdn. microsoft. com/downloads • XML Notepad http: //msdn. microsoft. com/xml/notepad/intro. asp • Windows NT 4 Resource Kit utilities ftp: //ftp. microsoft. com /bussys/winntpublic/reskit/nt 40/i 386/
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 : techwave@pauldonohue. com Web : http: //www. pauldonohue. com/techwave
About The Author Paul Donohue Paul has 15 years experience as a solution provider. He has worked with Power. Builder since version 2 and is a Certified Power. Builder Developer. He now concentrates on XML, Java, EJB, JSP and other distributed technologies.
- Slides: 69