soaptalend

Pass dynamic value type Date into tSOAP Message


I want to pass a value type date of this format "yyyy-MM-dd" (ex : 2023-09-06) to tSOAP message by using a global variable but not successful. It always give me this value Wed Sep 06 00:00:00 CEST 2023 instead of this value 2023-09-06. Here is my job (test) :

enter image description here

So in this job, I will stock my last date execution of a job in a file csv. Then at the beginning of a job, I will assign this value to a global variable so I could pass it to tSOAP message. Here is my code in tJavaFlex_1 :

// start part of your Java code
System.out.println("Date last update:");

//Déclaration des variables qui stockent la date de dernière update
String str_date_last_update;
Date dat_date_last_update;

//Maintenant on attribue les bonnes valeurs aux variables
str_date_last_update = row8.contenu;
dat_date_last_update = TalendDate.parseDate("yyyy-MM-dd", str_date_last_update);


//Enfin on expose les variables locales commes des variables global pour pouvoir les réutiliser
globalMap.put("dat_date_last_update", dat_date_last_update);
globalMap.put("str_date_last_update", str_date_last_update);

System.out.println("End of file");
System.out.println((String)globalMap.get("str_date_last_update"));
System.out.println((Date)globalMap.get("dat_date_last_update"));

So example, for the code System.out.println((String)globalMap.get("str_date_last_update")); will give me this value 2023-09-06 while this code System.out.println((Date)globalMap.get("dat_date_last_update")); give me this value Wed Sep 06 00:00:00 CEST 2023 . But I need to pass a value of type Date with this value 2023-09-06. Because if not, I always receive a bad response.

Here is my tSOAP message (simplifié):

"<soap:Envelope ...
               <!--- type date with restriction pattern([0-9]{4}-[0-9]{2}-[0-9]{2}):-->
               <LowerBoundaryDate>" +(Date)globalMap.get("dat_date_last_update") + "</LowerBoundaryDate>
               <UpperBoundaryDate>2023-09-06</UpperBoundaryDate>
            </SelectionByChangedSinceDate>
      ....  
</soap:Envelope>" 

I have tried to pass this code in tSOAP message but it didn't work :

"<soap:Envelope ...
               <!--- type date with restriction pattern([0-9]{4}-[0-9]{2}-[0-9]{2}):-->
               <LowerBoundaryDate>" + TalendDate.parseDate("yyyy-MM-dd", (String)globalMap.get("str_date_last_update")) + "</LowerBoundaryDate>
               <UpperBoundaryDate>2023-09-06</UpperBoundaryDate>
            </SelectionByChangedSinceDate>
      ....  
</soap:Envelope>" 

Solution

  • All your soap envelope is evaluated as a String (see the double quotes at start/end). So I guess passing ((String)globalMap.get("str_date_last_update")) in your element should do the trick. No need to pass the value as a Date.