How to get request headers in Lisa?
Run the REST testcase in the ITR, Click on the Step and look at the properties.
You will see a propertycalled lisa.<stepName>.httpheaders.rsp. This should have the header information.
In the VSM, Select the Listen Step, Add a Filter, and look in HTTP/HTML. Review the available filters for parsing header values and cookies.
If scripting is your approach, the lisa_vse_request.getMetaData() returns a ParameterList of headers.
com.itko.util.ParameterList metaData = lisa_vse_request.getMetaData();
Review the SDK for methods available on the ParameterList object.
The MetaData captured during recording is seen in the VSI under the MetaData tab. The VSI depicts only the headers observed during recording, whereas the Filters and Scripts obtain the desired header data on the specific incoming request at runtime.
Thanks Joel , Actually we are not working on virtual services , we are performing web service /API Automation , I have to capture Request headers and body while running a REST Step.
Thanks in advance.
Isn't the property name called lisa.<stepName>.http.headers? I don't see a property named as lisa.<stepName>.httpheaders.rsp
lisa.<stepName>.http.headers will contain the headers extracted from the response. The original question was how to get the request headers
Thanks Shiney and Prem
Actually Prem is correct ,my question is not to capture the response headers but my question is how to capture the request headers.
Response header property is created in properties. please find the below image. I want to capture the property containing request headers.
To access the headers passed in on a Test Case call, you will need to code a small amount of script. Here is a picture of the flow so you can see what is happening.
The Rest Call will set up two headers in this example.
The Retrieve and Print Request Headers script (JSR-223) step will print the ParameterList containing these headers.
The key to accessing the request headers is to access the headers using the Step Name.
// RESTNodeName is the name of the REST Step having the request headers
String RESTNodeName = "RESTGET";ParameterList pl = testExec.TestCase.getNode( RESTNodeName ).getHeaderFields();
// return the ParameterList as a string
// add more code to iterate over the list if necessary
The output of the last two steps, when executed, looks like this:
The Output Log Message is set up with the following code
And, it returns:
I tried the above code but am getting the below error.
execution error so we assume false: javax.script.ScriptException: bsh.EvalError: Sourced file: inline evaluation of: ``import java.lang.*; import com.itko.util.ParameterList; import com.itko.lisa.w . . . '' : Typed variable declaration : Error in method invocation: Method getHeaderFields() not found in class'com.itko.lisa.ws.nx.NxWSStep' : at Line: 11 : in file: inline evaluation of: ``import java.lang.*; import com.itko.util.ParameterList; import com.itko.lisa.w . . . '' : .getHeaderFields ( ) in inline evaluation of: ``import java.lang.*; import com.itko.util.ParameterList; import com.itko.lisa.w . . . '' at line number 11
could you please help ,what can be the reason?
What version of DevTest are you using? The example I used was REST and is taken from DT 10.1.0.
It looks like your step uses a NxWSStep class which returns a CustomHTTPHeaderInfo class rather than a ParameterList.
The below is just a hack... See if this works. If not, I will have to find some time to play with it to see if I can print a list of the headers.
//WEB SERVICE ACCESS TO REQUEST HEADERS WHEN THE STEP IS NxWSStep
// WS_STEP_NAME_HERE -- replace this with the name of your WebService Step
CustomHTTPHeaderInfo chi = testExec.TestCase.getNode( "WS_Step_NAME_HERE" ).getHeaderInfo();
ParameterList pl = chi.getHeaders();
Retrieving data ...