How to calculate hours between two dateTime node in BPEL.
654976Mar 3 2010 — edited Feb 27 2020In my BPEL there's a requirement need calculate hours between two dateTime type..
I tried 2 solutions, both of them failed:
1. use xslt calculate duration(xml type, like PT12H) between two dateTime, and then use embedded java code to get the hours.. The problem is : I need to parse the xml duration format...(like this real one: -P80DT17H47M36S....), and to parse it in java , maybe have the same problem with solution 2..
* [Subtracting 2 dateTime values into a duration using XPath 2.0|http://blogs.oracle.com/rammenon/2007/07/subtracting_2_datetime_values.html]
2. use embed java code, but it seems we can't use some class in embedded java code:
my code(input begin, end both dateTime in xml. output: diff, int in xml):
1 System.out.println("\n\nTimeTestBegin");
2 String begin=getVariableData("begin").toString();
3 String end=getVariableData("end").toString();
4 System.out.println(begin+"-----"+end);
5 //Class c1=Class.forName("javax.xml.datatype.XMLGregorianCalendar");
6 //Class c2=Class.forName("javax.xml.datatype.DatatypeFactory");
7 //System.out.println(c1.getName());
8 //System.out.println(c2.getName());
9 javax.xml.datatype.XMLGregorianCalendar beginTime = javax.xml.datatype.DatatypeFactory.newInstance().newXMLGregorianCalendar(begin);
10 javax.xml.datatype.XMLGregorianCalendar endTime = javax.xml.datatype.DatatypeFactory.newInstance().newXMLGregorianCalendar(end);
11 long diff=beginTime.toGregorianCalendar().getTimeInMillis()-endTime.toGregorianCalendar().getTimeInMillis();
12 setVariableData("diff",String.valueOf(diff/1000/3600));
13 System.out.println("DIFF======"+diff/1000/3600);
14 System.out.println("TimeTestEnd");
it's said can't compile java class, but can't find the detail error, I think the problem is how to import java class to embedded java code activity(use full package name like above code don't work), when I remove line 9-13, no compile error..
BTY: Jdeveloper is a IDE support java, but why the embedded java activity's edit window only have a simple "java code" editor, too simple that it can only edit you code snippet...
3.There's another sulotion: extend BPEL xpath functions(add a new function), but in my project, modify BPEL server(soa server)'s config file is not allowed..
Anyone know easy solution to my problem?
Thanks.