Search code examples
javasoapwsdl

How to pass an xml document to Java JWS SOAP method?


I'm quite new to web-services, I do understand how to pass a simple parameter to my method via SOAP UI tool. WSDL is generated based on my Java code.

Here is the implementation of my method

    @Override
    @WebMethod
   public String greetClient(String userName)
   {
      return "123  " + userName + "321...";
   }

And here is my "One Two" parameter in soap envelope in SOAP-UI.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://test.com/">
   <soapenv:Header/>
   <soapenv:Body>
      <web:sendGAFile>
         <arg0>One Two</arg0>
      </web:sendGAFile>
   </soapenv:Body>
</soapenv:Envelope>

How can I pass an XML document to my method? and how can I add xml file to my request in SOAP UI ?


Solution

  • For your code output will be as like below from soap..

     *<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
           <soap:Body>
              <ns2:giveOutputResponse xmlns:ns2="http://xmltest.sample.org/">
                 <return>123  One Two321...</return>
              </ns2:giveOutputResponse>
           </soap:Body>
        </soap:Envelope>*    
    

    Simply if you want pass xml pls try as like below . You need to use CDATA while sending request from soap.. Unless you will get parsing error.. As for below sample you wil get output with xml .. you can use parser inside your code and return the require value from xml ..

        *<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xt="http://xmltest.sample.org/">
       <soapenv:Header/>
       <soapenv:Body>
          <xt:giveOutput>
             <!--Optional:-->
            <arg0><![CDATA[<?xml version="1.0" encoding="utf-8"?><xml>One Two</xml]]></arg0>
          </xt:giveOutput>
       </soapenv:Body>
    </soapenv:Envelope>*