How can I output the current time in seconds (epoch time) every time a service is engaged?
To get the time output from your Gateway to the service please do the following
Prerequisites: An existing service to add assertions to
3. Give it a VariableName: Example: TimeAbsTest
Data Type: Message
Format: from the drop down menu select the following: Text/Plain; charset=utf-8
Expression: ${gateway.time.seconds}
<Please see attached file for image>
4. Add another assertion called “Return Template Response to Requester”
Change Response Content Type: text/plain; charset=UTF-8
Response Body: “${TimeAbsTest}”
<Please see attached file for image>
5. Once you have done this you can Save and activate your service and then go to the service URL
https://GatewayServer:8443/ServiceName
The ouput should be like the following (time in seconds)
<Please see attached file for image>
You should be able to see the output of the time stamp on the service if you see an error you can add the assertion “Customize SOAP Fault Response as Full Detail” to give you more details on what is causing the error.
Variables Descriptions
${gateway.time.<suffix>} Returns the current time on the Gateway; suffix is optional.
${request.time.<suffix>} Returns the time the request was received; suffix is optional.
There are a variety of suffixes that you can append (to both the built-in variables or to custom date/time variables) to modify or reformat the time that is returned. These suffixes are summarized in the following table.
When a date/time variable is used without a suffix, the time value returned is in ISO 8601 format, in the UTC (Coordinated Universal Time) time zone
Suffix Description
.local Returns the value in local time.
.utc Returns the value in UTC time. This is the same as using no suffix at all.
.<SimpleDateFormat> Returns the value in a specified format. You can append a format to the above suffixes (or on its own) to create unstructured suffixes using symbols from java.text.SimpleDateFormat. Examples:
${request.time.local.MM/dd/yyyy}
${gateway.time.MM/dd/yyyy
For more information on the SimpleDateFormat, see http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
.millis Access a timestamp in milliseconds for the variable. This suffix must appear directly after the variable (for example, ${mydate.millis}).
.seconds Access a second timestamp for the variable. This suffix must appear directly after the variable (for example, ${gateway.time.seconds}).
.<timezone>.<formatting> Returns the value in the specified time zone (case insensitive) with optional custom formatting.
Examples:
${myvar.BST} - value of myvar is in British Standard Time formatted as an ISO 8601 string
${request.time.BST.hh:mm:ss} - request is in British Standard Time with specified custom formatting
Time zone suffixes are all those supported by the java.util.TimeZone.getAvailableIDs() utility.
.<offset> Returns the value in the local time offset by the specified <offset> value. Examples of valid values:
${gateway.time.+07:00}
${gateway.time.-0700}
${gateway.time.+05:30}
${gateway.time.-0530}
${gateway.time.+07}
${gateway.time.-07}
The following are examples of invalid <offset> values:
${gateway.time.+7:00}
${gateway.time.-530}
${gateway.time.+7}
.<StructuredFormat> Returns the value in any of the following structured formats:
• .iso8601 - yyyy-MM-ddTHH:mm:ss.SSSX
• .rfc1123 - E, dd MM yyyy hh:mm:ss Z
• .rfc850 - EEEE, dd-MM-yy hh:mm:ss Z
• .asctime - E MMM d hh:mm:ss yyyy
These suffixes can be used directly after the variable name or after a timezone:
${myvar.BST.rfc1123} - BST date string formatted according to rfc1123
${myvar.rfc1123} - Date string formatted according to GMT (Zulu) time zone.