Wrox professional XML 2nd edition may 2001 ISBN 1861005059 pdf

1.3K 91 0
Wrox professional XML 2nd edition may 2001 ISBN 1861005059 pdf

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Professional XML 2nd Edition Mark Birbeck Jason Diamond Jon Duckett Oli Gauti Gudmundsson Pete Kobak Evan Lenz Steven Livingstone Daniel Marcus AM FL Y Stephen Mohr Nikola Ozu Jon Pinnock Keith Visco TE Andrew Watt Kevin Williams Zoran Zaev Wrox Press Ltd Team-Flyđ Professional XML 2nd Edition â 2001 Wrox Press All rights reserved No part of this book may be reproduced, stored in a retrieval system or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embodied in critical articles or reviews The author and publisher have made every effort in the preparation of this book to ensure the accuracy of the information However, the information contained in this book is sold without warranty, either express or implied Neither the authors, Wrox Press, nor its dealers or distributors will be held liable for any damages caused or alleged to be caused either directly or indirectly by this book Published by Wrox Press Ltd, Arden House, 1102 Warwick Road, Acocks Green, Birmingham, B27 6BH, UK Printed in the United States ISBN 1861005059 Trademark Acknowledgements Wrox has endeavored to provide trademark information about all the companies and products mentioned in this book by the appropriate use of capitals However, Wrox cannot guarantee the accuracy of this information Credits Authors Mark Birbeck Jason Diamond Jon Duckett Oli Gauti Gudmundsson Pete Kobak Evan Lenz Steven Livingstone Daniel Marcus Stephen Mohr Nikola Ozu Jon Pinnock Keith Visco Andrew Watt Kevin Williams Zoran Zaev Category Managers Dave Galloway Sonia Mulineux Technical Reviewers Daniel Ayers Martin Beaulieu Arnaud Blandin Maxime Bombadier Joseph Bustos David Carlisle Pierre-Antoine Champin Robert Chang Michael Corning Chris Crane Steve Danielson Chris Dix Sébastien Gignoux Tony Hong Paul Houle Craig McQueen Thomas B Passin Dave Pawson Gary L Peskin Phil Powers DeGeorge Eric Rajkovic Gareth Reakes Matthew Reynolds David Schultz Marc H Simkin Darshan Singh Paul Warren Karli Watson Project Administrator Beckie Stones Production Co-ordinator Pip Wonson Author Agent Marsha Collins Indexers Andrew Criddle Bill Johncocks Technical Architect Timothy Briggs Technical Editors Phil Jackson Simon Mackie Chris Mills Andrew Polshaw Proof reader Agnes Wiggers Production Manager Simon Hardware Diagrams Shabnam Hussain Cover Chris Morris About the Authors Mark Birbeck Mark Birbeck is Technical Director of Parliamentary Communications Ltd where he has been responsible for the design and build of their political portal, ePolitix.com He is also managing director of XML consultancy x-port.net Ltd., responsible for the publishing system behind spiked-online.com Although involved in XML for a number of years, his special interests lay in metadata, and in particular the use of RDF He particularly welcomes Wrox's initiative in trying to move these topics from out of the shadows and into the mainstream Mark would particularly like to thank his long-suffering partner Jan for putting up with the constant smell of midnight oil being burned He offers the consolation that at least he will already be up when their first child Louis demands attention during the small hours Jon Duckett Jon has been using and writing about XML since 1998, when he co-authored and edited Wrox's first XML publication Having spent the past years working for Wrox in the Birmingham UK offices, Jon is currently working from Sydney, so that he can get a different view out of the window while he is working and supping on a nice cup of tea Oli Gauti Gundmundsson Oli is working for SALT, acting as one of two Chief System Architects of the SALT Systems, and Development Director in New York He is currently working on incorporating XML and XSL into SALT’s web authoring and content management systems He has acted as an instructor in the Computer Science course (Java) at the University of Iceland, and Java is one of his greatest strengths (and pleasures!) As a hobby he is trying to finish his BS degree in Computer Engineering His nationality is Icelandic, but he is currently situated in New York with his girlfriend Edda He can be reached at oli.gauti@salt.is Pete Kobak Pete Kobak built and programmed his first computer from a kit in 1978, which featured 256 bytes of RAM and a single LED output After a fling as an electrical engineer for IBM, Pete gradually moved into software development to support mainframe manufacturing He earned geek programmer status in the late '80s when he helped to improve Burroughs' Fortran compiler by introducing vectorization of DO loops Justified by his desire to continue to pay his mortgage, Pete left Burroughs in 1991 to put lives in jeopardy by developing medical laboratory software in OS/2 In 1997, Pete somehow convinced The Vanguard Group to hire him to Solaris web development, even though he could barely spell “Unix” He has helped to add new features to their web site since then, specializing in secure web communication Pete's current interest is in web application security, trying to find the right techniques to enforce the strong security needed by a serious financial institution while meeting their need to rapidly extend business relationships Pete is thankful to be able to introduce interesting web technologies in the service of helping millions of people to reach for their financial dreams He can be contacted at kobak@ieee.org I'd like to dedicate my humble contribution to my wife Geraldine, and to my children Mary, John, and Patricia They have sacrificed my time and attention for me to be able to complete this project This chapter is a family effort Evan Lenz Evan Lenz currently works as a software engineer for XYZFind Corp in Seattle, WA His primary area of expertise is in XSLT, and he enjoys exploring new ways to utilize this technology for various projects His work at XYZFind includes everything from XSLT and Java development to writing user's manuals, to designing the XML query language used in XYZFind's XML database software Wielding a professional music degree and a philosophy major, he hopes to someday bring his varying interests together into one grand, masterful scheme Thanks to my precious wife, Lisa, and my baby son, Samuel, for putting up with Daddy's long nights And praise to my Lord and Savior, Jesus Christ, without whom none of this would be possible or meaningful Steven Livingstone Steven Livingstone is an IT Architect with IBM Global Services in Winnipeg, Canada He has contributed to numerous Wrox books and magazine articles, on subjects ranging from XML to ECommerce Steven’s current interests include E-Commerce, ebXML, NET, and Enterprise Application Architectures Steven would like to thank everyone at Wrox, especially for the understanding as he emigrated from Scotland to Canada (and that could be another book itself ;-) Most importantly he wants to thank Loretito for putting up with him whilst writing – gracias mi tesoro Congratulations Celtic on winning the Treble :) Daniel Marcus Dr Marcus has twenty years of experience in software architecture and design He is co-founder, President, and Chief Operating Officer at Speechwise Technologies, an applications software company at the intersection of speech, wireless, and Internet technologies Prior to starting Speechwise, he was Director of E-Business Consulting at Xpedior, leading the strategy, architecture, and deployment of e-business applications for Global 2000 and dot-com clients Dr Marcus has been a Visiting Scholar at Princeton's Institute for Advanced Study, a research scientist at the Lawrence Livermore National Laboratory, and is the author of over twenty papers in computational science He is a Sun-Certified Java Technology Architect and holds a Ph.D in Mechanical Engineering from the University of California, Berkeley Stephen Mohr Stephen Mohr is a software systems architect with Omicron Consulting, Philadelphia, USA He has more than ten years' experience working with a variety of platforms and component technologies His research interests include distributed computing and artificial intelligence Stephen holds BS and MS degrees in computer science from Rensselaer Polytechnic Institute For my wife, Denise, and my sons James and Matthew Nikola Ozu Nikola Ozu is an independent systems architect who lives in Wyoming at the end of a few miles of dirt road – out where the virtual community is closer than town, but only flows at 24kb/s, and still does not deliver pizza His current project involves bringing semantic databases, text searching, and multimedia components together with XML – on the road to Xanadu Other recent work has included the usual web design consulting, some XML vocabularies, and an XML-based production and fulltext indexing system for a publisher of medical reference books and databases In the early 90s, Nik designed and developed a hypertext database called Health Reference Center; followed by advanced versions of InfoTrac Both of these were bibliographic and full-text databases, delivered as monthly multi-disc CD-ROM subscriptions Given the large text databases involved, some involvement with SGML was unavoidable His previous work has ranged from library systems on mainframes to embedded micro systems (telecom equipment, industrial robots, toys, arcade games, and videogame cartridges) In the early 70s, he was thrilled to learn programming using patch boards, punch cards, paper tape, and printouts (and Teletypes, too) When not surfing the 'net, he surfs crowds, the Tetons, and the Pacific; climbs wherever there is rock; and tries to get more than a day's walk from the nearest road now and then He enjoys these even more when accompanied by his teenage son, who's old enough now to appreciate the joy of mosh pits and sk8ing the Mission District after midnight To Noah: May we always think of the next (23 - 1) generations instead of just our own 20 My thanks to the editors and illustrators at Wrox and my friend Deanna Bauder for their help with this project Also, thanks and apologies to my family and friends who endured my disappearances into the WriterZone for days on end Jonathan Pinnock Jonathan Pinnock started programming in Pal III assembler on his school's PDP 8/e, with a massive 4K of memory, back in the days before Moore's Law reached the statute books These days he spends most of his time developing and extending the increasingly successful PlatformOne product set that his company, JPA, markets to the financial services community He seems to spend the rest of his time writing for Wrox, although he occasionally surfaces to say hello to his long-suffering wife and two children JPA’s home page is www.jpassoc.co.uk Keith Visco Keith Visco currently works for Intalio, Inc., the leader in Business Process Management, as a manager and project leader for XML based technologies Keith is the project leader for the open source data-binding framework, Castor He has been actively working on open source projects since 1998, including the Mozilla project where he is the original author of Mozilla's XSLT processor (donated by his previous employer, The MITRE Corporation) and is the current XSLT module owner In all aspects of his life, Keith is most inspired after drinking a large Dunkin' Donuts Hazelnut Coffee Keith relieves what little stress his life does encounter by playing guitar or keyboards (he apologizes to his neighbors) He is also a firm believer that life cannot exist without three basic elements: music, coffee, and Red Sox baseball I would like to acknowledge Intalio, Inc and The Exolob Group for giving me the opportunity to work on many industry-leading technologies I would like to thank my team at Intalio, specifically Arnaud Blandin and Sebastien Gignoux, for their hard work as well as their invaluable feedback on this chapter I would also like to thank my family for their unconditional support and incessant input into all phases of my life A special thanks to Cindy Iturbe, whose encouragement means so much to me and for teaching me that with a little patience and hard work all things are possible, no matter how distant things may seem Andrew Watt Andrew Watt is an independent consultant who enjoys few things more than exploring the technologies others have yet to sample Since he wrote his first programs in 6502 Assembler and BBC Basic in the mid 1980s, he has sampled Pascal, Prolog, and C++, among others More recently he has focused on the power of web-relevant technologies, including Lotus Domino, Java and HTML His current interest is in the various applications of the Extensible Markup Meta Language, XMML, sometimes imprecisely and misleadingly called XML The present glimpse he has of the future of SVG, XSL-FO, XSLT, CSS, XLink, XPointer, etc when they actually work properly together is an exciting, if daunting, prospect He has just begun to dabble with XQuery Such serial dabbling, so he is told, is called “life-long learning” In his spare time he sometimes ponders the impact of Web technologies on real people What will be the impact of a Semantic Web? How will those other than the knowledge-privileged fare? To the God of Heaven who gives human beings the capacity to see, think and feel To my father who taught me much about life My heartfelt thanks go to Gail, who first suggested getting into writing, and now suffers the consequences on a fairly regular basis, and to Mark and Rachel, who just suffer the consequences Kevin Williams Kevin’s first experience with computers was at the age of 10 (in 1980) when he took a BASIC class at a local community college on their PDP-9, and by the time he was 12, he stayed up for four days straight hand-assembling 6502 code on his Atari 400 His professional career has been focused on Windows development – first client-server, then onto Internet work He’s done a little bit of everything, from VB to Powerbuilder to Delphi to C/C++ to MASM to ISAPI, CGI, ASP, HTML, XML, and any other acronym you might care to name; but these days, he’s focusing on XML work Kevin is a Senior System Architect for Equient, an information management company located in Northern Virginia He may be reached for comment at kevin@realworldxml.com Zoran Zaev Zoran is a Sr Web Solutions Architect with Hitachi Innovative Solutions, Corp in the Washington DC area He has worked in technology since the time when MHz CPUs and 48Kb was considered a 'significant power', in the now distant 1980s In mid 1990s, Zoran became involved in web applications development Since then, he has worked helping large and small clients alike leverage the power of web applications His more recent emphasis has been web applications and web services with XML, SOAP, and other related technologies When he's not programming, you'll find him traveling, exploring new learning opportunities I would like to thank my wife, Angela, for her support and encouragement, as well as sharing some of her solid writing knowledge And, you can never go wrong thanking your parents, so 'fala' to my mom, Jelica and dad, Vanco On the professional side, I would like to thank Ellen Manetti for her strong project management example, and Pete Johnson, founder of Virtualogic, Inc., for his vision inspiring influence Finally, thanks to Beckie and Marsha from Wrox for their always-timely assistance and to Jan from "Images by Jan" Zoran can be reached at zoran.zaev@hitachisolutions.net Chapter 27 This diagram shows how these elements are related: business Entity binding Service Model binding Template The rest of this chapter is going to look at how we can use the UDDI APIs to make simple inquiries of and publish to the various publicly available registries We're not actually going to touch on much of the elements involved in a registry entry; once we've established how to access and update a simple part of the business entity (its description), we can extend that process to any other part of the structure UDDI Inquiries AM FL Y Before we can make any inquiries on any of the registries, we need to set up some test data Since we need to be registered as publishers for the next section (because we're going to be publishing business information as well as making inquiries), we might as well that now This is quite a straightforward process, and all we need to is go to each web site in turn and follow all the steps to register ourselves The steps involved are different in each case, but they are quite self-explanatory, so we won't waste space by discussing them further here The sites in question are: ❑ Ariba: http://uddi.ariba.com ❑ IBM: http://www.ibm.com/services/uddi ❑ Microsoft: http://uddi.microsoft.com TE Once we've registered ourselves, then we can go on and add a business In the case of IBM, use the test registry, rather than the live one; in the other two cases, we don't get a choice For the time being, just create a business with a name and a simple description For the purposes of this chapter, we created a business called "WroxDemo" We will also need the APIs The IBM UDDI API is called uddi4j (UDDI for Java), and this is included as part of the Web Services Toolkit that we loaded in the first part of this chapter You should make sure that the uddi4j.jar archive is in the Java CLASSPATH The Microsoft API can be found at http://msdn.microsoft.com/downloads/default.asp?URL=/code/sample.asp?url=/msdnfiles/027/001/527/msdncompositedoc.xml Both APIs are essentially the same, although implemented using different technologies (Java for IBM, COM for Microsoft) The Microsoft version, as we shall see, exposes a little more of the underlying SOAP technology than IBM; however, most of the calls are functionally identical 26 Team-Fly® B2B Futures: WSDL and UDDI Inquiries the IBM Way We will start with a very simple application to get a feel for what we're doing We'll code it up as a single Java class using command line I/O, called UDDIClient.java Here is how the code starts, importing the necessary UDDI Java classes: import import import import import com.ibm.uddi.client.UDDIProxy; com.ibm.uddi.response.BusinessList; com.ibm.uddi.response.BusinessInfos; com.ibm.uddi.response.BusinessInfo; java.util.Vector; Here's the main() method: public class UDDIClient { public static void main (String[] args) throws Exception { byte input[] = new byte[128]; System.out.print ("Search for? "); int nRead = System.in.read (input, 0, 128); String strSearch = new String (input, 0, nRead - 2); System.out.print ("Registry? "); nRead = System.in.read (input, 0, 128); All we're doing here is getting a company name to search for, plus an identifier for the registry that we're going to search in (A for Ariba, I for IBM, and M for Microsoft) Let us look a bit further: String strRegistry; String strURL; switch (input[0]) { case 'A': strRegistry = "Ariba"; strURL = new String("http://uddi.ariba.com/UDDIProcessor.aw/ad/process"); break; case 'I': strRegistry = "IBM"; strURL = new String( "http://www-3.ibm.com/services/uddi/testregistry/inquiryapi"); break; case 'M': strRegistry = "Microsoft"; strURL = new String("http://test.uddi.microsoft.com/inquire"); break; default: System.out.println ("Invalid registry specified - exiting"); return; } System.out.println ("Searching for at " + strRegistry + " "); 27 Chapter 27 Here, we're setting up the URL of the registry that we're going for Notice that in the case of IBM, we have specified the test registry (http://www-3.ibm.com/services/uddi/testregistry/inquiryapi) rather than the live registry (http://www-3.ibm.com/services/uddi/inquiryapi) Now comes our first glimpse into the API: UDDIProxy proxy = new UDDIProxy(); proxy.setInquiryURL (strURL); The UDDIProxy object is our way of talking to the registry Every interaction with the registry is done via this object It needs one URL for inquiries, and another one for publishing; however, we won't need the second one yet It's time to carry out our search: BusinessList list = proxy.find_business (strSearch, null, 10); At this stage, I've chosen a very simple partial string match search, and I've limited the number of hits to 10, as experience has shown that specifying an unlimited number of hits (-1) can result in an indefinite wait Once we have a response, we can extract the information that we need: BusinessInfos infos = list.getBusinessInfos (); Vector vInfo = infos.getBusinessInfoVector (); int nInfo = vInfo.size(); System.out.println (nInfo + " items found:"); for (int iInfo = 0; iInfo < nInfo; iInfo++) { BusinessInfo info = (BusinessInfo) vInfo.elementAt (iInfo); System.out.println (info.getNameString ()); Vector vDesc = info.getDescriptionStrings (); int nDesc = vDesc.size (); for (int iDesc = 0; iDesc < nDesc; iDesc++) System.out.println ((String) vDesc.elementAt (iDesc)); } } } A BusinessInfo object contains all the information for a single business, so all we're doing here is extracting the name and description for each of the businesses found by our search In practice, it is only possible to enter a single description via any of the UDDI web sites, so we will only manage to extract one Let us see what happens when we try out an extraction from Ariba: Search for? Wrox Registry? A Searching for at Ariba items found: WroxDemo Wrox Demonstration Business (Ariba version) How about IBM: 28 B2B Futures: WSDL and UDDI Search for? Wrox Registry? I Searching for at IBM items found: WroxDemo Wrox Demonstration Business (IBM version) Finally, we will try Microsoft: Search for? Wrox Registry? M Searching for at Microsoft Exception in thread "main" [SOAPException: faultCode=SOAP-ENV:Protocol; msg=Miss ing content type.] at org.apache.soap.transport.TransportMessage.read(TransportMessage.java :214) at org.apache.soap.util.net.HTTPUtils.post(HTTPUtils.java:296) at org.apache.soap.transport.http.SOAPHTTPConnection.send(SOAPHTTPConn ection.java:208) at org.apache.soap.messaging.Message.send(Message.java:120) at com.ibm.uddi.client.UDDIProxy.send(UDDIProxy.java:1215) at com.ibm.uddi.client.UDDIProxy.send(UDDIProxy.java:1187) at com.ibm.uddi.client.UDDIProxy.find_business(UDDIProxy.java:192) at UDDIClient.main(UDDIClient.java:52) Now that doesn't look quite right This problem arose during the period when we were working on this book, and is apparently due to the Microsoft registry returning a content type of "text/xml;", which causes Apache SOAP to enter a loop With any luck, this will all have been resolved between the various parties by the time this book goes on sale Inquiries the Microsoft Way Let's see how Microsoft does it There is a moderately sophisticated example provided with the UDDI API, but for clarity's sake, we're going to build something somewhat less ambitious, along very similar lines to the Java one We'll use Microsoft Visual Basic version Once we've created a new project, we'll need to add references to the two UDDI COM DLL's via Project | References: 29 Chapter 27 Next, we'll create our form: The three text boxes are as follows: txtSearch, txtName and txtDescription The combo box is cmbRegistry, and the command button is cmdSearch We only need to attach any code to two events In Form_Load(), all we need to is set up the registry selection combo box: Private Sub Form_Load() cmbRegistry.AddItem ("Ariba") cmbRegistry.AddItem ("IBM") cmbRegistry.AddItem ("Microsoft") cmbRegistry.ListIndex = End Sub In cmdSearch_Click(), we start off by declaring a number of UDDI-related variables, which we'll discuss as we go on Then we set up the first of these, the UDDI request manager This is equivalent to the Java UDDIProxy object, in that it's the object that every UDDI interaction passes through: Private Sub cmdSearch_Click() Dim strSearch As String Dim strRegistry As String Dim req As UDDIEnv.RequestManager Dim envOut As UDDIEnv.Envelope Dim findBiz As UDDI10.find_business Dim envIn As UDDIEnv.Envelope Dim bizList As UDDI10.businessList Dim bizInfo As UDDI10.businessInfo strSearch = txtSearch.Text strRegistry = cmbRegistry.Text Set req = New RequestManager If (strRegistry = "Ariba") Then req.UDDI_Address = "http://uddi.ariba.com/UDDIProcessor.aw/ad/process" ElseIf (strRegistry = "IBM") Then req.UDDI_Address = _ "http://www-3.ibm.com/services/uddi/testregistry/inquiryapi" Else req.UDDI_Address = "http://uddi.microsoft.com/inquire" End If 30 B2B Futures: WSDL and UDDI Next, we need to set up our find_business object This object defines the parameters for our search: Set findBiz = New find_business Then we have to create a UDDI SOAP envelope, and insert our find_business object into it Once we've done that, we can safely populate it: Set outEnv = New Envelope Set outEnv.Plugin = findBiz findBiz.Name = strSearch findBiz.maxRows = 10 This exposes a little more of the underlying architecture than the IBM Java implementation (remember all we did last time was invoke the find_business method on the UDDIProxy object?) Now we can send off our request and get a response The request goes off in one envelope and comes back in another Strictly speaking, we could re-use the same envelope; however, for the sake of clarity, I've used a separate one: Set inEnv = req.UDDIRequest(outEnv) If all goes well, we can extract a list of businesses from the incoming envelope: Set bizList = New businessList Set inEnv.Plugin = bizList Having done that, we can simply iterate through the list, displaying the name and description (although we're actually only set up to display one at a time): For Each bizInfo In bizList.businessInfos txtName.Text = bizInfo.Name txtDescription.Text = bizInfo.Description(1) Next bizInfo End Sub Let's try it out on Ariba: 31 Chapter 27 IBM: And, finally, Microsoft: Publishing to UDDI The majority of interactions with UDDI are likely to be inquiries However, it's also unlikely that corporations in the future will want to be saddled with the hassle of using a web-style user interface every time they want to update their details In this section, we look at how we can extend the way in which we interact with UDDI to include amendments as well as simple retrievals Amending UDDI information involves several additional steps, and we are going to amend both of our implementations accordingly All we are actually going to is change the description field However, once we can that successfully, we can effectively amend anything Publishing the IBM Way As before, we will start off with the IBM Java implementation We start by copying our previous class to UDDIClient2.java Here's how it starts now, with a few additional imports (we'll see what these are doing as we go through the rest of the code): import import import import import import import 32 com.ibm.uddi.client.UDDIProxy; com.ibm.uddi.response.BusinessList; com.ibm.uddi.response.BusinessInfos; com.ibm.uddi.response.BusinessInfo; com.ibm.uddi.response.BusinessDetail; com.ibm.uddi.datatype.business.BusinessEntity; com.ibm.uddi.response.AuthToken; B2B Futures: WSDL and UDDI import java.util.Vector; import java.security.Security; import java.util.Properties; In the new version, we are going to have to access the publishing URL for each of the registries, using a secure connection Therefore, we are going to have to enable secure sockets: public class UDDIClient2 { public static void main (String[] args) throws Exception { Properties props = System.getProperties (); props.put ("java.protocol.handler.pkgs", "com.ibm.net.ssl.internal.www.protocol"); System.setProperties (props); Security.addProvider(new com.ibm.jsse.JSSEProvider()); The next section remains unchanged: byte input[] = new byte[128]; System.out.print ("Search for? "); int nRead = System.in.read (input, 0, 128); String strSearch = new String (input, 0, nRead - 2); System.out.print ("Registry? "); nRead = System.in.read (input, 0, 128); We now have to set up a URL for publishing as well as inquiries: String strRegistry; String strInquiryURL; String strPublishURL; switch (input[0]) { case 'A': strRegistry = "Ariba"; strInquiryURL = new String( "http://uddi.ariba.com/UDDIProcessor.aw/ad/process"); strPublishURL = new String( "https://uddi.ariba.com/UDDIProcessor.aw/ad/process"); break; case 'I': strRegistry = "IBM"; strInquiryURL = new String( "http://www-3.ibm.com/services/uddi/testregistry/inquiryapi"); strPublishURL = new String( "https://www-3.ibm.com/services/uddi/ testregistry/protect/publishapi"); break; 33 Chapter 27 case 'M': strRegistry = "Microsoft"; strInquiryURL = new String("http://uddi.microsoft.com/inquire"); strPublishURL = new String("https://uddi.microsoft.com/publish"); break; default: System.out.println ("Invalid registry specified - exiting"); return; } System.out.println ("Searching for at " + strRegistry + " "); UDDIProxy proxy = new UDDIProxy(); proxy.setInquiryURL (strInquiryURL); proxy.setPublishURL (strPublishURL); The next section, where we are setting up the initial inquiry, remains unchanged: BusinessList list = proxy.find_business (strSearch, null, 10); BusinessInfos infos = list.getBusinessInfos (); Vector vInfo = infos.getBusinessInfoVector (); However, from this point on, we are in new territory The first difference is that this time around, we're just going to focus on the first item found (if any) The second difference is that we're going to have to get access to the business entity, because that's what we're going to be changing The first step to doing this is to get hold of the unique key for the record; the registry allocated this when we first registered the business: int nInfo = vInfo.size(); if (nInfo == 0) { System.out.println ("None found"); return; } BusinessInfo info = (BusinessInfo) vInfo.elementAt (0); String strKey = info.getBusinessKey (); Now we have that, we make a request via the proxy for the business details relating to this key, and from that we can extract the business entity: System.out.println ("Getting business entity for key " + strKey + " "); BusinessDetail detail = proxy.get_businessDetail (strKey); Vector vEntity = detail.getBusinessEntityVector (); int nEntity = vEntity.size (); 34 B2B Futures: WSDL and UDDI if (nEntity == 0) { System.out.println ("Failed to retrieve business entity"); return; } BusinessEntity entity = (BusinessEntity) vEntity.elementAt (0); As a check that we have the right entity, we output the name and description from this object, rather than the business info object: String strName = entity.getNameString (); System.out.println ("Name = " + strName); Vector vDesc = entity.getDescriptionStrings (); int nDesc = vDesc.size (); if (nDesc > 0) System.out.println ("Description = " + (String) vDesc.elementAt (0)); Now we ask the user for a new description, and put it into the entity, as the first description Then we load the entity back into the entity vector: System.out.print ("New description? "); nRead = System.in.read (input, 0, 128); String strDescription = new String (input, 0, nRead - 2); if (nDesc > 0) vDesc.setElementAt (strDescription, 0); else vDesc.addElement (strDescription); entity.setDescriptionStrings (vDesc); vEntity.setElementAt (entity, 0); In order to publish, we need to give the registry the user name and password that we established when we registered ourselves with UDDI in the first place We use these to get an authentication token, which we can use for subsequent publishing operations: System.out.print ("User name? "); nRead = System.in.read (input, 0, 128); String strUser = new String (input, 0, nRead - 2); System.out.print ("Password? "); nRead = System.in.read (input, 0, 128); String strPassword = new String (input, 0, nRead - 2); AuthToken auth = proxy.get_authToken (strUser, strPassword); 35 Chapter 27 Having got that, we can now save the business entity with its new description: proxy.save_business (auth.getAuthInfoString (), vEntity); } } This is what happens when we run it; the username and password is the business name entered when we first registered a company at the start of this section: Search for? Wrox Registry? A Searching for at Ariba Getting business entity for key 3d528bf1-00e5-ec77-f22c-cefb19a7aa77 Name = WroxDemo Description = Wrox Demonstration Business (Ariba version) New description? Ariba Wrox Demo User name? … Password? … If we run it again, we can see that the description has indeed been changed The IBM registry behaves similarly, but once again, the Microsoft registry is currently inaccessible from IBM Publishing the Microsoft Way TE AM FL Y Let's complete the set now, and extend our VB application to publish a new description Copy the project and form to UDDIClient2.vbp and UDDIClient2.frm, respectively, and amend the form as follows: The new text boxes are called txtUser and txtPassword, respectively The new command button is called cmdAmend Seeing as we're now going to be holding information between the Search and Amend commands, we'll need to add a couple of global variables: Dim mReq As UDDIEnv.RequestManager Dim mEntity As UDDI10.businessEntity Form_Load() remains unchanged, but we've also got to add one or two new variables to cmdSearch_Click(): 36 Team-Fly® B2B Futures: WSDL and UDDI Private Sub cmdSearch_Click() Dim strSearch As String Dim strRegistry As String Dim outEnv As UDDIEnv.Envelope Dim findBiz As UDDI10.find_business Dim getBiz As UDDI10.get_businessDetail Dim inEnv As UDDIEnv.Envelope Dim bizList As UDDI10.businessList Dim bizInfo As UDDI10.businessInfo Dim bizDetail As UDDI10.businessDetail Dim strKey As String As with the Java implementation, we need to set up both the inquiry address and the publishing (or secure, in Microsoft terms) address We also need to use the global request variable now: strSearch = txtSearch.Text strRegistry = cmbRegistry.Text Set mReq = New RequestManager If (strRegistry = "Ariba") Then mReq.UDDI_Address = "http://uddi.ariba.com/UDDIProcessor.aw/ad/process" mReq.UDDI_SecureAddress = "http://uddi.ariba.com/UDDIProcessor.aw/ad/process" ElseIf (strRegistry = "IBM") Then mReq.UDDI_Address = "http://www-3.ibm.com/services/uddi/testregistry/inquiryapi" mReq.UDDI_SecureAddress = "https://www-3.ibm.com/services/uddi" & _ "/testregistry/protect/publishapi" Else mReq.UDDI_Address = "http://uddi.microsoft.com/inquire" mReq.UDDI_SecureAddress = "https://uddi.microsoft.com/publish" End If The next section, which retrieves the business information from UDDI, remains unchanged: Set findBiz = New find_business Set outEnv = New Envelope Set outEnv.Plugin = findBiz findBiz.Name = strSearch findBiz.maxRows = 10 Set inEnv = mReq.UDDIRequest(outEnv) Set bizList = New businessList Set inEnv.Plugin = bizList However, as before, from here on in we're in uncharted waters The first thing we need to is extract the business key: If (bizList.businessInfos.Count = 0) Then MsgBox ("None found") Exit Sub 37 Chapter 27 End If Set bizInfo = bizList.businessInfos(1) strKey = bizInfo.businessKey Now we get the business details, and extract the entity from it: Set getBiz = New get_businessDetail Set outEnv = New Envelope Set outEnv.Plugin = getBiz getBiz.AddbusinessKey = strKey Set inEnv = mReq.UDDIRequest(outEnv) Set bizDetail = New businessDetail Set inEnv.Plugin = bizDetail If (bizDetail.Count = 0) Then MsgBox ("Failed to retrieve business entity") Exit Sub End If Set mEntity = bizDetail.businessEntity(1) Again, we use this to populate the name and description fields: txtName.Text = mEntity.Name txtDescription.Text = mEntity.Description(1) End Sub Now let's look at what happens when we click on the Amend button: Private Sub cmdAmend_Click() Dim save As UDDI10.save_business Dim outEnv As UDDIEnv.Envelope Dim inEnv As UDDIEnv.Envelope The first thing that we have to is get our authentication token The slight difference here is that the actual token is stored within the request object, so we don't actually need to deal with it explicitly: mReq.Authenticate txtUser.Text, txtPassword.Text Now we can amend our entity, and we're nearly home and dry: mEntity.Description(1) = txtDescription.Text At this point, we encounter a problem Because the Microsoft implementation is wrapped in COM objects, there is no easy way to copy across an entire entity into an envelope without copying each element in turn So that's what we're going to have to do: 38 B2B Futures: WSDL and UDDI Set save = New save_business Set outEnv = New Envelope Set outEnv.Plugin = save With save.AddbusinessEntity Adddescription = mEntity.Description(1) businessKey = mEntity.businessKey Name = mEntity.Name End With In fact, in real life, there would be a whole lot more! However, we are nearly finished, and we can send off our save to the registry: Set inEnv = mReq.UDDIRequest(outEnv) MsgBox ("Done") End Sub Let's try the application out and see if it works Here is the result of our search on Ariba: Let's change that description back to what it was before: If we now clear that description and issue the search again, the new value will reappear And the really good news is that this works with the IBM and Microsoft registries as well 39 Chapter 27 Summary In this chapter, we have looked a little into the future In particular, we have: ❑ Looked at how our systems are going to be talking to each other, using WSDL ❑ Succeeded in getting two completely unrelated systems to work together in a reasonably satisfactory manner ❑ Discussed what impact this might have on future software development processes We have also looked at how: ❑ Our systems are going to find compatible partners, via the UDDI registry ❑ We can search this registry to find the information we need ❑ We can publish data to it Again, we have done this with two entirely different technologies 40 ... Andrew Watt Kevin Williams Zoran Zaev Wrox Press Ltd Team-Flyđ Professional XML 2nd Edition â 2001 Wrox Press All rights reserved No part of this book may be reproduced, stored in a retrieval... http://www.w3.org/TR/2000/REC -xml- 20001006-review.html The first edition is at http://www.w3.org/TR/1998/REC -xml- 19980210, with Bray's annotated version available at http://www .xml. com/axml/axml.html There is an XML 1.0... Ecommerce applications may use XML to describe business rules and XML (as SOAP or XML- RPC) for distributed processing calls and messages Financial transactions may be encoded in signed XML packets, and

Ngày đăng: 20/03/2019, 14:04

Từ khóa liên quan

Mục lục

  • sample.pdf

    • sterling.com

      • Welcome to Sterling Software

Tài liệu cùng người dùng

Tài liệu liên quan