-
Notifications
You must be signed in to change notification settings - Fork 138
/
proxies.xml
84 lines (74 loc) · 2.12 KB
/
proxies.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<spring:beans xmlns="http://membrane-soa.org/proxies/1/"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://membrane-soa.org/proxies/1/ http://membrane-soa.org/schemas/proxies-1.xsd">
<spring:bean name="myBean" class="java.lang.String">
<spring:constructor-arg value="Greetings from Spring"/>
</spring:bean>
<router>
<api port="2000">
<request>
<groovy>
// Return Json as Map
[id:7,city:'Berlin']
</groovy>
</request>
<return contentType="application/json"/><!-- Return response to client -->
<!-- <target host="myhost" port="myport"/> Instead forward to your backend -->
</api>
<api port="2010">
<request>
<groovy>
// JSON to JSON transformation
// The json-Variable contains the request or response body as JSON object.
import java.text.*
def dfIn = new SimpleDateFormat("d MMM yyyy",Locale.US)
def dfOut = new SimpleDateFormat("yyyy-MM-dd")
[
id: json.id,
date: dfOut.format(dfIn.parse(json.date)),
client: json.customer,
total: json.items.collect { it.price * it.quantity }.sum(),
positions: json.items.collect {
[
pieces: it.quantity,
price: it.price,
article: it.description
]
}
]
</groovy>
</request>
<return/>
</api>
<api port="2020">
<request>
<groovy>
println "Request headers:"
header.allHeaderFields.each {
print it
}
CONTINUE
</groovy>
</request>
<!-- Execute groovy-Interceptor in response flow -->
<response>
<groovy>
header.add("X-Groovy", "42") // Set Header
CONTINUE
</groovy>
</response>
<target host="localhost" port="2030" />
</api>
<api port="2030">
<request>
<groovy>
// Create response and set the body to the value of the Spring Bean
Response.ok().body(spring.getBean('myBean')).build()
</groovy>
</request>
<return/>
</api>
</router>
</spring:beans>