The JavaTM Web Services Tutorial


About This Tutorial

Introduction to Web Services

The Role of XML and the Java Platform
What Is XML?
What Makes XML Portable?
Overview of the Java APIs for XML
Overview of JAX-RPC
Creating a Web Service
Coding a Client
Invoking a Remote Method
Getting a Connection
Creating a Message
Populating a Message
Sending a Message
Using JAXR
Sample Scenario

Understanding XML

Introduction to XML
What Is XML?
Why Is XML Important?
How Can You Use XML?
XML and Related Specs: Digesting the Alphabet Soup
Basic Standards
Schema Standards
Linking and Presentation Standards
Knowledge Standards
Standards That Build on XML
Designing an XML Data Structure
Saving Yourself Some Work
Attributes and Elements
Normalizing Data
Normalizing DTDs

Getting Started With Tomcat

Setting Up
Getting the Example Code
Setting the PATH Variable
Creating the Build Properties File
Quick Overview
Creating the Getting Started Application
The ConverterBean Component
The Web Client
Building the Getting Started Application Using Ant
Creating the Build and Deploy File for Ant
Compiling the Source Files
Deploying the Application
Starting Tomcat
Installing the Application using Ant
Deploying the Application Using deploytool
Running the Getting Started Application
Running the Web Client
Shutting Down Tomcat
Using admintool
Understanding Roles, Groups, and Users
Adding Roles Using admintool
Adding Users Using admintool
Modifying the Application
Modifying a Class File
Modifying the Web Client
Common Problems and Their Solutions
Errors Starting Tomcat
Compilation Errors
Deployment Errors
Further Information

Web Applications

Web Application Life Cycle
Web Application Archives
WAR Directory Structure
Tutorial Example Directory Structure
Creating a WAR
Configuring Web Applications
Alias Paths
Context and Initialization Parameters
Event Listeners
Filter Mappings
Error Mappings
References to Environment Entries, Resource Environment Entries, or Resources
Installing Web Applications
Deploying Web Applications
Listing Installed and Deployed Web Applications
Running Web Applications
Updating Web Applications
Reloading Web Applications
Redeploying Web Applications
Removing Web Applications
Undeploying Web Applications
Internationalizing and Localizing Web Applications
Accessing Databases from Web Applications
The Examples
Installing and Starting the Database Server
Populating the Database
Configuring the Web Application to Reference a Data Source
Defining a Data Source in Tomcat
Configuring Tomcat to Map the JNDI Name to a Data Source
Further Information

Java API for XML Processing

An Overview of the Packages
The Simple API for XML (SAX) APIs
The SAX Packages
The Document Object Model (DOM) APIs
The DOM Packages
The XML Stylesheet Language for Transformation (XSLT) APIs
The XSLT Packages
Compiling and Running the Programs
Where Do You Go from Here?

Simple API for XML

When to Use SAX
Writing a Simple XML File
Creating the File
Writing the Declaration
Adding a Comment
Defining the Root Element
Adding Attributes to an Element
Adding Nested Elements
Adding HTML-Style Text
Adding an Empty Element
The Finished Product
Echoing an XML File with the SAX Parser
Creating the Skeleton
Importing Classes
Setting up for I/O
Implementing the ContentHandler Interface
Setting up the Parser
Writing the Output
Spacing the Output
Handling Content Events
Compiling and Running the Program
Checking the Output
Identifying the Events
Compressing the Output
Inspecting the Output
Documents and Data
Adding Additional Event Handlers
Identifying the Document's Location
Handling Processing Instructions
Handling Errors with the Nonvalidating Parser
Substituting and Inserting Text
Handling Special Characters
Using an Entity Reference in an XML Document
Handling Text with XML-Style Syntax
Handling CDATA and Other Characters
Creating a Document Type Definition (DTD)
Basic DTD Definitions
Defining Text and Nested Elements
Limitations of DTDs
Special Element Values in the DTD
Referencing the DTD
DTD's Effect on the Nonvalidating Parser
Tracking Ignorable Whitespace
Documents and Data
Empty Elements, Revisited
Defining Attributes and Entities in the DTD
Defining Attributes in the DTD
Defining Entities in the DTD
Echoing the Entity References
Additional Useful Entities
Referencing External Entities
Echoing the External Entity
Summarizing Entities
Referencing Binary Entities
Using a MIME Data Type
The Alternative: Using Entity References
Choosing your Parser Implementation
Using the Validating Parser
Configuring the Factory
Validating with XML Schema
Experimenting with Validation Errors
Error Handling in the Validating Parser
Defining Parameter Entities and Conditional Sections
Creating and Referencing a Parameter Entity
Conditional Sections
Parsing the Parameterized DTD
DTD Warnings
Handling Lexical Events
How the LexicalHandler Works
Working with a LexicalHandler
Using the DTDHandler and EntityResolver
The DTDHandler API
The EntityResolver API
Further Information

Document Object Model

When to Use DOM
Documents vs. Data
Mixed Content Model
A Simpler Model
Increasing the Complexity
Choosing Your Model
Reading XML Data into a DOM
Creating the Program
Additional Information
Looking Ahead
Displaying a DOM Hierarchy
Echoing Tree Nodes
Convert DomEcho to a GUI App
Create Adapters to Display the DOM in a JTree
Finishing Up
Examining the Structure of a DOM
Displaying A Simple Tree
Displaying a More Complex Tree
Finishing Up
Constructing a User-Friendly JTree from a DOM
Compressing the Tree View
Acting on Tree Selections
Handling Modifications
Finishing Up
Creating and Manipulating a DOM
Obtaining a DOM from the Factory
Normalizing the DOM
Other Operations
Finishing Up
Using Namespaces
Defining a Namespace in a DTD
Referencing a Namespace
Defining a Namespace Prefix
Validating with XML Schema
Overview of the Validation Process
Configuring the DocumentBuilder Factory
Validating with Multiple Namespaces
Further Information

XML Stylesheet Language for Transformations

Introducing XSLT and XPath
The JAXP Transformation Packages
Choosing the Transformation Engine
Performance Considerations
Functionality Considerations
Making Your Choice
How XPath Works
XPATH Expressions
The XSLT/XPath Data Model
Templates and Contexts
Basic XPath Addressing
Basic XPath Expressions
Combining Index Addresses
Extended-Path Addressing
XPath Data Types and Operators
String-Value of an Element
XPath Functions
Writing Out a DOM as an XML File
Reading the XML
Creating a Transformer
Writing the XML
Writing Out a Subtree of the DOM
Generating XML from an Arbitrary Data Structure
Creating a Simple File
Creating a Simple Parser
Modifying the Parser to Generate SAX Events
Using the Parser as a SAXSource
Doing the Conversion
Transforming XML Data with XSLT
Defining a Simple <article> Document Type
Creating a Test Document
Writing an XSLT Transform
Processing the Basic Structure Elements
Writing the Basic Program
Trimming the Whitespace
Processing the Remaining Structure Elements
Process Inline (Content) Elements
Printing the HTML
What Else Can XSLT Do?
Transforming from the Command Line
Compiling the Translet
Running the Translet
Concatenating Transformations with a Filter Chain
Writing the Program
Understanding How the Filter Chain Works
Testing the Program
Further Information

Java API for XML-based RPC

What Is JAX-RPC?
A Simple Example: HelloWorld
HelloWorld at Runtime
HelloWorld Files
Setting Up
Building and Deploying the Service
Building and Running the Client
Iterative Development
Implementation-Specific Features
Types Supported By JAX-RPC
J2SE SDK Classes
Application Classes
JavaBeans Components
A Dynamic Proxy Client Example
Dynamic Proxy HelloClient Listing
Building and Running the Dynamic Proxy Example
A Dynamic Invocation Interface (DII) Client Example
DII HelloClient Listing
Building and Running the DII Example
Security for JAX-RPC
Basic Authentication Over SSL
Mutual Authentication Over SSL
JAX-RPC on the J2EE SDK 1.3.1
Example Code
Packaging the JAX-RPC Client and Web Service
Setting Up the J2EE SDK 1.3.1
Deploying the GreetingEJB Session Bean
Deploying the JAX-RPC Service
Running the JAX-RPC Client
Undoing the Effects of jwsdponj2ee
Creating a JAX-RPC Service With deploytool
Compiling the Source Code
Building the Web Application
Deploying the Web Application
Checking the Status of the Web Service
Running the Client
Further Information

Java API for XML Messaging

Overview of JAXM
Messaging Providers
Running the Samples
The Sample Programs
Source Code for the Samples
Client without a Messaging Provider
Client with a Messaging Provider
Adding Attachments
SOAP Faults
Code Examples and
Further Information

Java API for XML Registries

Overview of JAXR
What Is a Registry?
What Is JAXR?
JAXR Architecture
Implementing a JAXR Client
Establishing a Connection
Querying a Registry
Managing Registry Data
Using Taxonomies in JAXR Clients
Running the Client Examples
Further Information

Java Servlet Technology

What is a Servlet?
The Example Servlets
Servlet Life Cycle
Handling Servlet Life Cycle Events
Handling Errors
Sharing Information
Using Scope Objects
Controlling Concurrent Access to Shared Resources
Accessing Databases
Initializing a Servlet
Writing Service Methods
Getting Information from Requests
Constructing Responses
Filtering Requests and Responses
Programming Filters
Programming Customized Requests and Responses
Specifying Filter Mappings
Invoking Other Web Resources
Including Other Resources in the Response
Transferring Control to Another Web Component
Accessing the Web Context
Maintaining Client State
Accessing a Session
Associating Attributes with a Session
Session Management
Session Tracking
Finalizing a Servlet
Tracking Service Requests
Notifying Methods to Shut Down
Creating Polite Long-Running Methods
Further Information

JavaServer Pages Technology

What Is a JSP Page?
The Example JSP Pages
The Life Cycle of a JSP Page
Translation and Compilation
Initializing and Finalizing a JSP Page
Creating Static Content
Creating Dynamic Content
Using Objects within JSP Pages
JSP Scripting Elements
Including Content in a JSP Page
Transferring Control to Another Web Component
jsp:param Element
Including an Applet
Extending the JSP Language
Further Information

JavaBeans Components in JSP Pages

JavaBeans Component Design Conventions
Why Use a JavaBeans Component?
Creating and Using a JavaBeans Component
Setting JavaBeans Component Properties
Retrieving JavaBeans Component Properties

Custom Tags in JSP Pages

What Is a Custom Tag?
The Example JSP Pages
Using Tags
Declaring Tag Libraries
Making the Tag Library Implementation Available
Types of Tags
Defining Tags
Tag Handlers
Tag Library Descriptors
Simple Tags
Tags with Attributes
Tags with Bodies
Tags That Define Scripting Variables
Cooperating Tags
An Iteration Tag
A Template Tag Library
How Is a Tag Handler Invoked?

JavaServer Pages Standard Tag Library

The Example JSP Pages
Using JSTL
Expression Language Support
Twin Libraries
JSTL Expression Language
Tag Collaboration
Core Tags
Expression Tags
Flow Control Tags
URL Tags
XML Tags
Core Tags
Flow Control Tags
Transformation Tags
Internationalization Tags
Setting the Locale
Messaging Tags
Formatting Tags
SQL Tags
query Tag Result Interface
Further Information

Web Application Security

Users, Groups, and Roles
Security Roles
Managing Roles and Users
Mapping Application Roles to Realm Roles
Web-Tier Security
Protecting Web Resources
Controlling Access to Web Resources
Security Settings without deploytool
Authenticating Users of Web Resources
Using Programmatic Security in the Web Tier
Unprotected Web Resources
EIS-Tier Security
Configuring Sign-On
Container-Managed Sign-On
Component-Managed Sign-On
Installing and Configuring SSL Support on Tomcat
Using JSSE
Setting Up a Server Certificate
Configuring the SSL Connector
Verifying SSL Support
Troubleshooting SSL Connections
General Tips on Running SSL
Further information on SSL
Further Information

The Coffee Break Application

Coffee Break Overview
JAX-RPC Distributor Service
Service Interface
Service Implementation
Publishing the Service in the Registry
Deleting the Service From the Registry
JAXM Distributor Service
JAXM Client
JAXM Service
Coffee Break Server
JSP Pages
JavaBeans Components
Building, Installing, and Running the Application
Building the Common Classes
Building and Installing the JAX-RPC Service
Building and Installing the JAXM Service
Building and Installing the Coffee Break Server
Running the Coffee Break Client
Deploying the Coffee Break Application

Tomcat Administration Tool

Running admintool
Configuring Tomcat
Setting Server Properties
Configuring Services
Configuring Connector Elements
Configuring Host Elements
Configuring Logger Elements
Configuring Realm Elements
Configuring Valve Elements
Configuring Resources
Configuring Data Sources
Configuring Environment Entries
Configuring User Databases
Administering Roles, Groups, and Users
Further Information

Tomat Web Application Manager

Running the Web Application Manager
Running Manager Commands Using Ant Tasks

The Java WSDP Registry Server

Setting Up the Registry Server
Using the JAXR API to Access the Registry Server
Using the Command Line Client Script with the Registry Server
Obtaining Authentication
Saving a Business
Finding a Business
Obtaining Business Details
Deleting a Business
Validating UDDI Messages
Retrieving a User's Businesses
Sending UDDI Request Messages
Using the Indri Tool to Access the Registry Server Database
Saving a Business
Obtaining Business Details
Finding a Business
Deleting a Business
Displaying Database Contents
Adding New Users to the Registry
Further Information

Registry Browser

Starting the Browser
Querying a Registry
Querying by Name
Querying by Classification
Managing Registry Data
Adding an Organization
Adding Services to an Organization
Adding Service Bindings to a Service
Adding and Removing Classifications
Submitting the Data
Deleting an Organization
Stopping the Browser
Using the JAXR Registry Browser with the Registry Server
Adding and Deleting Organizations
Querying the Registry

Provider Administration Tool

HTTP Overview

HTTP Requests
HTTP Responses

Java Encoding Schemes

Further Information


About the Authors



This tutorial contains information on the 1.0 version of the Java Web Services Developer Pack.

All of the material in The Java Web Services Tutorial is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.