Oracle SOA, AIA BPEL ESB and OSB knowledge base

Saturday, April 18, 2009

Friday, April 3, 2009

OSB: XSD Validation and Exception Handling

Thanks Edwin for beautiful post.

In OSB ( Oracle Service Bus , aqualogic service bus ) it is relative easy to add schema validation to your proxy service and to make a custom exception handling for this validation. Just follow the next steps. First in this example I use these xml schema's for the request and response operation.

The request xsd

<xs:schema xmlns="http://www.test.com/request" xs="http://www.w3.org/2001/XMLSchema" targetnamespace="http://www.test.com/request" elementformdefault="qualified" attributeformdefault="unqualified">
<xs:element name="request">
<xs:complextype>
<xs:sequence>
<xs:element name="runid" type="xs:short"/>
<xs:element name="message" type="xs:string" minoccurs="0"/>
</xs:sequence>
</xs:complextype>
</xs:element>
</xs:schema>




And the response xsd


<xs:schema xmlns="http://www.test.com/response" xs="http://www.w3.org/2001/XMLSchema" targetnamespace="http://www.test.com/response" elementformdefault="qualified" attributeformdefault="unqualified">
<xs:element name="response">
<xs:complextype>
<xs:sequence>
<xs:element name="runid" type="xs:short"/>
<xs:element name="message" type="xs:string" minoccurs="0"/>
<xs:element name="errorid" type="xs:string" minOccurs="0"/>
<xs:element name="error" type="xs:anyType" minOccurs="0"/>
</xs:sequence>
</xs:complextype>
</xs:element>
</xs:schema>


When everything goes well I will only return the runid element else we get the full message with the errorcode. With these xsd's I made a simple WSDL which I can use in the proxy service.

First part of this blog entry is to make the happy flow when this works we can add the xsd validation.
Make a new proxy service and use this WSDL.
The next step is to make a simple business service with file transport
In my case I put the request xml in the c drive temp folder.
Go back to your proxy service where we create a new message flow.
Add a route-node to the flow with inside a new routing. This routing will call the file business service.
Add an assign component to request action flow so I can retrieve the runid from the request and add this to the runid variable. This variable I can use for the response.
To make a return message I add an assign to the response action.Now I add the response template xml to the body variable.
Add an insert to the response action after the assign. In this insert we will add the runid of the request to the runid of the response message.
The first part is finished, you service should work now. In the second part we will add the XSD validation.
To make a custom exception handling for the xsd we need to add a Pipeline Pair node.
In the request pipeline I will add a new stage.
In this stage I use the validation component. Now we have to select an element in the body variable which OSB will validate against the XSD. Provide the XSD and use the raise error option.
Add an error handler to this stage.
Add a new stage in the error handler

First we add an assign to the stage to retrieve the runid of the request message so I can use this for the response.
Add a second assign to the stage. In this assign I will add the response template xml to the body variable.
Add the runid to the response xml
Add the error details to the response xml

And the error code
With the reply we can give back the response xml back to the client. Very important report no error because this is a handled exception.


The second part is also finished, we only have to test this proxy service by adding a unknow element to the request and look at the response. Here is a picture of the result.

FEEDJIT Live Traffic Map

My Blog List