4
3
2

Hi Avoka Team.

We are trialling the Transact SDK and are trying to construct a SOAP Envelope for one of our integration points. When I try to use the MarkupBuilder, which worked fine in the legacy Groovy Environment, I encounter type checking errors. If I try to bypass the type checking with @TypeChecked(SKIP), I receive a message that this is not allowed.

What's the recommended way of generating XML in the Transact SDK?

    CommentAdd your comment...

    2 answers

    1.  
      1
      0
      -1

      Hi Sean

      One of the options is to use the class "com.avoka.tm.util.XmlDoc". Also you may consider (since SDK 17.10.0+) "com.avoka.tm.util.ObjectMapper" if you want to transform object into xml and vice versa.


      Not quite sure why groovy.transform.TypeChecked is not white listed but we will need some time to evaluate the impact of whitelisting it.


      Regards
      Rado

      1. Sean Colyer

        Thanks Rado. Getting the TypeChecking to be allowed will be a huge win for development productivity.

        I haven't used the ObjectMapper, but when I review the docs it isn't clear how to create an XML Document from an object.

        Also, does ObjectMapper support Namespaces?

        My current workaround for this is the create nodes using the W3C DOM objects in 

        org.w3c.dom
      2. Radoslav Ivanov

        1. Here is an example of the ObjectMapper create scenario. You may add/edit person's field values and then call update on ObjectMapper to update the xml.

        import com.avoka.tm.util.*
        
        Person person = new ObjectMapper()
            			.setDoc(document)
            			.setFormXPath('/PrimaryApplicant')
           		        .create(Person.class)
        
        
        class Person {
            public String firstName
            public String lastName
            public String emailAddress
            public String mobileNumber
        }
        
        
        /* document could be like that one:
        <PrimaryApplicant>
         <FirstName>Peter</FirstName>
         <LastName>Pan</LastName>
         ...
        </PrimaryApplicant>
        */

        2. You may give it a try with XPath querying by namespace (look at method setFormXPath('....'))

      3. Sean Colyer

        This doesn't seem like a great way of assembling a SOAP Message from scratch though. Do you have an example of constructing a simple SOAP message using the ObjectMapper?

        How do you tell the object mapper to write xsi:nil on various nodes as an attribute, for example?

      4. Radoslav Ivanov

        That is right. The ObjectMapper has a different use-case. 

        However, you can use the available javax.xml.*, org.w3c..*, org.xml.sax.*, etc. packages.

      5. Sean Colyer

        Thanks Rado - that's what I have been doing (smile)

      CommentAdd your comment...
    2.  
      1
      0
      -1

      Hi Sean,

      we've started using the Fluent SDK for some of our integration; for SOAP calls we use a Velocity Template for the SOAP Envelope, and a model for the data variables.

      So, the code is in the following format:

      Map myModel = [:]
      String myTemplate = "<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
      ...
              <MemberNumber>${memberNumber}<MemberNumber>
      ...
      </soap:Envelope>"
      String soapEnvelope = new VelTemplate().setTemplate(myTemplate).setModel(myModel).merge()

      That works for us and does not give any type-check errors.

      Hope that helps.

      Mark

      1. Sean Colyer

        Great tip! Thanks Mark!

      CommentAdd your comment...