Skip to Content

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;

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


To report this post you need to login first.

6 Comments

You must be Logged on to comment or reply to a post.

  1. James Wood
    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!

    (0) 
    1. Shabarish Vijayakumar Post author
      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

      (0) 
  2. Alexander Bundschuh
    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
    (0) 
    1. Shabarish Vijayakumar Post author
      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

      (0) 
  3. Liang Ji

    Hi Shabarish,

    Nice blog, I just want to know where is “import generated.Book” come from in the Java mapping code?

    My guess you mean the book class is generated from JAXB script ?

    Regards

    -Liang

    (0) 

Leave a Reply