BPM, Workflow, and Case

BPM, Workflow, and Case

Come for answers. Stay for best practices. All we’re missing is you.

 View Only
Expand all | Collapse all

How to create blank XML from complex business object

  • 1.  How to create blank XML from complex business object

    Posted Wed September 23, 2020 10:40 AM
    I have a requirement - I am passing a complex business object as XML format to another system. BPM does not send blank tags in the XML for null attributes.
    Is there any generic way to create blank tags for null attributes in BPM ?



    ------------------------------
    Atanu Roy
    ------------------------------


  • 2.  RE: How to create blank XML from complex business object

    Posted Wed September 23, 2020 07:07 PM
    HI Atanu,

    Would you be able to elaborate how are you passing BPM data to the external systems? Are you using a web service or something else? A snippet of your code as well?

    ------------------------------
    Thong Huynh
    Sydney NSW
    ------------------------------



  • 3.  RE: How to create blank XML from complex business object

    Posted Thu September 24, 2020 02:58 AM
    Hi Thong,

    Yes, BPM is consuming WDSL of the external system and integrated through OOTB Web Service Integration component. 
    There no specific code to prepare the request, we are sending business objects. When that system is receiving the request, that does not have the tags for null values fields. 





    ------------------------------
    Atanu Roy
    ------------------------------



  • 4.  RE: How to create blank XML from complex business object

    Posted Thu September 24, 2020 09:56 AM
    Hi Atanu,

    From this I understand that concerned element is defined minOccurs="0" in the WSDL, right?
    If so, an element with a minOccurs="0" attribute, whose value is null, simply does not appear in the XML instance. This is general approach and is not BPM specific.
    Since, the WSDL is provided by the web service server, I would expect the server to able to interpret this way of representing null fields.

    ------------------------------
    Markus Siebert
    ------------------------------



  • 5.  RE: How to create blank XML from complex business object

    Posted Thu September 24, 2020 10:58 AM
    Thanks @Markus Siebert. I also thinks so, but the web service provider is internally sending the XML to another back end system which is expecting the blank tags.

    Business case:

    The service is performing some insert/update to another system.
    For example user is adding some value in the UI to a field which is going as -
    <name>XYZ</name>​​​Next time, let's say the user removes the value from the UI and saves it. Then, as the field is minOccurs="0", the tag is getting removed from the XML and the 3rd system is unable to identify which field got changed.



    ------------------------------
    Atanu Roy
    ------------------------------



  • 6.  RE: How to create blank XML from complex business object

    Posted Thu September 24, 2020 11:53 AM
    Yikes!  This sounds like a very fraught use case.  That is it sounds like the target system is expecting the XML to contain the changed data, but if a value is not included they assume that value is unchanged.  Is that correct?  If so then it sounds like they are treating an empty tag differently than a missing one.  I can't think of a good way to solve that TBH, unless the other system is willing to adjust in some way.  The XML you are submitting is valid according to the WSDL.  You could try putting in a single space for the value and seeing how that is interpreted.  

    If you had to you could hand construct the XML and submit it to them (assuming the SOAP service is still in the SDT in 8.6) but that requires you creating the XML for the entire message which isn't fun to create nor maintain.  You could also try copying the WSDL to a local (server)file, changing the minOccurs = 1, parsing that WSDL, and seeing if you get the XML you want for the use case.  If you do then there is a route to the answer, either have them update the WSDL or you hand modify it for your system.  You can give a file URL for the WSDL (or at least could a while ago) and I've done it when IBM couldn't parse the customer's WSDL properly.  Since the WSDL is parsed once and the result saved you just need to document how this was handled so someone in the future can do the same if the WSDL changes at a later date.  If you run this experiment I would do it in a different PA / TK to see how it works before doing it in the current code base.

    ------------------------------
    Andrew Paier
    ------------------------------



  • 7.  RE: How to create blank XML from complex business object

    Posted Thu September 24, 2020 11:54 AM

    I think this is rather a design question than a technical.  Empty string vs. NULL value

    Here the web service server is in the middle of BPM and another server. And the interface of the other server is different to the WSDL imported into BPM.
    So, the web service server can be considered as a mediator, who should care for transformation to match the interface of the other server.



    ------------------------------
    Markus Siebert
    ------------------------------



  • 8.  RE: How to create blank XML from complex business object

    Posted Thu September 24, 2020 02:38 PM
    1. First of all null in XML  is represented as attribute: <element xsi:nil="true"/>  -  not as empty element.   
    This is different explicit value.

    2. Web Services stack in BPM Standard is very, very limited.
    However, when I was last time using WS-Services (19.0.0.3) as external service nulls were supported (xsi:nil="true").  Check what you are sending "over the wire" (networks sniffer). Please note that it works differently if you try manually serialize object to XML.
    Then all attributes which are null or undefined are represented as not defined XML element ( "no blank tags")
    Only empty strings are serialized to empty elements (e.g. when using tw.local.yourobject.toXMLString())

    3. As somebody already said – contract between provider and client say what is allowed and what is not.  If elements are not mandatory it can be omitted (and this is rather good practice as sometimes new client can be compatible with old provider when using this pattern).

    4. If you are trying to do database update  based on values from screen – then your interface should be carefully designed and you should send only delta (changed variables). But this is a contract between you and other party.

    5. Based on what I said in point 2  (empty strings are serialized) if you re doing something not standard  you can try brute force method and replace your nulls with empty strings. You  can use fact that default serialization to JSON stores nulls:
    tw.local.yourobject = JSON.parse ( tw.local.yourobject.toJSONString(true).replace(/null/g,"\"\"") );
    However it will work for String type  only and fields which have been set  explicitly (field1 = null)
    So I would not go into that direction.  If  you can influence service provider – interface should be changed and properly designed to fit your needs.  If provider is something you don't control it is better to use Java client or different tooling between BPM and service provider (façade).
    And check twice that your external service definition is properly imported. 

    6. And totally off topic:  It should be not your problem what internally your service provider do.  You should fulfill only WSDL contract. If provider have to internally send this very specific XML, it is provider  issue how to create it :)

    ------------------------------
    Sebastian Tylko
    ------------------------------



  • 9.  RE: How to create blank XML from complex business object

    Posted Fri September 25, 2020 02:56 AM
    @Andrew Paier I already tried to change minOccurs = 1 but that did not work as expected. The option I am seeing to manually add empty space to the fields which are null to get the tags created.

    @Markus Siebert I totally agree with you, it is a design problem with the end system, they are just trying to improve their design by putting some burden on BPM.
    In my case the mediator is IIB and the end system in MDM, I think these things could have been handled in IIB.

    @Sebastian Tylko​ Thanks for your inputs. Even if we apply brute force, that will require some manual codes to manually make all fields as null.

    What I was thinking as a generic solution is - 

    1. Retrieve the XSD of the BO using Web API
    2. Create an intermediate template XML using the XSD
    3. Compare individual nodes of the actual XML with the template XML and add missing elements using XSLT

    The problem with this approach is - 
    1. Deeply nested elements
    2. Repeating elements

    I don't think this approach would be that simple and straightforward.
    Any suggestions around this please ?

    ------------------------------
    Atanu Roy
    ------------------------------



  • 10.  RE: How to create blank XML from complex business object

    Posted Fri September 25, 2020 06:43 AM
    You are trying to do something odd. The problem are not nulls but undefined parts of your object.
    Simpler version of your crazy plan is to prepare static sample with defaults and create object using serializer e.g.
    var yourXMLSampleWithDefaults = "<variable type=\"YourObject\" container=\"YourApp\"><field1/><field2/><field3/><field4/><field5 type=\"YourNestedObject \"><field1/><field2/><field3/></field5></variable>"
    tw.local.yourobject = tw.system.serializer.fromXml(yourXMLSampleWithDefaults );
    // now you can set proper value from UI

    The same you can do with JSON. But for XML it might be easier to generate this sample using some tooling as you have XSD.
    Example tools to generate sample: https://santhosh-tekuri.github.io/jlibs/xsd/XSInstance.html

    ------------------------------
    Sebastian Tylko
    ------------------------------