Forum Discussion

Arachselvi_Siva's avatar
Arachselvi_Siva
Frequent Visitor
9 years ago

Setting the Authentication type for WsdlRequest programmatically

Hi,

 

I need to set the authentication type for WsdlRequest programmatically through groovy script. I am using the below code

 

File projectFile =new File("D:\\TestProjectA-soapui-project.xml");

 

WsdlProject project=new WsdlProject("GroovyGeneratedProject");

WsdlInterface[] wsdls;

wsdls = WsdlImporter.importWsdl(project, "C:\\WSDL\\UserDetails.wsdl");

WsdlInterface wsdl

int operationCount;

def WssC;

for(int j=0;j<wsdls.length;j++)

{

wsdl = wsdls[j];

operationCount=wsdl.getOperationCount();

}

WssC=project.getWssContainer();

if(!WssC.getOutgoingWssList().contains("testing")){

                def owss = WssC.addOutgoingWss("testing");

   owss.setActor("Test");

   owss.setPassword("Test");

   owss.setUsername("Test");

   owss.setMustUnderstand(true);

}

for(int i=0;i<operationCount;i++)

{

WsdlOperation op = wsdl.getOperationByName("deleteUser");

String opName = op.getName();

WsdlRequest req = op.addNewRequest("Req_"+opName);

req.setRequestContent("somexmlformat");

req.setEndpoint("EndpointUrl");

req.setOutgoingWss("testing");

req.addBasicAuthenticationProfile("Basic");

break;

}

project.saveIn(projectFile);

 

 

With this code, I am able to set the outgoingWss config and BasicAuthentication Profile for WsdlRequest. Still I need to set the settings, Authtype and SelectedAuthProfile for WsdlRequest. I tried using setSettings() method. But it is throwing error like only getSettings() method can be used.

 

Please suggest me which methods should be used.

1 Reply

  • nmrao's avatar
    nmrao
    Champion Level 3
    I am not sure if you can possibly avoid that by following the below as that does not require all that.

    Here is you go:
    1. Go to Preferences, Http Settings, Authentication Preemtive and click the check box and save the preferences.

    2. In the project, go the interface (typicaly wsdl that is being imported) and provide the credentials details. You may do the same for other interfaces in the project.

    From now onwards, the security details are being sent automatically along with WsdlRequest.

    See if this works for you.