2 * ========================LICENSE_START=================================
5 * Copyright (C) 2021 Nordix Foundation
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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===================================
21 package org.oran.dmaapadapter;
23 import io.swagger.v3.oas.annotations.Operation;
24 import io.swagger.v3.oas.annotations.media.Content;
25 import io.swagger.v3.oas.annotations.media.Schema;
26 import io.swagger.v3.oas.annotations.responses.ApiResponse;
27 import io.swagger.v3.oas.annotations.responses.ApiResponses;
28 import io.swagger.v3.oas.annotations.tags.Tag;
30 import java.lang.invoke.MethodHandles;
31 import java.util.ArrayList;
32 import java.util.Collections;
33 import java.util.List;
35 import org.oran.dmaapadapter.controllers.VoidResponse;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
38 import org.springframework.http.HttpStatus;
39 import org.springframework.http.MediaType;
40 import org.springframework.http.ResponseEntity;
41 import org.springframework.web.bind.annotation.PostMapping;
42 import org.springframework.web.bind.annotation.RequestBody;
43 import org.springframework.web.bind.annotation.RestController;
45 @RestController("ConsumerSimulatorController")
46 @Tag(name = "Consts.PRODUCER_API_CALLBACKS_NAME")
47 public class ConsumerController {
49 private final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
51 public static final String CONSUMER_TARGET_URL = "/consumer";
53 public static class TestResults {
55 public List<String> receivedBodies = Collections.synchronizedList(new ArrayList<String>());
57 public TestResults() {}
60 receivedBodies.clear();
64 final TestResults testResults = new TestResults();
66 @PostMapping(path = CONSUMER_TARGET_URL, produces = MediaType.APPLICATION_JSON_VALUE)
67 @Operation(summary = "GET from topic", description = "The call is invoked to push data to consumer")
68 @ApiResponses(value = { //
69 @ApiResponse(responseCode = "200", description = "OK", //
70 content = @Content(schema = @Schema(implementation = VoidResponse.class))) //
72 public ResponseEntity<Object> postData(@RequestBody String body) {
73 logger.info("Received by consumer: {}", body);
74 testResults.receivedBodies.add(body);
75 return new ResponseEntity<>(HttpStatus.OK);