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!
Caspar
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=\"http://www.w3.org/2005/08/addressing\">" +"<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>");