Talend Pass Dynamic values into tSOAP Message - web

I am using BD5.6.1
i am using the tSOAP component and if i use the blow flow it works fine.
tsoap --> LogRow
I can paste the SOAP Request message into SOAP Message section of the tsoap node and it works fine..
But now i want to read the excel file and dynamically pass the value to SOAP Message of tSOAP component how this can be done?
Sample SOAP Message i need to pass.
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xml\" xmlns:urn=\"urn:HPD_Inc_Create_WS\">
<<urn:HelpDesk_Submit_Service>
<urn:First_Name> </urn:First_Name>
<urn:Impact> </urn:Impact>
</urn:HelpDesk_Submit_Service>
</soapenv:Body>
</soapenv:Envelope>"
the parameter is
FirstName values are in the file . I need to read these value from excel file and construct the soap message and then send it to tSOAP Component.
I saw on the forum that we can do that
on tSOAP, define the SOAP message to use a dynamic value passed from tFileInputExcel like this:
"...."+(String)globalMap.get("row1.First_Name")+"..."
//First_name is one of the column defined on tFileInputExcel, this column read the FirstName value from excel file.
But is not work for me

You can do this:
Read your excel file, and for each row (tFlowToIterate) call tSOAP and send it the message you construct:
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xml\" xmlns:urn=\"urn:HPD_Inc_Create_WS\">
<soapenv:Body>
<urn:HelpDesk_Submit_Service>
<urn:First_Name>" + (String)globalMap.get("row10.FirstName") + "</urn:First_Name>
<urn:Impact> </urn:Impact>
</urn:HelpDesk_Submit_Service>
</soapenv:Body>
</soapenv:Envelope>"
the global variable row10.FirstName comes from the tFlowToIterate which by default creates a global variable called rowX.Column for each incoming row's column, which you can rename in the component settings.
You can also use tESBConsumer along with a tXMLMap to constuct your message.

Related

How to parse and edit XML in TypeScript without converting to JSON

I need to repair an XML file in TypeScript and I cannot find any info on it, since everyone who posts something like this has different needs. I'd like to be pointed in the right direction here.
I have an XML request as shown below. It is autogenerated by node-soap when given JSON. Using the WSDL, node-soap attempts to fill in the namespace prefixes for each property. The problem is, it gets them wrong a lot.
In this example below, q106 should be replaced with hep3.
<soap:Envelope q15="some-good-url" q106="some-good-url-1" q98-"some-good-url-2>
...
<q98:SalesOrderAuditInfo>
<q15:ConfirmedBy xsi:nil="true"></q15:ConfirmedBy>
<q15:ConfirmedDate>0001-01-01T00:00:00</q15:ConfirmedDate>
<q15:CreatedBy>
<q106:ID>103</q106:ID>
<q106:Value>System, System</q106:Value>
</q15:CreatedBy>
<q15:CreatedDate>2022-10-26T00:43:13.413</q15:CreatedDate>
<q15:SalesOrderType>Standard</q15:SalesOrderType>
</q98:SalesOrderAuditInfo>
I know which namespace prefixes are bad because I have a sample request that was supplied to me. It's just XML. It looks like this:
<soap:Envelope hep="some-good-url" hep1="some-good-url-1" hep2-"some-good-url-2 hep3="some-good-url-3">
...
<hep2:SalesOrderAuditInfo>
<hep:ConfirmedBy xsi:nil="true"></hep:ConfirmedBy>
<hep:ConfirmedBy:ConfirmedDate>0</hep:ConfirmedByConfirmedDate>
<hep:CreatedBy>
<hep3:ID>103</hep3:ID>
<hep3:Value>System, System</hep3:Value>
</hep:CreatedBy>
<hep:CreatedDate>0</hep:CreatedDate>
<hep:SalesOrderType>Standard</hep:SalesOrderType>
</hep2:SalesOrderAuditInfo>
Here is the part that really matters. The Sample Request is the entire possible request body. The supplied request (with incorrect namespaces) is a subset of the sample request. I need to loop through each of the elements in the supplied request, and check to make sure the URL of that element matches the URL of the respective element in the sample request.
So in this example, loop through each element of supplied request. Start with SalesOrderAuditInfo. It's namespace URL is some-good-url-2. If we check the Sample Request, we can see that SalesOrderAuditInfo also corresponds to some-good-url-2.
Continue until we hit the ID tag. This has a namespace set to some-good-url-1. If we check the Same ID (inside of CreatedBy, inside of SalesOrderAuditInfo), we can see the namespace should actually be set to some-good-url-3. So we replace q106 with hep3.
I also need to take all of the namespaces defined in the Sample Request Envelope and move them into the supplied request envelope so that this new hep3 will be defined.
At this point, I need to edit the namespace prefix. In this example, q106:ID would be replaced be the string hep3:ID. Same with all of the closing tags.
Which library can I use to accomplish this in XML? Is anyone familiar with node-soap screwing these namespaces up and know of any fix?
I am using node-soap v0.43

SOAP UI how to configure a PUT request body programmatically

I'm configuring some requests programmatically in my test cases, I can set headers, custom properties, teardown scripts, etc. however I can't find how to set a standard json body for my put requests.
Is there any possibility from the restMethod class ?
So far I end up getting the method used :
restService = testRunner.testCase.testSuite.project.getInterfaceAt(0)
resource = restService.getOperationByName(resource_name)
request = resource.getRequestAt(0)
httpMethod = request.getMethod()
if (httpMethod.toString().equals("PUT"))
but then I'm stuck trying to find how to set a standard body for my PUT requests.
I try with the getRequestParts() method but it didn't give me what I expected ...
can anyone help, please
thank you
Alexandre
I’ve managed this. I had a tests of tests where I wanted to squirt the content of interest into the “bare bones” request. Idea being that I can wrap this in a data driven test. Then, for each row in my data spreadsheet I pull in the request body for my test. At first I simply pulled the request from a data source value in my spreadsheet, but this became unmanageable in my spreadsheet.
So, another tactic. In my test data sheet (data source) I stored the file name that contains the payload I want to squirt in.
In the test itself, I put in a groovy step immediately before the the step I want to push the payload into.
The groovy script uses the data source to firstly get the file name containing the payload, I then read the contents of the file.
In the step I want to push the data into, I just use a get from data, e.g. {groovyStep#result}.
If this doesn’t completely make sense, let me know and I’ll update with screenshot when I have access to SoapUi.

Replace/Update a existing node value in groovy

Below is my sample xml.
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Header>
<MessageHeader xmlns:ns3="http://csi.cingular.com/CSI/Namespaces/Types/Public/CingularDataModel.xsd" xmlns:ns39="http://csi.cingular.com/CSI/Namespaces/Types/Public/MessageHeader.xsd">
<ns39:TrackingMessageHeader>
<ns3:infrastructureVersion>86</ns3:infrastructureVersion>
<ns3:version>222</ns3:version>
<ns3:messageId>146100035386400076</ns3:messageId>
<ns3:originatorId>PEEPS</ns3:originatorId>
<ns3:timeToLive>120000</ns3:timeToLive>
<ns3:dateTimeStamp>2016-04-18T20:16:19.387Z</ns3:dateTimeStamp>
</ns39:TrackingMessageHeader>
<ns39:SecurityMessageHeader>
<ns3:userName></ns3:userName>
<ns3:userPassword></ns3:userPassword>
</ns39:SecurityMessageHeader>
<ns39:SequenceMessageHeader>
<ns3:sequenceNumber>1</ns3:sequenceNumber>
<ns3:totalInSequence>1</ns3:totalInSequence>
</ns39:SequenceMessageHeader>
</MessageHeader> </SOAP-ENV:Header> <SOAP-ENV:Body>
<InquireEnterpriseOrderListRequest xmlns="http://csi.cingular.com/CSI/Namespaces/InquireEnterpriseOrderListRequest.xsd">
<SelectionCriteria>
<organizationId>214256542</organizationId>
</SelectionCriteria>
</InquireEnterpriseOrderListRequest> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
I want to replace "organizationId" this tag value with the value read from file and trigger it using testRunner.runTestStepByName("InquireEnterpriseOrderList") once the value is updated in the node.
Can any help in understanding how to update/replace node with new value and re-trigger the API to capture result for many inputs.
Here you what you need to do:
Read file extract the required value and store it at test case level custom property. Assuming that you are using groovy script test step to do this. So, add the below additional code:
//You assign value from your code, for now using dummy assignment
def requiredvalue = '123453'
//Store that value at test case level custom property, say ORGANIZATION_ID
context.testCase.setPropertyValue('ORGANIZATION_ID', requiredValue.toString())
Now, you do not need to update the request. Instead use, property expansion as below, so that SoapUI automatically takes care of the required value from proerties
<organizationId>${#TestCase#ORGANIZATION_ID}</organizationId>

How to display actual value of a property which is using property expansion

I require some help on being able to get around displaying an endpoint from a SOAP Request.
Below I have a piece of code which retrieves an endpoint from a SOAP Request named 'TestAvailability' and outputs it to a file (the code is within a groovy script step).
def endpoint = testRunner.testCase.getTestStepByName('TestStep').get
Now here is the catch, in the file it outputs the endpoint as so:
ENDPOINT: ${#Project#BASE_URL}this_is_the_endpoint
The reason it displays ${#Project#BASE_URL} is because this is a variable set at project level so that the user can select their relevant environment from a drop down menu and that value will be displayed for the variable: ${#Project#BASE_URL}
But I don't want the project variable to be displayed but instead its value like so if ${#Project#BASE_URL} is set to 'testenv'
ENDPOINT: testenv_this_is_the_endpoint
My question is how do I change the code in order to display the endpoint correctly when outputted to a file?
You have a trivial issue. Since it is using property expansion in the endpoint, it request to expand it.
All you need is to change below statement
From:
testResult.append "\n\nENDPOINT: " +endpoint
To:
testResult.append "\n\nENDPOINT: ${context.expand(endpoint)}"

How to pass variable to SOAP Request. Variable contains a value read from xls using groovy script

I have some set of data in xls for a SOAP webservice. Using Groovy script I can read the data and can print using variables. But how can I use this variable into Webservice XML.
I feel Property Transfer feature won't help me here as value are being picked from XLS
Currently I have tried:
in Groovy line is :
def myTestCase = context.testCase;
myTestCase.setPropertyValue("web:StateCode", d[1]);
OR
testrunner.testcase.setPropertyValue("web:StateCode", d[1]);
AND In SOAP Request I have passed variable as:
<web:StatefCode>${d[1]}</web:StateCode>
There are multiple solutions to your problem. The easiest, which seems you are attempting, is to store the value in a test case property:
def data // something from your Excel
testRunner.testCase.setPropertyValue('stateCode', data)
To use this in a subsequent request, use property expansion: ${TestCase#stateCode#}.

Resources