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

No header information in web socket sampler like HTTP header manager in HTTP sampler

Open rahulchhimpa opened this issue 11 years ago • 2 comments

how to add header information with websocket sampler like http sampler.i want to send request with some header information with it to the server..but there is no way to add header in web socket sampler

rahulchhimpa avatar Apr 25 '14 10:04 rahulchhimpa

how can we add header like HTTP header manger in web socket sampler.?

rahulchhimpa avatar Apr 30 '14 05:04 rahulchhimpa

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);

ceritandogan avatar Aug 28 '15 14:08 ceritandogan