Forum Discussion

prm_svm's avatar
prm_svm
New Contributor
9 years ago

How to add parameter in SOAPUI-4.5.0 jar java in soap request

I have an WSDL soap service, Am using SOAPUI-4.5.0 jar in java to generate all the operations, am creating a new request by using WsdlOperation.createRequest(true); but am unable to pass the parameter to the created request.

Java code:

WsdlInterface[] wsdls = WsdlImporter.importWsdl(project,
                "http://xx.xxx.xxx:3263/xxxx?Wsdl");
WsdlInterface iwsdl= wsdls[0];
WsdlOperation wsdlOperation=iwsdl.getOperationByName("CreateDevice");
WsdlRequest request = wsdlOperation.addNewRequest("My request");
String requestContent = wsdlOperation.createRequest(true);

requestContent value:
---------------------

<xml-fragment xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://soap.xxxx.com">
  <soapenv:Header/>
  <soapenv:Body>
    <soap:Create>
      <!--Optional:-->
      <soap:name>?</soap:name>
      <!--Optional:-->
      <soap:size>?</soap:size>
    </soap:CreateDevice>
  </soapenv:Body>
</xml-fragment>

request.setRequestContent(requestXmlObject.toString());
request.setEndpoint("http://xx.xxx.xxx:3263/xxxx");
WsdlSubmitContext wsdlSubmitContext = new WsdlSubmitContext(request);
WsdlSubmit<?> subm = request.submit(wsdlSubmitContext, false);
Response response = subm.getResponse();

name = String type
size = int type

response value:
---------------
<faultstring xml:lang="en-US">The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://soap.xxxx.com:size. The InnerException message was 'There was an error deserializing the object of type System.Int32. The value '?' cannot be parsed as the type 'Int32'.'.  Please see InnerException for more details.</faultstring>

Am getting the above error, while passing the request.
I need to pass parameter for name and size.
Please share the code

3 Replies

    • rupert_anderson's avatar
      rupert_anderson
      Valued Contributor

      So, in particular you can create the request XML as you did and use Groovy Slurper to amend it:

      ...

      //Create the request and capture the XML content

      String requestXMLString = operation.createRequest( true ).toString()

       

      System.out.println("Request String Content: "+requestXMLString);

       

      //Use XMLSlurper to pass and update the invoiceNo=7 in my getInvoice operation

      def envelopeNode = new XmlSlurper().parseText(requestXMLString)

      envelopeNode.Body.getInvoice.invoiceNo=7

       

      //This is just to serialize the XML objects back to a request XML String

      XmlUtil xmlUtil = new XmlUtil()

      requestXMLString = xmlUtil.serialize(envelopeNode)

      println( "modified request: g"+requestXMLString)

       

      //Update the SoapUI request content with the new updated XML request content

      request.setRequestContent(requestXMLString)

      ...

      Then when you submit the request it should be fine.

       

      Hope this helps,

      Cheers,

      Rupert

      • prm_svm's avatar
        prm_svm
        New Contributor

        Hi Rupert,

         

        Thanks,

        As per your suggestions, I have created a new groovy class and write the below method in groovy class

         

        class ParseXML {

           def parseFile(xmlString) {

               def envelopeNode = new XmlSlurper().parseText(requestXMLString)

               envelopeNode.Body.CreateDevice.name="testSoapUI"

               return envelopeNode

           }

        }

         

        But am unable to set the parameter in the request

         

        In java code:

        -------------

        String requestContent = wsdlOperation.createRequest(true).toString();
        System.out.println(requestContent);
        ParseXML xml = new ParseXML(); //  groovy file name
        Object obj = xml.parseFile(requestContent);

         

        But the envelopeNode returns -  ??

         

        My request is (requestContent):

        <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://soap.xxx.com">
           <soapenv:Header/>
           <soapenv:Body>
              <soap:CreateDevice>
                 <!--Optional:-->
                 <soap:name>?</soap:name>
                 <!--Optional:-->
                 <soap:size>?</soap:size>
              </soap:CreateDevice>
           </soapenv:Body>
        </soapenv:Envelope>

         

        Kindly guide me..