70e0c609c05e20d19696cbbaa049ada3098cdb76
[integration.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * Simulator
4  * ================================================================================
5  * Copyright (C) 2019 Nokia. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.pnfsimulator.integration;
22
23 import com.google.gson.Gson;
24 import com.google.gson.JsonObject;
25 import org.springframework.beans.factory.annotation.Autowired;
26 import org.springframework.web.bind.annotation.PostMapping;
27 import org.springframework.web.bind.annotation.RequestBody;
28 import org.springframework.web.bind.annotation.RequestMapping;
29 import org.springframework.web.bind.annotation.RestController;
30
31 @RequestMapping("ves-simulator")
32 @RestController
33 public class VesSimulatorController {
34
35     private final VesSimulatorService vesSimulatorService;
36     private final Gson gson;
37
38     @Autowired
39     public VesSimulatorController(VesSimulatorService vesSimulatorService, Gson gson) {
40         this.vesSimulatorService = vesSimulatorService;
41         this.gson = gson;
42     }
43
44     @PostMapping("eventListener/v5")
45     String sendEventToDmaapV5(@RequestBody String body) {
46         System.out.println("Received event" + body);
47         JsonObject jsonObject = gson.fromJson(body, JsonObject.class);
48         vesSimulatorService.sendEventToDmaapV5(jsonObject);
49         return "MessageAccepted";
50     }
51
52     @PostMapping("eventListener/v7")
53     String sendEventToDmaapV7(@RequestBody String body) {
54         System.out.println("Received event" + body);
55         JsonObject jsonObject = gson.fromJson(body, JsonObject.class);
56         vesSimulatorService.sendEventToDmaapV7(jsonObject);
57         return "MessageAccepted";
58     }
59 }