-package org.openecomp.sdc.common.ecomplogwrapper;
-
-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;
+package org.openecomp.sdc.common.log.wrappers;
-import java.util.List;
-import java.util.StringTokenizer;
+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 org.openecomp.sdc.common.ecomplog.Enums.EcompLoggerErrorCode;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import static java.net.HttpURLConnection.*;
/**
* Created by dd4296 on 12/20/2017.
*
- * base class for metric and audit ecomplog logging
+ * base class for metric and audit log logging
* holding the specific logic for data extraction
*/
-public class EcompLoggerSdcUtilBase {
+public class LoggerSdcUtilBase {
- protected static Logger log = LoggerFactory.getLogger(EcompLoggerSdcUtilBase.class.getName());
+ protected static Logger log = LoggerFactory.getLogger(LoggerSdcUtilBase.class.getName());
String getRequestIDfromHeaders(List<Object> requestHeader) {
// this method gets list of type object.
}
+
// 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))
+ if (isSuccessError(httpResponseCode)) {
return EcompLoggerErrorCode.SUCCESS;
+ }
- if (isSchemaError(httpResponseCode))
+ if (isSchemaError(httpResponseCode)) {
return EcompLoggerErrorCode.SCHEMA_ERROR;
-
- if (isDataError(httpResponseCode))
+ }
+ if (isDataError(httpResponseCode)) {
return EcompLoggerErrorCode.DATA_ERROR;
-
- if (isPermissionsError(httpResponseCode))
+ }
+ if (isPermissionsError(httpResponseCode)) {
return EcompLoggerErrorCode.PERMISSION_ERROR;
-
- if (isTimeoutOrAvailabilityError(httpResponseCode))
+ }
+ if (isTimeoutOrAvailabilityError(httpResponseCode)) {
return EcompLoggerErrorCode.AVAILABILITY_TIMEOUTS_ERROR;
-
- if (isBusinessProcessError(httpResponseCode))
+ }
+ if (isBusinessProcessError(httpResponseCode)) {
return EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR;
-
-
+ }
return EcompLoggerErrorCode.UNKNOWN_ERROR;
}
case HTTP_CLIENT_TIMEOUT:
case HTTP_GONE:
return true;
+ default:
+ return false;
}
- return false;
}
private boolean isPermissionsError(int httpResponseCode) {
protected String getPartnerName(String userAgent, String userId, String url) {
- if (!isNullOrEmpty(userId)) {
+ if (!StringUtils.isEmpty(userId)) {
return userId;
}
String urlUser = getUserIdFromUrl(url);
- if (!isNullOrEmpty(urlUser))
+ if (!StringUtils.isEmpty(urlUser))
return urlUser;
String userAgentName = getUserIdFromUserAgent(userAgent);
- if (!isNullOrEmpty(userAgentName))
+ if (!StringUtils.isEmpty(userAgentName))
return userAgentName;
return "";
return url;
}
- private boolean isNullOrEmpty(String str) {
- return (str == null || str.isEmpty());
- }
-
protected String getServiceName(ContainerRequestContext requestContext) {
return (requestContext.getUriInfo().getRequestUri().toString())
.replace(requestContext.getUriInfo().getBaseUri().toString(), "/");