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