MiniH
MiniH

Reputation: 35

Save SOAP UI mock requests to a file

I m using Soap UI basic version for some mocking. I need to persist my requests to some file. I just have generated mock services with some predefined input to output rules, and i searched on net and found this:

def logArea = com.eviware.soapui.SoapUI.logMonitor.getLogArea( "http log" );
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context) 

Date startTime = new Date();
def cur_Time = startTime.getMonth() + "_" + startTime.getDate()
cur_Time = cur_Time + "_" + startTime.getHours()  + "_" + startTime.getMinutes() +startTime.getSeconds()

def testPath = "C:/Users/..." + cur_Time  + ".log"
def logFile = new File(testPath)

logFile.write("soapUI Logs In a file.\r\n")
   if( logArea !=null )
   {
      def model = logArea.model
      if( model.size > 0 )            
         for( c in 0..(model.size-1) )         
           logFile.append("\n" + model.getElementAt( c ))         
   }

logArea.clear() 

and this works fine only from Soap UI GUI request calling. How can i persist my requests even if i call this mock service from external services?

I don't have any test cases, and don't need to save requests from them, only direct requests from external system.

Thanks!

Upvotes: 1

Views: 3414

Answers (1)

albciff
albciff

Reputation: 18507

If you want to save in a file all request that your Mock service recieve, simply do the follow. In your mock service open the onRequest script tab as in the follow image (this script executes each time that your service receives a request):

enter image description here

And add the follow groovy script in this tab.

def myRequestPath = 'C:/temp/request_' + System.currentTimeMillis()  + ".log"
def logFile = new File(myRequestPath)
logFile.append(mockRequest.getRequestContent())

In the onRequest script context you've available a mockRequest object (of com.eviware.soapui.impl.wsdl.mock.WsdlMockRequest type) and from this object you can get the request content using getRequestContent() method, and then this script save this object in a file.

This script is easier than yours because it takes directly the response from the object instead of trying to get the response from the soapui log tabs...

Hope this helps,

Upvotes: 2

Related Questions