Forum Discussion

Emric-Test's avatar
Emric-Test
Occasional Contributor
17 years ago

Saving entire response in database/excel

Hi!
I'm, new to this, so please be patient.

I'm trying to create a mockup service, but before doing so I'd like to get some replies from the existing webservice and store in a database, so I later can use the mockup service and make a simple select and get the entire response. I have suceeded in retrieving a response (manually added) from the database as response, so I believe the end part is almost done. What I need help in understandig is how I can get the response and save the entire xml in a database (or excel). I don't understand what property or mechanism to use to get the entire response.
Probably easy if you know the onbjcts, but since I don't I ask instead :-)

6 Replies

  • omatzura's avatar
    omatzura
    Super Contributor
    Hi!

    you can get the entire response via the "Response" property; try something like this in your groovy-script:

    // get response from Request 1 Test step
    def response = context.expand( '${Request 1#Response}' )

    // save to database
    ...


    Alternatively you can use the new DataSink teststep; specify a property in the DataSink editor and set its value to the above property-expansion, configure the JDBC DataSink, and off you go!

    Hope this helps,

    regards,

    /Ole
    eviware.com
  • Emric-Test's avatar
    Emric-Test
    Occasional Contributor
    Hi!
    Yes I got it working, when I do it manually. I did however run into connection problems to the database.
    What is the preferred (easiest in my case) method of saving data...

    I have a MS SQL Server Express installed, and have tried a few combinations od datasource, odbc Datasink and Groovy script. I have however not got it working completly.
    Is there perhaps somekind of tutorial etc available on how to write the connectionstrings to a ODBC sink for the DataSink?
  • omatzura's avatar
    omatzura
    Super Contributor
    Hi!

    Sorry, no tutorial available yet for the DataSink step.. If you send me your project file (ole@eviware.com) maybe I can have a look at the scripts / configurations to see if I can help you forward.

    regards!

    /Ole
    eviware.com
  • Emric-Test's avatar
    Emric-Test
    Occasional Contributor
    Hi again!
    I've been experimenting, and I got somethings straight and others not... my problem right now is what I think you refer to as property expansion. I need to geth the "object" (see request) from the request to use a primarykey in my select staement...I can't get it, I get null!
    Request:

     

     
         
           
                XXXX
                XXXX
               
               
                Emric
                false
           

           
                141312-7686
               
               
               
               
               
                3000
           

         

     


    Mock response script
    ===================
    import groovy.sql.Sql
    sql = Sql.newInstance("jdbc:jtds:sqlserver://CWS-Fredrik_C/uc_resp;domain=", "soapUI","soapUI", "net.sourceforge.jtds.jdbc.Driver")
    objectRefIn=mockRequest.getProperty("//ucor:individualReport/individualReportQuery/object/")
    row=sql.firstRow("select UCresponse from resp where socid = ${objectRefIn}")
    mockResponse.setResponseContent("${row.UCresponse}")
  • omatzura's avatar
    omatzura
    Super Contributor
    Hi!

    sorry for the delay.. please try the following in your MockResponse script:


    import groovy.sql.Sql

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    def holder = groovyUtils.getXmlHolder(  mockRequest.requestContent )
    def objectRefIn=holder["//ucor:object/text()"]

    sql = Sql.newInstance("jdbc:jtds:sqlserver://CWS-Fredrik_C/uc_resp;domain=", "soapUI","soapUI", "net.sourceforge.jtds.jdbc.Driver")
    def row=sql.firstRow("select UCresponse from resp where socid ={objectRefIn}")

    mockResponse.setResponseContent("${row.UCresponse}")


    Hope this helps!

    regards,

    /Ole
    eviware.com
  • Emric-Test's avatar
    Emric-Test
    Occasional Contributor
    delay  That was fast in my world!

    It worked like charm, I only (for those who possibly use the snippet in the future)  had to replace ...socid=${objectRefIn}" with socid='" +objectRefIn+"'") to get the correc t sql syntax.