httpClient 4 & Java understanding - jmeter

What use of httpClient 4 & Java. Need an easy understanding word. I am confused if I am not used this all then also script is created, As per jmeter property set default httpClient 4 but in property active
jmeter.httpsampler=HTTPSampler
and
# HttpClient4.x is commented #jmeter.httpsampler=HttpClient4
Why?

I am not sure to understand what you want. But JMeter uses HttpClient4 as default implementation.
You can change that by setting property :
jmeter.httpsampler
But I don't advise it.
If you look at jmeter.properties, the following lines which would set Java implementation are commented :
jmeter.httpsampler=HTTPSampler
jmeter.httpsampler=Java
You can also change the implementation with:
Http Request Default
HTTP Request

Related

JMeter, How to encrypt whole bodydata in HTTP Request Sampler?

I'm using jmeter 5.0 to test my web application.How to encrypt the whole bodydata using AES before post ?
I've tried to do it with BeanShell PreProcessor,but it seems there is no method to reset the bodydata,what I found is how to print the bodydata.
log.info("test");
String bodydata = sampler.getArguments().toString();
log.info(bodydata);
I've aleardy known how to implement the AES funtion by importing a java calss.What I expect is resetting the bodydata of plaintext to encrypted text.
Put in body data just a JMeter variable as ${encryptData}
And in preprocessor set the variable with your encrypted value:
vars.put("encryptData", encryptData)
There is Arguments.removeAllArguments() function which clears the sampler body
You can add the new body via Arguments.addArgument() function. Example code:
sampler.getArguments().removeAllArguments();
sampler.addNonEncodedArgument("","your_encrypted_data_here","");
sampler.setPostBodyRaw(true);
Since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting mainly due to the fact that Groovy has much better performance comparing to Beanshell. So consider migrating to JSR223 PreProcessor on next available opportunity, the same code should work fine.
Under your "HTTP Request" add an "User Defined Variables" (empty values), Make sure as well to key in ${inputJson} in the "Parameters" text field in the "BeanShell PreProcessor" Element.

How to update the "Replacement Value" in ReplaceText Processor using Rest API?

I need to know how to update the values in nifi processors using Rest API.
https://nifi.apache.org/docs/nifi-docs/rest-api/index.html
For example: I have used below processor structure
GetFile>SplitText>ExtractText>ReplaceText>ConvertJSONToSQL>PUTSQL.
I have passed following inputs for above processors.,
FileLocation(GetFile).
validation(ExtractText).
ReplacementValue(ReplaceText).
DBCP ConnectionPool,username and pwd for SQL.
I just need to use nifi rest api client to write above inputs into processors.
For example : If I give Processor name and input file in Rest API Client then it will write into processor.
Please stop me if anything i'm doing wrong.
Help Appreciated and Tell me any other ways is possible?
Mahen,
You can issue a PUT request to /processors/{id} and provide the new value of the "Replacement Value" property. You'll need to provide JSON body in the request to do this, and you can see the structure by expanding the endpoint noted above on the documentation link you provided, then clicking ProcessorEntity > ProcessorDTO > ProcessorConfigDTO to see the pop-up dialogs with the element listing and examples. You can also quickly get the current values of the processor by issuing a GET request to /processors/{id}.

JMeter treating "${COOKIE_[cookiename]}" as a string

I have looked at numerous examples of setting properties from cookies, and they all seem to be indicate that using a BeanShell PostProcessor, I should be able to do the following, given a cookie named 'FOO'.
props.put( "fooCookie", "${COOKIE_FOO}" );
However, when I try to write that value to the console, as you see here...
print( props.get( "fooCookie" ) );
... the value is always the string ${COOKIE_FOO} as if the dollar/curly bracket notation is not being parsed.
I feel like I must be missing something painfully obvious here, but after several hours of fighting this, I am bringing it to the experts. Any advice would be appreciated.
EDIT: Adding a bit more detail. This is the layout of my test plan
Test Plan
User Defined Variables
HTTP Cookie Manager
HTTP Request Defaults
Login Thread (setup)
[page request - login POST]
HTTP Header Manager
BeanShell PostProcessor
[more page requests]
And I do indeed have CookieManager.save.cookies=true set in the jmeter.bat file that I am launching it with.
Do you have HTTP Cookie Manager in your test plan? If not, you need to have that.
You also need to set the CookieManager.save.cookies=true in the jmeter.properties file which you can find in JMETER_HOME/bin folder.
${COOKIE_FOO} will return the actual cookie value.
Check that your ${COOKIE_FOO} variable is really set using Debug Sampler and View Results Tree listener combination. Your code is OK so my expectation is that the variable is not set.
Those who suggest using Beanshell where it is possible to handle the situation using JMeter built-in test elements should probably consider quitting IT. There are:
__setProperty() function to put something to JMeter Properties
__P() and/or __property() function to read something from them
See How to Use Variables in Different Thread Groups guide for real-life example.

JMeter - Using cookie field as variable

have been looking into JMeter recently. I need to get an authentication string from a cookie and use it when posting a request to a different path. The Auth string changes each time the login page is hit.
Is there a way in JMeter to use one cookie for all paths in a test when the paths are different?
IE-
Path to Get Cookie:
Webserver: someURL.net
Path: /some/login/path
Use the cookie value:
Webserver: someURL.net
Path: /somewhere/different
I have set the below JMeter properties to be able to use Cookies as needed.
CookieManager.check.cookies=false
CookieManager.save.cookies=true
CookieManager.allow_variable_cookies=true
When I run the samplers the result for the request to /somewhere/different
Returns [no cookies]
I can see the cookie data present in the Request when the path is /some/login/path
I have tried defining a User-Defined cookie but I need to get the auth string first to use it in the different path.
When I do this I can see the cookie data added to the request to /somewhere/different but the var is not being set. I don't think this is the right way to solve the challenge.
To get the auth string first I tried to use the Controller "User defined Variables" to store the cookie value and pass it back to the Cookie Manager- this did not work.
And I looked at using the RegEx extractor to get the value so I could use it but I'm not sure that this can be used to get cookie values?
My understanding is that you cannot use more than one cookie manager per Thread group. As I type this I realize that the solution might be that I must use separate threads and pass the cookie value from one thread to another.
Apologies if the question is framed poorly first time here, signed up to ask after searches didn't turn up a solution. If you need more info/screens of my JMeter set up for any of the scenarios I tried above I'll add them. And thank you.
I'm afraid you won't be able to manipulate cookies using built-in JMeter features, you'll need to go deeper and invoke JMeter API methods from scripting test elements.
For instance:
Add a Beanshell PostProcessor as a child of the first request
Put the following code into the PostProcessor(s) "Script" area:
import org.apache.jmeter.protocol.http.control.Cookie;
import org.apache.jmeter.protocol.http.control.CookieManager;
CookieManager manager = ctx.getCurrentSampler().getCookieManager();
for (int i = 0; i < manager.getCookieCount(); i++) {
Cookie cookie = manager.get(i);
if (cookie.getName().equals("your_cookie_name")) {
Cookie newCookie = cookie;
newCookie.setPath("/your/new/path");
manager.remove(i);
manager.add(newCookie);
ctx.getCurrentSampler().setCookieManager(manager);
break;
}
}
Change your_cookie_name and /your/new/path as per your requirements
It will create a new one with the different path. JMeter's HTTP Cookie Manager doesn't allow 2 cookies with the same name so the old one has to be removed.
References:
CookieManager class JavaDoc
JMeterContext class JavaDoc
How to Use BeanShell: JMeter's Favorite Built-in Component guide - overview of scripting, extra information on pre-defined variables, "cookbook" with some examples.

Jmeter: Parameterize the headers in "HTTP header manager" using "CSV data set config"

Jmeter: I tried to Parameterize the headers(pass about 5 dynamic headers) in "HTTP header manager" using "CSV data set config". But i could not, can anybody help me??
Just use the CSV data setup variables in the HTTP header manager.
Can you be more specific on where you're stuck?
YouTube tutorial on using CSV data with JMeter:
http://www.youtube.com/watch?v=aEJNc3TW-g8
Blog that explains exactly what to do:
http://community.blazemeter.com/knowledgebase/articles/65138-using-csv-data-set-config
If you need to add 5 dynamic headers one by one, i.e. one header per request just change the value on each consecutive request - it's pretty easy doable, just place your CSV Data Set Config as a child of required request, the same for HTTP Header Manager.
If you need to add all 5 headers before any testing starts - you'll need to consider do it in a separate thread group or use combination of Loop Controller with Once Only Controller
If none above is applicable to your test scenario try updating it and provide as much information as you can.

Resources