Forum Discussion

bik's avatar
bik
Occasional Contributor
7 years ago

extracting location header from raw response and using that as a endpoint for next step in a request

The response is of a post

HTTP/1.1 201 Created
Date: Fri, 15 Jun 2018 08:01:27 GMT
Server: Apache
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-XSS-Protection: 1; mode=block
X-Frame-Options: DENY
X-Content-Type-Options: nosniff
Set-Cookie: JSESSIONID=2YCtIlPMfCYNO3mQ3V2AlGqu.hfs-support-service_test_0; Path=/hfs-support-service
X-Application-Context: application
Location: http://xx/abcde
Keep-Alive: timeout=6, max=69
Connection: Keep-Alive
 
the groovy script is used to extract the location which is working fine
 
 
def vals = testRunner.testCase.getTestStepByName("TC_POST_EXTUSER").httpRequest.response.responseHeaders["Location"]
 
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
groovyUtils.setPropertyValue("Request2", "Endpoint", vals.toString())
 
but while trying to use the extracted location header value in next request with a null pointer exception.
 
I would like the endpoint of next request to be populated with the value.
 
  • Lucian's avatar
    Lucian
    Community Hero

    Hey,

     

    Well if you didn't figure it out yet here is the answer... The code you can put into the groovy script can be this:

     

    // Get the location header
    def vals = testRunner.testCase.getTestStepByName("TC_POST_EXTUSER").httpRequest.response.responseHeaders["Location"][0]
    
    // Set a test case property for the header
    testRunner.testCase.setPropertyValue( "LocationHeader", vals )

    ... and then you can use it in a future request like:

     

     

    Cheers! :smileyhappy:

    • bik's avatar
      bik
      Occasional Contributor

      Thanks for the solution.

      I did like this because the location header value for my next request would be the endpoint .

       

      def vals = testRunner.testCase.getTestStepByName("TC_POST_EXTUSER").httpRequest.response.responseHeaders["Location"][0]

      def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)

      return vals

      GETV.setPropertyValue('Endpoint',vals)

       

      thanks a lot Lucina for that [0] ,i could able to get rid off the square brackets. (which was my latest problem)

       

       

  • Lucian's avatar
    Lucian
    Community Hero

    Ah I see now what was the point. 

     

    Well that's good that you solved the problem.  :smileyhappy: 

    • groovyguy's avatar
      groovyguy
      Community Hero

      Thanks for the script, Lucian. That's super useful and I've been working on something similar so that'll help.

      • Lucian's avatar
        Lucian
        Community Hero

        Well I didn't think this would help a community leader :manvery-happy: but I am glad it did.