cancel
Showing results for 
Search instead for 
Did you mean: 

Default headers for all resources

SOLVED
Highlighted
New Contributor

Default headers for all resources

Is there any way in ReadAPI 1.5 and SoapUI NG to create a default header that will be used across all resources? We have a standard set of headers (such as X-Requested-By) that need to be included with every request.

 

Right now I am defining these headers on each resource, but it would be helpful if I could define these at a higher level (perhaps on the service, environment, or project?)

Tags (1)
2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
Community Hero

You can use Events - Before run of a test step.


Regards,
Rao.

View solution in original post

Highlighted
New Contributor

Thanks, I ended up creating a RequestFilter.filterRequest event handler with a script like the following:

 

def headers = request.requestHeaders
headers["X-Requested-By"] = ["test"] request.requestHeaders = headers

 

Update: Be careful to set headers to a new List rather than using the add method because this actually modifies the request definition rather than the outgoing request instance. The add method will keep adding a new copy of the header on every run

View solution in original post

5 REPLIES 5
Highlighted
Community Hero

You can use Events - Before run of a test step.


Regards,
Rao.

View solution in original post

Highlighted
New Contributor

Thanks, I ended up creating a RequestFilter.filterRequest event handler with a script like the following:

 

def headers = request.requestHeaders
headers["X-Requested-By"] = ["test"] request.requestHeaders = headers

 

Update: Be careful to set headers to a new List rather than using the add method because this actually modifies the request definition rather than the outgoing request instance. The add method will keep adding a new copy of the header on every run

View solution in original post

Highlighted
Occasional Contributor

Hi,

 

Im new to SOAP UI and i came across this post and used RequestFilter.filterRequest to be used as a global header. However, as mentioned in the post below "add method will keep adding a new copy of the header on every run" - as seen in the image attached every time i run the the TestCase 1 test suite, the "Headers(4)" tab increments by 2 as there are 2 headers. After i run the TestCase many times, the test steps dont run any more as the Header are keep on adding on top.

 

May i know how can i set the header as global but not get incremented everytinme i run the test case?

 

Thanks for helping,

Sudha

Highlighted
Senior Member

Hi,

 

I tried to update in the OnRequest script, the header of the request by using the code below, I have this error :

 

import com.eviware.soapui.support.types.StringToStringMap
def headers = mockRequest.requestHeaders//.each {log.info it}
def header = new StringToStringMap(headers)
header.remove('SOAPAction')

log.info header

mockRequest.requestHeaders = header; // the error comes from this line.

com.eviware.soapui.impl.wsdl.mock.DispatchException: Failed to dispatch using script; groovy.lang.ReadOnlyPropertyException: Cannot set readonly property: requestHeaders for class: com.eviware.soapui.impl.wsdl.mock.WsdlMockRequest.

Can you help me?

 

Highlighted
Community Expert

If you are still looking for a solution, there is one here.

New Here?
Join us and watch the welcome video:
Announcements
TechCorner Leaderboard
Want a fun and easy way to learn ReadyAPI and show off your skills? Try solving weekly TechCorner challenges and get into the Leaderboard!


Challenge Status

Get a full Raw JMS request

Participate!

Compare an expected JSON value and actual response in Events

Participate!

Fetch value/data from JSON response using Groovy Script

See replies!

Get data from Petstore and add it to Excel sheets

Participate!