Exemplo n.º 1
0
 @Around(value = "allOperation()||athenaServiceOperation()||spartanServiceOperation()")
 @Order(1)
 public Object aroundAdvice1(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
   System.out.println(
       "In aroundAdvice Order 1 : Calling method : "
           + proceedingJoinPoint.getSignature().getName());
   HttpServletRequest request =
       ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
   ServletWebRequest servletWebRequest = new ServletWebRequest(request);
   HttpServletResponse response = servletWebRequest.getResponse();
   HttpSession session = request.getSession();
   long nextAutoNum = autoRequestId.getAndIncrement();
   methodCallStack.setRequestId(UUID.randomUUID().toString().toUpperCase());
   MethodCallDetails methodCallDetails =
       new MethodCallDetails(
           methodCallStack.getRequestId(),
           HealthConstants.CLASS_TYPE.SERVICE,
           request.getRemoteHost(),
           request.getMethod(),
           proceedingJoinPoint.getTarget().getClass().toString(),
           proceedingJoinPoint.getSignature().getName(),
           loggedInUserId(request),
           getSessionId(request));
   String entityName =
       incrementUricounter(
           proceedingJoinPoint.getSignature().getDeclaringType().getSimpleName(),
           proceedingJoinPoint.getSignature().getName());
   ResponseEntity<ResponseBean> responseEntity = new ResponseEntity<>(HttpStatus.OK);
   /*
    * Needs to get user id from request header and pass it to entityAudit
    * and RuntimeLogInfo
    */
   /* create logging info object (Needs to call from login service only */
   runtimeLogInfoHelper.setCustomerId(getCustomerId(request));
   runtimeLogInfoHelper.createRuntimeLogUserInfo(
       1, loggedInUserId(request), request.getRemoteHost());
   /* validate request */
   try {
     if (request.getHeader("Job-Execution") == null) {
       if (request.getHeader("isBeforeSession") == null) {
         validateRequest(session, request, response);
         if (!sessionValidation.checkIgnoreURL(request)) {
           /** Sets user's last access time in table */
           java.sql.Timestamp currentTime = new java.sql.Timestamp(System.currentTimeMillis());
           loginSessionRepo.updateLastAccessTime(
               loggedInUserId(request), session.getAttribute("usidHash").toString(), currentTime);
           runtimeLogInfoHelper.setUserAccessCode(
               Integer.parseInt(session.getAttribute("userAccessCode").toString()));
         }
       }
     }
     Object obj = proceedingJoinPoint.proceed();
     responseEntity = (ResponseEntity<ResponseBean>) obj;
     httpStatusCode = responseEntity.getStatusCode();
     methodCallDetails.setPostCallDetails(
         HealthConstants.METHOD_NORMAL_EXECUTION, responseEntity.getStatusCode().name());
   } catch (SpartanAccessDeniedException e) {
     sprinkler.logger.log(
         runtimeLogInfoHelper.getRuntimeLogInfo(),
         4005,
         proceedingJoinPoint.getSignature().getDeclaringTypeName(),
         proceedingJoinPoint.getSignature().getName(),
         request.getRemoteHost(),
         e);
     ResponseBean exceptionbean =
         e.prepareExceptionBean(
             sprinkler,
             runtimeLogInfoHelper.getRuntimeLogInfo(),
             " Access Denied " + e.getMessage());
     methodCallDetails.setPostCallDetails(
         HealthConstants.METHOD_EXCEPTION,
         e.getExceptionId(),
         responseEntity.getStatusCode().name());
     return new ResponseEntity<ResponseBean>(exceptionbean, responseEntity.getStatusCode());
   } catch (SpartanPersistenceException e) {
     sprinkler.logger.log(
         runtimeLogInfoHelper.getRuntimeLogInfo(),
         e.getExceptionId(),
         proceedingJoinPoint.getSignature().getDeclaringTypeName(),
         proceedingJoinPoint.getSignature().getName(),
         request.getRemoteHost(),
         e);
     ResponseBean exceptionbean =
         e.prepareExceptionBean(
             sprinkler,
             runtimeLogInfoHelper.getRuntimeLogInfo(),
             " Can not perform Operation on entity:" + e.getMessage());
     methodCallDetails.setPostCallDetails(
         HealthConstants.METHOD_EXCEPTION,
         e.getExceptionId(),
         responseEntity.getStatusCode().name());
     return new ResponseEntity<ResponseBean>(exceptionbean, responseEntity.getStatusCode());
   } catch (SpartanTransactionException e) {
     sprinkler.logger.log(
         runtimeLogInfoHelper.getRuntimeLogInfo(),
         e.getExceptionId(),
         proceedingJoinPoint.getSignature().getDeclaringTypeName(),
         proceedingJoinPoint.getSignature().getName(),
         request.getRemoteHost(),
         e);
     ResponseBean exceptionbean =
         e.prepareExceptionBean(
             sprinkler, runtimeLogInfoHelper.getRuntimeLogInfo(), e.getMessage());
     methodCallDetails.setPostCallDetails(
         HealthConstants.METHOD_EXCEPTION,
         e.getExceptionId(),
         responseEntity.getStatusCode().name());
     return new ResponseEntity<ResponseBean>(exceptionbean, responseEntity.getStatusCode());
   } catch (SpartanDataNotFoundException e) {
     sprinkler.logger.log(
         runtimeLogInfoHelper.getRuntimeLogInfo(),
         e.getExceptionId(),
         proceedingJoinPoint.getSignature().getDeclaringTypeName(),
         proceedingJoinPoint.getSignature().getName(),
         request.getRemoteHost(),
         e);
     ResponseBean exceptionbean =
         e.prepareExceptionBean(sprinkler, runtimeLogInfoHelper.getRuntimeLogInfo());
     methodCallDetails.setPostCallDetails(
         HealthConstants.METHOD_EXCEPTION,
         e.getExceptionId(),
         responseEntity.getStatusCode().name());
     return new ResponseEntity<ResponseBean>(exceptionbean, responseEntity.getStatusCode());
   } catch (com.athena.framework.server.exception.biz.SpartanBusinessValidationFailedException e) {
     sprinkler.logger.log(
         runtimeLogInfoHelper.getRuntimeLogInfo(),
         e.getExceptionId(),
         proceedingJoinPoint.getSignature().getDeclaringTypeName(),
         proceedingJoinPoint.getSignature().getName(),
         request.getRemoteHost(),
         e);
     ResponseBean exceptionbean =
         e.prepareExceptionBean(sprinkler, runtimeLogInfoHelper.getRuntimeLogInfo());
     methodCallDetails.setPostCallDetails(
         HealthConstants.METHOD_EXCEPTION,
         e.getExceptionId(),
         responseEntity.getStatusCode().name());
     return new ResponseEntity<ResponseBean>(exceptionbean, responseEntity.getStatusCode());
   } catch (Exception e) {
     sprinkler.logger.log(
         runtimeLogInfoHelper.getRuntimeLogInfo(),
         4005,
         proceedingJoinPoint.getSignature().getDeclaringTypeName(),
         proceedingJoinPoint.getSignature().getName(),
         request.getRemoteHost(),
         e);
     ResponseBean responseBean = new ResponseBean();
     responseBean.add("success", false);
     responseBean.add("message", " Access Denied:" + e.getMessage());
     methodCallDetails.setPostCallDetails(
         HealthConstants.METHOD_EXCEPTION,
         HealthConstants.DEFAULT_EXCEPTION_ID,
         responseEntity.getStatusCode().name());
     return new ResponseEntity<ResponseBean>(responseBean, responseEntity.getStatusCode());
   } finally {
     /** Sets user's last access time in table */
     /*if (request.getHeader("Job-Execution") == null) {
     if (request.getHeader("isBeforeSession") == null) {
     java.sql.Timestamp currentTime = new java.sql.Timestamp(System.currentTimeMillis());
     loginSessionRepo.updateLastAccessTime(loggedInUserId(request), session.getAttribute("usidHash").toString(), currentTime);
     }
     }*/
     methodCallStack.addServiceMethodCallDetails(methodCallDetails);
     healthmeter.apphealth.writeHealthLog((ArtMethodCallStack) methodCallStack.clone());
     Integer existingValue = 0;
     Metric metric = repository.findOne("gauge." + "total.Time " + entityName + "");
     if (metric != null) {
       existingValue = metric.getValue().intValue();
     }
     gaugeservice.submit(
         "total.Time " + entityName + "", executionTimer.getSystemTime + existingValue);
   }
   return responseEntity;
 }
 @Around("allOperation()")
 @Order(1)
 public Object aroundAdvice1(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
   HttpServletRequest request =
       ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
   ServletWebRequest servletWebRequest = new ServletWebRequest(request);
   HttpServletResponse response = servletWebRequest.getResponse();
   HttpSession session = request.getSession();
   long nextAutoNum = autoRequestId.getAndIncrement();
   methodCallStack.setRequestId(UUID.randomUUID().toString().toUpperCase());
   methodCallStack.setAppSessionId(getSessionId(request));
   MethodCallDetails methodCallDetails =
       new MethodCallDetails(
           methodCallStack.getRequestId(),
           methodCallStack.getCallSequence(),
           HealthConstants.CLASS_TYPE.SERVICE,
           request.getRemoteHost(),
           request.getMethod(),
           proceedingJoinPoint.getTarget().getClass().toString(),
           proceedingJoinPoint.getSignature().getName(),
           loggedInUserId(request),
           getSessionId(request));
   String entityName =
       incrementUricounter(
           proceedingJoinPoint.getSignature().getDeclaringType().getSimpleName(),
           proceedingJoinPoint.getSignature().getName());
   ResponseEntity<ResponseBean> responseEntity = new ResponseEntity<>(HttpStatus.OK);
   try {
     serviceLogic(session, request, response);
     Object obj = proceedingJoinPoint.proceed();
     responseEntity = (ResponseEntity<ResponseBean>) obj;
     httpStatusCode = responseEntity.getStatusCode();
     methodCallDetails.setPostCallDetails(
         HealthConstants.METHOD_NORMAL_EXECUTION, responseEntity.getStatusCode().name());
   } catch (SpartanAccessDeniedException e) {
     sprinkler.logger.log(
         runtimeLogInfoHelper.getRuntimeLogInfo(),
         4005,
         proceedingJoinPoint.getSignature().getDeclaringTypeName(),
         proceedingJoinPoint.getSignature().getName(),
         request.getRemoteHost(),
         e);
     ResponseBean exceptionbean =
         e.prepareExceptionBean(
             sprinkler,
             runtimeLogInfoHelper.getRuntimeLogInfo(),
             "Access Denied" + e.getMessage());
     methodCallDetails.setPostCallDetails(
         HealthConstants.METHOD_EXCEPTION,
         e.getExceptionId(),
         responseEntity.getStatusCode().name());
     return new ResponseEntity<ResponseBean>(exceptionbean, responseEntity.getStatusCode());
   } catch (SpartanPersistenceException e) {
     sprinkler.logger.log(
         runtimeLogInfoHelper.getRuntimeLogInfo(),
         e.getExceptionId(),
         proceedingJoinPoint.getSignature().getDeclaringTypeName(),
         proceedingJoinPoint.getSignature().getName(),
         request.getRemoteHost(),
         e);
     ResponseBean exceptionbean =
         e.prepareExceptionBean(
             sprinkler,
             runtimeLogInfoHelper.getRuntimeLogInfo(),
             "Can not perform Operation on entity:" + e.getMessage());
     methodCallDetails.setPostCallDetails(
         HealthConstants.METHOD_EXCEPTION,
         e.getExceptionId(),
         responseEntity.getStatusCode().name());
     return new ResponseEntity<ResponseBean>(exceptionbean, responseEntity.getStatusCode());
   } catch (SpartanTransactionException e) {
     sprinkler.logger.log(
         runtimeLogInfoHelper.getRuntimeLogInfo(),
         e.getExceptionId(),
         proceedingJoinPoint.getSignature().getDeclaringTypeName(),
         proceedingJoinPoint.getSignature().getName(),
         request.getRemoteHost(),
         e);
     ResponseBean exceptionbean =
         e.prepareExceptionBean(sprinkler, runtimeLogInfoHelper.getRuntimeLogInfo());
     methodCallDetails.setPostCallDetails(
         HealthConstants.METHOD_EXCEPTION,
         e.getExceptionId(),
         responseEntity.getStatusCode().name());
     return new ResponseEntity<ResponseBean>(exceptionbean, responseEntity.getStatusCode());
   } catch (SpartanDataNotFoundException e) {
     sprinkler.logger.log(
         runtimeLogInfoHelper.getRuntimeLogInfo(),
         e.getExceptionId(),
         proceedingJoinPoint.getSignature().getDeclaringTypeName(),
         proceedingJoinPoint.getSignature().getName(),
         request.getRemoteHost(),
         e);
     ResponseBean exceptionbean =
         e.prepareExceptionBean(sprinkler, runtimeLogInfoHelper.getRuntimeLogInfo());
     methodCallDetails.setPostCallDetails(
         HealthConstants.METHOD_EXCEPTION,
         e.getExceptionId(),
         responseEntity.getStatusCode().name());
     return new ResponseEntity<ResponseBean>(exceptionbean, responseEntity.getStatusCode());
   } catch (com.athena.framework.server.exception.biz.SpartanBusinessValidationFailedException e) {
     sprinkler.logger.log(
         runtimeLogInfoHelper.getRuntimeLogInfo(),
         e.getExceptionId(),
         proceedingJoinPoint.getSignature().getDeclaringTypeName(),
         proceedingJoinPoint.getSignature().getName(),
         request.getRemoteHost(),
         e);
     ResponseBean exceptionbean =
         e.prepareExceptionBean(sprinkler, runtimeLogInfoHelper.getRuntimeLogInfo());
     methodCallDetails.setPostCallDetails(
         HealthConstants.METHOD_EXCEPTION,
         e.getExceptionId(),
         responseEntity.getStatusCode().name());
     return new ResponseEntity<ResponseBean>(exceptionbean, responseEntity.getStatusCode());
   } catch (com.athena.framework.server.exception.biz.SpartanConstraintViolationException e) {
     sprinkler.logger.log(
         runtimeLogInfoHelper.getRuntimeLogInfo(),
         e.getExceptionId(),
         proceedingJoinPoint.getSignature().getDeclaringTypeName(),
         proceedingJoinPoint.getSignature().getName(),
         request.getRemoteHost(),
         e);
     ResponseBean exceptionbean =
         e.prepareExceptionBean(sprinkler, runtimeLogInfoHelper.getRuntimeLogInfo());
     methodCallDetails.setPostCallDetails(
         HealthConstants.METHOD_EXCEPTION,
         e.getExceptionId(),
         responseEntity.getStatusCode().name());
     httpStatusCode = HttpStatus.PRECONDITION_FAILED;
     return new ResponseEntity<ResponseBean>(exceptionbean, responseEntity.getStatusCode());
   } catch (Exception e) {
     sprinkler.logger.log(
         runtimeLogInfoHelper.getRuntimeLogInfo(),
         4005,
         proceedingJoinPoint.getSignature().getDeclaringTypeName(),
         proceedingJoinPoint.getSignature().getName(),
         request.getRemoteHost(),
         e);
     ResponseBean responseBean = new ResponseBean();
     responseBean.add("success", false);
     responseBean.add("message", "Access Denied:" + e.getMessage());
     methodCallDetails.setPostCallDetails(
         HealthConstants.METHOD_EXCEPTION,
         HealthConstants.DEFAULT_EXCEPTION_ID,
         responseEntity.getStatusCode().name());
     return new ResponseEntity<ResponseBean>(responseBean, responseEntity.getStatusCode());
   } finally {
     methodCallStack.addMethodCallDetails(methodCallDetails);
     healthmeter.apphealth.writeHealthLog((ArtMethodCallStack) methodCallStack.clone());
     Integer existingValue = 0;
     Metric metric = repository.findOne("gauge." + "total.Time" + entityName + "");
     if (metric != null) {
       existingValue = metric.getValue().intValue();
     }
     gaugeservice.submit(
         "total.Time" + entityName + "", executionTimer.getSystemTime + existingValue);
   }
   return responseEntity;
 }