-
Notifications
You must be signed in to change notification settings - Fork 0
/
ResourceController.java
330 lines (284 loc) · 9.53 KB
/
ResourceController.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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
package TeamAware.Policy.Enforcer.controller;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import TeamAware.Policy.Enforcer.module.Message;
import lombok.extern.slf4j.Slf4j;
// REST Endpoint controller.
// You modify endpoints from here.
@RestController
@Slf4j
@RequestMapping("/api")
@CrossOrigin("*")
public class ResourceController {
@Autowired
private Environment env;
public void sendToNifi(String message, String path) throws IOException {
URL url = new URL("http", env.getProperty("nifi.endpoint"),
Integer.parseInt(env.getProperty("nifi.port")),
path);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
if (message.contains("ADS")) {
con.setRequestProperty("Content-Type", "application/xml; charset=UTF-8");
} else {
con.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
}
con.setRequestProperty("Accept", "application/json");
con.setDoOutput(true);
con.setRequestProperty("X-HTTP-Method-Override", "PATCH");
con.setRequestMethod("POST");
try (OutputStream os = con.getOutputStream()) {
byte[] input = message.getBytes("utf-8");
os.write(input);
log.info("Request is sent to Nifi");
} catch (Exception e) {
log.error("I/O Error occured during sending message to Nifi.");
e.printStackTrace();
}
try (BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), "utf-8"))) {
StringBuilder response = new StringBuilder();
String responseLine = null;
while ((responseLine = br.readLine()) != null) {
response.append(responseLine.trim());
}
log.info("Response :\n" + response.toString());
}
}
//ADS Data
@GetMapping("/ADSData")
public Message readADSData() {
return new Message("Read ADS Data");
}
@PostMapping("/ADSData")
public Message createADSData(@RequestBody String message) {
try {
sendToNifi(message, "/api/ADSData");
} catch (IOException e) {
e.printStackTrace();
}
return new Message("Create ADS Data");
}
@PutMapping("/ADSData")
public Message updateADSData() {
return new Message("Update ADS Data");
}
@DeleteMapping("/ADSData")
public Message deleteADSData() {
return new Message("Delete ADS Data");
}
//AMS Data
@GetMapping("/AMSData")
public Message readAMSData() {
return new Message("Read AMS Data");
}
@PostMapping("/AMSData")
public Message createAMSData(@RequestBody String message) {
try {
sendToNifi(message, "/api/AMSData");
} catch (IOException e) {
e.printStackTrace();
}
return new Message("Create AMS Data");
}
@PutMapping("/AMSData")
public Message updateAMSData() {
return new Message("Update AMS Data");
}
@DeleteMapping("/AMSData")
public Message deleteAMSData() {
return new Message("Delete AMS Data");
}
//CDS Data
@GetMapping("/CDSData")
public Message readCDSData() {
return new Message("Read CDS Data");
}
@PostMapping("/CDSData")
public Message createCDSData() {
return new Message("Create CDS Data");
}
@PutMapping("/CDSData")
public Message updateCDSData() {
return new Message("Update CDS Data");
}
@DeleteMapping("/CDSData")
public Message deleteCDSData() {
return new Message("Delete CDS Data");
}
//CICIS Data
@GetMapping("/CICISData")
public Message readCICISData() {
return new Message("Read CICIS Data");
}
@PostMapping("/CICISData")
public Message createCICISData() {
return new Message("Create CICIS Data");
}
@PutMapping("/CICISData")
public Message updateCICISData() {
return new Message("Update CICIS Data");
}
@DeleteMapping("/CICISData")
public Message deleteCICISData() {
return new Message("Delete CICIS Data");
}
//COILS Data
@GetMapping("/COILSData")
public Message readCOILSData() {
return new Message("Read COILS Data");
}
@PostMapping("/COILSData")
public Message createCOILSData(@RequestBody String message) {
try {
sendToNifi(message, "/api/COILSData");
} catch (IOException e) {
e.printStackTrace();
}
return new Message("Create COILS Data");
}
@PutMapping("/COILSData")
public Message updateCOILSData() {
return new Message("Update COILS Data");
}
@DeleteMapping("/COILSData")
public Message deleteCOILSData() {
return new Message("Delete COILS Data");
}
//Docker Image
@GetMapping("/DockerImage")
public Message readDockerImage() {
return new Message("Read Docker Image");
}
@PostMapping("/DockerImage")
public Message createDockerImage() {
return new Message("Create Docker Image");
}
@PutMapping("/DockerImage")
public Message updateDockerImage() {
return new Message("Update Docker Image");
}
@DeleteMapping("/DockerImage")
public Message deleteDockerImage() {
return new Message("Delete Docker Image");
}
//IMS Data
@GetMapping("/IMSData")
public Message readIMSData() {
return new Message("Read IMS Data");
}
@PostMapping("/IMSData")
public Message createIMSData() {
return new Message("Create IMS Data");
}
@PutMapping("/IMSData")
public Message updateIMSData() {
return new Message("Update IMS Data");
}
@DeleteMapping("/IMSData")
public Message deleteIMSData() {
return new Message("Delete IMS Data");
}
//Kubernetes Deployment Description
@GetMapping("/KubernetesDeploymentDescription")
public Message readKubernetesDeploymentDescription() {
return new Message("Read Kubernetes Deployment Description");
}
@PostMapping("/KubernetesDeploymentDescription")
public Message createKubernetesDeploymentDescription() {
return new Message("Create Kubernetes Deployment Description");
}
@PutMapping("/KubernetesDeploymentDescription")
public Message updateKubernetesDeploymentDescription() {
return new Message("Update Kubernetes Deployment Description");
}
@DeleteMapping("/KubernetesDeploymentDescription")
public Message deleteKubernetesDeploymentDescription() {
return new Message("Delete Kubernetes Deployment Description");
}
//Log
@GetMapping("/Log")
public Message readLog() {
return new Message("Read Log");
}
@PostMapping("/Log")
public Message createLog() {
return new Message("Create Log");
}
@PutMapping("/Log")
public Message updateLog() {
return new Message("Update Log");
}
@DeleteMapping("/Log")
public Message deleteLog() {
return new Message("Delete Log");
}
//Operational Data
@GetMapping("/OperationalData")
public Message readOperationalData() {
return new Message("Read Operational Data");
}
@PostMapping("/OperationalData")
public Message createOperationalData() {
return new Message("Create Operational Data");
}
@PutMapping("/OperationalData")
public Message updateOperationalData() {
return new Message("Update Operational Data");
}
@DeleteMapping("/OperationalData")
public Message deleteOperationalData() {
return new Message("Delete Operational Data");
}
//Platform Data
@GetMapping("/PlatformData")
public Message readPlatformData() {
return new Message("Read Platform Data");
}
@PostMapping("/PlatformData")
public Message createPlatformData() {
return new Message("Create Platform Data");
}
@PutMapping("/PlatformData")
public Message updatePlatformData() {
return new Message("Update Platform Data");
}
@DeleteMapping("/PlatformData")
public Message deletePlatformData() {
return new Message("Delete Platform Data");
}
//VSAS Data
@GetMapping("/VSASData")
public Message readVSASData() {
return new Message("Read VSAS Data");
}
@PostMapping("/VSASData")
public Message createVSASData(@RequestBody String message) {
try {
sendToNifi(message, "/api/VSASData");
} catch (IOException e) {
e.printStackTrace();
}
return new Message("Create VSAS Data");
}
@PutMapping("/VSASData")
public Message updateVSASData() {
return new Message("Update VSAS Data");
}
@DeleteMapping("/VSASData")
public Message deleteVSASData() {
return new Message("Delete VSAS Data");
}
}