A synchronous service wsdl can be updated with additional schema element to represent fault message and make it as an output variable in the event of fault.
In this example, we will show how to update WSDL and how various faults(system and business) can be caught and how to dynamically pass fault message through variables.
(1) Designed a simple web service to return a credit card status. The Reference component is a simple DB Adapter which queries a table with Credit card number as input and get status as output. The dummy values are as below.
1234-1234-1234-1234 VALID
1111-1111-1111-1111 INVALID
9999-9999-9999-9999 DATE EXPIRED
(2) Update the WSDL to include fault as output.
step1: Extend the schema to represent fault element.
step2: add a message to represent message type for fault data.
<wsdl:message name="QueryCCStatusBpelFaultMessage">
<wsdl:part name="payload" element="ns1:CCFault"/>
</wsdl:message>
step3: Add wsdl:fault within the wsdl operation.
<wsdl:operation name="process">
<wsdl:input message="client:QueryCCStatusBpelRequestMessage"/>
<wsdl:output message="client:QueryCCStatusBpelResponseMessage"/>
<wsdl:fault name="InvalidCreditCard" message="client:QueryCCStatusBpelFaultMessage"/>
</wsdl:operation>
(3) As you noted above, the process should return InvalidCreditCard as a fault message in all fault scenarios. However, we will design in a way that proper message is sent to Client within the CCFault element.
(4) With in BPEL, check the DB Adapter output. Following that ,implement below If logic.
a. If credit card status is INVALID, throw a fault with faultName as InvalidCreditCard. Do not choose any fault variable.
b. If credit card status is DATE EXPIRED, throw a fault with faultName as InvalidCreditCard. create a fault variable based on message type. We did not choose fault variable in previous case just to demo on how the catch activity is chosen when there are multiple for same fault.
(5) Create multiple catch activities.
step1: Create catch for the fault: InvalidCreditCard with out any fault variable.
step2: Create catch for the same fault: InvalidCreditCard with same variable which is created in step: 4.b.
You can note how the catch activity is choosen. The one with variable is chosen with priority.
step3: Create a catchall activity to handle all the system faults. You can use the function ora;getFaultAsString() to get runtime fault message.
(6) In all the catch Activities do a reply with Fault along with Fault variable. Update the fault element with appropriate fault reason message.
In this example, we will show how to update WSDL and how various faults(system and business) can be caught and how to dynamically pass fault message through variables.
(1) Designed a simple web service to return a credit card status. The Reference component is a simple DB Adapter which queries a table with Credit card number as input and get status as output. The dummy values are as below.
1234-1234-1234-1234 VALID
1111-1111-1111-1111 INVALID
9999-9999-9999-9999 DATE EXPIRED
(2) Update the WSDL to include fault as output.
step1: Extend the schema to represent fault element.
step2: add a message to represent message type for fault data.
<wsdl:message name="QueryCCStatusBpelFaultMessage">
<wsdl:part name="payload" element="ns1:CCFault"/>
</wsdl:message>
step3: Add wsdl:fault within the wsdl operation.
<wsdl:operation name="process">
<wsdl:input message="client:QueryCCStatusBpelRequestMessage"/>
<wsdl:output message="client:QueryCCStatusBpelResponseMessage"/>
<wsdl:fault name="InvalidCreditCard" message="client:QueryCCStatusBpelFaultMessage"/>
</wsdl:operation>
(3) As you noted above, the process should return InvalidCreditCard as a fault message in all fault scenarios. However, we will design in a way that proper message is sent to Client within the CCFault element.
(4) With in BPEL, check the DB Adapter output. Following that ,implement below If logic.
a. If credit card status is INVALID, throw a fault with faultName as InvalidCreditCard. Do not choose any fault variable.
b. If credit card status is DATE EXPIRED, throw a fault with faultName as InvalidCreditCard. create a fault variable based on message type. We did not choose fault variable in previous case just to demo on how the catch activity is chosen when there are multiple for same fault.
(5) Create multiple catch activities.
step1: Create catch for the fault: InvalidCreditCard with out any fault variable.
step2: Create catch for the same fault: InvalidCreditCard with same variable which is created in step: 4.b.
You can note how the catch activity is choosen. The one with variable is chosen with priority.
step3: Create a catchall activity to handle all the system faults. You can use the function ora;getFaultAsString() to get runtime fault message.
(6) In all the catch Activities do a reply with Fault along with Fault variable. Update the fault element with appropriate fault reason message.
No comments:
Post a Comment