1 package org.onap.vid.aai;
3 import org.onap.vid.aai.util.AAIRestInterface;
4 import org.onap.vid.aai.util.HttpClientMode;
5 import org.onap.vid.aai.util.HttpsAuthClient;
6 import org.onap.vid.utils.Logging;
7 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
8 import org.springframework.http.HttpMethod;
10 import javax.ws.rs.client.Client;
11 import javax.ws.rs.client.Entity;
12 import javax.ws.rs.core.MediaType;
13 import javax.ws.rs.core.Response;
14 import java.util.Date;
15 import java.util.UUID;
17 import static org.onap.vid.utils.Logging.REQUEST_ID_HEADER_KEY;
19 public class PombaRestInterface extends AAIRestInterface {
21 public PombaRestInterface (HttpsAuthClient httpsAuthClientFactory) {
22 super(httpsAuthClientFactory);
25 private Client client = null;
27 private void initRestClient()
31 client = httpsAuthClientFactory.getClient(HttpClientMode.UNSECURE);
34 logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== Exception in REST call to DB in initRestClient" + e.toString());
35 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== Exception in REST call to DB : " + e.toString());
41 public Response RestPost(String fromAppId, String url, String payload) {
42 String methodName = "RestPost";
43 String transId = UUID.randomUUID().toString();
45 String responseType = MediaType.APPLICATION_JSON;
48 Logging.logRequest(outgoingRequestsLogger, HttpMethod.POST, url, payload);
49 final Response cres = client.target(url)
52 .header(TRANSACTION_ID_HEADER, transId)
53 .header(FROM_APP_ID_HEADER, fromAppId)
54 .header(REQUEST_ID_HEADER_KEY, extractOrGenerateRequestId())
55 .post(Entity.entity(payload, MediaType.APPLICATION_JSON));
56 Logging.logResponse(outgoingRequestsLogger, HttpMethod.POST, url, cres);
58 if (cres.getStatus() == 200 && cres.getStatus() <= 299) {
59 logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + methodName + URL_DECLARATION);
60 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + URL_DECLARATION);
62 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " with status="+cres.getStatus()+ URL_DECLARATION +url);
65 } catch (Exception e) {
66 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + URL_DECLARATION +url+ ", Exception: " + e.toString());