Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for headers and cookies in WebSocket upgrade request #22

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

tradingscreen
Copy link
Collaborator

No description provided.

@vladimir-gritsenko
Copy link

Hi Vadim,

Appreciate for adding cookies and headers stuff into client upgrade request.

Could you please tell me who surrounds cookies send in upgrade request with quotes? Have you faced with similar problem and what did you do?

Thanks.

@tradingscreen
Copy link
Collaborator Author

Nope - I have not seen this happening. From what I can tell, the HTTP Cookie Manager faithfully preserves the cookie value as it was sent in the server response. The CookieStore created by the code I've just added does not add quotes either. The server I am using does not received the cookie values quoted. The only thing I can think of is that the server itself sends the values quoted to be begin with. You can try to debug this using something like WireShark.

@vladimir-gritsenko
Copy link

Found the problem.
Java API 1.8, I'm using set, HttpCookie version to 1 by default - this is done to make it compatibile with RFC 2965/2109. In this version java api surrounds cookie value with quotes.

Fortunately, you used exactly HttpCookie object inside modified WebSocketSampler code so I'm just simly calling the method setVersion(0) every time I add cookie to cookieStore.

It took me a day to find it out but now ... I'm happy.

Thanks again for this improvement!

P.S. Do not want to commit code here as it may affect someone in other environemnts.
Just in case add this code rows here:

HttpCookie tmpCookie = new HttpCookie(cookieManager.get(i).getName(),cookieManager.get(i).getValue());

             tmpCookie.setVersion(0);

             cookieStore.add(
                        new URI(null,
                                cookieManager.get(i).getDomain(),
                                cookieManager.get(i).getPath(),
                                null),tmpCookie
                        );

@tradingscreen
Copy link
Collaborator Author

I've incorporated your cookie version suggestion using the existing version data maintained by CookieManager.

Vadim Elkin added 4 commits September 3, 2014 15:52
If a sampler reuses a streaming websocket created by some earlier sampler, the new sampler's parameters are picked up
@lovexiaov
Copy link

hi, tradingscreen!
Could you supply a jar file with headers support? thanks a lot.

@paldaz
Copy link

paldaz commented Feb 12, 2015

Hello.
It'd be great if you supply a jar file with headers support.
Thanks

@tradingscreen
Copy link
Collaborator Author

Hi. I’ve added ZIPped JAR file at the root of source tree.

From: paldaz [mailto:[email protected]]
Sent: Thursday, February 12, 2015 9:09 AM
To: maciejzaleski/JMeter-WebSocketSampler
Cc: TSNext
Subject: Re: [JMeter-WebSocketSampler] Added support for headers and cookies in WebSocket upgrade request (#22)

Hello.
It'd be great if you supply a jar file with headers support.
Thanks


Reply to this email directly or view it on GitHubhttps://github.com//pull/22#issuecomment-74075871.

@paldaz
Copy link

paldaz commented Feb 13, 2015

Thanks tradingscreen 👍

@tahsintahsin
Copy link

Hello,
Do you have any examples explaining how to use your code to add headers to a websocket sampler?
Thanks

@tradingscreen
Copy link
Collaborator Author

Websocket sampler does not manage headers (nor cookies) itself. Websocket sampler just obeys the same rules that any sampler should and picks up headers from the standard JMeter "HTTP Header Manager" and cookies from "HTTP Cookie Manager". Take a look at JMeter manual to see how these work.

@tahsintahsin
Copy link

thank you for the answer

@crezyforjava
Copy link

@tradingscreen
I am able to open web socket connection using this sampler. my next requirement is to send different JSON message on every second.

is it possible to send these message using this sampler?
if yes than how?

Thanks in advance.

@tradingscreen
Copy link
Collaborator Author

You can have a "loop" with a "pause" set to 1s and the websocket sampler that has the JSON in "Request data" field. You can use regular expression extractor to pull whatever values you may need from the server messages coming over the websocket.

@tradingscreen
Copy link
Collaborator Author

I would also recommend looking at mkaczara/JMeter-WebSocketSampler repository as it pulled in the fixes from this repository as well as added a bunch of other improvements

@crezyforjava
Copy link

@tradingscreen Thank you Sir. It is working fine.

@angelqing
Copy link

hi, tradingscreen!
Could you supply a jar file with headers support? thanks in adwance

@tradingscreen
Copy link
Collaborator Author

Please, take a look at the Feb 13 and Aug 14 comments.

@ChittaRanjan1981
Copy link

@tradingscreen

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.

@angelqing
Copy link

angelqing commented Feb 15, 2017 via email

@ChittaRanjan1981
Copy link

Thanks for your reply.. Attached Jar is not working for my signalr request. I already added HTTP cookie manager & Header manger with the test plan. Could you please let me know is there any extra configuration required.

In view result tree I can observe no cookie is passing.

You have a release on Feb 13 & In Oct in GIT. The latest release on October don't have any jar why? Feb 13 jar is not working for me with SignalR..

@ChittaRanjan1981
Copy link

ChittaRanjan1981 commented Feb 15, 2017 via email

@ChittaRanjan1981
Copy link

ChittaRanjan1981 commented Feb 16, 2017 via email

@buaban
Copy link

buaban commented May 5, 2017

I've a problem with this plugin. It seems to be a race condition.
When I subscribe a service via websocket. my service returns 2 messages.
The problem occurs when these 2 messages came at the same time. There is an error at WebSocketSampler.java, method: "sample" at the lines below:

if (socket.getResponseMessage() == null || socket.getResponseMessage().isEmpty()) {
    sampleResult.setResponseCode("204");
}

Error Message:
[Problems]

- Unexpected error: null
java.util.LinkedList$ListItr.checkForComodification(Unknown Source)
java.util.LinkedList$ListItr.next(Unknown Source)
JMeter.plugins.functional.samplers.websocket.ServiceSocket.getResponseMessage(ServiceSocket.java:106)
JMeter.plugins.functional.samplers.websocket.WebSocketSampler.sample(WebSocketSampler.java:155)
org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:465)
org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:410)
org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:241)
java.lang.Thread.run(Unknown Source)

Can you advise?

@buaban
Copy link

buaban commented May 5, 2017

I have one question.
My service returns 2 messages and we don't know which one will come first.
Is it possible to hold the sampler until it has received 2 messages instead of checking the response pattern?

@ChittaRanjan1981
Copy link

ChittaRanjan1981 commented May 5, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants