-
Notifications
You must be signed in to change notification settings - Fork 0
/
HomeController.java
46 lines (38 loc) · 1.27 KB
/
HomeController.java
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
package org.act.arch.client.controller;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.act.arch.client.security.HTTPClient;
import org.act.arch.client.security.TokenManager;
import org.apache.http.HttpResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class HomeController {
private HTTPClient httpClient;
public HomeController() {
httpClient = new HTTPClient();
}
@RequestMapping(value = "/")
public ModelAndView test(HttpServletResponse response) throws IOException {
ModelAndView mv = new ModelAndView("home");
mv.addObject("learningObjects", getLearningObjects());
return mv;
}
private String getLearningObjects() {
TokenManager tm = new TokenManager();
return getLearningObjects(tm.getToken("admin", "admin")
.getAccessToken());
}
public String getLearningObjects(String token) {
String submitUrl = "http://localhost:8280/rest/1.0.0/learningObjectives";
try {
HttpResponse httpResponse = httpClient.doGet(submitUrl, "Bearer "
+ token);
return httpClient.getResponsePayload(httpResponse);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
}