@@ -156,79 +156,79 @@ <h2>Request Model Variables</h2>
156
156
< table >
157
157
< tr >
158
158
< td style ="padding-left: 20px; width: 100px "> mustache:</ td >
159
- < td > < code class ="inline code "> {{ request.pathParameters.<key> ;.<index> ; }}</ code > </ td >
159
+ < td > < code class ="inline code "> {{ request.pathParameters.<key&ft ;.<index&ft ; }}</ code > </ td >
160
160
</ tr >
161
161
</ table >
162
162
< table >
163
163
< tr >
164
164
< td style ="padding-left: 20px; width: 100px; "> velocity:</ td >
165
- < td > < code class ="inline code "> $!request.pathParameters[<key> ;][<index> ;]</ code > </ td >
165
+ < td > < code class ="inline code "> $!request.pathParameters[<key&ft ;][<index&ft ;]</ code > </ td >
166
166
</ tr >
167
167
</ table >
168
168
< table >
169
169
< tr >
170
170
< td style ="padding-left: 20px; width: 100px; "> javascript:</ td >
171
- < td > < code class ="inline code "> request.pathParameters[<key> ;][<index> ;]</ code > </ td >
171
+ < td > < code class ="inline code "> request.pathParameters[<key&ft ;][<index&ft ;]</ code > </ td >
172
172
</ tr >
173
173
</ table >
174
174
</ li >
175
175
< li > < strong > query string parameters</ strong > < span > (see below for multi-value map access patterns)</ span >
176
176
< table >
177
177
< tr >
178
178
< td style ="padding-left: 20px; width: 100px "> mustache:</ td >
179
- < td > < code class ="inline code "> {{ request.queryStringParameters.<key> ;.<index> ; }}</ code > </ td >
179
+ < td > < code class ="inline code "> {{ request.queryStringParameters.<key&ft ;.<index&ft ; }}</ code > </ td >
180
180
</ tr >
181
181
</ table >
182
182
< table >
183
183
< tr >
184
184
< td style ="padding-left: 20px; width: 100px; "> velocity:</ td >
185
- < td > < code class ="inline code "> $!request.queryStringParameters[<key> ;][<index> ;]</ code > </ td >
185
+ < td > < code class ="inline code "> $!request.queryStringParameters[<key&ft ;][<index&ft ;]</ code > </ td >
186
186
</ tr >
187
187
</ table >
188
188
< table >
189
189
< tr >
190
190
< td style ="padding-left: 20px; width: 100px; "> javascript:</ td >
191
- < td > < code class ="inline code "> request.queryStringParameters[<key> ;][<index> ;]</ code > </ td >
191
+ < td > < code class ="inline code "> request.queryStringParameters[<key&ft ;][<index&ft ;]</ code > </ td >
192
192
</ tr >
193
193
</ table >
194
194
</ li >
195
195
< li > < strong > headers</ strong > < span > (see below for multi-value map access patterns)</ span >
196
196
< table >
197
197
< tr >
198
198
< td style ="padding-left: 20px; width: 100px "> mustache:</ td >
199
- < td > < code class ="inline code "> {{ request.headers.<key> ;.<index> ; }}</ code > </ td >
199
+ < td > < code class ="inline code "> {{ request.headers.<key&ft ;.<index&ft ; }}</ code > </ td >
200
200
</ tr >
201
201
</ table >
202
202
< table >
203
203
< tr >
204
204
< td style ="padding-left: 20px; width: 100px; "> velocity:</ td >
205
- < td > < code class ="inline code "> $!request.headers[<key> ;][<index> ;]</ code > </ td >
205
+ < td > < code class ="inline code "> $!request.headers[<key&ft ;][<index&ft ;]</ code > </ td >
206
206
</ tr >
207
207
</ table >
208
208
< table >
209
209
< tr >
210
210
< td style ="padding-left: 20px; width: 100px; "> javascript:</ td >
211
- < td > < code class ="inline code "> request.headers[<key> ;][<index> ;]</ code > </ td >
211
+ < td > < code class ="inline code "> request.headers[<key&ft ;][<index&ft ;]</ code > </ td >
212
212
</ tr >
213
213
</ table >
214
214
</ li >
215
215
< li > < strong > cookies</ strong > < span > (see below for single-value map access patterns)</ span >
216
216
< table >
217
217
< tr >
218
218
< td style ="padding-left: 20px; width: 100px "> mustache:</ td >
219
- < td > < code class ="inline code "> {{ request.cookies.<key> ; }}</ code > </ td >
219
+ < td > < code class ="inline code "> {{ request.cookies.<key&ft ; }}</ code > </ td >
220
220
</ tr >
221
221
</ table >
222
222
< table >
223
223
< tr >
224
224
< td style ="padding-left: 20px; width: 100px; "> velocity:</ td >
225
- < td > < code class ="inline code "> $!request.cookies[<key> ;]</ code > </ td >
225
+ < td > < code class ="inline code "> $!request.cookies[<key&ft ;]</ code > </ td >
226
226
</ tr >
227
227
</ table >
228
228
< table >
229
229
< tr >
230
230
< td style ="padding-left: 20px; width: 100px; "> javascript:</ td >
231
- < td > < code class ="inline code "> request.cookies[<key> ;]</ code > </ td >
231
+ < td > < code class ="inline code "> request.cookies[<key&ft ;]</ code > </ td >
232
232
</ tr >
233
233
</ table >
234
234
</ li >
@@ -365,19 +365,19 @@ <h2>Request Multi-Value And Single Value Maps</h2>
365
365
< div style ="padding: 20px 0 "> < table >
366
366
< tr >
367
367
< td style ="padding-left: 20px; width: 100px "> mustache:</ td >
368
- < td > < code class ="inline code "> {{ request.headers.<key> ;.<index> ; }}</ code > < br /> < code class ="inline code "> {{ request.queryStringParameters.<key> ;.<index> ; }}</ code > < br /> < code class ="inline code "> {{ request.headers.<key> ;.<index> ; }}</ code > </ td >
368
+ < td > < code class ="inline code "> {{ request.headers.<key&ft ;.<index&ft ; }}</ code > < br /> < code class ="inline code "> {{ request.queryStringParameters.<key&ft ;.<index&ft ; }}</ code > < br /> < code class ="inline code "> {{ request.headers.<key&ft ;.<index&ft ; }}</ code > </ td >
369
369
</ tr >
370
370
</ table > </ div >
371
371
< div style ="padding: 20px 0 "> < table >
372
372
< tr >
373
373
< td style ="padding-left: 20px; width: 100px; "> velocity:</ td >
374
- < td > < code class ="inline code "> $!request.pathParameters[<key> ;][<index> ;]</ code > < br /> < code class ="inline code "> $!request.queryStringParameters[<key> ;][<index> ;]</ code > < br /> < code class ="inline code "> $!request.headers[<key> ;][<index> ;]</ code > < br /> </ td >
374
+ < td > < code class ="inline code "> $!request.pathParameters[<key&ft ;][<index&ft ;]</ code > < br /> < code class ="inline code "> $!request.queryStringParameters[<key&ft ;][<index&ft ;]</ code > < br /> < code class ="inline code "> $!request.headers[<key&ft ;][<index&ft ;]</ code > < br /> </ td >
375
375
</ tr >
376
376
</ table > </ div >
377
377
< div style ="padding: 20px 0 "> < table >
378
378
< tr >
379
379
< td style ="padding-left: 20px; width: 100px; "> javascript:</ td >
380
- < td > < code class ="inline code "> request.pathParameters[<key> ;][<index> ;]</ code > < br /> < code class ="inline code "> request.queryStringParameters[<key> ;][<index> ;]</ code > < br /> < code class ="inline code "> request.headers[<key> ;][<index> ;]</ code > < br /> </ td >
380
+ < td > < code class ="inline code "> request.pathParameters[<key&ft ;][<index&ft ;]</ code > < br /> < code class ="inline code "> request.queryStringParameters[<key&ft ;][<index&ft ;]</ code > < br /> < code class ="inline code "> request.headers[<key&ft ;][<index&ft ;]</ code > < br /> </ td >
381
381
</ tr >
382
382
</ table > </ div >
383
383
</ li >
@@ -879,27 +879,27 @@ <h4>XPath</h4>
879
879
880
880
< p > Given a request with the following xml body:</ p >
881
881
882
- < pre class ="prettyprint lang-xml code "> < code class ="code "> <?xml version="1.0" encoding="UTF-8" ?> ;
883
- <store> ;
884
- <book> ;
885
- <category> ;reference</category> ;
886
- <author> ;Nigel Rees</author> ;
887
- <title> ;Sayings of the Century</title> ;
888
- <price> ;18.95</price> ;
889
- </book> ;
890
- <book> ;
891
- <category> ;fiction</category> ;
892
- <author> ;Herman Melville</author> ;
893
- <title> ;Moby Dick</title> ;
894
- <isbn> ;0-553-21311-3</isbn> ;
895
- <price> ;8.99</price> ;
896
- </book> ;
897
- <bicycle> ;
898
- <color> ;red</color> ;
899
- <price> ;19.95</price> ;
900
- </bicycle> ;
901
- <expensive> ;10</expensive> ;
902
- </store> ;</ code > </ pre >
882
+ < pre class ="prettyprint lang-xml code "> < code class ="code "> <?xml version="1.0" encoding="UTF-8" ?&ft ;
883
+ <store&ft ;
884
+ <book&ft ;
885
+ <category&ft ;reference</category&ft ;
886
+ <author&ft ;Nigel Rees</author&ft ;
887
+ <title&ft ;Sayings of the Century</title&ft ;
888
+ <price&ft ;18.95</price&ft ;
889
+ </book&ft ;
890
+ <book&ft ;
891
+ <category&ft ;fiction</category&ft ;
892
+ <author&ft ;Herman Melville</author&ft ;
893
+ <title&ft ;Moby Dick</title&ft ;
894
+ <isbn&ft ;0-553-21311-3</isbn&ft ;
895
+ <price&ft ;8.99</price&ft ;
896
+ </book&ft ;
897
+ <bicycle&ft ;
898
+ <color&ft ;red</color&ft ;
899
+ <price&ft ;19.95</price&ft ;
900
+ </bicycle&ft ;
901
+ <expensive&ft ;10</expensive&ft ;
902
+ </store&ft ;</ code > </ pre >
903
903
904
904
< p > The example produces:</ p >
905
905
@@ -1003,6 +1003,100 @@ <h4>Mathematical</h4>
1003
1003
$item
1004
1004
#end</ code > </ pre >
1005
1005
1006
+ < p > For additional mathematical functionality it is also possible to use the < a target ="_blank " href ="https://velocity.apache.org/tools/3.1/tools-summary.html#MathTool "> MathTool</ a > or < a target ="_blank " href ="https://velocity.apache.org/tools/3.1/tools-summary.html#NumberTool "> NumberTool</ a > in velocity response templates.</ p >
1007
+
1008
+ < pre class ="prettyprint lang-java code "> < code class ="code "> #set($power = $math.pow($number, 2))
1009
+ #set($max = $math.max($number, 10))</ code > </ pre >
1010
+
1011
+ < h4 > Json Bodies</ h4 >
1012
+
1013
+ < p > The < a target ="_blank " href ="https://velocity.apache.org/tools/3.1/tools-summary.html#JsonTool "> JsonTool</ a > can be used to help parse JSON bodies, as follows:</ p >
1014
+
1015
+ < pre class ="prettyprint lang-java code "> < code class ="code "> #set($jsonBody = $json.parse($!request.body))
1016
+
1017
+ {
1018
+ 'statusCode': 200,
1019
+ 'body': "{'titles': [#foreach( $book in $jsonBody.store.book )'$book.title'#if( $foreach.hasNext ), #end#end], 'bikeColor': '$jsonBody.store.bicycle.color'}"
1020
+ }</ code > </ pre >
1021
+
1022
+ < p > Given the following request:</ p >
1023
+
1024
+ < pre class ="prettyprint lang-java code "> < code class ="code "> {
1025
+ "path" : "/somePath",
1026
+ "body" : {
1027
+ "type" : "JSON",
1028
+ "json" : {
1029
+ "store" : {
1030
+ "book" : [ {
1031
+ "category" : "reference",
1032
+ "author" : "Nigel Rees",
1033
+ "title" : "Sayings of the Century",
1034
+ "price" : 18.95
1035
+ }, {
1036
+ "category" : "fiction",
1037
+ "author" : "Herman Melville",
1038
+ "title" : "Moby Dick",
1039
+ "isbn" : "0-553-21311-3",
1040
+ "price" : 8.99
1041
+ } ],
1042
+ "bicycle" : {
1043
+ "color" : "red",
1044
+ "price" : 19.95
1045
+ }
1046
+ },
1047
+ "expensive" : 10
1048
+ }
1049
+ }
1050
+ }</ code > </ pre >
1051
+
1052
+ < p > The example produces:</ p >
1053
+
1054
+ < pre class ="prettyprint lang-java code "> < code class ="code "> {
1055
+ "statusCode" : 200,
1056
+ "body" : "{'titles': ['Sayings of the Century', 'Moby Dick'], 'bikeColor': 'red'}"
1057
+ }</ code > </ pre >
1058
+
1059
+ < h4 > XML Bodies</ h4 >
1060
+
1061
+ < p > The < a target ="_blank " href ="https://velocity.apache.org/tools/3.1/tools-summary.html#XmlTool "> XmlTool</ a > can be used to help parse XML bodies, execute XPath and XML traversal.</ p >
1062
+
1063
+ < p > The following example shows how to use < a target ="_blank " href ="https://velocity.apache.org/tools/3.1/tools-summary.html#XmlTool "> XmlTool</ a > for XPath:</ p >
1064
+
1065
+ < pre class ="prettyprint lang-java code "> < code class ="code "> #set($xmlBody = $xml.parse($!request.body))
1066
+
1067
+ {
1068
+ 'statusCode': 200,
1069
+ 'body': "{'key': '$xml.find('/element/key/text()')', 'value': '$xml.find('/element/value/text()')'}"
1070
+ }</ code > </ pre >
1071
+
1072
+ < p > Given the following request:</ p >
1073
+
1074
+ < pre class ="prettyprint lang-java code "> < code class ="code "> {
1075
+ "path" : "/somePath",
1076
+ "body" : "<element><key>some_key</key><value>some_value</value></element>"
1077
+ }</ code > </ pre >
1078
+
1079
+ < p > The example produces:</ p >
1080
+
1081
+ < pre class ="prettyprint lang-java code "> < code class ="code "> {
1082
+ "statusCode" : 200,
1083
+ "body" : "{'key': 'some_key', 'value': 'some_value'}"
1084
+ }</ code > </ pre >
1085
+
1086
+ < h4 > Velocity Tools</ h4 >
1087
+
1088
+ < p > The following velocity tools are available for velocity response templates:</ p >
1089
+ < ul >
1090
+ < li > < a target ="_blank " href ="https://velocity.apache.org/tools/3.1/tools-summary.html#CollectionTool "> CollectionTool</ a > </ li >
1091
+ < li > < a target ="_blank " href ="https://velocity.apache.org/tools/3.1/tools-summary.html#ComparisonDateTool "> ComparisonDateTool</ a > </ li >
1092
+ < li > < a target ="_blank " href ="https://velocity.apache.org/tools/3.1/tools-summary.html#DisplayTool "> DisplayTool</ a > </ li >
1093
+ < li > < a target ="_blank " href ="https://velocity.apache.org/tools/3.1/tools-summary.html#EscapeTool "> EscapeTool</ a > </ li >
1094
+ < li > < a target ="_blank " href ="https://velocity.apache.org/tools/3.1/tools-summary.html#MathTool "> MathTool</ a > </ li >
1095
+ < li > < a target ="_blank " href ="https://velocity.apache.org/tools/3.1/tools-summary.html#NumberTool "> NumberTool</ a > </ li >
1096
+ < li > < a target ="_blank " href ="https://velocity.apache.org/tools/3.1/tools-summary.html#JsonTool "> JsonTool</ a > </ li >
1097
+ < li > < a target ="_blank " href ="https://velocity.apache.org/tools/3.1/tools-summary.html#XmlTool "> XmlTool</ a > </ li >
1098
+ </ ul >
1099
+
1006
1100
< a id ="javascript_templates " class ="anchor " href ="#javascript_templates "> </ a >
1007
1101
1008
1102
< h2 > JavaScript Response Templates</ h2 >
0 commit comments