Building web serivices with Java making sencse of XML


2 months ago
Full text

Building Web Services with Java™: Making Sense of XML, SOAP, WSDL, and UDDI

  Library of Congress Cat alog Card Num ber: 2001090920Print ed in t he Unit ed St at es of Am ericaFirst Print ing: Decem ber 2001 04 03 02 01 4 3 2 1 Trademarks All t erm s m ent ioned in t his book t hat are know n t o be t radem arks or service m arks have been appropriat ely capit alized. Theaut hors and t he publisher shall have neit her liabilit y nor responsibilit y t o any person or ent it y w it h respect t o any loss or dam ages arising from t he inform at ion cont ained in t hisbook.

About the Authors

  Prior t o t his, St eve w orked as at echnologist and consult ant on various em erging t echnologies such as Java and XML, and before t hat he w as an archit ect and consult ant w it h t he I BM Sm allt alk consult ingorganizat ion. Glen Daniels, in his 13 years in t he soft ware indust ry, has run t he gam ut from device drivers and net w ork st acks up t hrough user int erface and Web sit e w ork, in everyt hingfrom assem bly language t o C+ + t o Lisp.


  My t hanks also t o t he st aff at Sam s, part icularly Tiffany Taylor and Michael St ephens, for t he hard w ork t hat w ent int o m aking t his proj ect a realit y. —Doug DavisFor all m y friends and fam ily w ho so pat ient ly cont inue t o be t here for m e t hrough even t he busiest t im es—love and t hanks t o all of you.

Tell Us What You Think!

  We value your opinion and w ant t o know w hat w e're doing right , w hat w e could do bet t er, w hatareas you'd like t o see us publish in, and any ot her w ords of w isdom you're w illing t o pass our way. Please not e t hat I cannot help you w it h t echnical problem s relat ed t o t he t opic of t his book, and t hat due t o t he high volum e of m ail I receive, I m ight not be able t o reply t oevery m essage.

Goals of this Book

  The overall goal of t his book is t o fam iliarize you w it h t he concept of Web services and w hat it w ill t ake t o incorporat e Web services as part of your business. We w ill int roduce t he concept of Web services and give you a fram ew ork t hat describes how you can posit ion t he various em erging st andards t hat are associat ed w it h Webservices, such as Sim ple Obj ect Access Prot ocol ( SOAP) , Web Services Descript ion Language ( WSDL) , and Universal Descript ion Discovery and I nt egrat ion ( UDDI ) .

Assumed Background

  I f you do not have any experience w it h t hese t echniques, som e of t he m at erial could be a lit t leconfusing—part icularly som e of t he code exam ples—but you should st ill be able t o get a lot out of t his book. I f you need t o supplem ent your underst anding of t hese t echniques, m any, m any good You w ill also discover t hat t he Ext ensible Markup Language ( XML) is at t he core of all t hings dealing w it h Web service.


  These layersproduce a series of Web services t echnology " st acks." For each of t he t echnologies and st andards in t he Web services arena, w e focus on underst anding t he t echnology from t heperspect ive of w hat problem s it solves, balancing t he explanat ion of t he t echnology it self. The use of t he running exam ple adds insight t o t he explanat ion of t he concept in t he t ext of t he book and support s t he progressive disclosure approach as w efollow t he exam ple, adding t he layers of Web services t echnology t o t he solut ion.


  We have included a glossary at t he back of t his book t hat act s as a great reference guide t o t het erm inology used in t he book. We w ill annot at e t he first use of each t erm appearing in t he glossary using t he sym bol.

Introducing SkatesTown

  Of t he t hree, Chad is t he real gearhead, and he has been responsible for m ost of t he daring const ruct ion and design choices t hat have helped Skat esTow n get w here it ist oday. A few years back, Dean realized t hat net w orking t echnology w as going t o be big, and he w ant ed t o m ake sure t hat Skat esTow n could cat ch t he w ave and ut ilize dist ribut edcom put ing t o leverage it s business.

Our Story Begins…

  He realizes t hat as t he business grow s, t he m anual t asks associat ed w it h order gat hering and invent ory resupply w ill lim it t he com pany'ssuccess. As w e m ove t hrough t he rest of t he book, w e'll keep an eye on how Skat esTow n uses t echnologies like XML and, lat er, SOAP, WSDL, and UDDI t o increase efficiency,product ivit y, and est ablish new and valuable relat ionships w it h it s cust om ers and business part ners.

What Is a Web Service?

  Alt hough t here seem s t o be a slow convergencet ow ards a com m on underst anding of w hat t he t erm m eans, t here is no single, universally adopt ed definit ion of w hat is m eant by t he t erm Web service. The nat ure of t he int erface hides t he im plem ent at ion det ails of t he service so t hat it can be used independent ly of t he hardw are or soft w are plat formon w hich it is im plem ent ed and independent ly of t he program m ing language in w hich it is w rit t en.

Business Perspective

Technical Perspective

  Just as I T is fundam ent al t o t he efficient operat ions of an organizat ion, Web services- based syst em s int egrat ionw ill be fundam ent al t o flexible, light w eight syst em s int egrat ion—for int ernal applicat ion int egrat ion w it hin an organizat ion over an int ranet and ext ernal part ner int egrat ion overt he I nt ranet or ext ended virt ual privat e net w ork. Wit h Web services, t he I T indust ry is t rying t o address t he fundam ent al challenge of dist ribut edcom put ing t hat has been around for decades—locat ing and accessing rem ot e syst em s.

The Web Service Opportunity

  I n eit her of t hese cat egories, Web services can range in sophist icat ionfrom sim ple request response funct ions such as a credit card check t o very com plicat ed m ult i- part y, m ult i- st age long- running business t ransact ions such as a supplyconfigurat ion and order syst em . Regardless of t he applicat ion, Web services w ill be used for syst em s int egrat ion: flexible, loosely- coupled syst em s int egrat ion yielding syst em s t hat can be decom posed andrecom posed t o reflect changes in t he business.

Enterprise Application Integration

  Ent erprise Applicat ion I nt egrat ion is st ill a field w here large consult ing com panies com m and m ult im illion dollar cont ract s t o help t heir client s deal w it h a m ess ofapplicat ions t hat w ere never m eant t o int eroperat e. I n m any organizat ions, part icularly organizat ions t hat result from a m erger of t w o previously independent com panies, I Tint egrat ion cost s can seriously im pact t he financial healt h of t he com pany.


  The challenges of building B2B applicat ions com bined w it h t heir huge m arket pot ent ial drove rapid innovat ion t hat has t aken t he indust ry from sim ple business- t o- consum er( B2C) applicat ions t o SOAP- enabled Web services in a m at t er of five years. To access t his funct ionalit y, a hum an being needs t o use a Web brow ser t o navigat e t he com pany's sit e t hrough m ult iple paget ransit ions, input inform at ion using Web form s, subm it t hem , and get t he result s back in hum an- readable form .

Area B2C application B2B application

Backend logic Java classes and EJBs Java classes and EJBs Custom logic Servlets and JSPs Web service engineCommunication HTTP HTTP, SMTP, FTP, TCP/IP, EDI, protocol JMS, RMI/IIOP…Data input HTTP GET/POST XML parametersData output HTML XML UI HTML + script N/AClient Human behind a Software application browser

Trends in e-business I t is clear t hat t he net w ork econom y is current ly driving t he evolut ion of business

  I t t ook t headvent of t he World Wide Web for t he next m aj or shift , w it h HTML and HTTP providing t he first t ruly universal open and port able user int erface. Program s t hat use t he older schem a don'tnecessarily break w hen t he new XML elem ent is added ( t his is a propert y of XML nam espaces t hat you w ill see in Chapt er 2 , " XML Prim er" ) .

Why Do We Need a Web Services Approach?

  The beginning of t his chapt er explained t he m ot ivat ion for applicat ion- t o- applicat ion com m unicat ion over t he I nt ernet t o address t he current challenges of dist ribut edcom put ing and B2B int egrat ion in part icular. As aresult , w e are able t o do t hings out side t he scope of t radit ional dist ribut ed com put ing approaches: Support both document-centric messaging and RPCs I n ot her words, Web services are bet t er suit ed for t he t ask t han what we have so far because w e have specifically built t hem w it h t his in m ind.

Core Technologies

  I t is possible t o com pare t heWeb services approach t o t radit ional dist ribut ed com put ing approaches level- by- level t o see w hy t he t echnical foundat ion of Web services is m ore appropriat e for t he problem s itneeds t o solve. I n short , t rust t hat som e of t he very best m inds in t he indust ry w orking t oget her under t he aegis of organizat ions such as t he W3C and OASI S w ill beable t o com e up w it h a good solut ion t o t he problem s of e- business int egrat ion.

Distributed Computing History

  I n m ost cases, t he syst em s were sodifferent t hat t he requirem ent t o perform fine- grain int egrat ion via RPCs w as im possible t o sat isfy. The bind operation embodies the client-server relationship between 4 , " Sim ple Obj ect Access Prot ocol ( SOAP) " and " Creat ing Web Services ," focus on t he use of SOAP t o fulfill t he bind operat ion; Chapt er 5 , " Using SOAP for e- Business," det ails how t he bind can be m ade ready for e- business.

Web Services Interoperability Stacks

  To help put a fram ew ork around t hese t echnologies, w e refer t o a t rio of Web services int eroperabilit y st acks, first proposed t o t he W3C by I BM and Microsoft in March 2001( ht t p: / / w w w .w 2001/ 03/ WSWS- popa/ paper51 ) . This proposal fact ored Web services t echnologies int o t hree st acks: The wire stack • The description stack The cont ent s of t he st acks present ed in t his book reflect a different fact oring t han originally proposed t o t he W3C, due in part t o t he addit ional st andards effort s t hat havecom e int o play since March 2001.

The Description Stack

  Wit h WSDL, a developer describes t he set of operat ions support ed by a Web service, including t he kinds of obj ect s t hat are expect ed as input and out put of t heoperat ions, t he various bindings t o concret e net w ork and dat a encoding schem es. The role of t he endpoint definit ion is t o layer on t op of t he WSDL descript ioninform at ion about charact erist ics of t he Web service t hat are im pact ed by it s im plem ent at ion environm ent .

The Discovery Stack

  Given t he abilit y t o describe Web services, w e are bet t er off t han w e w ere, but w e st ill have solved only part of t he Web service int egrat ion problem . I nspect ion is a t echnique of discovering t he service descript ion given t hat t he det ails about t he service( a service ident ifier or URL, for exam ple) are already known.

Putting the Interoperability Stacks Together

  Techniques such as t he Web ServicesI nvocat ion Fram ew ork ( WSI F) ( ht t p: / / w w w .alphaw .com / t ech/ w sif ) discuss t he possibilit y of a Web service being a sim ple Java m et hod invocat ion, w here t he servicerequest or and service provider are in t he sam e Java Virt ual Machine. I n t hese cases, t he com m onalit y t hat m akes t hese com ponent s Web services is t he use of WSDL t o describe t he service.


  Because t he t erm is confusing ( a m arkup language specificat ion is not a piece of soft w are) , it is rarely used now adays, but you st ill m ight encount er it in som e of t hereference m at erials point ed out at t he end of t he chapt er. Unfort unat ely, due t o t he rapid grow t h of t heI nt ernet and t he m arket pressure caused by t he brow ser w ars, t he leading brow ser vendors int roduced a num ber of incom pat ible t ags t o HTML com plet ely out side t he scopeof t he HTML specificat ion.

Document- Versus Data-Centric XML

Document-Centric XML

  Because of it s SGML origins, in t he early days of it s exist ence XML gained rapid adopt ion w it hin publishing syst em s as a m echanism for represent ing sem i- st ruct ured docum ent ssuch as t echnical m anuals, legal docum ent s, and product cat alogs. The usage rules for t ags such as <B> <I> <LINK> , and are very loosely defined; t hey could appear pret t y m uch anyw here in t he docum ent : <H1>Skat eboard Usage Requi rement s</H1> <P>I n order t o use t he <B>Fast Gl i de</B> skat eboard you have t ohave: </P> <LI ST><I TEM>A st rong pai r of l egs.

Data-Centric XML

  By cont rast , dat a- cent ric XML is used t o m ark up highly st ruct ured inform at ion such as t he t ext ual represent at ion of relat ional dat a from dat abases, financial t ransact ioninform at ion, and program m ing language dat a st ruct ures. I t is XML's nat ural abilit yt o nest and repeat m arkup t hat m akes it t he perfect choice for represent ing t hese t ypes of dat a.

Document Lifetime

  I f you om it t he XML declarat ion, t he XML version is assum ed t o be 1.0, and t he processing applicat ion w ill t ry t o guess t he encoding of t he docum ent based on cluessuch as t he raw byt e order of t he dat a st ream . Probably t he best exam ple is , w hich is used t o ident ify t he language of t he t ext t hat is t he cont ent of t he elem ent w it h t hat at t ribut e.

Character Data

  Most XML developers t end t o t hink of t hese as m apping t ot he st ring dat a t ype in t heir program m ing language of choice. I t is not im port ant t o com plet ely define t hese rules here, but acouple of t hem are w ort h m ent ioning: An XML processor is required to convert any carriage return (CR) Luckily, m ost dat a- orient ed XML applicat ions care lit t le about w hit espace.

Character Escape sequence

  How ever, asapplicat ion com plexit y increases and t he num ber of applicat ions t hat need t o w ork w it h som e part icular com posed docum ent t ype grow s, t he need t o clearly dist inguish bet w eent he XML elem ent s becom es param ount . .</po: po> </i t em> </at t achment > </message> Default nam espaces w ork because t he cont ent of any nam espace- prefixed elem ent is considered t o belong t o t he nam espace of it s parent elem ent unless, of course, t he xmlns elem ent is explicit ly defined t o be in anot her nam espace w it h it s ow n - t ype at t ribut e.

Namespace-Prefixed Attributes

  The com m on use-case scenario is t he desire t o ext end t he inform at ion provided by an XML elem ent w it hout having t o m ake changes direct ly t o it s docum ent t ype. Because item t he at t ribut e w ill be in a nam espace different from t hat of t he elem ent , t he order The exam ple in List ing 2.9 uses t his m echanism t o m ake t he backpacks high priorit y and priority t he prom ot ional m at erials low priorit y.

Dereferencing URIs

  This rigidm andat e m akes it easy t o separat e t he doings of t he soft w are focused on t he logical st ruct ure of an XML docum ent ( w hat t he m arkup m eans) from t he m undane det ailsof t he physical st ruct ure of t he docum ent ( t he m arkup synt ax) . The not ion of form at applies t o t he set of rules describing po Skat esTow n's purchase orders: " The docum ent m ust begin w it h a elem ent t hat has id submitted billTo t w o at t ribut es ( and ) w hich w ill be follow ed by a elem ent …" and so on.

Document Structure

  One way t o visualize t he st ruct ure of a docum ent is as a t ree of possible elem ent and at t ribut ecom binat ions. The im age uses som e synt ax fromregular expressions t o visualize t he m ult iplicit y of elem ent s: quest ion m ark ( ?) st ands for opt ional ( zero or one) , ast erisk ( * ) st ands for any ( zero or m ore) , and plus ( + ) st andsfor at least som e ( one or m ore) .

X, Y, Z, B, D •

  For exam ple, t he m odel group ( A, B?, C* ,D+ ) allow s for t he follow ing com binat ions of child elem ent s ( … st ands for " pot ent ially m any m ore of t he sam e elem ent " ) : A, D… • A, B, D… • A, B, C…, D… Docum ent s associat ed wit h DTDs are a huge st ep forward from basic XML m arkup. DTDs allow for validat ing docum ent st ruct ure ( elem ent cont ent , allow ed at t ribut es, and t heirvalue t ypes) , w hich significant ly reduces t he am ount of cust om validat ion code t hat needs t o be w rit t en in XML applicat ions.

XML Schemas

  As part of XML 1.0, DTDs offered t he basicm echanism for defining a vocabulary specifying t he st ruct ure of XML docum ent s in an at t em pt t o est ablish a cont ract ( how an XML docum ent w ill be st ruct ured) bet w eenm ult iple part ies w orking w it h t he sam e t ype of XML. To address t hese issues,t he XML com m unit y, under t he leadership of t he W3C, t ook up t he t ask of creat ing a m et a- language for describing bot h t he st ruct ure of XML docum ent and t he m apping of XML synt ax t o dat a t ypes.

Simple Type Examples (delimited by commas) Notes

  The facet s ident ify various charact erist ics of t he t ypes such as: , minLength and — t he exact , m inim um and m axim um charact er lengt h of t he value ID — a regular expression pat t ern for t he value — a list of all possible values — t he rules for handling w hit espace in t he value , minInclusive , maxInclusive and maxExclusive — t he range of num eric values t hat are allow ed / value. A not e on ID / IDREF at t ribut es: An XML processor is required t o generat e an error if a docum ent cont ains t w o ID at t ribut es w it h t he sam e value or an IDREF w it h a value t hat has no m at ching 2.4 cross- link t he pre- defined t ypes and t he facet s t hat are applicable for t hem .

Max Max Min Min Total Fraction Inclusive Exclusive Inclusive Exclusive Digits Digits

  I t is based on a st ring and it rest rict s it t o have t he pat t ern of t hree digit s follow ed by dash follow ed by t w o uppercase let t ers. Listing 2.12 Using Patterns to Define String Format <xsd: si mpl eType name="skuType"> <xsd: rest ri ct i on base="xsd: st ri ng"><xsd: pat t ern val ue="\d{ 3} - [ A- Z] { 2} "/> </xsd: rest ri ct i on></xsd: si mpl eType>List ing 2.13 show s how t o force purchase order ids t o be great er t han 10,000 but less t han 100,000 and define an enum erat ion of all U.

Complex types

  The m ost com m only used t op- levelm odel group elem ent s you w ill see are: — A sequence of elem ent s — Allow s one out of a num ber of elem ent s — Allow s a cert ain set of elem ent s t o appear once or not at all but in any order — References a m odel group t hat is defined som eplace else xsd:group These could be furt her nest ed t o creat e m ore com plex m odel groups. The special value for of is used for t he st reet elem ent t o indicat e t hat t here m ust be at least one present ( " " in t he docum ent xsd:element Every elem ent is associat ed w it h a t ype using t he t ype at t ribut e .

Basic Schema Reusability

  The root of t he problem is t hat t he and contact elem ent s are defined in one nam espace () , w hereas t he elem ent s belonging t o t he name company street city state postalCode country address t ype— , , , , , , —are defined in anot her ( ) . A bet t er design for t he class, PO unfort unat ely, requires som e duplicat ion of 's dat a m em bers: cl ass I nvoi ce {i nt i d; Dat e submit t ed;Address bi l l To; Address shi pTo;I nvoi ceI t em order[ ] ; f l oat t ax;f l oat shi ppi ngAndHandl i ng; f l oat t ot al Cost ;} Item InvoiceItem InvoiceItem Not e t hat subclassing t o get is a good decision because Item is a pure ext ension of .

Basic Operations The basic XML processing archit ect ure shown in Figure 2.5 consist s of t hree key layers

  Cont rol of cont ext refers t o who has t o m anage cont ext inform at ion such as t he level of nest ing of elem ent s and t heir locat ion relat ive t o one anot her. Hybrid parsers at t em pt t o offer t he best of bot h w orlds by present ing a t ree view of t he docum ent but doing increm ent al parsing behind t he scenes.

Hybrid Parser Parser Medium Medium Highest (JDOM)

  I n m any cases, it m ight beeasier for t he applicat ion t o const ruct a dat a st ruct ure ( DOM or JDOM t ree) describing t he XML docum ent t hat should be generat ed. Then, t he applicat ion can use a serializat ion process t o t raverse t he docum ent t ree and em it XML m arkup corresponding t o it selem ent s.

Data-Oriented XML Processing

  When you're t hinking about applicat ions w orking w it h XML, it is im port ant t o not e t hat all t he m echanism s for parsing and generat ing XML described so far are synt ax- orient ed. They are not concerned w it h t he physical st ruct ureof t he dat a, be it charact ers and lines in t he case of t ext files or elem ent s and at t ribut es in t he case of XML docum ent s.

The act ual im plem ent at ion of w ill have t o do t he follow ing: 1. Obtain an XML parser

  Based on t he nam e of t he elem ent , w e decidew het her t o save t he am ount as t he t ot al cost of t he invoice or w het her t o add it t o t he running t ot al. When w e process charact er dat a and w e are expect ing a dollar value, w e ext ract t he amount elem ent cont ent , convert it t o a double value, and save it in t he class m em ber for endElement() use by t he callback.endElement() Not e t hat w e could have skipped im plem ent ing alt oget her if w e had also st ored t he elem ent nam e as a st ring m em ber of t he class or used an enum erat ed value.

Defines and classes

  The DOM defines API s t hat allow applicat ions t o navigat e XML docum ent s and t o m anipulat e t heir cont ent and st ruct ure. I t provided t he basic funct ionalit y t o navigat e and m anipulat e XML The DOM Level 2 Core API builds upon Level 1, fixes some problem • spots, and defines additional ways to navigate and manipulate thecontent and structure of documents.

The DOM Level 2 HTML API specifies interfaces that provide • programmers with the ability to work with HTML documents

  One of t he m ost useful m et hods of t he getParameter() request obj ect is , w hich ret rieves t he value of a param et er passed from t he Web such as a form field or ret urns null if t his param et er did not com e w it h t he getParameter("xml") request . I t t hen xml checks t he invoice by passing t he value of t he t ext area on t he page t o t he checkInvoice() m et hod.


  Wit h com pet it ive and m arket pressures driving t heWeb services indust ry in a hard race t o provide m eaningful solut ions t o cross- ent erprise int egrat ion problem s, SOAP is t he go- t o- m arket t echnology of choice. Last but not least , youw ill be ready t o handle t he rest of t he book and clim b st ill higher t ow ard t he t op of t heWeb services int eroperabilit y st ack.

Building and consuming Web services using the Java-based Apache Axis • Web services engine

  This chapt er is not iceably longer, because t he purpose of t his book is t o be som et hing m ore t han an annot at ed spec or a t ut orial for building Web services. We've t ried hard t ocreat e a t horough t reat m ent of Web services for people w ho w ant answ ers t o quest ions t hat begin not only w it h " w hat " and " how " but also wit h " why." To becom e an expert atWeb services, you need t o be com fort able dealing w it h t he lat t er t ype of quest ions.

First-Generation XML Protocols

  You can seefrom it t hat t he dat a form at is a recordset ( t abular dat a) w it h t hree fields cont aining t heURL t o t he full art icle, it s headline t ext , and t he publishing source: <wddxPacket versi on="1. To sum t hings up, t he need t o provide broad ext ensibilit y w it hout cent ralized st andardizat ion and t he need t o com bine dat at ype inform at ion w it h sem ant ic inform at ionw ere t he driving forces behind t he effort t o im prove upon first - generat ion effort s and t o creat e SOAP, t he de fact o st andard XML prot ocol for m odern Web services and B2Bapplicat ions.

The Making of SOAP

  This change, and t he fact t hat I BM im m ediat ely released a Java SOAP im plem ent at ion t hat w as subsequent ly donat ed t o t he Apache XML Proj ect ( ht t p: / / xm ) for open- source developm ent , convincedeven t he great est skept ics t hat SOAP is som et hing t o pay at t ent ion t o. Right before t he XTech 2000 Conference, t he W3C m ade an announcem ent t hat it w as looking int o st art ing an act ivit y in t he area of XML prot ocols: " We've been under pressurefrom m any sources, including t he advisory board, t o address t he t hreat of fragm ent at ion of and invest igat e t he excit ing opport unit ies in t he area of XML prot ocols.

What Should SOAP Do?

  Here are som e " facet s" you can use t o t hink about a part icular dist ribut ed com put ing scenario: t he prot ocol st ack used for com m unicat ion, connect ion m anagem ent , securit y,t ransact ion support , m arshalling and unm arshalling of dat a, prot ocol evolut ion and version m anagem ent , error handling, audit t rails, and so on. How ever, t he ubiquit y of SOAP is also a curse, because one t echnology specificat ion should be able t o support m any differentt ypes of dist ribut ed com put ing scenarios, from t he st ock t icker service t o t he e- com m erce paym ent - processing service.

What Is SOAP, Really?

  Despit e t he hype,how ever, SOAP is st ill of great im port ance because it is t he indust ry's best effort t o dat e t o st andardize on t he infrast ruct ure t echnology for cross- plat form XML dist ribut edcom put ing. The t ext of t he specificat ion has grow n since t hen ( t he aut hors have t o m ake sure t hespecificat ion is clear and has no holes) , but t he core concept s rem ain sim ple.

A binding mechanism for SOAP messages to HTTP, because HTTP is the • most common communication protocol on the Internet

  Note A not e of caut ion: t his book's sam ple applicat ions dem onst rat e realist ic uses of Java t echnology and Web services t o solve real business problem s w hile, at t he sam e t im e,rem aining sim ple enough t o fit in t he book's scope and size lim it at ions. Then, you call t he m et hod of t he , passing in t he nam e of t he operat ion you are t rying t o invoke and an obj ect array of t he t w o operat ion String Integer param et ers: a for t he SKU and an for t he quant it y.

SOAP on the Wire

  I n t his case, t his elem ent has t he sam e nam e as t he m et hod on t he Web service t hat you w ant t o doCheck() ServiceClient invoke— . The elem ent cont ained w it hin uses t he sam e pat t ern but w it hResult appended t o indicat e t hat t he cont ent of t he elem ent is t he result of t he operat ion.

SOAP Envelope Framework

  True, you can em bed arbit rary XML inside t he SOAP BodyEnvelope elem ent , but naïve validat ion w ill fail w hen it encount ers t he elem ent at t he t op of t he docum ent inst ead of t he t op docum ent elem ent of your schem a. I nst ead of going t his w ay, SOAP leverages t he capabilit ies of XML nam espaces and defines t he prot ocol version t o be t he URI of t he SOAP envelopenam espace.

SOAP Headers

  Before leaving t he t opic of headers, it is im port ant t o point out t hat , despit e t he obvious need for header ext ensions t o support such basic dist ribut ed com put ing concept s such asaut hent icat ion credent ials or t ransact ion inform at ion, t here hasn't been a broad st andardizat ion effort in t his area, w it h t he except ion of som e securit y ext ensions t hatw e'll review in Chapt er 5 . This is a com binat ion of t w o part s: t he URL of t he Axis servlet t hat list ens for SOAP request s over /bws/services HTTP ( ) and t he nam e of t he service w e w ant t o invoke InventoryCheck SOAPAction ( ) .

The Need for Intermediaries

  The SOAP specificat ion st at es, " t he role of a recipient of a header elem ent issim ilar t o t hat of accept ing a cont ract in t hat it cannot be ext ended beyond t he recipient ." This m eans t hat t he int erm ediary should rem ove any header t arget ed for itt hat it has processed. The goal here is t o reduce syst em com plexit y by requiring t hat cont ract s about t he presence, absence, and cont ent of inform at ion in SOAP m essages bevery narrow in scope—from t he originat or of t hat inform at ion t o t he first SOAP applicat ion t hat handles it and not beyond.

Putting It All Together

  The applicat ions in t he purchasing depart m ent w ill use t his ident it y t o check w het her part nerA is aut horized t o perform t he operat ion request ed in t he SOAP m essage body. Aut hent i cat i onFai l ure</f aul t code> <f aul t st ri ng>Fai l ed t o aut hent i cat e cl i ent </f aul t st ri ng><f aul t act or>urn: X- Skat esTown: Part nerGat eway</f aul t act or> </SOAP- ENV: Faul t ></SOAP- ENV: Body> </SOAP- ENV: Envel ope> 500 Internal Server Before we look at t he XML, not e t hat t he HTTP response code is Error .

Envelope uses by inspecting the namespace value of the SOAP element

  All t hese t ypes have xsi:type direct represent at ion in XML Schem a so it w as easy, t hrough t he use of t he at t ribut e, t o describe t he t ype of dat a being passed in a m essage. For xsi:type exam ple, if t he schem a cont ent t ype is " any" , it again m akes sense t o use as m uch as possible t o specify t he exact t ype of value t hat is being t ransferred.

Choosing a Data Encoding

  I f no one w ill ever ext ernally reference specific I Ds w it hin t he prot ocol m essage dat a, t hen your XML prot ocol t oolset canaut om at ically re- w rit e t he I Ds and references t o t hem as you include t he XML inside t he m essage, as follows: <message i d="msg- 1"> A message wi t h an at t ached .<at t achment i d="at t achment - 1"> <! I f, on t he ot her hand, you j ust w ant t o m akean RPC call over SOAP t o pass som e dat a t o a Web service, t hen t he exact form at of t he XML represent ing your RPC param et ers does not m at t er.

Architecting Distributed Systems with Web Services

  The last configurat ion is t he m ost int erest ing, in t hat t he m essage can be m oved from t he local t o t he rem ot e syst emw it hout eit her t he sender or t he receiver being online—t he m essage queuing syst em s can do t he j ob by t hem selves. Anot her w ay t o st at e t he m ain difference bet w een m essaging and RPC is t o not e t hat sendMessage() getMessage() m essaging deals wit h generic API s such as , , and registerMessageResponseCallback() , w hereas RPCs deal w it h special- purpose API s t hat vary based on t he int erface of t he t arget t hat is being invoked.

Pros Cons

Direct m essaging manual data encoding/decoding.

Dokumen baru