Forum Discussion

casp8's avatar
casp8
Occasional Contributor
5 years ago
Solved

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 wit...
  • casp8's avatar
    casp8
    5 years ago

    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>");