Articles
Enterprise Architecture
Practical Enterprise Service Bus Use Cases for SOA
Pages:
1,
2,
3
In a non-ESB Web service environment, validation of incoming SOAP requests must be included in the service implementation layer either as part of a handler chain or embedded within the service itself. Here are some things to consider with these approaches:
With an ESB Web service environment, it is possible to perform data validation at the ESB layer; by doing so, validation logic is separated from business logic and the service implementation is insulated from dynamically changing validation requirements. From a deployment perspective the use of an ESB has the added benefit of being able to reject invalid requests without invoking the actual service implementation. Therefore, the service implementation layer will not be forced to handle the load of invalid requests.
For the sake of this example, let's assume the validation requirements include a number of validation rules that cannot be expressed simply with XML Schema and it is expected that the validation rules will need to be updated at a higher frequency than the application. Let's consider a Web service request and response messages that are defined by the XML schema elements below:
<xs:element name="purchaseLoanRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="loanAmount"
type="xs:decimal" />
<xs:element name="interestRate"
type="xs:decimal" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="purchaseLoanResponse"
type="xs:anyType" />
<xs:element name="validationResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="passedValidation"
type="xs:boolean" />
<xs:element name="validationErrors"
type="tns:validationErrorType" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="validationErrorType">
<xs:sequence>
<xs:element name="message" type="xs:string" />
<xs:element name="targetElement"
type="xs:string" />
</xs:sequence>
</xs:complexType>
In the above XML schema snippet, you'll notice there are request and response messages defined for the purchaseLoan operation. Notice the response is defined as an xs:anyType and there is a definition for a validationResponse. This response type will be returned if incoming data fails validation.
For the purposes of this example, let's consider a validation rule that states if the loanAmount is less than $250,000, then the interestRate of the loan must be greater than 5%.
This business rule can be implemented by configuring the Message Flow of a Proxy Service. The high-level steps to implement this solution are described below. If you wish to view the completed configuration in full detail, import use-case-3.jar into your ALSB domain and view the configuration through the service bus console.
$body/loan:purchaseLoanRequest/loan:loanAmount < 250000 and $body/loan:purchaseLoanRequest/loan:interestRate <= 5
<passedValidation>false</passedValidation>to variable passedValidation.
<loan:validationResponse>
<loan:passedValidation>false</loan:passedValidation>
<loan:validationErrors>
<loan:message>
Interest Rate must be higher than
5% for loans less than 250,000
</loan:message>
<loan:targetElement>
{fn:node-name($body/loan:validationRequest/loan:interestRate)}
</loan:targetElement>
</loan:validationErrors>
</loan:validationResponse>
to variable validationError.
passedValidation = "false"
Figure 6. The Loan Service Message Flow
Figure 7. The Failed Validation Branch Node Message Flow
Figure 6 and Figure 7 show the implementation of a simple business rule in the ESB layer. This is a viable strategy for handling simple Boolean comparisons through XQuery expressions. If a more complex business rules implementation is necessary, the ESB layer can be configured to perform a Web service callout to an external business rules implementation and handle the routing of the rules evaluation results in a similar fashion.
After gaining some experience with ALSB through the use cases and the solutions discussed in this article, the ALSB interpretation of an ESB becomes apparent. Each of the use cases described in the article involves the ALSB providing, though configuration, an "aspect" of a web service in a similar way that aspects are defined in Aspect-Oriented Programming:
In addition to the aspects discussed in this article, an ESB could certainly handle other aspects such as monitoring, message-level security, data mediation, and transactions.
By utilizing an ESB to provide and implement these aspects, the Web service implementation layer can be enriched with a great deal of functionality with a minimal amount of development effort. The abstraction of these Web service aspects at the ESB layer allows for a Web service implementation to focus solely on implementing business logic, greatly simplifying the complexity of the implementation. As additional Web service standards become finalized, ESB products will be able to provide support for a larger set of Web service aspects, thereby increasing the overall value of an ESB in an enterprise.
Kenny Shin is an independent consultant based in the Washington, DC metro area.