Search code examples
switch-statementwso2wso2-data-services-serverwso2-esb

Wso2esb : Error while handling null value in switch case


i'm using wso2esb 4.7.0 and wso2dss 3.1.0.i wish to select some column from table.For that i have used following query in dss :

select roleid,rolename,rolecode from mrole where clientid = ? and ModifiedOn = ?

It's working fine in dss as well as esb also.Output is like :

{"roleid":"1077282521908571","rolename":"adminrole","rolecode":"adminrole"},{"roleid":"1077282521908571","rolename":"adminrole","rolecode":"adminrole"},{"roleid":"1077278842127704","rolename":"everyonerole","rolecode":"everyonerole"},{"roleid":"1077282521908571","rolename":"adminrole","rolecode":"adminrole"}

this is one case.Now in second case if i didn't got modifiedon then obvious it shows error in dss like :

Caused by: javax.xml.stream.XMLStreamException: DS Fault Message: Error in 'SQLQuery.processNormalQuery'
DS Code: DATABASE_ERROR
Source Data Service:-
Name: muser_DataService2.0
Location: /muser_DataService2.0.dbs
Description: N/A
Default Namespace: http://ws.wso2.org/dataservice
Current Request Name: Select_Role_Details_Op
Current Params: {clientid=214057357158656, modifiedon=}
Nested Exception:-
java.lang.NumberFormatException: For input string: ""

To solve that i'm using switch case in esb like :

 <switch source="get-property('ModifiedOn')">
            <case regex="''">
               <property name="ModifiedOn" value="0" scope="default" type="STRING"/>
               <log level="custom">
                  <property name="ModifiedOn in case of null: "
                            expression="get-property('ModifiedOn')"/>
               </log>
            </case>           
 </switch>

it shows warning message in esb like :

[2014-10-08 11:43:54,100]  WARN - SwitchCase Provided character sequence for switch case condition is 'null'. Switch case will not be executed.

and without executing switch case it directly move forward and generate fault as well as dss shows error as above.How should i give the null condition in switch case?


Solution

  • use boolean xpath function to verify if your property exist :

    <filter xpath="boolean(get-property('ModifiedOn'))">
       <then> 
          ...
       </then>
       <else>
          ...
       </else>
    </filter>