The Java™ Web Services Tutorial
616 pages
English

The Java™ Web Services Tutorial

Le téléchargement nécessite un accès à la bibliothèque YouScribe
Tout savoir sur nos offres
616 pages
English
Le téléchargement nécessite un accès à la bibliothèque YouScribe
Tout savoir sur nos offres

Description

The Java™ Web
Services Tutorial
Eric Armstrong
Stephanie Bodoff
Debbie Carson
Maydene Fisher
Dale Green
Kim Haase
March 15, 2002 iii
Copyright © 2002 by Sun Microsystems, Inc.
901 San Antonio Road, Palo Alto, California 94303 U.S.A.
All rights reserved.
RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by the United States Government is subject to the
restrictions set forth in DFARS 252.227-7013(c)(1)(iii) and FAR 52.227-19.
The release described in this book may be protected by one or more U.S. patents, foreign patents, or pending applica-
tions.
Sun, Sun Microsystems, Sun Microsystems Computer Corporation, the Sun logo, the Sun Microsystems Computer
Corporation logo, Java, JavaSoft, Java Software, JavaScript, JDBC, JDBC Compliant, JavaOS, JavaBeans, Enterprise
JavaBeans, JavaServer, JavaServer Pages, J2EE, J2SE, JavaMail, Java Naming and Directory Interface, EJB, and JSP
®are trademarks or registered trademarks of Sun Microsystems, Inc. UNIX is a registered trademark in the United
States and other countries, exclusively licensed through X/Open Company, Ltd. All other product names mentioned
herein are the trademarks of their respective owners.
THIS PUBLICATION IS PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR
IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
THIS PUBLICATION COULD INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS.
CHANGES ARE ...

Sujets

Informations

Publié par
Nombre de lectures 62
Langue English
Poids de l'ouvrage 2 Mo

Extrait

The Java™ Web Services Tutorial Eric Armstrong Stephanie Bodoff Debbie Carson Maydene Fisher Dale Green Kim Haase March 15, 2002 iii Copyright © 2002 by Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California 94303 U.S.A. All rights reserved. RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by the United States Government is subject to the restrictions set forth in DFARS 252.227-7013(c)(1)(iii) and FAR 52.227-19. The release described in this book may be protected by one or more U.S. patents, foreign patents, or pending applica- tions. Sun, Sun Microsystems, Sun Microsystems Computer Corporation, the Sun logo, the Sun Microsystems Computer Corporation logo, Java, JavaSoft, Java Software, JavaScript, JDBC, JDBC Compliant, JavaOS, JavaBeans, Enterprise JavaBeans, JavaServer, JavaServer Pages, J2EE, J2SE, JavaMail, Java Naming and Directory Interface, EJB, and JSP ®are trademarks or registered trademarks of Sun Microsystems, Inc. UNIX is a registered trademark in the United States and other countries, exclusively licensed through X/Open Company, Ltd. All other product names mentioned herein are the trademarks of their respective owners. THIS PUBLICATION IS PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. THIS PUBLICATION COULD INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS. CHANGES ARE PERIODICALLY ADDED TO THE INFORMATION HEREIN; THESE CHANGES WILL BE INCORPORATED IN NEW EDITIONS OF THE PUBLICATION. SUN MICROSYSTEMS, INC. MAY MAKE IMPROVEMENTS AND/OR CHANGES IN THE PRODUCT(S) AND/OR THE PROGRAM(S) DESCRIBED IN THIS PUBLICATION AT ANY TIME. iv Contents Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii Chapter 1: Introduction to Web Services . . . . . . . . . . . . . . . . . . 1 The Role of XML and the Java™ Platform 2 What Is XML? 4 What Makes XML Portable? 5 Overview of the Java APIs for XML 6 JAXP 7 The SAX API 8 The DOM API 10 The XSLT API 13 JAX-RPC 16 Overview of JAX-RPC 16 Using JAX-RPC 18 Creating a Web Service 19 Coding a Client 21 Invoking a Remote Method 22 JAXM 22 Getting a Connection 24 Creating a Message 25 Populating a Message 26 Sending a Message 28 JAXR 29 Using JAXR 29 Sample Scenario 32 Scenario 32 Conclusion 33 v vi CONTENTS Chapter 2: Understanding XML. . . . . . . . . . . . . . . . . . . . . . . . . .35 Introduction to XML 36 What Is XML? 36 Why Is XML Important? 41 How Can You Use XML? 43 XML and Related Specs: Digesting the Alphabet Soup 46 Basic Standards 47 Schema Standards 49 Linking and Presentation Standards 52 Knowledge Standards 53 Standards That Build on XML 54 Summary 56 Designing an XML Data Structure 57 Saving Yourself Some Work 57 Attributes and Elements 57 Normalizing Data 60 Normalizing DTDs 61 Chapter 3: Getting Started With Tomcat . . . . . . . . . . . . . . . . . .63 Setting Up 64 Getting the Example Code 64 Checking the Environment Variables 66 Creating the Build Properties File 66 Creating the Getting Started Application 67 The ConverterBean Component 67 The Web Client 69 Building the Getting Started Application Using Ant 71 Creating the Build and Deploy File for Ant 71 Compiling the Source Files 73 Deploying the Application 74 Starting Tomcat 74 Installing the Application using Ant 74 Deploying the Application Using the Application Deployment Tool 75 Running the Getting Started Application 77 Running the Web Client 77 Shutting Down Tomcat 78 Using admintool 79 Adding Roles Using admintool 79 Adding Users Using admintool 80 Modifying the Application 80 CONTENTS vii Modifying a Class File 81 Modifying the Web Client 81 Common Problems and Their Solutions 81 Compilation Errors 82 Deployment Errors 83 Chapter 4: Java API for XML Processing . . . . . . . . . . . . . . . . . . 85 The JAXP APIs 86 An Overview of the Packages 86 The Simple API for XML (SAX) APIs 87 The SAX Packages 90 The Document Object Model (DOM) APIs 90 The DOM Packages 92 The XML Stylesheet Language for Transformation (XSLT) APIs 93 The XSLT Packages 94 Compiling and Running the Programs 94 Where Do You Go from Here? 94 Chapter 5: Simple API for XML . . . . . . . . . . . . . . . . . . . . . . . . . . 97 Writing a Simple XML File 98 Creating the File 99 Writing the Declaration 99 Adding a Comment 99 Adding Nested Elements 101 Adding HTML-Style Text 102 Adding an Empty Element 102 The Finished Product 103 Echoing an XML File with the SAX Parser 104 Creating the Skeleton 104 Importing Classes 105 Setting up for I/O 105 Implementing the ContentHandler Interface 106 Setting up the Parser 107 Writing the Output 108 Spacing the Output 109 Handling Content Events 109 Compiling and Running the Program 112 Checking the Output 113 Identifying the Events 114 viii CONTENTS Compressing the Output 116 Inspecting the Output 117 Documents and Data 118 Adding Additional Event Handlers 119 Identifying the Document’s Location 119 Handling Processing Instructions 121 Summary 122 Handling Errors with the Nonvalidating Parser 123 Substituting and Inserting Text 132 Handling Special Characters 133 Using an Entity Reference in an XML Document 134 Handling Text with XML-Style Syntax 135 Handling CDATA and Other Characters 136 Creating a Document Type Definition (DTD) 137 Basic DTD Definitions 137 Defining Text and Nested Elements 139 Limitations of DTDs 139 Special Element Values in the DTD 140 Referencing the DTD 141 DTD’s Effect on the Nonvalidating Parser 142 Tracking Ignorable Whitespace 143 Cleanup 145 Documents and Data 145 Empty Elements, Revisited 145 Defining Attributes and Entities in the DTD 146 Defining Attributes in the DTD 146 Defining Entities in the DTD 148 Echoing the Entity References 150 Additional Useful Entities 151 Referencing External Entities 151 Echoing the External Entity 152 Summarizing Entities 153 Referencing Binary Entities 153 Using a MIME Data Type 153 The Alternative: Using Entity References 155 Using the Validating Parser 155 Configuring the Factory 156 Changing the Environment Variable 156 Experimenting with Validation Errors 157 Error Handling in the Validating Parser 159 Defining Parameter Entities and Conditional Sections 159 CONTENTS ix Creating and Referencing a Parameter Entity 159 Conditional Sections 161 Parsing the Parameterized DTD 163 DTD Warnings 165 Handling Lexical Events 166 How the LexicalHandler Works 167 Working with a LexicalHandler 167 Using the DTDHandler and EntityResolver 173 The DTDHandler API 173 The EntityResolver API 175 Chapter 6: Document Object Model . . . . . . . . . . . . . . . . . . . 177 Reading XML Data into a DOM 178 Creating the Program 178 Additional Information 183 Looking Ahead 185 Displaying a DOM Hierarchy 185 Echoing Tree Nodes 185 Convert DomEcho to a GUI App 185 Create Adapters to Display the DOM in a JTree 191 Finishing Up 201 Examining the Structure of a DOM 201 Displaying A Simple Tree 202 Displaying a More Complex Tree 204 Finishing Up 208 Constructing a User-Friendly JTree from a DOM 209 Compressing the Tree View 209 Acting on Tree Selections 214 Handling Modifications 223 Finishing Up 223 Creating and Manipulating a DOM 223 Obtaining a DOM from the Factory 223 Normalizing the DOM 227 Other Operations 229 Finishing Up 229 Using Namespaces 230 Defining a Namespace 230 Referencing a Namespace 231 Defining a Namespace Prefix 232 x CONTENTS Chapter 7: XML Stylesheet Language for Transformations. . .235 Introducing XSLT and XPath 236 The XSLT Packages 236 How XPath Works 237 Summary 246 Writing Out a DOM as an XML File 247 Reading the XML 247 Creating a Transformer 249 Writing the XML 251 Writing Out a Subtree of the DOM 252 Summary 253 Generating XML from an Arbitrary Data Structure 253 Creating a Simple File 254 Creating a Simple Parser 256 Modifying the Parser to Generate SAX Events 259 Using the Parser as a SAXSource 265 Doing the Conversion 267 Transforming XML Data with XSLT 268 Defining an Ultra-Simple article Document Type 268 Creating a Test Document 270 Writing an XSLT Transform 271 Processing the Basic Structure Elements 272 Writing the Basic Program 276 Trimming the Whitespace 278 Processing the Remaining Structure Elements 281 Process Inline (Content) Elements 286 Printing the HTML 290 What Else Can XSLT Do? 290 Concatenating XSLT Transformations with a Filter Chain 293 Writing the Program 293 Understanding How it Works 296 Testing the Program 298 Conclusion 300 Chapter 8: Java API for XML Messaging . . . . . . . . . . . . . . . . .301 Overview of JAXM 302 Messages 302 Connections 305 Messaging Providers 307 Running the Samples 310
  • Univers Univers
  • Ebooks Ebooks
  • Livres audio Livres audio
  • Presse Presse
  • Podcasts Podcasts
  • BD BD
  • Documents Documents