Forum Discussion

rafaljanik's avatar
rafaljanik
New Contributor
15 years ago

how can I access the contentLenght from response?

Hi, I have a problem with accessing ContentLenght in messageExchange.
My Rest Service returns octetStream, in XML view I can see:

<data contentType="application/octet-stream" contentLength="119623"> ...</data>
How can I access this value (119623) which is real size of my content (and write the assertion script)?

Methods from interface com.eviware.soapui.model.iface.MessageExchange

exchangeMessage.getResponseContent()

and

exchangeMessage.getRawResponseData()

.length() return different values - in each case not the contentLength.

Is there a possibility to get get the contentLength ?

Regards,

rafal

2 Replies

  • You can instead use Xpath Match assertion to get the value and test it.

    If you must use Script assertion, I imagine it would look something like:

    def len = context.expand( '${StepName#Response#//data[1]/@contentLength' )
    assert len == "119623"
  • rafaljanik's avatar
    rafaljanik
    New Contributor
    thanks a lot - in XPath expression I used

    //data[1]/@contentLength 


    and everything works fine.