Chapter 5. Web Services with SAAJ

Introduction

This chapter examines how to build Java clients that can talk to SOAP-based web services using the SOAP with Attachments API for Java (SAAJ) API.

SOAP, standardized by the W3C in 2000, is a platform-agnostic way of creating and sending messages in a distributed system.

Note

You may be familiar with SOAP as an acronym for Simple Object Access Protocol, but version 1.2 of the spec, published in 2003, throws out the explanation of the acronym with the direct, clear, and yet mysterious statement that “This is no longer the case.” Perhaps they decided it wasn’t so simple after all….

Because SOAP is based on XML, it is relatively easy for humans to read and understand, and the structure of a SOAP message itself is simple. SOAP messages are always wrapped in a container called the envelope; the envelope always contains a body, which carries the payload of the message in one or more XML documents. Optionally, your envelope can include headers, very similar to HTTP headers. If something goes wrong during processing, a SOAP fault will be added as the body content. The structure of a SOAP 1.1 envelope is depicted in Figure 5-1. The * in the figure denotes that there can be multiple instances of that type.

Structure of a SOAP envelope
Figure 5-1. Structure of a SOAP envelope

Developers on either end of the web service can extract the content of the SOAP envelope using XML tools for ...

Get Java SOA Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.