JMeter-WebSocketSampler icon indicating copy to clipboard operation
JMeter-WebSocketSampler copied to clipboard

Headers and Cookies

Open ksunda200 opened this issue 10 years ago • 2 comments

Does the Sampler support insertion of custom header (via HTTP Header Manager) and insertion of Cookies (via HTTP Cookie Manager) in the Upgrade request?

ksunda200 avatar Nov 17 '14 04:11 ksunda200

You can use HeaderManager for changing the request headers. 1)Add this code in the source WebSocketSampler.java

private void fillHttpHeadersElement(ClientUpgradeRequest request) { JMeterProperty property = JMeterContextService.getContext().getCurrentSampler().getProperty("HeaderManager.headers"); ArrayList<JMeterProperty> objectValue = (ArrayList<JMeterProperty>) property.getObjectValue(); for (int i = 0; i < objectValue.size(); i++) { JMeterProperty next = objectValue.get(i); Header header = (Header) next.getObjectValue(); request.setHeader(header.getName(), header.getValue()); }

}
  1. In "private ServiceSocket getConnectionSocket() throws URISyntaxException, Exception" method, you can call this method (fillHttpHeadersElement) . //Start WebSocket client thread and upgrage HTTP connection webSocketClient.start(); ClientUpgradeRequest request = new ClientUpgradeRequest(); ///>>> fillHttpHeadersElement(request); ///>>> webSocketClient.connect(socket, uri, request);

For headers you use "HeaderManager.headers". For cookies you can use "CookieManager.cookies"

ceritandogan avatar Aug 28 '15 15:08 ceritandogan

@ceritandogan I am working on Signalr, This is my project requirement hence downloaded websocket version websocket-9.1.1.v20140108, I dont have a good knowledge on JAVA. I am using maciejzaleski websocket sampler in JMeter First time. After a lot of r&d I success to communicate with Signalr via your Websocket sampler. Now my project build got upgraded & they are passing a Cookie Data: .ASPXAUTH=0AE3BF3FE55AAADC5FFEAFE1120F1E45B84AC2C7D227BC8F8E1585E74D14852798F5D27B688D4AFC2C1E494263077178ECBAFC126F4D7D258A21F258779B4B9749BE9D819C51FCBE7D116691F2020FC8EABE622396AA80201872F5C671009EBB in each (Http & WS) request. Via Jmeter cookie manager in each http request cookie handled correctly & requests were passing but my Websocket requests were failing because its not passing the Cookie data.

I have gone through all above comments. As I told I can rate myself 1 outof 10 in JVAV.

Could you please let me know or send me the required websocket JAR file which handles cookies @ [email protected].

Or any guide line also help me...Please

Thanks In Advance.

ChittaRanjan1981 avatar Feb 13 '17 05:02 ChittaRanjan1981