Ask a Question

Add custom soap Header using Java API

Occasional Contributor

Add custom soap Header using Java API

Dear all, 


I want to test if our soap webservice properly declines requests with a custom header in the envelope 'soapenv:Header'.


I'm experiencing trouble in generating a testrequest with such a header through the JAVA packages. I hoped to get away with something like below;

String request = testStepName.getPropertyValue("Request");
request.replace( "</soapenv:Header>", "<customHeader>test</customHeader></soapenv:Header>");
testStepName.setPropertyValue("Request", request);

But at compile time the RawRequest with soapenv:Header is not availble yet. Untill now, I only made changes to the soapenv on wsa:Headers  for which there are special methods, or through changes in a WSDL.

However, for adding other custom headers I can't find any methods in the packages. 


So my questions is; Which methods can I user to create custom soapenv:Headers in a teststep using Java ?


Thanks in Advance!


Occasional Contributor

Actually comming to think about it, I would like to have the option to directly set how the RAWrequest would come to look like. 


Setting it like this won't work since it's read-only

testStepName.setPropertyValue("RawRequest", "testtesttest"


Occasional Contributor

I was able to solve this problem using this rather low-tech functie:

 public static void replacePartRawRequestAsString(WsdlTestStep step, String oldStringValue, String newStringValue){
        WsaConfig wsaConfig = ((WsdlTestRequestStep) step).getHttpRequest().getWsaConfig();
((WsdlTestRequestStep)step).getHttpRequest().setWsaEnabled(false); String request= (step.getPropertyValue("Request")); String requestHeaders="<soapenv:Header xmlns:wsa=\"\">" +"<wsa:Action>"+wsaConfig.getAction()+"</wsa:Action>" +"<wsa:From><wsa:Address>"+wsaConfig.getFrom()+"</wsa:Address></wsa:From>" +"<wsa:MessageID>uuid:5c644a44-419e-4ff1-b716-e8e5bd37caec</wsa:MessageID>" +"<wsa:To>"+wsaConfig.getTo()+"</wsa:To>" +"</soapenv:Header>"; request=request.replace("<soapenv:Header/>", requestHeaders); request=request.replace(oldStringValue, newStringValue); ((WsdlTestRequestStep)step).getHttpRequest().setRequestContent(request); }

Which I can call like this:

replacePartRawRequestAsString(newStep, "</soapenv:Header>", "<illegalHeader>test</illegalHeader></soapenv:Header>");
SmartBear Alumni (Retired)

Hi @casp8,


Great to hear you have found a solution! Thank you for sharing it!

Olga Terentieva
SmartBear Assistant Community Manager

Showing results for 
Search instead for 
Did you mean: