2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.examples.grpc;
23 import java.io.IOException;
24 import java.nio.file.Files;
25 import java.nio.file.Paths;
26 import javax.ws.rs.GET;
27 import javax.ws.rs.POST;
28 import javax.ws.rs.Path;
29 import javax.ws.rs.QueryParam;
30 import javax.ws.rs.core.Response;
31 import org.slf4j.ext.XLogger;
32 import org.slf4j.ext.XLoggerFactory;
35 * The Class GrpcTestRestSimEndpoint creates rest server endpoints for simulating sending/receiving events on DMaaP.
38 public class GrpcTestRestSimEndpoint {
39 private static final XLogger LOGGER = XLoggerFactory.getXLogger(GrpcTestRestSimEndpoint.class);
40 private static String loggedOutputEvent = null;
41 private final Object lock = new Object();
44 * DCAE input of events (simulation of DMaaP). This input event triggers the policy
46 * @param timeout the timeout to wait for
47 * @return the response
48 * @throws IOException on I/O errors
50 @Path("events/unauthenticated.DCAE_CL_OUTPUT/APEX/1")
52 public Response dcaeClOutput(@QueryParam("timeout") final int timeout) throws IOException {
53 String createSubscriptionRequest =
54 Files.readString(Paths.get("src/main/resources/examples/events/APEXgRPC/CreateSubscriptionEvent.json"));
55 LOGGER.info("Create subscription request received: \n {}", createSubscriptionRequest);
57 return Response.status(200).entity(createSubscriptionRequest).build();
61 * Post to Policy management log (Simulation of DMaaP).
63 * @param jsonString the json string
64 * @return the response
66 @Path("/events/POLICY_CL_MGT")
68 public Response policyLogRequest(final String jsonString) {
69 LOGGER.info("\n*** POLICY LOG ENTRY START ***\n {} \n *** POLICY LOG ENTRY END ***", jsonString);
71 loggedOutputEvent = jsonString;
73 return Response.status(200).build();
77 * Get the logged event for test verification.
79 * @return the response
81 @Path("/event/getLoggedEvent")
83 public Response getDetails() {
86 loggedEvent = loggedOutputEvent;
88 if (null == loggedEvent) {
89 return Response.status(500).entity("Error: Log event not yet generated.").build();
91 return Response.status(200).entity(loggedEvent).build();