The Java EE 5 Tutorial

Building and Running the SOAP Fault Example

    To build the program using NetBeans IDE, follow these steps:

  1. In NetBeans IDE, choose Open Project from the File menu.

  2. In the Open Project dialog, navigate to tut-install/javaeetutorial5/examples/saaj/.

  3. Select the fault folder.

  4. Select the Open as Main Project check box.

  5. Click Open Project.

    A Reference Problems dialog appears. Click Close.

  6. Right-click the fault project and choose Resolve Reference Problems.

  7. In the Resolve Reference Problems dialog, select the first of the missing JAR files and click Resolve.

    The missing files are activation.jar, javaee.jar, and appserv-ws.jar.

  8. Navigate to the as-install/lib/ directory.

  9. Select the missing JAR file (activation.jar, for example) and click Open.

    In the Resolve Reference Problems dialog, all the files have green check marks to the left of their names.

  10. Click Close.

  11. Right-click the project and choose Build.

    To run the program using NetBeans IDE, follow these steps:

  1. Right-click the fault project and choose Properties.

  2. Select Run from the Categories tree.

  3. In the Arguments field, type the following:


    1.1
    

    This argument specifies the version of SOAP to be used in generating the message.

  4. Click OK.

  5. Right-click the project and choose Run.

  6. Right-click the project and choose Properties.

  7. Select Run from the Categories tree.

  8. In the Arguments field, type the following:


    1.2
    
  9. Click OK.

  10. Right-click the project and choose Run.

To build and run SOAPFaultTest using Ant, go to the directory tut-install/javaeetutorial5/examples/saaj/fault/. Use one of the following commands:


ant run-fault -Dsoap=1.1

ant run-fault -Dsoap=1.2

When you run SOAPFaultTest to generate a SOAP 1.1 message, you will see output like the following (line breaks have been inserted in the message for readability):


Here is what the XML message looks like:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/><SOAP-ENV:Body>
<SOAP-ENV:Fault><faultcode>SOAP-ENV:Client</faultcode>
<faultstring>Message does not have necessary info</faultstring>
<faultactor>http://gizmos.com/order</faultactor>
<detail>
<PO:order xmlns:PO="http://gizmos.com/orders/">
Quantity element does not have a value</PO:order>
<PO:confirmation xmlns:PO="http://gizmos.com/confirm">
Incomplete address: no zip code</PO:confirmation>
</detail></SOAP-ENV:Fault>
</SOAP-ENV:Body></SOAP-ENV:Envelope>

SOAP fault contains:
 Fault code = {http://schemas.xmlsoap.org/soap/envelope/}Client
 Local name = Client
 Namespace prefix = SOAP-ENV, bound to http://schemas.xmlsoap.org/soap/envelope/
 Fault string = Message does not have necessary info
 Fault actor = http://gizmos.com/order
 Detail entry = Quantity element does not have a value
 Detail entry = Incomplete address: no zip code

When you run SOAPFaultTest to generate a SOAP 1.2 message, the output looks like this:


Here is what the XML message looks like:

<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
<env:Header/><env:Body>
<env:Fault>
<env:Code><env:Value>env:Sender</env:Value></env:Code>
<env:Reason><env:Text xml:lang="en-US">
Message does not have necessary info
</env:Text></env:Reason>
<env:Role>http://gizmos.com/order</env:Role>
<env:Detail>
<PO:order xmlns:PO="http://gizmos.com/orders/">
Quantity element does not have a value</PO:order>
<PO:confirmation xmlns:PO="http://gizmos.com/confirm">
Incomplete address: no zip code</PO:confirmation>
</env:Detail></env:Fault>
</env:Body></env:Envelope>

SOAP fault contains:
 Fault code = {http://www.w3.org/2003/05/soap-envelope}Sender
 Local name = Sender
 Namespace prefix = env, bound to http://www.w3.org/2003/05/soap-envelope
 Fault reason text = Message does not have necessary info
 Fault role = http://gizmos.com/order
 Detail entry = Quantity element does not have a value
 Detail entry = Incomplete address: no zip code