forked from membrane/api-gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxies.xml
More file actions
83 lines (72 loc) · 2.38 KB
/
proxies.xml
File metadata and controls
83 lines (72 loc) · 2.38 KB
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
<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">
<!-- this is a Java string object defined as a spring bean. It serves as value for the X-Javascript header -->
<spring:bean name="myBean" class="java.lang.String">
<spring:constructor-arg value="Greetings from Javascript"/>
</spring:bean>
<router>
<api port="2000">
<request>
<javascript>
console.log("Query parameters: " + params);
// Return Json as Map
({ id: params.get('id').get(0), city: params.get('city').get(0) })
</javascript>
</request>
<return contentType="application/json"/><!-- Return response to client -->
<!-- <target host="myhost" port="myport"/> Instead forward to your backend -->
</api>
<api port="2010">
<request>
<javascript>
// JSON to JSON transformation
function convertDate(d) {
return d.getFullYear() + "-" + ("0"+(d.getMonth()+1)).slice(-2) + "-" + ("0"+d.getDate()).slice(-2);
}
({
id: json.id,
date: convertDate(new Date(json.date)),
client: json.customer,
total: json.items.map(i => i.quantity * i.price).reduce((a,b) => a+b),
positions: json.items.map(i => ({
pieces: i.quantity,
price: i.price,
article: i.description
}))
})
</javascript>
</request>
<return/>
</api>
<api port="2020">
<request>
<javascript>
console.log("Request headers:")
for (var entry of header.entrySet()) {
console.log(entry.getKey() + ": " + entry.getValue());
}
</javascript>
</request>
<!-- Execute javascript-Interceptor in response flow -->
<response>
<javascript>
header.add("X-Javascript", "42") // Set Header
CONTINUE
</javascript>
</response>
<target host="localhost" port="2030" />
</api>
<api port="2030">
<request>
<javascript>
// Create response and set the body to the value of the Spring Bean
Response.ok().body(spring.getBean('myBean')).build()
</javascript>
</request>
<return/>
</api>
</router>
</spring:beans>