Try OpenEdge Now
skip to main content
Web Services
Creating ABL Clients to Consume OpenEdge SOAP Web Services : Handling Errors in ABL Requests to OpenEdge SOAP Web Services : Examples of ABL accessing a SOAP fault : Traditional error handling example
 
Traditional error handling example
The code in the following example:
1. Uses the ABL VALID-HANDLE function to determine if a given ERROR condition (ERROR-STATUS:ERROR = TRUE) is caused by a SOAP fault by testing the validity of the handle returned by the ERROR-STATUS:ERROR-OBJECT-DETAIL attribute
2. Assigns a handle variable (hSoapFault) to any valid SOAP-fault object returned by the ERROR-STATUS:ERROR-OBJECT-DETAIL attribute for code readability
Note: You can also use the ERROR-STATUS:ERROR-OBJECT-DETAIL handle attribute directly to work with the SOAP-fault object.
3. Examines the values of SOAP fault elements, as required, using appropriate attributes (SOAP-FAULT-CODE) on the SOAP-fault object handle
4. Uses the ABL VALID-HANDLE function to determine if this SOAP fault has SOAP fault detail by testing the validity of the handle returned by hSoapFault:SOAP-FAULT-DETAIL
5. Assigns a handle variable (hSoapFaultDetail) to the SOAP fault-detail object returned by the hSoapFault:SOAP-FAULT-DETAIL attribute for code readability
Note: You can also use the ERROR-STATUS:ERROR-OBJECT-DETAIL:SOAP-FAULT-DETAIL handle attribute directly to work with the SOAP fault-detail object.
6. Returns the root node of the underlying SOAP fault <detail> element by using the hSoapFaultDetail:GET-NODE( ) method to assign the root node to the x-noderef object referenced by the handle variable hxnoderef
7. Can now use the methods and attributes of the x-noderef object handle (hxnoderef) and additional handle variables to walk the XML DOM subtree referenced by hxnoderef to examine the content of the SOAP fault <detail> element as specified by the WSDL for the Web service
Table 42. Sample SOAP fault procedure
DEFINE VARIABLE hWS            AS HANDLE.
DEFINE VARIABLE hStockPortType AS HANDLE.
DEFINE VARIABLE price          AS DECIMAL.

CREATE SERVER hWS.
/* Create a WebServicePortType object, using server & port information. */

hWS:CONNECT( "-WSDL http: //www.stockvend.com/application/wsdl/stock.wsdl
              -Service stockSVC
              -Port stockPort" ).
RUN stock SET hStockPortType ON SERVER hWS.

RUN getPrice IN hStockPortType( INPUT "error", OUTPUT price ) NO-ERROR.
IF ERROR-STATUS:ERROR THEN DO:
/*1*/
  /* Error occurred on the RUN. Did the Web service generate the error or was
     it an internal ABL error? */
  IF VALID-HANDLE( ERROR-STATUS:ERROR-OBJECT-DETAIL ) THEN DO:
    DEFINE VARIABLE hSoapFault as HANDLE.
/*2*/
    hSoapFault = ERROR-STATUS:ERROR-OBJECT-DETAIL.
/*3*/
    IF INDEX( "VersionMismatch", hSoapFault:SOAP-FAULT-CODE ) > 0 THEN DO:

/*4*/
      IF VALID-HANDLE( hSoapFault:SOAP-FAULT-DETAIL ) THEN DO:

        DEFINE VARIABLE hSoapFaultDetail as HANDLE.
/*5*/
        hSoapFaultDetail = hSoapFault:SOAP-FAULT-DETAIL.

        DEFINE VARIABLE hxnoderef AS HANDLE.
        CREATE X-NODEREF hxnoderef.
/*6*/
        hSoapFaultDetail:GET-NODE( hxnoderef ).
/*7*/
        /* From here the application can walk the detail XML and retrieve the
           relevant information. */

        . . .

      END. /* Examine SOAP-FAULT-DETAIL */
    END. /* Return SOAP-FAULT-CODE info */
  END. /* Examine ERROR-OBJECT-DETAIL */
END.

DELETE PROCEDURE hStockPortType.
hWS:DISCONNECT( ).