JMeter - How to extract values from a response which has been decoded from base64 and stored in a variable? All under the same sampler - regex

I am trying to test a webservice's performance, and having a few issues with using and passing variables. There are multiple sequential requests, which depend on some data coming from a previous response. All requests need to be encoded to base64 and placed in a SOAP envelope namespace before sending it to the endpoint. It returns and encoded response which needs to be decoded to see the xml values which need to be used for the next request. What I have done so far is:
1) Beanshell preprocessor added to first sample to encode the payload which is called from a file.
2) Regex to pull the encoded response bit from whole response.
3) Beanshell post processor to decode the response and write to a file (just in case). I have stored the decoded response in a variable 'Output' and I know this works since it writes the response to file correctly.
4) After this, I have added 4 regex extractors and tried various things such as apply to different parts, check different fields, check JMeter variable etc. However, it doesn't seem to work.
This is what my tree is looking like.
JMeter Tree
I am storing the decoded response to 'Output' variable like this and it works since it's writing to file properly:
import org.apache.commons.io.FileUtils;
import org.apache.commons.codec.binary.Base64;
String Createresponse= vars.get("Createregex");
vars.put("response",new String(Base64.decodeBase64(Createresponse.getBytes("UTF-8"))));
Output = vars.get("response");
f = new FileOutputStream("filepath/Createresponse.txt");
p = new PrintStream(f);
this.interpreter.setOut(p);
print(Output);
f.close();
And this is how I using Regex after that, I have tried different options:
Regex settings
Unfortunately though, the regex is not picking up these values from 'Output' variable. I basically need them saved so i can use ${docID} in the payload file for next request.
Any help on this is appreciated! Also happy to provide more detail if needed.
EDIT:
I had a follow up question. I am trying to run this with multiple users. I have a field ${searchuser} in my payload xml file called in the pre-processor here.
The CSV Data set above it looks like this:
However, it is not picking up the values from CSV and substituting in the payload file. Any help is appreciated!

You have 2 problems with your Regular Expression Extractor configuration:
Apply to: needs to be response
Field to check: needs to be Body, Body as a Document is being used for binary file formants like PDF or Word.
By the way, you can do Base64 decoding and encoding using __base64Decode() and __base64Encode() functions available via JMeter Plugins. The plugins in their turn can be installed in one click using Plugin Manager

Related

JMeter extract 500 errors from list of URLs and output them in a csv file

I'm running JMeter 5.4 (via Jenkins) to work through a long list of URLs (from a .txt file) in order to check that they have a 200/301 Status Code.
When I run the test, some of them fail, so what I'd like to do is somehow extract any URLs that have a 500 status code, and then output these (just the 500 status code URLs) to a separate csv file so I can easily see what URLs fail.
I would also like to be able to view this (500 failure) new csv file in Jenkins (I have the performance module up and running), but think I'll try and walk before I run! :)
Is this possible, and if so how would I go about extracting 500 status code URLs in JMeter?
Any help would be greatly appreciated.
You can use a Listener like Simple Data Writer in order to store the failed requests URLs into a file, example configuration for Simple Data Writer:
You can use a JSR223Post processor to write the URLs to a CSV file.
Add a JSR223_PostProcessor to your HTTP Request as a child element
Inside the script area check the response code (=='500') and write the URL
println("Before checking the response code ")
if (prev.getResponseCode().equalsIgnoreCase("500")) {
//print
println("Start writing to file ")
FileWriter fstream = new FileWriter("failed-urls.csv",true);
fstream.write(vars.get('URL')+"\n");
fstream.close();
}
Methods available from the previous sample result (prev variable) can be found in API documentation.
JSR223 Post Processor need to be places as a child element to the HTTP Request

How to capture request and response values in Jmeter and store it in file?

I am using Jmeter as Load Test tool.
I passing one parameter through request and in response I am getting only one parameter in result. response. I want to save both request and response in csv file.
I am using Regular Expression Extractor to capture response and Bean Shell Postprocessor to save it in csv file. But not able to capture respective request param.
Example: Request : http://localhost:8080/myService?input=abcd123455
and Response : pqrst1245/84985==
While here input for request I am taking it from another csv file.
and I want to capture both input parameter and corresponding response and store it in csv file like input,response ie. abcd123455,pqrst1245/84985==
Try using this Beanshell... I didn't try it out, but it should work.
import org.apache.jmeter.services.FileServer;
if (sampleEvent.getResult() instanceof org.apache.jmeter.protocol.http.sampler.HTTPSampleResult) {
String request = (sampleEvent.getResult().getSamplerData());
String response = prev.getResponseDataAsString();
fos = new FileOutputStream("/home/user/output.csv", true);
ps = new PrintStream(fos);
StringBuilder sb = new StringBuilder();
sb.append(request).append(",").append(response).append("\n");
ps.println(sb.toString());
ps.close();
fos.close();
}
The easiest way would be using Sample Variables property. Given you have 2 variables i.e. ${request}and ${response} just add the next line to user.properties file:
sample_variables=request,response
and restart JMeter to pick the property up. Once your test will be finished you will see 2 additional columns in the .jtl results file holding ${request}and ${response} variable values.
Another way to temporarily set the property is passing it via -J command-line argument like
jmeter -Jsample_variables=request,response -n -t test.jmx -l result.jtl
See Apache JMeter Properties Customization Guide article for more information on working with JMeter properties
I would not recommend to use scripting as when it comes to high load you may experience problems with multiple threads concurrently writing into the same file and you will need to think about implementing some form of write lock

WSO2 CEP - Custom Receiver Adapter: Event Formats

I am trying to build a custom receiver adaptor. Which will read from CSV file and push events to a stream.
As far a I understand, we have to follow any of the WSO2 standard format(TEXT, XML or JSON) to push data to a stream.
Problem is, CSV files doesn't match with any of the standard format stated above. We have to convert csv values to any of the supported format within the custom adapter.
As per my observation, WSO2 TEXT format doesn't support comma(,) within a string value. So, I have decided to convert CSV JSON.
My questions are below:
How to generate WSO2 TEXT events if values ave comma ?
(if point 1 is not possible) In my custom adapter MessageType, if I add either only TEXT or all 3 (TEXT, XML, JSON) it works fine. But if I add only JSON I get below error. My target is to add only JSON and convert all the CSV to JSON to avoid confusion.
[2016-09-19 15:38:02,406] ERROR {org.wso2.carbon.event.receiver.core.EventReceiverDeployer} - Error, Event Receiver not deployed and in inactive state, Text Mapping is not supported by event adapter type file
To read from CSV file and push events to a stream, you could use the file-tail adapter. Refer the sample 'Receiving Custom RegEx Text Events via File Tail'. This sample contains the regex patterns which you could use to map your CSV input.
In addition to this, as Charini has suggested in a comment, you could also check out the event simulator. However, the event simulator is not an event receiver - meaning, it will not receive events in realtime, rather it will "play" a previously defined set of events (in the CSV file, in this case) to simulate a flow of events. It will not continuously monitor the file for new events. If you want to monitor the file for new events, then consider using the file-tail adapter.
I have just made it. Not an elegant way. However it worked fine for me.
As I have mentioned, JSON format is the most flexible one to me. I am reading from file and converting each line/event to WSO2 JSON format.
Issue with this option was, I want to limit message format only to JSON from management console ("Message Format" menu while creating new receiver). If I add only JSON [supportInputMessageTypes.add(MessageType.JSON)] it shows error as I mentioned in question#2 above.
The solution is, instead of putting static variable from MessageType class, use corresponding string directly. So now, my method "getSupportedMessageFormats()" in EventAdapterFactory class is as below:
#Override
public List<String> getSupportedMessageFormats() {
List<String> supportInputMessageTypes = new ArrayList<String>();
// just converting the type to string value
// to avoid error "Text Mapping is not supported by event adapter type file"
String jsonType = MessageType.JSON;
supportInputMessageTypes.add(jsonType);
//supportInputMessageTypes.add(MessageType.JSON);
//supportInputMessageTypes.add(MessageType.XML);
//supportInputMessageTypes.add(MessageType.TEXT);
return supportInputMessageTypes;
}
My request to WSO2 team, please allow JSON format event adapter type file.
Thanks, Obaid

How to extract an ID from a request's subsample or body in Jmeter & save it in CSV

I am a beginner in Jmeter & trying to save an ID (like ID=1234567) in a HTTP request's response data using regex extractor & a 3rd party plugin called Dummy sampler with Filewriter but I am failing every time. Here is what it looks like:
/Registration/PaymentInformation?accountRegistrationId=372036
My objective is to save these accountRegistrationId in a CSV file & then use them in the following request as a parameter. The only part where I am stuck is capturing them & saving a file. After that I can manage. I have googled everywhere but cant find a solution. Please help me.
Following regex should work - (.*accountRegistrationId=)([0-9]+)(.*)
Use $2$ to retrieve the id.
JMeter regex reference

read file from url path and display in chart format

i working on one project. i want to read file which path from url,this file containing xml data i have to show this data in chart format.
Basically, your steps may be these:
Validate the URL data (StructKeyExists + FileExists + isFile).
Read and parse XML file, you can do this with XmlParse.
Convert XML object into the query (see query functions).
Render the data using great charting tags.
If you want more detailed help -- please expand your question, to make it more specific.