/** Validate request Json object for get, put and post method of HostAddress API. */
 @Override
 public final void validate(final String method, final JsonObject requestBody)
     throws VtnServiceException {
   LOG.trace("Start HostAddressResourceValidator#validate()");
   boolean isValid = false;
   try {
     isValid = validateUri();
     LOG.info("Validating request for " + method + " of HostAddressResourceValidator");
     if (isValid && requestBody != null && VtnServiceConsts.GET.equals(method)) {
       isValid = validator.isValidGet(requestBody, isListOpFlag());
       setInvalidParameter(validator.getInvalidParameter());
       updateOpParameterForList(requestBody);
     } else if (isValid && requestBody != null && VtnServiceConsts.PUT.equals(method)) {
       isValid = validatePut(requestBody);
     } else if (isValid) {
       setInvalidParameter(VtnServiceConsts.INCORRECT_METHOD_INVOCATION);
       isValid = false;
     }
   } catch (final NumberFormatException e) {
     if (method.equals(VtnServiceConsts.GET)) {
       setInvalidParameter(validator.getInvalidParameter());
     }
     LOG.error("Inside catch:NumberFormatException");
     isValid = false;
   } catch (final ClassCastException e) {
     if (method.equals(VtnServiceConsts.GET)) {
       setInvalidParameter(validator.getInvalidParameter());
     }
     LOG.error("Inside catch:ClassCastException");
     isValid = false;
   }
   // Throws exception if validation fails
   if (!isValid) {
     LOG.error("Validation failed");
     throw new VtnServiceException(
         Thread.currentThread().getStackTrace()[1].getMethodName(),
         UncJavaAPIErrorCode.VALIDATION_ERROR.getErrorCode(),
         UncJavaAPIErrorCode.VALIDATION_ERROR.getErrorMessage());
   }
   LOG.info("Validation successful");
   LOG.trace("Complete HostAddressResourceValidator#validate()");
 }
예제 #2
0
 /** Validate request json for Set Password API */
 @Override
 public final void validate(final String method, final JsonObject requestBody)
     throws VtnServiceException {
   LOG.trace("Start UserResourceValidator#validate()");
   LOG.info("Validating request for " + method + " of UserResourceValidator");
   boolean isValid = false;
   isValid = validateUri();
   if (isValid && requestBody != null && VtnServiceConsts.PUT.equalsIgnoreCase(method)) {
     isValid = validatePut(requestBody);
   } else if (isValid) {
     setInvalidParameter(VtnServiceConsts.INCORRECT_METHOD_INVOCATION);
     isValid = false;
   }
   // Throws exception if validation fails
   if (!isValid) {
     LOG.error("Validation failed");
     throw new VtnServiceException(
         Thread.currentThread().getStackTrace()[1].getMethodName(),
         UncJavaAPIErrorCode.VALIDATION_ERROR.getErrorCode(),
         UncJavaAPIErrorCode.VALIDATION_ERROR.getErrorMessage());
   }
   LOG.info("Validation successful");
   LOG.trace("Complete UserResourceValidator#validate()");
 }