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 org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
26 import org.onap.vid.aai.util.*;
27 import org.onap.vid.utils.Logging;
28 import org.springframework.http.HttpMethod;
30 import javax.ws.rs.client.Client;
31 import javax.ws.rs.client.Entity;
32 import javax.ws.rs.core.MediaType;
33 import javax.ws.rs.core.Response;
34 import java.util.UUID;
36 import static org.onap.vid.utils.Logging.REQUEST_ID_HEADER_KEY;
38 public class PombaRestInterface extends AAIRestInterface {
40 private Client client = null;
42 public PombaRestInterface (HttpsAuthClient httpsAuthClientFactory, ServletRequestHelper servletRequestHelper, SystemPropertyHelper systemPropertyHelper) {
43 super(httpsAuthClientFactory, servletRequestHelper, systemPropertyHelper);
47 protected void initRestClient()
51 client = httpsAuthClientFactory.getClient(HttpClientMode.WITH_KEYSTORE);
54 logger.info(EELFLoggerDelegate.errorLogger, "Exception in REST call to DB in initRestClient", e);
55 logger.debug(EELFLoggerDelegate.debugLogger, "Exception in REST call to DB : ", e);
61 public Response RestPost(String fromAppId, String url, String payload) {
62 String methodName = "RestPost";
63 String transId = UUID.randomUUID().toString();
67 Logging.logRequest(outgoingRequestsLogger, HttpMethod.POST, url, payload);
68 final Response cres = client.target(url)
70 .accept(MediaType.APPLICATION_JSON)
71 .header(TRANSACTION_ID_HEADER, transId)
72 .header(FROM_APP_ID_HEADER, fromAppId)
73 .header(REQUEST_ID_HEADER_KEY, extractOrGenerateRequestId())
74 .post(Entity.entity(payload, MediaType.APPLICATION_JSON));
75 Logging.logResponse(outgoingRequestsLogger, HttpMethod.POST, url, cres);
77 if (cres.getStatusInfo().getFamily().equals(Response.Status.Family.SUCCESSFUL)) {
78 logger.info(EELFLoggerDelegate.errorLogger, getValidResponseLogMessage(methodName));
79 logger.debug(EELFLoggerDelegate.debugLogger, getValidResponseLogMessage(methodName));
81 logger.debug(EELFLoggerDelegate.debugLogger, getInvalidResponseLogMessage(url, methodName, cres));
84 } catch (Exception e) {
85 logger.debug(EELFLoggerDelegate.debugLogger, getFailedResponseLogMessage(url, methodName, e));