-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChatClientController.java
58 lines (51 loc) · 2.06 KB
/
ChatClientController.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
47
48
49
50
51
52
53
54
55
56
57
58
package client;
import sirius.biz.isenguard.Isenguard;
import sirius.biz.isenguard.RateLimitingInfo;
import sirius.biz.web.BizController;
import sirius.kernel.async.CallContext;
import sirius.kernel.di.std.ConfigValue;
import sirius.kernel.di.std.Part;
import sirius.kernel.di.std.Register;
import sirius.web.controller.Controller;
import sirius.web.controller.DefaultRoute;
import sirius.web.controller.Routed;
import sirius.web.http.WebContext;
/**
* Simple Controller that serves a html file under the main route.
*/
@Register(classes = Controller.class)
public class ChatClientController extends BizController {
@Part
private static Isenguard isenguard;
private static final String RATE_LIMIT_REALM_REQUEST = "request";
/**
* Simple route that calls the pasta template containing the name chooser.
*
* @param webContext the context of the web request
*/
@DefaultRoute
@Routed("/")
public void chooseName(WebContext webContext) {
webContext.respondWith().template("/templates/name.html.pasta");
}
/**
* Simple route that calls the pasta template containing the JavaScript client and provides it with some parameters.
*
* @param webContext the context of the web request
*/
@DefaultRoute
@Routed("/chat")
public void client(WebContext webContext) {
// TODO SIDE-QUEST-3, here is an example of Isenguard...
isenguard.enforceRateLimiting(
// We limit per remote IP address
webContext.getRemoteIP().toString(),
// Names the config section in application.conf from where to load the limits
RATE_LIMIT_REALM_REQUEST,
// In case the limit is hit, we need some more infos to log the incident, by default we extract
// this from the current web request....
RateLimitingInfo::fromCurrentContext);
String userName = webContext.get("username").asString(CallContext.getNodeName());
webContext.respondWith().template("/templates/client.html.pasta", userName);
}
}