2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2018 - 2019 Nokia. All rights reserved.
7 * Modifications Copyright (C) 2019 IBM.
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.vid.aai;
25 import static org.onap.vid.utils.Logging.REQUEST_ID_HEADER_KEY;
27 import java.util.UUID;
28 import javax.ws.rs.client.Client;
29 import javax.ws.rs.client.Entity;
30 import javax.ws.rs.core.MediaType;
31 import javax.ws.rs.core.Response;
32 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
33 import org.onap.vid.aai.util.AAIRestInterface;
34 import org.onap.vid.aai.util.HttpClientMode;
35 import org.onap.vid.aai.util.HttpsAuthClient;
36 import org.onap.vid.aai.util.ServletRequestHelper;
37 import org.onap.vid.aai.util.SystemPropertyHelper;
38 import org.onap.vid.utils.Logging;
39 import org.springframework.http.HttpMethod;
41 public class PombaRestInterface extends AAIRestInterface {
43 private Client client = null;
45 public PombaRestInterface (HttpsAuthClient httpsAuthClientFactory,
46 ServletRequestHelper servletRequestHelper,
47 SystemPropertyHelper systemPropertyHelper,
48 Logging loggingService) {
49 super(httpsAuthClientFactory, servletRequestHelper, systemPropertyHelper, loggingService);
53 protected void initRestClient()
57 client = httpsAuthClientFactory.getClient(HttpClientMode.WITH_KEYSTORE);
60 logger.info(EELFLoggerDelegate.errorLogger, "Exception in REST call to DB in initRestClient", e);
61 logger.debug(EELFLoggerDelegate.debugLogger, "Exception in REST call to DB : ", e);
67 public Response RestPost(String fromAppId, String url, String payload) {
68 String methodName = "RestPost";
69 String transId = UUID.randomUUID().toString();
73 loggingService.logRequest(outgoingRequestsLogger, HttpMethod.POST, url, payload);
74 final Response cres = client.target(url)
76 .accept(MediaType.APPLICATION_JSON)
77 .header(TRANSACTION_ID_HEADER, transId)
78 .header(FROM_APP_ID_HEADER, fromAppId)
79 .header(REQUEST_ID_HEADER_KEY, extractOrGenerateRequestId())
80 .post(Entity.entity(payload, MediaType.APPLICATION_JSON));
81 loggingService.logResponse(outgoingRequestsLogger, HttpMethod.POST, url, cres);
83 if (cres.getStatusInfo().getFamily().equals(Response.Status.Family.SUCCESSFUL)) {
84 logger.info(EELFLoggerDelegate.errorLogger, getValidResponseLogMessage(methodName));
85 logger.debug(EELFLoggerDelegate.debugLogger, getValidResponseLogMessage(methodName));
87 logger.debug(EELFLoggerDelegate.debugLogger, getInvalidResponseLogMessage(url, methodName, cres));
90 } catch (Exception e) {
91 logger.debug(EELFLoggerDelegate.debugLogger, getFailedResponseLogMessage(url, methodName, e));