Forum Discussion

mcbootus's avatar
mcbootus
Contributor
13 years ago

[Res.] Cannot Collect Data From Request Made To Mock Service

Dear all,

I have a mock service and another application makes a request to the mock service - I would like to grab the data in the request but for some reason it always returns null. Attached is a screenshot showing the code I have placed in the "OnRequest Script" tab on the mock service. In this example I am trying to grab the "DataType" element of the request to the mock service. Below is the actual request being sent to the mock service which I am trying to grab.



<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<CoDeCallback xmlns="http://ec.europa.eu/digit/codecallback/v3.0" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<webServiceJob>
<DataType>JobStatus</DataType>
<WSJobId>TESTGGZ9PW3H5S3XHSEZHUPK</WSJobId>
<StatusCategory>Success</StatusCategory>
<StatusCode>10290</StatusCode>
<StatusMessage>Dummy message from the TestCallback method.</StatusMessage>
<ConvertedFiles>
<ConvertedFile>
<Direction>InOut</Direction>
<FileName>ULH23SKZZ2.D74</FileName>
<OriginalFileName>KRVX5CDDLT.5E5</OriginalFileName>
<StatusCategory>Success</StatusCategory>
<StatusCode>42648</StatusCode>
<StatusMessage>Dummy message from the TestCallback method.</StatusMessage>
</ConvertedFile>
<ConvertedFile>
<Direction>InOut</Direction>
<FileName>97SB1CPLDR.MUB</FileName>
<OriginalFileName>W5S1JBNT8M.XK9</OriginalFileName>
<StatusCategory>Success</StatusCategory>
<StatusCode>66143</StatusCode>
<StatusMessage>Dummy message from the TestCallback method.</StatusMessage>
</ConvertedFile>
<ConvertedFile>
<Direction>InOut</Direction>
<FileName>D8SCMXEBS8.RDU</FileName>
<OriginalFileName>EYD4AA1G9U.TL3</OriginalFileName>
<StatusCategory>Success</StatusCategory>
<StatusCode>52236</StatusCode>
<StatusMessage>Dummy message from the TestCallback method.</StatusMessage>
</ConvertedFile>
</ConvertedFiles>
</webServiceJob>
</CoDeCallback>
</s:Body>
</s:Envelope>




Thanks in advance,
Armen
  • Problem solved - code provided by SOAP UI team!



    import javax.xml.xpath.*
    import javax.xml.parsers.DocumentBuilderFactory

    def xpath = XPathFactory.newInstance().newXPath()
    String xml = mockRequest.getRequestContent()
    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    def holder = groovyUtils.getXmlHolder(xml)
    def dt = holder['//ns1:REQUEST MADE/ns1:TO YOUR/ns1:MOCKSERVICE']
    context.mockService.project.setPropertyValue("XML ELEMENT YOU WISH TO GRAB", dt)
    log.info dt


    and put it in MockService onRequestScript tab.