Forum Discussion

paullux's avatar
paullux
New Contributor
13 years ago

How to load a list of objects into a Request (in Groovy)

Hey pros,
My SOAP request takes one parameter which is a List object. Objects in list are of type Order, a complexType in my soap.
I have the spreadsheet as input and trying to create objects to be placed in a list to be made part of Request.
**Important** I just want to send out SINGLE soap request out as part of my testing with this list as soap parameter **.
Now, I am able to read from spread sheet but how to create objects from it in Groovy script? How to reference 'Order' class so that I can create Order object from spreadsheet data?

If not Groovy, is there any other idea to accomplish this?

Any help would be greately appreciated. I just put in a small diagram of my Request object below
Thanks
Paul.

---------------|
Request |
---------------|
List <orders> |<=====load from spread sheet
|
|
---------------|
  • paullux's avatar
    paullux
    New Contributor
    Thanks a lot for the reply.
    Your example says "used the property after exiting the loop", which is exactly my question. How to create my 'ComplexType' object with the info and stick it in the request?

    Do you have an example of creating 'ComplexType' object in Groovy?

    Thank you very much.
    Paul.
  • paullux's avatar
    paullux
    New Contributor
    It is here. The one in bold, I want to create in Groovy and push it to Request.

    <soapenv:Header/>
    <soapenv:Body>
    <mut:PlaceOrderRequest>
    <bas:firmID>777</bas:firmID>
    <bas:userID>B777AT</bas:userID>
    <mut:OrderList>
    <mut:Order>
    <mut:accountNumber>XXXXXXX</mut:accountNumber>
    <mut:type>Buy</mut:type>
    <mut:quantity>24.11</mut:quantity>
    </mut:Order>
    </mut:OrderList>
    </mut:PlaceOrderRequest>
  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    Assuming variables called accountNumber, type and quantity:

    gu.setPropertyValue('Properties', 'XmlFragment', "${frag}<mut:Order><mut:accountNumber>${accountNumber}</mut:accountNumber><mut:type>${type}</mut:type><mut:quantity>${quantity}</mut:quantity></mut:Order>"

    Then in request:

    <soapenv:Header/>
    <soapenv:Body>
    <mut:PlaceOrderRequest>
    <bas:firmID>777</bas:firmID>
    <bas:userID>B777AT</bas:userID>
    <mut:OrderList>
    ${Properties#XmlFragment}
    </mut:OrderList>
    </mut:PlaceOrderRequest>
  • paullux's avatar
    paullux
    New Contributor
    That worked, You da man!!

    Thank you very much, appreciate it.

    Paul.