Forum Discussion

amitnimbhorkar's avatar
amitnimbhorkar
New Contributor
9 years ago

How to attach ssl certificates to response using Groovy script

Hi,

 

I am trying to connect a web service using Groovy script which is happening successfuly and I am getting soap message back.However, I am not getting how to attach in incoming ssl certificates to in my response object. I am using following script.

 

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def soapUrl = new URL("https://xxxxxxxxxxxxx")
def connection = soapUrl.openConnection()

connection.setRequestMethod("POST")
connection.setRequestProperty("Accept-Encoding" ,"gzip,deflate")
connection.setRequestProperty("Content-Type" ,"text/xml;charset=UTF-8")
connection.setRequestProperty("SOAPAction", "xxxxxxxxxxxxxxxx")
connection.doOutput = true

def soapRequest = mockRequest.getRequestContent()
writer.write(soapRequest)
writer.flush()
writer.close()

connection.setConnected(true)
connection.connect()

def soapResponse = connection.content.text

requestContext.responseMessage = soapResponse

connection.disconnect()
  • As this script was meant for the default mock responses which access actual web service in case we have requests other than the mocked ones, I created a keystore locally and imported the client certificates in cacerts in /java/jdk/jre/lib/security/.

    Then in preferences->ssl settings, I pointed my 'keystore', 'mock keystore' and 'mock truststore' to my local keystore. Also enabled mock ssl. Its not mandatory to use 8443 as mock port as advised everywhere on net, I just used port 9443 and it worked.

     

    Make sure to call your mock service over https instead http.

     

  • rupert_anderson's avatar
    rupert_anderson
    Valued Contributor

    Hi,

     

    I haven't tried it from Groovy script, in SoapUI, as you are doing, but I think that the keystore details (that holds the client SSL cert) are normally supplied to the JVM as System properties. They have been whenever I have used Java clients / frameworks anyway - I saw this post where someone was setting the properties via SoapUI in Groovy script:

     

    http://community.smartbear.com/t5/SoapUI-NG/How-to-set-Keystore-using-Groovy-script/m-p/114979#U114979

     

    Out of interest, why do you want to code a Groovy based client to make your request? Is it that there's something missing in the UI driven framework?

     

    Regards,

    Rupert

    • amitnimbhorkar's avatar
      amitnimbhorkar
      New Contributor

      Thank you for quick response rupert_anderson. Our client webservices in test environment often go down which causes downtime for our test teams. To overcome this, and reduce overall traffic to our client webservices, we are creating soapui mock services, which will return mocked responses if requested, else our groovy script will redirect the request to the client webservices and return back the responses.

       

      However, now we are facing the exact same problems as described by @andsoulnd in this post here.

  • As this script was meant for the default mock responses which access actual web service in case we have requests other than the mocked ones, I created a keystore locally and imported the client certificates in cacerts in /java/jdk/jre/lib/security/.

    Then in preferences->ssl settings, I pointed my 'keystore', 'mock keystore' and 'mock truststore' to my local keystore. Also enabled mock ssl. Its not mandatory to use 8443 as mock port as advised everywhere on net, I just used port 9443 and it worked.

     

    Make sure to call your mock service over https instead http.