Forum Discussion

AbdelwahabSadek's avatar
AbdelwahabSadek
Occasional Contributor
10 years ago
Solved

Creating soap request in Groovy script

Hi,

 

I have the following scenario that I am trying to replicate in Soap UI:

 

1-Client initate request.

2-Service resposes with an empty soap message

3-Service invokes another request based on a custom header in the initial request.

 

So i figured I need to set my Mock service dispatcher to a groovy script. now is there a way to invoke a request from the Groovy script?

 

// create XmlHolder for request content
def holder = new com.eviware.soapui.support.XmlHolder( mockRequest.requestContent )
// get arguments
def replyto = holder["//replyto"]
log.info("Reply to: "+replyto);
// create a rerquest for the reply to header

????

return "EmptySoapMessage"

8 Replies

  • rupert_anderson's avatar
    rupert_anderson
    Valued Contributor

    Hi,

     

    It sounds like you might be trying to mock up a kind of async calback type scenario?

     

    If so, one way to trigger the request via your mock is to invoke a TestCase which makes the Request - for an example please see:

     

    http://community.smartbear.com/t5/SoapUI-Open-Source/How-to-simulate-an-asynchronous-web-service-with-mock-services/m-p/98348#M17494

     

    Of course you can also programatically make the SOAP call from your mock, heres an example of making a SOAP request programtically:

     

    http://community.smartbear.com/t5/SoapUI-Open-Source/How-to-get-parameter-of-SOAP-operation/m-p/99768#M17648

     

    Or something similar is shown here for programatically creating a REST call:

     

    community.smartbear.com/t5/SoapUI-Open-Source/How-to-create-REST-project-using-Groovy-script/m-p/99305#M17568

     

    One advantage of the first approach (triggering a TestCase) is that the Mock can dispatch its response before the callback SOAP request is made. 

     

    Hope this helps give you some ideas,

     

    Rupert

    • AbdelwahabSadek's avatar
      AbdelwahabSadek
      Occasional Contributor

      Thank you for answering.

      However I still have issues trying to make the first solution work.

       

      for example I get the following error:

       

      Unable to resolve StringToObjectMap() and couldn`t find any descent solution or clear docuemntation. I am sure I am missing something here or just being stupid.

       

      Here is what i have so far 

       

      // create XmlHolder for request content
      def holder = new com.eviware.soapui.support.XmlHolder( mockRequest.requestContent )
      
      // get arguments
      def synReplyTo = holder["//syn:ReplyTo"];
      def synMessageId = holder["//syn:MessageId"];
      
      // log the information
      log.info("Reply to: "+synReplyTo);
      log.info("Message Id: "+synMessageId);
      
      // create a rerquest for the reply to header
      def map = new StringToObjectMap() 
      map.put("messageID", synMessageId)
      map.put("ReplyTo", synReplyTo)
      def testSuite = context.mockService.project.getTestSuiteByName("TestSuiteCallingService")
      def callBackTestCase = testSuite.getTestCaseByName("SOAP Request")
      def callBackRequest = (WsdlTestRequestStep) callBackTestCase.getTestStepsOfType(WsdlTestRequestStep.class).get(0)
      //callBackRequest.testRequest.setEndpoint(replyTo)
      callBackTestCase.run(map,true) 
      
      return "EmptySoapResponse"

       

      • AbdelwahabSadek's avatar
        AbdelwahabSadek
        Occasional Contributor

        I replaced StringToObjectMap()  with what I assume is the full qualified name  new com.eviware.soapui.support.types.StringToObjectMap() and it worked.

         

        I`ll dig more now for more behaviors like passing parameters to the case and resolve this class WsdlTestRequestStep.

         

        Again thank you so much for your help.