aboutsummaryrefslogtreecommitdiffstats
path: root/common-app-logging/src/main/java/org/openecomp/sdc/common/log/wrappers/LoggerSdcUtilBase.java
diff options
context:
space:
mode:
Diffstat (limited to 'common-app-logging/src/main/java/org/openecomp/sdc/common/log/wrappers/LoggerSdcUtilBase.java')
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/wrappers/LoggerSdcUtilBase.java62
1 files changed, 28 insertions, 34 deletions
diff --git a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/wrappers/LoggerSdcUtilBase.java b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/wrappers/LoggerSdcUtilBase.java
index 6ca71281d3..87c2c2d759 100644
--- a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/wrappers/LoggerSdcUtilBase.java
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/wrappers/LoggerSdcUtilBase.java
@@ -1,21 +1,34 @@
package org.openecomp.sdc.common.log.wrappers;
+import static java.net.HttpURLConnection.HTTP_BAD_METHOD;
+import static java.net.HttpURLConnection.HTTP_BAD_REQUEST;
+import static java.net.HttpURLConnection.HTTP_CLIENT_TIMEOUT;
+import static java.net.HttpURLConnection.HTTP_CONFLICT;
+import static java.net.HttpURLConnection.HTTP_ENTITY_TOO_LARGE;
+import static java.net.HttpURLConnection.HTTP_FORBIDDEN;
+import static java.net.HttpURLConnection.HTTP_GONE;
+import static java.net.HttpURLConnection.HTTP_LENGTH_REQUIRED;
+import static java.net.HttpURLConnection.HTTP_NOT_ACCEPTABLE;
+import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
+import static java.net.HttpURLConnection.HTTP_PAYMENT_REQUIRED;
+import static java.net.HttpURLConnection.HTTP_PRECON_FAILED;
+import static java.net.HttpURLConnection.HTTP_PROXY_AUTH;
+import static java.net.HttpURLConnection.HTTP_REQ_TOO_LONG;
+import static java.net.HttpURLConnection.HTTP_UNAUTHORIZED;
+import static java.net.HttpURLConnection.HTTP_UNSUPPORTED_TYPE;
+
+import java.util.List;
+import java.util.StringTokenizer;
+import javax.ws.rs.container.ContainerRequestContext;
import org.apache.commons.lang3.StringUtils;
import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.ws.rs.container.ContainerRequestContext;
-import java.util.List;
-import java.util.StringTokenizer;
-
-import static java.net.HttpURLConnection.*;
-
/**
* Created by dd4296 on 12/20/2017.
- *
- * base class for metric and audit log logging
- * holding the specific logic for data extraction
+ * <p>
+ * base class for metric and audit log logging holding the specific logic for data extraction
*/
public class LoggerSdcUtilBase {
@@ -23,20 +36,18 @@ public class LoggerSdcUtilBase {
String getRequestIDfromHeaders(List<Object> requestHeader) {
// this method gets list of type object.
+
// toString method returns the RequestId with brackets.
String requestHeaderString = requestHeader.toString();
- return requestHeaderString.replace("[","").replace("]","");
+ return requestHeaderString.replace("[", "").replace("]", "");
}
-
-
-
// this method translates http error code to ECOMP Logger Error code
+
// this is a naive translation and is not a result of any documented format ECOMP specification
protected EcompLoggerErrorCode convertHttpCodeToErrorCode(int httpResponseCode) {
if (isSuccessError(httpResponseCode)) {
return EcompLoggerErrorCode.SUCCESS;
}
-
if (isSchemaError(httpResponseCode)) {
return EcompLoggerErrorCode.SCHEMA_ERROR;
}
@@ -56,7 +67,6 @@ public class LoggerSdcUtilBase {
}
private boolean isTimeoutOrAvailabilityError(int httpResponseCode) {
-
switch (httpResponseCode) {
case HTTP_BAD_REQUEST:
case HTTP_UNAUTHORIZED:
@@ -67,11 +77,9 @@ public class LoggerSdcUtilBase {
default:
return false;
}
-
}
private boolean isPermissionsError(int httpResponseCode) {
-
switch (httpResponseCode) {
case HTTP_PAYMENT_REQUIRED:
case HTTP_FORBIDDEN:
@@ -79,12 +87,10 @@ public class LoggerSdcUtilBase {
case HTTP_PROXY_AUTH:
return true;
}
-
return false;
}
private boolean isDataError(int httpResponseCode) {
-
switch (httpResponseCode) {
case HTTP_NOT_ACCEPTABLE:
case HTTP_LENGTH_REQUIRED:
@@ -94,7 +100,6 @@ public class LoggerSdcUtilBase {
case HTTP_UNSUPPORTED_TYPE:
return true;
}
-
return false;
}
@@ -111,28 +116,23 @@ public class LoggerSdcUtilBase {
}
protected String getPartnerName(String userAgent, String userId, String url, String xOnapPartnerName) {
-
//On called side (receiver) If the API call is authenticated, then log the userid/mechid (fully qualified if that is what was provided)
if (isFound(userId)) {
return userId;
}
-
String urlUser = getUserIdFromUrl(url);
if (isFound(urlUser)) {
return urlUser;
}
-
//Otherwise, if X-ONAP-PartnerName was provided, then log that
- if (isFound(xOnapPartnerName)){
+ if (isFound(xOnapPartnerName)) {
return xOnapPartnerName;
}
-
//Otherwise, for an HTTP API call, log the part of the URI specifying the agent that the caller used to make the call
String userAgentName = getUserIdFromUserAgent(userAgent);
if (isFound(userAgentName)) {
return userAgentName;
}
-
return "UNKNOWN";
}
@@ -141,15 +141,12 @@ public class LoggerSdcUtilBase {
if (userAgent.toLowerCase().contains("firefox")) {
return "fireFox_FE";
}
-
if (userAgent.toLowerCase().contains("msie")) {
return "explorer_FE";
}
-
if (userAgent.toLowerCase().contains("chrome")) {
return "chrome_FE";
}
-
return userAgent;
}
return null;
@@ -169,7 +166,6 @@ public class LoggerSdcUtilBase {
protected String getUrl(ContainerRequestContext requestContext) {
String url = "";
-
try {
if (requestContext.getUriInfo() != null && requestContext.getUriInfo().getRequestUri() != null) {
url = requestContext.getUriInfo().getRequestUri().toURL().toString();
@@ -177,13 +173,11 @@ public class LoggerSdcUtilBase {
} catch (Exception ex) {
log.error("failed to get url from request context ", ex);
}
-
return url;
}
protected String getServiceName(ContainerRequestContext requestContext) {
- return (requestContext.getUriInfo().getRequestUri().toString())
- .replace(requestContext.getUriInfo().getBaseUri().toString(), "/");
+ return (requestContext.getUriInfo().getRequestUri().toString()).replace(requestContext.getUriInfo().getBaseUri().toString(), "/");
}
private boolean isFound(String value) {
@@ -192,4 +186,4 @@ public class LoggerSdcUtilBase {
}
return false;
}
-} \ No newline at end of file
+}