Possiblity to receive a NULL or missing parameter in WSDL SOAP request | Community
Skip to main content
December 12, 2023
Question

Possiblity to receive a NULL or missing parameter in WSDL SOAP request

  • December 12, 2023
  • 1 reply
  • 988 views

Hello, Im currently trying to set up an endpoint where the producing system sometimes doesnt send a parameter at all but sometimes does. I know how to set up the endpoint with the parameters but not sure how to handle requests that doesn't have all the parameters that is in the method. This is how the method looks like:

<method library="lf:dropingOff.js" name="createDropOff"> <parameters> <param desc="pnr" inout="in" name="personalNumber" type="string"/> <param desc="objectNumber" inout="in" name="objectNumber" optional="true" type="string"/> <param desc="type" inout="in" name="type" type="string"/> <param desc="status" inout="in" name="status" type="string"/> <param desc="level" inout="in" name="level" optional="true" type="string"/> <param desc="purchaseService" inout="in" name="purchaseService" type="string"/> <param desc="Id" inout="out" name="Id" type="int"/> </parameters> </method>

and the parameters that they don't always send is ObjectNumber and Level.

 

This is the javascript logic so far:

function lf_dropOff_createDropOff(personalNumber, objectNumber, type, status, level, purchaseService) { logInfo("createDropOff is called"); var flag = 0; var recp = 0; try { recp = getRecipient(personalNumber); logInfo("recp:" + recp); if (recp) { // Recipient exists logInfo("Recipient exists"); var dropOffXML = <dropOff xtkschema="lf:dropingOff" _key="@pnr, @14236791" pnr={personalNumber} type={type} status={status} purchaseService={purchaseService} _operation="insert"/>; // Check if objectNumber is provided if (objectNumber !== null && objectNumber !== undefined) { dropOffXML.@objectNumber = objectNumber; } // Check if level is provided if (level !== null && level !== undefined) { dropOffXML.@level = level; } xtk.session.Write(dropOffXML); logInfo("createDropOff successful"); flag = 1; } else { // Recipient does not exist logInfo("Recipient does not exist") // logInfo("createDropOff recipient found for pnr: " + personalNumber + "and onr: " + objectRegistrationNumber); } } catch (e) { // logInfo("Error:" + e + " createDropOff throws error for pnr:orgnr=>" + personalNumber + ":" + objectRegistrationNumber);x logInfo("Error:" + e) } return flag; }

 But this throws and error when I comment out the parameters in the wsdl in PostMan:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <tns:createDropOff xmlns="urn:lf:dropingOff"> <tns:sessiontoken>thesession ID</tns:sessiontoken> <tns:entity/> <tns:personalNumber>A FAKE PNR</tns:personalNumber> <!-- <tns:objectNumber></tns:objectNumber> --> <tns:type>Car</tns:type> <tns:status>START</tns:status> <!-- <tns:level></tns:level> --> <tns:purchaseService>Motor</tns:purchaseService> </tns:createDropOff> </soap:Body> </soap:Envelope>

The error:

<?xml version='1.0'?> <SOAP-ENV:Envelope xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'> <SOAP-ENV:Body> <SOAP-ENV:Fault> <faultcode>SOAP-ENV:Server</faultcode> <faultstring xsi:type='xsd:string'>SOP-330011 Error while executing the method 'createDropOffResponse' of service 'lf:dropingOff'.</faultstring> <detail xsi:type='xsd:string'>SCR-160025 Javascript&colon; cannot convert the value to an XML document. JST-310001 Error while evaluating a JavaScript code, line 1: SCR-160017 Function 'createDropOff', argument 0: cannot convert argument to an XML document.. JST-310001 Error while evaluating a JavaScript code, line 1: SCR-160020 Function 'createDropOff': not enough arguments..</detail> </SOAP-ENV:Fault> </SOAP-ENV:Body> </SOAP-ENV:Envelope>

 

Does anyone know if this is possible?

 

Best Regards,

Martin

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

isahore
Community Advisor
Community Advisor
January 4, 2024

Hi @martinviking233,

 

I think it should be possible for the external application to send an empty parameter. In that case there would be no error.

Otherwise, it is better to have the request parameters encapsulated in a parent xml element, and then your SOAP method should take only one input parameter of type DOMElement. Then your method implementation can parse this xml input and detect which parameter is present and which not. Based on that you can work your business logic.

This way, the request can have or exclude any parameter. Your business logic should then return an appropriate response (error or success) based on what information is mandatory.

 

Let me know if that helps.

 

Regards,

Ishan