Blogs

Shabarish Vijayakumar

XML / XSD Validation - An Alternative for SAP PI
Shabarish Vijayakumar Active Contributor Platinum: 2,500+ points SAP Mentor
Business Card
Company: Wipro Technologies
Posted on Jan. 30, 2012 03:17 AM in SAP Process Integration (PI)

Subscribe.Subscribe
Print. Print
Permalink Permalink
Share

XML / XSD validations are often common customer requirements. Today, from PI 7.1 and above, SAP offers a standard feature for doing such validations in the Adapter engine or the Integration engine. 

 

To be frank I am disappointed. The standard feature isnt what I expected it to be. So what are my complaints?

1. Flexibility - First of all you need to start with uploading the XSD file in some weird location on the file system. Ideally, I would have preferred it to be directly linked from my ESR. if not, at least give me the flexibility to upload it to a preferred location.

2. Error handling - As I understand it, if the validation fails it throws up an alert and the processing stops. But thats not how integration works isnt it? We all need better control on the message flow. What If I want to check if it has failed validation and then instead of the process coming to a halt, continue on further and take some action.

ex. If validation fails, write the input message to an error folder or on failure, send the message back to the sender itself citing the failure reason.

 

If you do a simple search on SDN, you will find many blogs around custom solutions on how to do a XML/XSD validation. In this blog I will like to introduce another alternative and extend the options using the JAXB framework. Using JAXB, we will implement a PI java mapping to do the validation.

 

Note: It is not in the scope of this document to explain how the JAXB framework works and I will assume that the reader has the knowledge of using JAXB for XML binding. 

 

The Prerequisites;

1. Setup your NWDS

2. Create a Java Project

3. Add a source folder, import the XSD file and generate the required Java classes for your XSD using the XJC tool or any other XJC plugin available for Eclipse

4. Create a folder or copy the XSD file to one of the existing folders in the PI file system. Note that the <SID>adm user should have access to this folder and the XSD file.

 

You can access the code and other resources using to implement the validation in this wiki link

 

XSD Structure:

 

 

All the fields are of string type except 'edition' which is an Integer

 

Now that we have a control on the validation, we can then thus formulate the  output to suit specific integration needs. 

Case 1: Valid XML structure

 

 

Case 2: Invalid XML - Missing Mandatory Node/Fields

In the below, the input XML does not contain the AdditionalInfo node and its fields.

 

Case 3: Invalid XML - Non integer value for field Edition

In the below, the input XML contain a non integer value in the field Edition. This is not correct since the XSD definition states that the field is an integer type

 

Hope this provides you an insight into yet another alternative you can put to use where your integration scenario has requirements around XSD validation.

 

PS: A special thanks to colleague Abhishek Saha, in helping revive my interest in JAXB.

 


Shabarish Vijayakumar  Active Contributor Platinum: 2,500+ points SAP Mentor is an Integration Lead Consultant with Wipro Technologies. He has over 8 yrs of Integration experience across multiple domains involving both A2A and B2B integration scenarios. He is a top contributor & a SAP Mentor in the XI/PI area on SDN. Shabarish has also co-authored the book 'The Essentials on SAP Process Integration - A SAP Mentor 2010 Series'. The views & opinions posted on SDN by him are solely his and are not in any way, of his employer.


Comment on this articleWhat do you think about the standard XSD validation option in PI? What alternative do you use?
Comment on this weblog
Showing messages 1 through 5 of 5.

Titles Only Main Topics Oldest First

  • xml validation has been improved with 7.30
    2012-01-31 00:49:35 Alexander Bundschuh SAP Employee Business Card [Reply]

    Hi Shabarish,
    thanks for your blog. I agree, when we introduced the xml validation in 7.10, the usability was pretty poor. However, with 7.30 we actually have improved the user experience. You no longer have to store the xsd onto the file share, now you directly refer to the schema definition that you anyway have defined in ESR. When using xml validation, you simply have to select the respective check box in the sender/receiver agreements or in the Integrated Configuration object (latter, in case of local processing on the adapter engine), and the schema will be automatically put into the cache. The schema validation will run without further configuration.
    From error handling point of view, depending on where you carry out the xml validation, you either get directly response if the validation fails or the message goes into an error status. In latter case, you can either edit the payload (i.e., fixing the schema validation issue) and restart the message or restart while skipping the xml validation.
    If this is not sufficient, let me know what other error handling you have in mind.
    Regards
    Alex
    • xml validation has been improved with 7.30
      2012-01-31 02:04:46 Shabarish Vijayakumar Business Card [Reply]

      Alex,
      Thanks for you comment and clarification.
      So I do see that SAP has been kind enough to address my frustration on the 'flexibility' part :)


      From an error handling point of view, it will be great if we can take the processing further and not only notify via an alert but also maybe capture the error and also the payload enabling it to be transmitted via email or write to a file etc.


      Shabz

  • Nice Blog
    2012-01-30 14:52:26 James Wood Business Card [Reply]

    Hi Shabarish,


    This is a nice blog. Like you, I have also been frustrated by SAP's support for XML Schema validation in PI. Personally, I'm a big fan of JAXB. However, my experience using it in PI has been met with mixed results. In my experience (both in PI and other Java-based EAI tools), JAXB tends to scale poorly for large complex messages. So, for anybody thinking about using this approach, I would recommend that you spend some time performance testing the maps just to make sure they scale as expected. Hope this helps. Thanks!

    • Nice Blog
      2012-01-30 23:47:21 Shabarish Vijayakumar Business Card [Reply]

      thanks for your comment James.
      Nice of you to point out potential performance issues in JAXB based transformations. In comparison to DOM and SAX, what has been your exp. with JAXB? How does it fare?


      Shabz

      • Nice Blog
        2012-02-20 10:49:30 James Wood Business Card [Reply]

        For large messages, I've found that it performs quite poorly, and not just for PI. I've seen the same effects in other Java-based EAI tools. I think the reality is that JAXB is one of those projects at Sun that sort of got caught up in the shuffle during the Oracle takeover and probably didn't get as much attention as is needed to make it production-ready. If you're dealing with smallish messages, then it's great.


        I love the idea of XML binding, and think it certainly has its place. Hopefully in time these performance issues will be of little concern. Conceptually, I don't see why there should be much more overhead with JAXB than what is there with DOM.


        With large messages, I've found myself using SAX more and more with the help of a utils tool which allows me to look for specific elements using an XPath-like syntax. Simplifies the SAX API quite a bit overall, and you can't beat the performance of not sucking up the entire XML payload into memory at once.


Showing messages 1 through 5 of 5.