forked from cloudfoundry-samples/cf-sample-app-spring
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.groovy
38 lines (29 loc) · 951 Bytes
/
app.groovy
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
@Grab("thymeleaf-spring4")
import org.springframework.core.env.*
import com.fasterxml.jackson.databind.*
@Controller
class Application {
@Autowired
private ObjectMapper json;
@Value('${VCAP_APPLICATION:{}}')
private String application;
@Value('${VCAP_SERVICES:{}}')
private String services;
@RequestMapping("/")
public String index(Model model) {
model.addAttribute("cfapp", json.readValue(application, LinkedHashMap.class))
try {
def cfservices = json.readValue(services, LinkedHashMap.class)
def cfservicename = cfservices.keySet().iterator().next();
def cfservice = cfservices.get(cfservicename).get(0);
model.addAttribute("cfservices", cfservices)
model.addAttribute("cfservicename", cfservicename)
model.addAttribute("cfservice", cfservice)
} catch (Exception ex) {
// No services
model.addAttribute("cfservice", "")
model.addAttribute("cfservice", new LinkedHashMap())
}
return "index"
}
}