2015-05-19 38 views
1

我試圖使用BeanShell將SOAP請求打印到文件中,因爲我不得不做一些驗證。Jmeter中存儲的SOAP調用的請求在哪裏

我能夠使用String response = prev.getResponseDataAsString();獲得SOAP調用的響應,這些響應可以打印到文件中。

類似的,可以用什麼方法來獲取在Jmeter中爲SOAP調用發送的請求?

注:我試圖使用SoapSampler.getxmldata()。但它沒有給我結果。

回答

1

如果將SOAP請求作爲HTTP POST調用進行提交,並將xml內容用作POST主體,則prev.getSamplerData()將包含請求信息。

例子:
在BeanShell的後處理器:vars.put("requestData", prev.getSamplerData());

結果:

requestData=POST url 

POST data: 
<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Body> 
     ... 
    </soap:Body> 
</soap:Envelope> 
+0

太棒了!這正是我在API文檔中所尋找的。你能告訴我哪種類的API持有這種方法嗎? – Maniram

+0

https://jmeter.apache.org/api/org/apache/jmeter/samplers/SampleResult.html#getSamplerData() – RaGe

+0

酷...非常感謝...我已經經歷過這個類,但沒有檢查這個.. – Maniram

1

如果使用SOAP/XML-RPC Request你可以訪問它的XML身體Beanshell PostProcessor爲:

String body = ctx.getCurrentSampler().getXmlData(); 

哪裏ctx是的簡寫class

+0

我無法使用ctx獲取請求SOAP消息。 BeanShell PostProcessor中的代碼存在一些問題嗎? 'f = new FileOutputStream(ResultDir,true); p = new PrintStream(f); String a = ctx.getCurrentSampler()。getxmlData(); (a);' – Maniram

+0

1.在'getXmlData();'2中注意大寫「X」;我會推薦關閉像'p.close();'的流,因爲讓它們打開可能會導致打開句柄缺少 –

+0

可愛..是的,它確實工作..感謝糾正.. 和是的,我已經使用p.close()和f.close()以及。 – Maniram