cancel
Showing results for 
Search instead for 
Did you mean: 

Add custom soap Header using Java API

SOLVED
Highlighted
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!

Caspar

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Occasional Contributor

Re: Add custom soap Header using Java API

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

View solution in original post

3 REPLIES 3
Highlighted
Occasional Contributor

Re: Add custom soap Header using Java API

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"

 

Highlighted
Occasional Contributor

Re: Add custom soap Header using Java API

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

View solution in original post

Highlighted
Moderator

Re: Add custom soap Header using Java API

Hi @casp8,

 

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


Olga Terentieva
SmartBear Assistant Community Manager

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors