JavaScript Codelets To Make BPEL Process Wait for Random Duration Up to a Maximum

Author: Michael.Czapski@sun.com Updated and Verified on OpenEsb2.3 by Jay Shankar Gupta, Logicoy Inc Table of Contents Introduction ISO Duration Literals and Random Time Periods Random ISO8601 Duration Java Script Codelet Interface Sample Instance Documents JavaScript Code Create BPEL BPEL Design Create Composite Application TEST CASE Introduction In some specific circumstances, for example when testing high availability and failover scenarios, it may be desirable to make a BPEL process wait for a random amount of time, not exceeding some maximum duration, before continuing. This Note describes the JavaScript Codelet which, given a maximum duration in Milliseconds, will return a random time up to that maximum duration, as an ISO8601 duration literal, suitable for use in the BPEL Wait activity. An example process that uses this Codelet is also developed and discussed. This Note relies on the material presented in the Blog Entry “GlassFish ESB v2.1 -Using JavaScript Codelets to Extend BPEL 2.0 Functionality”, at http://blogs.sun.com/javacapsfieldtech/entry/glassfish_esb_v2_1_using. ISO Duration Literals and Random Time Periods ISO 8601 Standard, which unfortunately is not free hence is not available on-line, defines how a Duration Literal must be constructed. Duration data types in XML Schema and BPEL are both ISO 8601 Duration types. See Wikipedia, “ISO 8601”, http://en.wikipedia.org/wiki/ISO_8601, for a discussion of ISO 8601. It will suffice to say that a Duration Literal P1Y2M3DT4H5M6S defines a time P(eriod) of 1 Y(ear), 2 M(onths), 3 D(ays), T(ime) 4 H(ours), 5 M(inutes), 6.0 S(econds). Duration literals can be abbreviated so 10 minutes can be represented as DT10M, and 10 Seconds as DT10S. To make a BPEL process wait for a random amount of time one must first get...