* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
* ============LICENSE_END=========================================================
*/
package org.openecomp.aai.logging;
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
+
+import javax.ws.rs.core.MediaType;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Marshaller;
+
import org.apache.commons.lang.StringUtils;
+import org.slf4j.MDC;
+
import org.openecomp.aai.exceptions.AAIException;
import org.openecomp.aai.logging.LoggingContext.StatusCode;
+import org.openecomp.aai.util.AAIConfig;
import org.openecomp.aai.util.AAIConstants;
import org.openecomp.aai.util.MapperUtil;
-import org.slf4j.MDC;
-import javax.ws.rs.core.MediaType;
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.Marshaller;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.StringWriter;
-import java.util.*;
-import java.util.Map.Entry;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
/**
*
* @throws Exception the exception
*/
public static void loadProperties() throws IOException, ErrorObjectFormatException {
- final String filePath = AAIConstants.AAI_HOME_ETC_APP_PROPERTIES + "error.properties";
+ final String filePath = AAIConstants.AAI_HOME_ETC_APP_PROPERTIES + "error.properties";
final InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath);
final Properties properties = new Properties();
*
* @param key The key for the error in the error.properties file
* @throws IOException
- * @throws ErrorObjectNotFoundException
- * @throws ErrorObjectFormatException
+ * @throws ErrorObjectNotFoundException
+ * @throws ErrorObjectFormatException
*/
public static ErrorObject getErrorObject(String code) throws ErrorObjectNotFoundException {
* @param are must have a restError value whose numeric value must match what should be returned in the REST API
* @param variables optional list of variables to flesh out text in error string
* @return appropriately formatted JSON response per the REST API spec.
- * @throws ErrorObjectFormatException
- * @throws ErrorObjectNotFoundException
+ * @throws ErrorObjectFormatException
+ * @throws ErrorObjectNotFoundException
* @throws IOException
* @deprecated
*/
* @param are must have a restError value whose numeric value must match what should be returned in the REST API
* @param variables optional list of variables to flesh out text in error string
* @return appropriately formatted JSON response per the REST API spec.
- * @throws ErrorObjectFormatException
- * @throws ErrorObjectNotFoundException
+ * @throws ErrorObjectFormatException
+ * @throws ErrorObjectNotFoundException
* @throws IOException
*/
public static String getRESTAPIErrorResponse(List<MediaType> acceptHeadersOrig, AAIException are, ArrayList<String> variables) {
* @param variables the variables
* @param logline the logline
* @return the RESTAPI error response with logging
- * @throws ErrorObjectFormatException
- * @throws ErrorObjectNotFoundException
+ * @throws ErrorObjectFormatException
+ * @throws ErrorObjectNotFoundException
* @throws IOException
*/
public static String getRESTAPIErrorResponseWithLogging(List<MediaType> acceptHeadersOrig, AAIException are, ArrayList<String> variables) {
* @param acceptHeaders the accept headers
* @param areList the are list
* @return the RESTAPI info response
- * @throws ErrorObjectFormatException
- * @throws ErrorObjectNotFoundException
+ * @throws ErrorObjectFormatException
+ * @throws ErrorObjectNotFoundException
* @throws IOException
*/
public static Object getRESTAPIInfoResponse(List<MediaType> acceptHeaders, HashMap<AAIException,ArrayList<String>> areList) {
org.openecomp.aai.domain.restResponseInfo.ObjectFactory factory = new org.openecomp.aai.domain.restResponseInfo.ObjectFactory();
org.openecomp.aai.domain.restResponseInfo.Info info = factory.createInfo();
org.openecomp.aai.domain.restResponseInfo.Info.ResponseMessages responseMessages = factory.createInfoResponseMessages();
- Iterator<Entry<AAIException, ArrayList<String>>> it = areList.entrySet().iterator();
-
+ Iterator<Map.Entry<AAIException, ArrayList<String>>> it = areList.entrySet().iterator();
+
while (it.hasNext()) {
- Entry<AAIException,ArrayList<String>> pair = (Entry<AAIException, ArrayList<String>>)it.next();
+ Map.Entry<AAIException,ArrayList<String>> pair = (Map.Entry<AAIException, ArrayList<String>>)it.next();
AAIException are = pair.getKey();
ArrayList<String> variables = pair.getValue();
* @param are must have a restError value whose numeric value must match what should be returned in the REST API
* @param variables optional list of variables to flesh out text in error string
* @return appropriately formatted JSON response per the REST API spec.
- * @throws ErrorObjectFormatException
- * @throws ErrorObjectNotFoundException
+ * @throws ErrorObjectFormatException
+ * @throws ErrorObjectNotFoundException
* @throws IOException
*/
public static String getRESTAPIPolicyErrorResponseXML(AAIException are, ArrayList<String> variables) {
public static void logException(AAIException e) {
final ErrorObject errorObject = e.getErrorObject();
- MDC.put("severity", errorObject.getSeverity()); //TODO Use LoggingContext.severity(int severity)
+// MDC.put("severity", errorObject.getSeverity()); //TODO Use LoggingContext.severity(int severity)
+ String severityCode = errorObject.getSeverityCode(errorObject.getSeverity());
+
+ if (!AAIConfig.isEmpty(severityCode)) {
+ int sevCode = Integer.parseInt(severityCode);
+ if (sevCode > 0 && sevCode <= 3 )
+ {
+ LoggingContext.severity(sevCode);
+ }
+ }
final String errorMessage = new StringBuilder()
.append(errorObject.getErrorText())
.append(e.getMessage())
.toString();
- LoggingContext.responseCode(errorObject.getErrorCodeString());
+ LoggingContext.responseCode(Integer.toString(errorObject.getHTTPResponseCode().getStatusCode()));
LoggingContext.responseDescription(errorMessage);
LoggingContext.statusCode(StatusCode.ERROR);