Layer7 API Management

 View Only
  • 1.  Date/Time Variable Not Coming Out in the Correct Format. Version 9.2

    Posted Mar 27, 2020 08:08 AM
    • I am trying to understand what I have read regarding setting a Date/Time variable and expecting that the format would be a 10 digit seconds format. Yet when I debug the output of the below assertion I am seeing the following:
    • iat = {Date} "Fri Mar 27 07:58:31 EDT 2020"

    Am I misunderstanding the documentation?? Thank you for your feedback.  

     

    <?xml version="1.0" encoding="UTF-8"?>

    <wsp:Policy xmlns:L7p="http://www.layer7tech.com/ws/policy" xmlns:wsp="http://schemas.xmlsoap.org/ws/2002/12/policy">

        <wsp:All wsp:Usage="Required">

            <L7p:SetVariable>

                <L7p:Base64Expression stringValue="JHtnYXRld2F5LnRpbWUuc2Vjb25kc30="/>

                <L7p:DataType variableDataType="dateTime"/>

                <L7p:DateFormat stringValue="&lt;Second Timestamp>"/>

                <L7p:DateOffsetExpression stringValue=""/>

                <L7p:VariableToSet stringValue="iat"/>

            </L7p:SetVariable>

        </wsp:All>

    </wsp:Policy>

     

    Edward Lokiec
    Telephone: 860.226.5977
    E-mail Address:  Ed.Lokiec@CIGNA.com

    image009.png@01CF8950.C7C0E410

     

     

    Confidential, unpublished property of Cigna. Do not duplicate or distribute. Use and distribution limited solely to authorized personnel. © Copyright 2020

     

    ------------------------------------------------------------------------------
    CONFIDENTIALITY NOTICE: If you have received this email in error,
    please immediately notify the sender by e-mail at the address shown. 
    This email transmission may contain confidential information.  This
    information is intended only for the use of the individual(s) or entity to
    whom it is intended even if addressed incorrectly.  Please delete it from
    your files if you are not the intended recipient.  Thank you for your
    compliance.  Copyright (c) 2020 Cigna
    ==============================================================================



  • 2.  RE: Date/Time Variable Not Coming Out in the Correct Format. Version 9.2
    Best Answer

    Broadcom Employee
    Posted Mar 27, 2020 06:30 PM

    The documentation around Date/Time variables is a little confusing. The Set Context Variable takes whatever is in the expression and parses it into a Date/Time type context variable. So if you had a context variable ${myTimeStamp} that is set to 2020-03-27:12:51 (pulled from a text file or database or out of a request, etc) and want that in a Date/Time type of variable, then you would set the Format string to yyyy-MM-dd:HH:mm so the assertion knows how to parse it. Once you have a Date/Time context variable, which is set to the ms, then you add formatting strings to the context variable references to get what you want.

    ${gateway.time} is always a Date/Time context variable that represents the current time on the Gateway. Accessing it directly will convert it to a TimeStamp type of string for display. If you want to format it as something different, then follow the formatting string rules at https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html. If what you want is the current UnixTime (i.e. seconds since Jan 1 1970) then simply reference ${gateway.time.seconds}. There is no need to do anything fancy.

    This policy illustrates what I mean:

    <?xml version="1.0" encoding="UTF-8"?>
    <wsp:Policy xmlns:L7p="http://www.layer7tech.com/ws/policy" xmlns:wsp="http://schemas.xmlsoap.org/ws/2002/12/policy">
    <wsp:All wsp:Usage="Required">
    <L7p:CommentAssertion>
    <L7p:Comment stringValue="* Simple policy to illustrate Date/Time variables"/>
    </L7p:CommentAssertion>
    <L7p:AuditAssertion/>
    <L7p:SetVariable>
    <L7p:Base64Expression stringValue="MjAyMC0wMy0yNzoxMjo1MQ=="/>
    <L7p:VariableToSet stringValue="myTimeStamp"/>
    </L7p:SetVariable>
    <L7p:SetVariable>
    <L7p:Base64Expression stringValue="JHtteVRpbWVTdGFtcH0="/>
    <L7p:DataType variableDataType="dateTime"/>
    <L7p:DateFormat stringValue="yyyy-MM-dd:HH:mm"/>
    <L7p:DateOffsetExpression stringValue=""/>
    <L7p:VariableToSet stringValue="iat"/>
    </L7p:SetVariable>
    <L7p:HardcodedResponse>
    <L7p:Base64ResponseBody stringValue="bXlUaW1lU3RhbXA9JHtteVRpbWVTdGFtcH0KCmlhdD0ke2lhdH0KCmlhdC5ZWVk9JHtpYXQuWVlZfQoKaWF0LnNlY29uZHM9JHtpYXQuc2Vjb25kc30KCmlhdC5FRUVFJywgJ01NTU0nICdkJyBhdCAnSEg6TU1hID0gJHtpYXQuRUVFRScsICdNTU1NJyAnZCcgYXQgJ0hIOk1NYX0KCmdhdGV3YXkudGltZT0ke2dhdGV3YXkudGltZX0KCmdhdGV3YXkudGltZS5zZWNvbmRzPSR7Z2F0ZXdheS50aW1lLnNlY29uZHN9CgpnYXRld2F5LnRpbWUubWlsbGlzPSR7Z2F0ZXdheS50aW1lLm1pbGxpc30="/>
    <L7p:ResponseContentType stringValue="text/plain; charset=UTF-8"/>
    </L7p:HardcodedResponse>
    </wsp:All>
    </wsp:Policy>



    ------------------------------
    Jay MacDonald - Adoption Architect - Broadcom API Management (Layer 7)
    ------------------------------



  • 3.  RE: Date/Time Variable Not Coming Out in the Correct Format. Version 9.2

    Posted Mar 28, 2020 05:50 AM
    Jay, thank you for your reply but I should have been a bit clearer in what I was looking for. I understand I could have just appended a ".seconds'" to my context variable but I was try to understand the purpose of the "<Second Timestamp>" Format in the Date/Time in the set context function? Being a purist what is the sense of having a format function of <Second Timestamp> when it does not translate the value to seconds?? Again thank you for your time.​