Client Code

The revised client code is presented in Example 5-10. Most of the getProduct( ) method is the same as in the original ProductClient code, and therefore I have only included those pieces that illustrate the new fault-handling capability. First, if a fault is detected, the client code extracts the Fault object and embeds it into a ProductNotFoundException:

Fault fault = resp.getFault(  );
String faultString = fault.getFaultString(  );
throw new ProductNotFoundException (faultString, fault);

This enables us to examine the Fault object later. Second, the main( ) method includes a new printFaultDetails( ) method for printing out any fault details embedded in the Response object. Before we examine this method, however, we’ll test the code by sending a nonexistent SKU. Let’s try the SKU number Z358185. If you are using the TcpTunnelGui tool, you will see the following response from the SOAP server:

<?xml version='1.0' encoding='UTF-8'?>
                              Exception from service object: SKU Not Found:  Z358185

As you can see, ProductNotFoundException is not propagated directly back to the client. Rather, the rpcrouter ...

Get Web Services Essentials now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.