Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

wso2esb - How to get a formatted date as a Property in the WSO2 ESB

Im trying to format the date in payload using wso2 ESB 4.9.0.I can format the system date using below method.

<property expression="get-property('SYSTEM_DATE','MM-dd-yyyy')"
name="uri.var.TransactionDate" xmlns:ns="http://org.apache.synapse/xsd"/>

but i need is format property value as per below but its not format properly.

<property expression="get-property('uri.var.TransactionDate','MM-dd-yyyy')"
                name="TransactionDate" xmlns:ns="http://org.apache.synapse/xsd"/>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Using the formatting like that only works with the SYSTEM_DATE property. If you want to format your own property you will have to do it using other techniques. There are several date-format functions available in XSLT[1] for example. But while not as pretty, if your incoming Transaction date is always the same length you could also use a concatenation of substrings[2][3]. For example assuming your uri.var.TransActionDate is yyyyMMdd and you want to format to MM-dd-yyyy:

<property expression="concat(substring($ctx:uri.var.TransActionDate, 5, 2), '-', substring($ctx:uri.var.TransActionDate, 7, 2), '-', substring($ctx:uri.var.TransActionDate, 1, 4))" name="TransactionDate"/>

Hope this puts you on the right track!

[1] https://www.oreilly.com/library/view/xslt-2nd-edition/9780596527211/ch04s05.html [2]https://developer.mozilla.org/en-US/docs/Web/XPath/Functions/substring [3]https://developer.mozilla.org/en-US/docs/Web/XPath/Functions/concat


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...