Forum Discussion

Siemens__s_r_o_'s avatar
Siemens__s_r_o_
Occasional Contributor
11 years ago

[Resolved] Retrieveing request content from MockService

Hello SmartBear,

We are trying to log all requests incoming to our MockService.

I took this code:

// create XmlHolder for request content
def holder = new com.eviware.soapui.support.XmlHolder( mockRequest.requestContent )

// get target testcase
def project = mockResponse.mockOperation.mockService.project
def testCase = project.testSuites["TestSuite 1"].testCases["TestCase 1"]

// set arguments as properties
testCase.setPropertyValue( "arg1", holder["//arg1"] )
testCase.setPropertyValue( "arg2", holder["//arg2"] )


From your website (http://www.soapui.org/Service-Mocking/c ... vices.html) and modified it to:

import com.eviware.soapui.support.XmlHolder;

XmlHolder requestContent = new XmlHolder(mockRequest.requestContent);
log.info(requestContent[//"arg1"]);


This is used as OnRequest Script on the Mockservice.

Our incoming request looks something like this:

<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>
<env:Header/>
<env:Body>
<Message xmlns="http://www.iec.ch/TC57/2008/schema/message">
<Header>
<Verb>CREATE</Verb>
<Noun>EndDeviceAssets</Noun>
<MessageID>507-MeterAdd-1372758778123</MessageID>
</Header>
<Payload>
<EndDeviceAssets:EndDeviceAssets xmlns:EndDeviceAssets="http://iec.ch/TC57/2009/EndDeviceAssets#" xmlns="http://iec.ch/TC57/2009/EndDeviceAssets#">
<EndDeviceAsset>
<arg>someString</arg>
</EndDeviceAsset>
</EndDeviceAssets:EndDeviceAssets>
</Payload>
</Message>
</env:Body>
</env:Envelope>


I would expect that "someString" appears in the log, unfortunately, I get this:
Wed Dec 11 17:44:28 CET 2013:INFO:[Ljava.lang.String;@8b2e94


I suspect this is an issue with namespaces in the request, but I was unable to to resolve it

Any suggestions?

Thanks a lot,

Jakub

6 Replies

  • Siemens__s_r_o_'s avatar
    Siemens__s_r_o_
    Occasional Contributor
    Hi Marcus,

    After some experimenting, blood and tears, I figured out that this was indeed a namespace issue in xpath.

    "requestContent.getNodeValue("//EndDeviceAssets:arg")" did the trick

    Both

    import com.eviware.soapui.support.XmlHolder;

    XmlHolder requestContent = new XmlHolder(mockRequest.requestContent);
    log.info(requestContent.getNodeValue("//EndDeviceAssets:arg"));

    and

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    def requestContent = groovyUtils.getXmlHolder( mockRequest.requestContent )
    log.info requestContent.getNodeValue("//EndDeviceAssets:arg")

    work as expected ans return "somestring" from my request.

    Thanks for help, we can resolve the thread

    Jakub
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    Try requestContent.getNodeValue("//arg1"). Using that call for an XmlHolder is working for me.



    Regards,
    Marcus
    SmartBear Support
  • Siemens__s_r_o_'s avatar
    Siemens__s_r_o_
    Occasional Contributor
    Hi Markus,

    Thanks for the suggestion.

    With log.info(requestContent.getNodeValue("arg"));, I'm getting "Thu Dec 12 08:50:19 CET 2013:INFO:null".

    log.info(requestContent.getXml()); prints whole incoming request:

    Thu Dec 12 08:47:01 CET 2013:INFO:
    <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
    <env:Header/>
    <env:Body>
    <Message xmlns="http://www.iec.ch/TC57/2008/schema/message">
    <Header>
    <Verb>CREATE</Verb>
    <Noun>EndDeviceAssets</Noun>
    <MessageID>507-MeterAdd-1372758778123</MessageID>
    </Header>
    <Payload>
    <EndDeviceAssets:EndDeviceAssets xmlns:EndDeviceAssets="http://iec.ch/TC57/2009/EndDeviceAssets#" xmlns="http://iec.ch/TC57/2009/EndDeviceAssets#">
    <EndDeviceAsset>
    <arg>somestring</arg>
    </EndDeviceAsset>
    </EndDeviceAssets:EndDeviceAssets>
    </Payload>
    </Message>
    </env:Body>
    </env:Envelope>

    So the content is really there.

    What am I doing wrong?

    Thanks,

    Jakub
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    As an FYI, we do not support custom code solutions.

    You need to include an xpath for the argument, hence the //.


    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    def requestContent = groovyUtils.getXmlHolder( mockRequest.requestContent )
    log.info requestContent.getNodeValue("//arg")




    Regards,
    Marcus
    SmartBear Support
  • Siemens__s_r_o_'s avatar
    Siemens__s_r_o_
    Occasional Contributor
    Hi,

    There was a typo in my previous post, I meant "log.info(requestContent.getNodeValue("//arg"));", as I was using it in code - with the //. I just copypasted it wrong and I wasn't able to edit the post.

    Thanks for another solution, I have tried it already, returns null as well.

    Sorry for posting inappropriate stuff, I hoped this was "kind of not completely custom" I thought I just need to be pointed in the right direction with proper namespace handling in xpath.

    Regards,

    Jakub
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    Sorry for posting inappropriate stuff


    There is nothing wrong with posting this in the forum . I was just saying that we = SmartBear support, do not support custom code solutions as they can be very tedious at times and is custom functionality. Since the // is not working there must be something more to this. If you can up load your project to this post I'll take a look at it.



    Regards,
    Marcus
    SmartBear Support