Ask a Question

SOAP XML Request with Basic Authentication in java

dsindhumathi
New Contributor

SOAP XML Request with Basic Authentication in java

I am using SoapUI java client to automate soap based web services and trying generate XML at run time. Here is my xml which I have generated at run time

 

 **<soapenv:Envelope
        xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
        xmlns:v2="http://ws.soa.sms.sirius.com/schema/soacommon/v2"
        xmlns:log="http://ws.soa.sms.sirius.com/schema/csr/login/">
        <soapenv:Header>
    <v2:smsHeader>
        <v2:sourceName>STARSS</v2:sourceName>
        <v2:transactionId>csrlogin123</v2:transactionId>
        <v2:timeStamp>2021-08-24T01:59:01-00:00</v2:timeStamp>
        <v2:smsPortalOverride/>
    </v2:smsHeader>
        </soapenv:Header>
        <soapenv:Body>
    <log:csrLoginRequest>
        <username>CCManager</username>
        <password>password</password>
    </log:csrLoginRequest>
        </soapenv:Body>
    </soapenv:Envelope>**


and calling this xml through wsdl 

WsdlProject wsdlProject = new WsdlProject("C:\\SC\\Indhu\\XmlPOC\\sms_qa_selenium\\my-file.xml");
        WsdlProject wsdlProject = new WsdlProject(serviceXmlPath);
        WsdlTestSuite wsdlTestSuite1 = wsdlProject.getTestSuiteByName("CSRLogin");
        WsdlTestCase wsdlTestCase1 = wsdlTestSuite1.getTestCaseByName("CSRLogin");
        WsdlTestStep wsdlTestStep = wsdlTestCase1.getTestStepByName("CreateCustomer");
        WsdlTestCaseRunner wsdlTestCaseRunner = new WsdlTestCaseRunner(wsdlTestCase1,
                new StringToObjectMap(wsdlTestCase1.getProperties()));
        
        wsdlProject.setPropertyValue("username", "esbuser");
        wsdlProject.setPropertyValue("password", "password");
        wsdlProject.setPropertyValue("wssPasswordType", "PasswordText");
        
        TestStepResult testStepResult = wsdlTestCaseRunner.runTestStep(wsdlTestStep);
5 REPLIES 5
ChrisAdams
Community Leader

Hi,

 

What is your question/issue?

I dont know how to set  and where to set request properties in xml. 

Hi,

 

Authentication should be in the headers of your payload.

ReadyAPI/SoapUI make this as easy as it's in the UI for a request....

 

ChrisAdams_0-1639065278947.png

 

This can also be applied from the Project level and propagated down to all requests below if you have a licensed copy.  If you do have the licensed version, look at environments.

 

Thanks @ChrisAdams  for replying. Actually I m trying to automate web services in java. I have generated XML at run time and trying to make soap request by passing the xml. But in the code level I dont know where I have to set my username, password and password type. Weather we can insert these details in the xml itself or While creating the object for WsdlProject?. Or any other way to generate dynamic XML and make soap request. Since I am new to SoapUI need some suggestion which is good way to do.

You need to put the authorization in the header part of the XML.

Get it running in SoapUI.  Once you do, look at the Request step and the raw tab.  The raw tab shows EXACTLY what SoapUI sent to the service.  In there, look at the headers and you'll see the authorization hash that SoapUI generated using your user name and password.

Copy that into your Java code and test.  Obviously, this breaks if you change your password!

Once you have that working, the I'd suggest using Java to generate the hash.

 

cancel
Showing results for 
Search instead for 
Did you mean: