null ptr check
[appc.git] / appc-dispatcher / appc-request-handler / appc-request-handler-core / src / main / java / org / onap / appc / requesthandler / impl / AbstractRequestHandlerImpl.java
index 02ff3a3..cd9011f 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP : APPC
  * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Copyright (C) 2017 Amdocs
  * =============================================================================
@@ -18,7 +18,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  * 
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
  * ============LICENSE_END=========================================================
  */
 
@@ -75,7 +74,7 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
 import java.util.UUID;
-
+import java.util.TimeZone;
 import static com.att.eelf.configuration.Configuration.MDC_INSTANCE_UUID;
 import static com.att.eelf.configuration.Configuration.MDC_KEY_REQUEST_ID;
 import static com.att.eelf.configuration.Configuration.MDC_SERVER_FQDN;
@@ -227,11 +226,11 @@ public abstract class AbstractRequestHandlerImpl implements RequestHandler {
         }
         updateColumns.put(TransactionConstants.TRANSACTION_ATTRIBUTES.STATE, record.getRequestState());
         updateColumns.put(TransactionConstants.TRANSACTION_ATTRIBUTES.RESULT_CODE,
-            String.valueOf(record.getResultCode()));
+                String.valueOf(record.getResultCode()));
         if (RequestStatus.valueOf(record.getRequestState()).isTerminal()) {
-            Date endTime = new Date(System.currentTimeMillis());
+            Date endTime = new Date();
             updateColumns.put(TransactionConstants.TRANSACTION_ATTRIBUTES.END_TIME,
-                dateToStringConverterMillis(endTime));
+                    dateToStringConverterMillis(endTime));
         }
         try {
             transactionRecorder.update(record.getTransactionId(), updateColumns);
@@ -409,6 +408,13 @@ public abstract class AbstractRequestHandlerImpl implements RequestHandler {
         if (logger.isDebugEnabled())
             logger.debug("Metric getting initialized");
         MetricService metricService = getMetricservice();
+        // Check for the metric service created before trying to create registry using
+        // the metricService object
+        if (metricService == null) {
+            // Cannot find service reference for org.onap.appc.metricservice.MetricService
+            throw new NullPointerException("org.onap.appc.metricservice.MetricService is null. " +
+                    "Failed to init Metric");
+        }
         metricRegistry = metricService.createRegistry("APPC");
         DispatchingFuntionMetric dispatchingFuntionMetric = metricRegistry.metricBuilderFactory().
             dispatchingFunctionCounterBuilder().
@@ -462,6 +468,7 @@ public abstract class AbstractRequestHandlerImpl implements RequestHandler {
 
     public static String dateToStringConverterMillis(Date date) {
         SimpleDateFormat customDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
+        customDate.setTimeZone(TimeZone.getTimeZone("UTC"));
         if (date != null) {
             return customDate.format(date);
         }