INT-12: Mastering ProDataSets and Native XML Datatypes with Sonic ESB ® David Cleary

Download Report

Transcript INT-12: Mastering ProDataSets and Native XML Datatypes with Sonic ESB ® David Cleary

INT-12: Mastering ProDataSets and
Native XML Datatypes with Sonic ESB®
David Cleary
Principal Software Engineer
Agenda
 Designing Service Interfaces
 Weakly-typed vs. Strongly-typed
 Using ProDataSets with Sonic ESB
 Using Complex XML with Sonic ESB
2
INT-12: Mastering ProDataSets and Native XML Datatypes with Sonic ESB
© 2007 Progress Software Corporation
Products Used
 OpenEdge® 10.1B01
•
•
•
•
OpenEdge Architect
ProxyGen
OpenEdge Adapter for Sonic ESB®
OpenEdge Adapter for SonicMQ®
 Sonic Workbench 7.5
• SonicMQ
• Sonic ESB
3
INT-12: Mastering ProDataSets and Native XML Datatypes with Sonic ESB
© 2007 Progress Software Corporation
Problem Overview
 OpenEdge Adapter for Sonic ESB doesn’t

support ProDataSets
OpenEdge Adapter for Sonic ESB doesn’t
support “native” XML
• <anyType> XML Schema type
 Serialized XML != Character data
• <tag> → &lt;tag&gt;
• CBR and transformation services won’t
directly work
4
INT-12: Mastering ProDataSets and Native XML Datatypes with Sonic ESB
© 2007 Progress Software Corporation
How it is being solved…
 Use LONGCHARs at client and server
• Serialize ProDataSets or X-Documents to
LONGCHAR
• Specify XML Schema string datatype in
interface (WSDL)
• ABL Client and server see XML
 Sonic services see character data
• Write Javascript to double parse data
• Extract string data, parse string data
5
INT-12: Mastering ProDataSets and Native XML Datatypes with Sonic ESB
© 2007 Progress Software Corporation
There is a Better Way!
6
INT-12: Mastering ProDataSets and Native XML Datatypes with Sonic ESB
© 2007 Progress Software Corporation
Designing Interfaces
Public
Interface
Partner
System
Packaged
Application
Web
Services
Rest
Enterprise Service Bus
Public
Interface
ESB
Adapter
Private
Interface
AppServer
7
INT-12: Mastering ProDataSets and Native XML Datatypes with Sonic ESB
© 2007 Progress Software Corporation
Designing Interfaces
Public Interfaces

Web Services vs. REST
• Use SOAP when you can leverage tools
• Use REST for simplicity

Conform to the Industry Recommendations
• Web Services Interoperability Organization (ws-i.org)
• SOAP Encoding deprecated – use Literal
• Use Document instead of RPC for widest client support

Learn WSDL
• Create WSDL to conform to interface you want – make
it as simple as possible – it’s the contract
8
INT-12: Mastering ProDataSets and Native XML Datatypes with Sonic ESB
© 2007 Progress Software Corporation
Designing Interfaces
Private Interfaces






9
Interface between Sonic and OpenEdge
Service is one or more related operations
Operations should perform a complete unit of work –
make coarse-grained for efficiency
All OpenEdge services are Request-Reply and can
return a fault
RPC/Literal allows mapping of individual parameters
– can use Web Service Invocation Editor easier
Document/Literal allows using transformation of
entire message
INT-12: Mastering ProDataSets and Native XML Datatypes with Sonic ESB
© 2007 Progress Software Corporation
Weakly-typed Service Interfaces
 Exact data type not specified in interface
 Single interface supports multiple


object/entity/data types
Uses XML Schema anyType
Validation done by application
• Schema embedded in ProDataSet XML
representation
• External schema validation done by
namespace
 AutoEdge example of weakly-typed interface
10 INT-12: Mastering ProDataSets and Native XML Datatypes with Sonic ESB
© 2007 Progress Software Corporation
Strongly-typed Service Interfaces
 Explicitly defined by XML Schema
 Interface supports single object/entity/data

types
Validation should be part of infrastructure
11 INT-12: Mastering ProDataSets and Native XML Datatypes with Sonic ESB
© 2007 Progress Software Corporation
The OERA Service Interface
12 INT-12: Mastering ProDataSets and Native XML Datatypes with Sonic ESB
© 2007 Progress Software Corporation
The OERA Service Interface
 Dynamic service interface
• Single interface handles all available services
• Weakly typed
 ProDataSets represent Business Entities and
Service Context
• Schema travels with data
• NAMESPACE-URI attribute can be used for
identity
• Optionally validate against external schema
13 INT-12: Mastering ProDataSets and Native XML Datatypes with Sonic ESB
© 2007 Progress Software Corporation
OERA Service Interface in ABL
/* proSIgateway.p
Service interface layer procedure that runs nonpersistent on the AppServer to feed client requests to
server BEs. */
DEFINE INPUT PARAMETER pcEntityName AS CHARACTER.
DEFINE INPUT PARAMETER pcOpName AS CHARACTER.
DEFINE INPUT-OUTPUT PARAMETER DATASET-HANDLE phContext.
DEFINE INPUT-OUTPUT PARAMETER DATASET-HANDLE
phIODataSet.
DEFINE OUTPUT PARAMETER DATASET-HANDLE phOutputDataSet.
DEFINE OUTPUT PARAMETER pcExcStatus AS CHARACTER.
14 INT-12: Mastering ProDataSets and Native XML Datatypes with Sonic ESB
© 2007 Progress Software Corporation
OERA Service Interface in ABL On ESB
/* proSIgateway.p
Service interface layer procedure that runs nonpersistent on the AppServer to feed client requests to
server BEs. */
DEFINE INPUT PARAMETER pcEntityName AS CHARACTER.
DEFINE INPUT PARAMETER pcOpName AS CHARACTER.
DEFINE INPUT-OUTPUT PARAMETER phContext AS LONGCHAR.
DEFINE INPUT-OUTPUT PARAMETER phIODataSet AS LONGCHAR.
DEFINE OUTPUT PARAMETER phOutputDataSet AS LONGCHAR.
DEFINE OUTPUT PARAMETER pcExcStatus AS CHARACTER.
15 INT-12: Mastering ProDataSets and Native XML Datatypes with Sonic ESB
© 2007 Progress Software Corporation
Instantiating ProDataSet™ from XML
 Use the READ-XML method on DATASET
HANDLE
• Can validate with internal schema
 Use NAMESPACE-URI attribute to identify
 Use READ-XMLSCHEMA to do strict
validation
16 INT-12: Mastering ProDataSets and Native XML Datatypes with Sonic ESB
© 2007 Progress Software Corporation
Example of ProDataSet Instantiation
DEFINE VARIABLE dsHdl AS HANDLE.
sts = dsHdl:Read-XML("LONGCHAR", /* source-type
*/
phContext, /* source of XML
*/
"EMPTY",
/* read-mode
*/
?,
/* schema-location */
FALSE,
/* override mapping*/
?,
/* field mapping
*/
?).
/* verify-schema-mode*/
17 INT-12: Mastering ProDataSets and Native XML Datatypes with Sonic ESB
© 2007 Progress Software Corporation
Serializing ProDataSet to XML
 Use the WRITE-XML method on DATASET
HANDLE
• Write schema with Dataset
• Can specify minimum schema for non-ABL
clients
 Use NAMESPACE-URI attribute to identify
 Default UTF-8 encoding preferable
 Manually remove XML declaration if inserting
in XML document
18 INT-12: Mastering ProDataSets and Native XML Datatypes with Sonic ESB
© 2007 Progress Software Corporation
Example of ProDataSet Serialization
sts = dsHdl:Write-XML("LONGCHAR",
phContext,
FALSE,
?,
?,
TRUE,
FALSE).
19 INT-12: Mastering ProDataSets and Native XML Datatypes with Sonic ESB
/*
/*
/*
/*
/*
/*
/*
target-type */
target for XML */
formatted XML */
encoding(UTF-8) */
schema-location */
write-schema */
min-schema */
© 2007 Progress Software Corporation
Service Interface Demo
20 INT-12: Mastering ProDataSets and Native XML Datatypes with Sonic ESB
© 2007 Progress Software Corporation
Creating the Public Interface
 Interface created by an ESB Process
 Interface is strongly typed (mostly)
• Entity and operation are constants
• ProDataSets are XML Schema anyType – not
string
 Can be messaging-based
• ABL clients use OpenEdge Adapter for
SonicMQ
 Can be SOAP-based
21 INT-12: Mastering ProDataSets and Native XML Datatypes with Sonic ESB
© 2007 Progress Software Corporation
Messaging-based Interfaces
 Easier to model
• Uses multipart messages
• Direct support for TempTable and ProDataSets
in ABL
 Provides reliability
 Provides true asynchronicity
• Good for long running processes
 Client interface can be abstracted
22 INT-12: Mastering ProDataSets and Native XML Datatypes with Sonic ESB
© 2007 Progress Software Corporation
Message-based Demo
23 INT-12: Mastering ProDataSets and Native XML Datatypes with Sonic ESB
© 2007 Progress Software Corporation
SOAP-based Interface

Harder to model
• Really need to work with a single message part


Less reliable (unless you use WS-RM)
Synchronous
• Long running processes can timeout

Use document/literal SOAP
• Widest client support
• Takes advantage of Sonic features

Wrap message-based process to support both
24 INT-12: Mastering ProDataSets and Native XML Datatypes with Sonic ESB
© 2007 Progress Software Corporation
SOAP-based Demo
25 INT-12: Mastering ProDataSets and Native XML Datatypes with Sonic ESB
© 2007 Progress Software Corporation
Creating Strongly-Typed Service Interfaces
 Everything defined explicitly in XML Schema
• No anyType allowed
 XML Namespaces are important
• Required for identity
• Allows versioning of objects
…
26 INT-12: Mastering ProDataSets and Native XML Datatypes with Sonic ESB
© 2007 Progress Software Corporation
ABL Classes on Sonic ESB
 Not supported by WSA or ESB Adapter
 Binary representation opaque on bus
 Serialization as XML an excellent solution
• Take full advantage of ESB services
• Easy cross platform/language support (Java
and .Net)
27 INT-12: Mastering ProDataSets and Native XML Datatypes with Sonic ESB
© 2007 Progress Software Corporation
XML Serialization of ABL Classes
 Create XML Schema representation of class
• Use named types
• Define elements of those types
28 INT-12: Mastering ProDataSets and Native XML Datatypes with Sonic ESB
© 2007 Progress Software Corporation
Example of Customer Record Schema
<xs:schema targetNamespace="urn:CustomerRecord:0607“>
<xs:element name="Customer" type="tns:CustomerType“/>
<xs:complexType name="CustomerType">
<xs:sequence>
<xs:element name="CustNum"
type="xs:unsignedInt"/>
<xs:element name="Name">
…
<xs:element name="Orders">
<xs:complexType>
<xs:sequence>
<xs:element name="Order"
type="tns:OrderType" minOccurs="0"
maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
29 INT-12: Mastering ProDataSets and Native XML Datatypes with Sonic ESB
© 2007 Progress Software Corporation
Serializing ABL Class to XML
 Use SAX-WRITER and LONGCHAR
 Controlled outside of classes
 Classes implement standardized interface
• Calls same interface on embedded classes
 Ensure you conform to schema
30 INT-12: Mastering ProDataSets and Native XML Datatypes with Sonic ESB
© 2007 Progress Software Corporation
Example of Serializing Class
METHOD PUBLIC VOID WriteXML(INPUT saxWriter AS
HANDLE):
saxWriter:START-ELEMENT("Customer", xmlNS).
IF pCustNum <> ? THEN DO:
saxWriter:START-ELEMENT("CustNum", xmlNS).
saxWriter:WRITE-CHARACTERS
(STRING(myCustomer.CustNum)).
saxWriter:END-ELEMENT("CustNum", xmlNS).
IF myCustomer.Name <> ? THEN DO:
saxWriter:START-ELEMENT("Name", xmlNS).
saxWriter:WRITE-CHARACTERS(myCustomer.Name).
saxWriter:END-ELEMENT("Name", xmlNS).
END.
.
.
31 INT-12: Mastering ProDataSets and Native XML Datatypes with Sonic ESB
© 2007 Progress Software Corporation
Example of Serializing Class
.
.
saxWriter:START-ELEMENT("Orders", xmlNS).
FOR EACH myCustOrders:
CAST (orders, order):WriteXML(saxWriter).
END.
saxWriter:END-ELEMENT("Orders", xmlNS).
END.
saxWriter:END-ELEMENT("Customer", xmlNS).
32 INT-12: Mastering ProDataSets and Native XML Datatypes with Sonic ESB
© 2007 Progress Software Corporation
Instantiating Classes from XML
 Use X-DOCUMENT DOM model
• Completely parse and validate data before
class instantiation
 Walk the DOM tree
• Element node represents class
• All element children represent class data or
embedded classes
33 INT-12: Mastering ProDataSets and Native XML Datatypes with Sonic ESB
© 2007 Progress Software Corporation
Example of Instantiating a Class
METHOD PUBLIC VOID ReadXML(INPUT xNode AS HANDLE):
/* xNode points at Customer element */
REPEAT i = 1 TO xNode:NUM-CHILDREN:
ok = xNode:GET-CHILD(xNodeChild, i).
IF NOT OK THEN LEAVE.
cType = xNodeChild:SUBTYPE NO-ERROR.
IF cType = "ELEMENT" THEN DO:
nodeName = xNodeChild:LOCAL-NAME.
ok = xNodeChild:GET-CHILD(xNodeText, 1).
nodeValue = xNodeText:NODE-VALUE.
IF nodeName = "CustNum" THEN
/* set CustNum value */
ELSE IF nodeName = "Name" THEN
34 INT-12: Mastering ProDataSets and Native XML Datatypes with Sonic ESB
© 2007 Progress Software Corporation
Example of Instantiating a Class
IF nodeName = “Orders” THEN DO:
REPEAT j = 1 TO xNodeChild:NUM-CHILDREN:
ok = xNodeChild:GET-CHILD(xNodeClass, j).
IF NOT OK THEN LEAVE.
cType = xNodeClass:SUBTYPE NO-ERROR.
IF cType = "ELEMENT" THEN DO:
nodeName = xNodeClass:LOCAL-NAME.
IF nodeName = “Order" THEN DO:
myOrder = NEW Order().
myOrder:ReadXML(xNodeClass).
END.
END.
END.
END.
35 INT-12: Mastering ProDataSets and Native XML Datatypes with Sonic ESB
© 2007 Progress Software Corporation
In Summary
 Design your public and private
interfaces
• Strongly vs. Weakly typed
• SOAP vs. REST
 Use XML Namespaces
 Never specify string datatype for
XML in public interface
36 INT-12: Mastering ProDataSets and Native XML Datatypes with Sonic ESB
© 2007 Progress Software Corporation
ABL Class Demo
37 INT-12: Mastering ProDataSets and Native XML Datatypes with Sonic ESB
© 2007 Progress Software Corporation
For More Information, go to…
 PSDN
• Designing and Deploying SOA Applications
on Sonic ESB for the OpenEdge Developer
 Education Courses:
• OpenEdge Development with Sonic ESB
• Service Oriented Integration with Sonic ESB
• Using JMS in OpenEdge
38 INT-12: Mastering ProDataSets and Native XML Datatypes with Sonic ESB
© 2007 Progress Software Corporation
Relevant Exchange Sessions
 INT-12: Mastering ProDataSets and Native



XML Datatypes with Sonic ESB
SONIC-1: What’s New in Sonic 7.5
INT-3: Realistic Service Oriented
Architecture Approaches
INT-7: Middleware Roadmap and Info
Exchange
39 INT-12: Mastering ProDataSets and Native XML Datatypes with Sonic ESB
© 2007 Progress Software Corporation
Questions?
40 INT-12: Mastering ProDataSets and Native XML Datatypes with Sonic ESB
© 2007 Progress Software Corporation
Thank you for
your time
41 INT-12: Mastering ProDataSets and Native XML Datatypes with Sonic ESB
© 2007 Progress Software Corporation
42 INT-12: Mastering ProDataSets and Native XML Datatypes with Sonic ESB
© 2007 Progress Software Corporation