aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main/java
diff options
context:
space:
mode:
authorEylon Malin <eylon.malin@intl.att.com>2019-10-06 08:44:02 +0300
committerEylon Malin <eylon.malin@intl.att.com>2019-10-06 11:00:23 +0300
commit81aef70267474eaa2a212958e9b17d424e5d8480 (patch)
treee507bd95219af9e3bc17fa006cc454f96b0b0579 /vid-app-common/src/main/java
parent39b185a11e5978991eedd4763415eed51b7c9462 (diff)
all rest calls of AAIRestInterface use doRest method
Issue-ID: VID-253 Signed-off-by: Eylon Malin <eylon.malin@intl.att.com> Change-Id: Ie25a8be8d649fe322698c81a969c720dc123c629 Signed-off-by: Eylon Malin <eylon.malin@intl.att.com>
Diffstat (limited to 'vid-app-common/src/main/java')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/util/AAIRestInterface.java125
1 files changed, 17 insertions, 108 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/util/AAIRestInterface.java b/vid-app-common/src/main/java/org/onap/vid/aai/util/AAIRestInterface.java
index 45ced6bdf..8c05a8e6f 100644
--- a/vid-app-common/src/main/java/org/onap/vid/aai/util/AAIRestInterface.java
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/util/AAIRestInterface.java
@@ -31,6 +31,7 @@ import java.net.URI;
import java.net.URLEncoder;
import java.util.Optional;
import java.util.UUID;
+import java.util.function.Supplier;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation;
@@ -162,15 +163,6 @@ public class AAIRestInterface {
}
- /**
- * Rest get.
- *
- * @param fromAppId the from app id
- * @param transId the trans id
- * @param requestUri the request uri
- * @param xml the xml
- * @return the string
- */
public ResponseWithRequestInfo RestGet(String fromAppId, String transId, URI requestUri, boolean xml) {
return RestGet(fromAppId, transId, requestUri, xml, false);
}
@@ -180,11 +172,16 @@ public class AAIRestInterface {
}
public ResponseWithRequestInfo doRest(String fromAppId, String transId, URI requestUri, String payload, HttpMethod method, boolean xml, boolean propagateExceptions) {
+ return doRest(fromAppId, transId, ()->systemPropertyHelper.getFullServicePath(requestUri), payload, method, xml, propagateExceptions);
+ }
+
+
+ public ResponseWithRequestInfo doRest(String fromAppId, String transId, Supplier<String> urlSupplier, String payload, HttpMethod method, boolean xml, boolean propagateExceptions) {
String url = null;
String methodName = "Rest"+method.name();
try {
- url = systemPropertyHelper.getFullServicePath(requestUri);
+ url = urlSupplier.get();
initRestClient(propagateExceptions);
@@ -223,7 +220,7 @@ public class AAIRestInterface {
} catch (Exception e) {
logger.debug(EELFLoggerDelegate.debugLogger, getFailedResponseLogMessage(url, methodName, e));
if (propagateExceptions) {
- throw new ExceptionWithRequestInfo(method, defaultIfNull(url, requestUri.toASCIIString()), e);
+ throw new ExceptionWithRequestInfo(method, defaultIfNull(url, ""), e);
} else {
return new ResponseWithRequestInfo(null, url, method);
}
@@ -235,109 +232,21 @@ public class AAIRestInterface {
}
- /**
- * Delete.
- *
- * @param sourceID the source ID
- * @param transId the trans id
- * @param path the path
- * @return true, if successful
- */
- public boolean Delete(String sourceID, String transId, String path) {
- String methodName = "Delete";
- transId += ":" + UUID.randomUUID().toString();
- logger.debug(methodName + START_STRING);
- Boolean response = false;
- String url = systemPropertyHelper.getFullServicePath(path);
- try {
-
- initRestClient();
- loggingService.logRequest(outgoingRequestsLogger, HttpMethod.DELETE, url);
- final Response cres = client.target(url)
- .request()
- .accept(MediaType.APPLICATION_JSON)
- .header(TRANSACTION_ID_HEADER, transId)
- .header(PARTNER_NAME.getHeaderName(), PARTNER_NAME.getHeaderValue())
- .header(FROM_APP_ID_HEADER, sourceID)
- .header(REQUEST_ID_HEADER_KEY, extractOrGenerateRequestId())
- .delete();
- loggingService.logResponse(outgoingRequestsLogger, HttpMethod.DELETE, url, cres);
- if (cres.getStatusInfo().equals(Response.Status.NOT_FOUND)) {
- logger.debug(EELFLoggerDelegate.debugLogger, "Resource does not exist...: " + cres.getStatus()
- + ":" + cres.readEntity(String.class));
- response = false;
- } else if (cres.getStatusInfo().equals(Response.Status.OK) || cres.getStatusInfo().equals(Response.Status.NO_CONTENT)) {
- logger.debug(EELFLoggerDelegate.debugLogger, "Resource " + url + " deleted");
- logger.info(EELFLoggerDelegate.errorLogger, "Resource " + url + " deleted");
- response = true;
- } else {
- logger.debug(EELFLoggerDelegate.debugLogger, "Deleting Resource failed: " + cres.getStatus()
- + ":" + cres.readEntity(String.class));
- response = false;
- }
-
- } catch (Exception e) {
- logger.debug(EELFLoggerDelegate.debugLogger, getFailedResponseLogMessage(url, methodName, e));
- }
- return response;
- }
-
-
- /**
- * Rest put.
- *
- * @param fromAppId the from app id
- * @param path the path
- * @param payload the payload
- * @param xml the xml
- * @param propagateExceptions
- * @return the string
- */
public ResponseWithRequestInfo RestPut(String fromAppId, String path, String payload, boolean xml, boolean propagateExceptions) {
return doRest(fromAppId, UUID.randomUUID().toString(), Unchecked.toURI(path), payload, HttpMethod.PUT, xml, propagateExceptions);
}
-
- /**
- * Rest post.
- *
- * @param fromAppId the from app id
- * @param path the path
- * @param payload the payload
- * @param xml the xml
- * @return the string
- */
public Response RestPost(String fromAppId, String path, String payload, boolean xml) {
- String methodName = "RestPost";
- String url=systemPropertyHelper.getServiceBasePath(path);
- String transId = UUID.randomUUID().toString();
- logger.debug(EELFLoggerDelegate.debugLogger, methodName + START_STRING);
-
- Response response = null;
- try {
- initRestClient();
- loggingService.logRequest(outgoingRequestsLogger, HttpMethod.POST, url, payload);
- response = authenticateRequest(client.target(url)
- .request()
- .accept(xml ? MediaType.APPLICATION_XML : MediaType.APPLICATION_JSON)
- .header(TRANSACTION_ID_HEADER, transId)
- .header(PARTNER_NAME.getHeaderName(), PARTNER_NAME.getHeaderValue())
- .header(FROM_APP_ID_HEADER, fromAppId))
- .header(REQUEST_ID_HEADER_KEY, extractOrGenerateRequestId())
- .post(Entity.entity(payload, MediaType.APPLICATION_JSON));
- loggingService.logResponse(outgoingRequestsLogger, HttpMethod.POST, url, response);
-
- if (response.getStatusInfo().getFamily().equals(Response.Status.Family.SUCCESSFUL)) {
- logger.info(EELFLoggerDelegate.errorLogger, getValidResponseLogMessage(methodName));
- logger.debug(EELFLoggerDelegate.debugLogger, getValidResponseLogMessage(methodName));
- } else {
- logger.debug(EELFLoggerDelegate.debugLogger, getInvalidResponseLogMessage(url, methodName, response));
- }
- } catch (Exception e) {
- logger.debug(EELFLoggerDelegate.debugLogger, getFailedResponseLogMessage(url, methodName, e));
- }
- return response;
+ ResponseWithRequestInfo response = doRest(
+ fromAppId,
+ UUID.randomUUID().toString(),
+ ()->systemPropertyHelper.getServiceBasePath(path),
+ payload,
+ HttpMethod.POST,
+ xml,
+ false);
+ return response.getResponse();
}
protected String getFailedResponseLogMessage(String path, String methodName, Exception e) {