|
The Java Web Services Tutorial
About This Tutorial. . . . . . . . . . . . . . . . . . . . . . . . . . . .xi
Who Should Use This Tutorial xi
How to Read This Tutorial xi
About the Examples xiii
How to Print This Tutorial xiv
Typographical Conventions xv
Chapter 1: Introduction to Web Services . . . . . . . . . . . . . . . . . . 1
The Role of XML and the Java™ Platform 2
What Is XML? 3
Overview of the Java APIs for XML 6
JAXP 7
JAXB 15
JAX-RPC 20
JAXM 27
JAXR 34
Sample Scenario 37
Chapter 2: Understanding XML . . . . . . . . . . . . . . . . . . . . . . . . . 41
Introduction to XML 41
XML and Related Specs: Digesting the Alphabet Soup 51
Designing an XML Data Structure 63
Chapter 3: Getting Started With Tomcat . . . . . . . . . . . . . . . . . . 69
Setting Up 69
Quick Overview 72
Creating the Getting Started Application 73
Building the Getting Started Application Using Ant 77
Contents
iv CONTENTS
Deploying the Application 80
Running the Getting Started Application 82
Using admintool 83
Modifying the Application 85
Common Problems and Their Solutions 87
Further Information 91
Chapter 4: Web Applications . . . . . . . . . . . . . . . . . . . . . . . . . . .93
Web Application Life Cycle 94
Web Application Archives 96
Configuring Web Applications 98
Installing Web Applications 102
Deploying Web Applications 103
Listing Installed and Deployed Web Applications 104
Running Web Applications 105
Updating Web Applications 105
Removing Web Applications 107
Undeploying Web Applications 107
Internationalizing and Localizing Web Applications 108
Accessing Databases from Web Applications 109
Further Information 113
Chapter 5: Java API for XML Processing . . . . . . . . . . . . . . . . .115
The JAXP APIs 115
An Overview of the Packages 116
The Simple API for XML (SAX) APIs 117
The Document Object Model (DOM) APIs 120
The XML Stylesheet Language for Transformation (XSLT) APIs 122
Compiling and Running the Programs 123
Where Do You Go from Here? 123
Chapter 6: Simple API for XML . . . . . . . . . . . . . . . . . . . . . . . . .125
When to Use SAX 126
Writing a Simple XML File 127
Echoing an XML File with the SAX Parser 132
Adding Additional Event Handlers 151
Handling Errors with the Nonvalidating Parser 155
Substituting and Inserting Text 163
Creating a Document Type Definition (DTD) 168
CONTENTS v
DTD’s Effect on the Nonvalidating Parser 173
Defining Attributes and Entities in the DTD 177
Referencing Binary Entities 184
Choosing your Parser Implementation 186
Using the Validating Parser 187
Defining Parameter Entities and Conditional Sections 193
Parsing the Parameterized DTD 197
Handling Lexical Events 200
Using the DTDHandler and EntityResolver 207
Further Information 209
Chapter 7: Document Object Model . . . . . . . . . . . . . . . . . . . 211
When to Use DOM 212
Reading XML Data into a DOM 218
Displaying a DOM Hierarchy 225
Examining the Structure of a DOM 241
Constructing a User-Friendly JTree from a DOM 252
Creating and Manipulating a DOM 268
Using Namespaces 277
Validating with XML Schema 280
Further Information 286
Chapter 8: XML Stylesheet Language for Transformations . . 289
Introducing XSLT and XPath 290
Choosing the Transformation Engine 291
How XPath Works 294
Writing Out a DOM as an XML File 305
Generating XML from an Arbitrary Data Structure 312
Transforming XML Data with XSLT 327
Transforming from the Command Line 351
Concatenating Transformations with a Filter Chain 354
Further Information 361
Chapter 9: Binding XML Schema to Java Classes with JAXB 363
JAXB Architecture 364
XML Schemas 376
Representing XML Content 380
Binding XML Schemas 381
Customizing JAXB Bindings 384
vi CONTENTS
What is Not Supported 386
JAXB APIs and Tools 386
Chapter 10: Using JAXB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .387
General Usage Instructions 388
Basic Sample Applications 409
Customizing JAXB Bindings 422
Chapter 11: Building Web Services With JAX-RPC . . . . . . . . . .455
A Simple Example: HelloWorld 456
Types Supported By JAX-RPC 467
A Dynamic Proxy Client Example 470
A Dynamic Invocation Interface (DII) Client Example 471
The wscompile Tool 474
The wsdeploy Tool 477
Advanced Topics for wscompile and wsdeploy 480
Further Information 481
Chapter 12: Web Services Messaging with JAXM . . . . . . . . . .483
The Structure of the JAXM API 484
Overview of JAXM 485
Running the Samples 495
Tutorial 499
Code Examples 521
Further Information 535
Chapter 13: Publishing and Discovering Web Services with JAXR
537
Overview of JAXR 538
Implementing a JAXR Client 541
Running the Client Examples 562
Further Information 570
Chapter 14: Java Servlet Technology . . . . . . . . . . . . . . . . . . . .571
What is a Servlet? 571
The Example Servlets 572
Servlet Life Cycle 574
CONTENTS vii
Sharing Information 577
Initializing a Servlet 581
Writing Service Methods 582
Filtering Requests and Responses 587
Invoking Other Web Resources 594
Accessing the Web Context 598
Maintaining Client State 599
Finalizing a Servlet 602
Further Information 605
Chapter 15: JavaServer Pages Technology . . . . . . . . . . . . . . . 607
What Is a JSP Page? 607
The Example JSP Pages 610
The Life Cycle of a JSP Page 612
Initializing and Finalizing a JSP Page 615
Creating Static Content 615
Creating Dynamic Content 616
Including Content in a JSP Page 622
Transferring Control to Another Web Component 624
Including an Applet 624
JavaBeans Components in JSP Pages 627
Extending the JSP Language 635
Further Information 636
Chapter 16: Custom Tags in JSP Pages . . . . . . . . . . . . . . . . . . . 637
What Is a Custom Tag? 638
The Example JSP Pages 638
Using Tags 641
Defining Tags 645
Examples 661
Chapter 17: JavaServer Pages Standard Tag Library . . . . . . . 673
The Example JSP Pages 674
Using JSTL 674
Expression Language Support 677
Core Tags 683
XML Tags 689
Internationalization Tags 693
SQL Tags 696
viii CONTENTS
Further Information 700
Chapter 18: Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .701
Overview 701
Users, Groups, and Roles 702
Web-Tier Security 712
Installing and Configuring SSL Support 721
Security for JAX-RPC 734
EIS-Tier Security 744
Chapter 19: The Coffee Break Application . . . . . . . . . . . . . . . .747
Coffee Break Overview 747
JAX-RPC Distributor Service 749
JAXM Distributor Service 758
Coffee Break Server 773
Building, Installing, and Running the Application 777
Appendix A: Tomcat Administration Tool . . . . . . . . . . . . . . . . . .785
Running admintool 785
Configuring Tomcat 788
Configuring Services 789
Configuring Resources 816
Administering Roles, Groups, and Users 823
Further Information 824
Appendix B: Tomcat Web Application Manager . . . . . . . . . . .825
Running the Web Application Manager 825
Running Manager Commands Using Ant Tasks 826
Appendix C: The Java WSDP Registry Server . . . . . . . . . . . . . . .829
Starting the Registry Server 830
Using JAXR to Access the Registry Server 830
Using the Command Line Client Script to Access the Registry Server
831
Further Information 838
CONTENTS ix
Appendix D: Registry Browser . . . . . . . . . . . . . . . . . . . . . . . . . . . 839
Starting the Browser 839
Querying a Registry 841
Managing Registry Data 842
Deleting an Organization 845
Stopping the Browser 845
Appendix E: Provider Administration Tool . . . . . . . . . . . . . . . . . 847
Appendix F: HTTP Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . 849
HTTP Requests 850
HTTP Responses 850
Appendix G: Java Encoding Schemes. . . . . . . . . . . . . . . . . . . . 851
Further Information 852
Glossary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 853
About the Authors . . . . . . . . . . . . . . . . . . . . . . . . . 883
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 887
|