|
| 1 | +package controllers; |
| 2 | + |
| 3 | +import com.fasterxml.jackson.databind.node.ObjectNode; |
| 4 | +import play.Logger; |
| 5 | +import play.data.DynamicForm; |
| 6 | +import play.data.Form; |
| 7 | +import play.libs.Json; |
| 8 | +import play.mvc.Controller; |
| 9 | +import play.mvc.Http; |
| 10 | +import play.mvc.Result; |
| 11 | + |
| 12 | +public class Application extends Controller { |
| 13 | + |
| 14 | + public Result configure() { |
| 15 | + ObjectNode json = Json.newObject(); |
| 16 | + |
| 17 | + if (Logger.isInfoEnabled()) |
| 18 | + Logger.info("configure"); |
| 19 | + |
| 20 | + logRequest(request()); |
| 21 | + |
| 22 | + return ok(json); |
| 23 | + } |
| 24 | + |
| 25 | + public Result activate() { |
| 26 | + ObjectNode json = Json.newObject(); |
| 27 | + |
| 28 | + if (Logger.isInfoEnabled()) |
| 29 | + Logger.info("activate"); |
| 30 | + |
| 31 | + logRequest(request()); |
| 32 | + |
| 33 | + return ok(json); |
| 34 | + } |
| 35 | + |
| 36 | + public Result execute() { |
| 37 | + ObjectNode json = Json.newObject(); |
| 38 | + |
| 39 | + if (Logger.isInfoEnabled()) |
| 40 | + Logger.info("execute"); |
| 41 | + |
| 42 | + logRequest(request()); |
| 43 | + |
| 44 | + return ok(json); |
| 45 | + } |
| 46 | + |
| 47 | + public Result discover() { |
| 48 | + ObjectNode json = Json.newObject(); |
| 49 | + |
| 50 | + if (Logger.isInfoEnabled()) |
| 51 | + Logger.info("discover"); |
| 52 | + |
| 53 | + logRequest(request()); |
| 54 | + |
| 55 | + return ok(json); |
| 56 | + } |
| 57 | + |
| 58 | + public Result configurePost() { |
| 59 | + ObjectNode json = Json.newObject(); |
| 60 | + |
| 61 | + if (Logger.isInfoEnabled()) |
| 62 | + Logger.info("configurePost"); |
| 63 | + |
| 64 | + logRequest(request()); |
| 65 | + |
| 66 | + return ok(json); |
| 67 | + } |
| 68 | + |
| 69 | + public Result activatePost() { |
| 70 | + ObjectNode json = Json.newObject(); |
| 71 | + |
| 72 | + if (Logger.isInfoEnabled()) |
| 73 | + Logger.info("activatePost"); |
| 74 | + |
| 75 | + logRequest(request()); |
| 76 | + |
| 77 | + return ok(json); |
| 78 | + } |
| 79 | + |
| 80 | + public Result executePost() { |
| 81 | + ObjectNode json = Json.newObject(); |
| 82 | + |
| 83 | + if (Logger.isInfoEnabled()) |
| 84 | + Logger.info("executePost"); |
| 85 | + |
| 86 | + logRequest(request()); |
| 87 | + |
| 88 | + return ok(json); |
| 89 | + } |
| 90 | + |
| 91 | + public Result discoverPost() { |
| 92 | + ObjectNode json = Json.newObject(); |
| 93 | + |
| 94 | + if (Logger.isInfoEnabled()) |
| 95 | + Logger.info("discoverPost"); |
| 96 | + |
| 97 | + logRequest(request()); |
| 98 | + |
| 99 | + return ok(json); |
| 100 | + } |
| 101 | + |
| 102 | + private void logRequest(Http.Request request) { |
| 103 | + if(Logger.isInfoEnabled()) { |
| 104 | + StringBuilder requestString = new StringBuilder("Request:") |
| 105 | + .append("\n") |
| 106 | + .append("\tbody [") |
| 107 | + .append(request().body()) |
| 108 | + .append("]\n") |
| 109 | + .append("\tparameters ["); |
| 110 | + DynamicForm form = Form.form().bindFromRequest(); |
| 111 | + |
| 112 | + if(form != null) { |
| 113 | + form.data().forEach((key, value) -> { |
| 114 | + requestString.append("\n\tkey: ") |
| 115 | + .append(key) |
| 116 | + .append(", value: ") |
| 117 | + .append(value); |
| 118 | + }); |
| 119 | + } |
| 120 | + |
| 121 | + requestString.append("\n\t]"); |
| 122 | + |
| 123 | + Logger.info(requestString.toString()); |
| 124 | + } |
| 125 | + } |
| 126 | + |
| 127 | +} |
0 commit comments