Package com.betfair.cougar.core.api.exception

Examples of com.betfair.cougar.core.api.exception.CougarValidationException


          ValidationEventCollector validationHandler = new ValidationEventCollector();
      u.setEventHandler(validationHandler);
          setSchema(jc, u);
          Object obj = u.unmarshal(reader);
          if (!clazz.isAssignableFrom(obj.getClass())) {
              throw new CougarValidationException(ServerFaultCode.ClassConversionFailure, "Deserialised object was not of class "+clazz.getName());
          }
          validate(validationHandler);
          return obj;
    } catch (UnmarshalException e) {
            Throwable linkedException = e.getLinkedException();
            if(linkedException!=null) {
                logger.log(Level.FINE, linkedException.getMessage());
                if (linkedException instanceof SAXParseException) {
                    CougarValidationException cve = schemaValidationFailureParser.parse((SAXParseException)linkedException, SchemaValidationFailureParser.XmlSource.RESCRIPT);
                    if (cve != null) {
                        throw cve;
                    }
                }
                throw new CougarValidationException(ServerFaultCode.XMLDeserialisationFailure, linkedException);//NOSONAR
            }
            throw new CougarValidationException(ServerFaultCode.XMLDeserialisationFailure, e);
        } catch (CougarValidationException e) {
            throw e;
    } catch (Exception e) {
      throw new CougarServiceException(ServerFaultCode.XMLDeserialisationFailure, "Unable to deserialise REST/XML request", e);
        }
View Full Code Here


 
  private final static CougarValidationException newValidationException(String name, String value, Class clazz, Exception originalException) {
    final StringBuilder msg = new StringBuilder("Unable to convert '");
    msg.append(value).append("' to ").append(clazz.getName()).append(" for parameter: " + name);
   
    return new CougarValidationException(ServerFaultCode.ClassConversionFailure, msg.toString(), originalException);   
  }
View Full Code Here

  public Object unmarshall(InputStream inputStream, Class<?> clazz, String encoding) {
    try {
      Reader reader = new BufferedReader(new InputStreamReader(inputStream,encoding));
      return objectMapper.readValue(reader, clazz);
    } catch (JsonProcessingException e) {
      throw new CougarValidationException(ServerFaultCode.JSONDeserialisationParseFailure, e);
    } catch (IOException e) {
      throw new CougarServiceException(ServerFaultCode.JSONDeserialisationParseFailure, "Failed to unmarshall object", e);
    }
  }
View Full Code Here

                String result = mf.format(args);
                if (result.equals(toParse)) {
                    // we've found the key, if we have a mapping then return the appropriate exception, otherwise no point continuing
                    ServerFaultCode sfc = faultCodes.get(key);
                    if (sfc != null) {
                        return new CougarValidationException(sfc, spe);
                    }
                    return null;
                }
            } catch (ParseException e) {
                // no match
View Full Code Here

      if (argIndex < args.length) {
        currentArgument = args[argIndex++];
      }

      if (param.isMandatory() && currentArgument == null) {
        throw new CougarValidationException(ServerFaultCode.MandatoryNotDefined,"MANDATORY parameter cannot be null: " + parameterName);
      }

            switch (parameterSource) {

                case BODY:
View Full Code Here

        }.start();
    }

    private boolean validateCTX(ExecutionContext ctx, ExecutionObserver observer) {
        // Ensure that the context passed is valid
        CougarValidationException ex = null;
        if (ctx == null) {
            ex = new CougarValidationException(ServerFaultCode.MandatoryNotDefined, "Execution Context must not be null");
        } else if (ctx.getLocation() == null) {
            ex = new CougarValidationException(ServerFaultCode.MandatoryNotDefined, "Geolocation details must not be null");
        }
        if (ex != null) {
            observer.onResult(new ExecutionResult(ex));
            return false;
        }
View Full Code Here

    }


    private Class<? extends Event> getEventClass(String eventName) {
        if (!bindingDescriptorMap.containsKey(eventName.toLowerCase())) {
            throw new CougarValidationException(ServerFaultCode.NoSuchOperation, "Unable to find binding for event named[" + eventName + "]");
        }
        EventBindingDescriptor eventBindingDescriptor = bindingDescriptorMap.get(eventName.toLowerCase());
        final Class<? extends Event> eventClass = eventBindingDescriptor.getEventClass();
        return eventClass;
    }
View Full Code Here

    for (int i = 0 ; i < args.length; i++) {

        if (args[i] == null) {
              if (parms[i].isMandatory()) {
                return new InterceptorResult(InterceptorState.FORCE_ON_EXCEPTION,
                    new CougarValidationException(ServerFaultCode.MandatoryNotDefined,
                        "Mandatory attributes not defined for parameter '"+parms[i].getName() + "'"));
              }
          } else {
                try {
                    ValidationUtils.validateMandatory(args[i]);
                } catch (IllegalArgumentException e) {
                    return new InterceptorResult(InterceptorState.FORCE_ON_EXCEPTION,
                            new CougarValidationException(ServerFaultCode.MandatoryNotDefined,
                                    "Embedded fields not defined for parameter '"+parms[i].getName() + "'", e));
                }
          }
    }
    return SUCCESS;
View Full Code Here

        public String extractVersion(String uri) {
            Matcher m = regex.matcher(uri);
            if (m.matches()) {
                return m.group(1).toLowerCase();
            }
            throw new CougarValidationException(ServerFaultCode.NoSuchService, "Uri [" + uri + "] did not contain a version");
        }
View Full Code Here

    for (int i = 0 ; i < args.length; i++) {
     
        if (args[i] == null) {
              if (parms[i].isMandatory()) {
                return new InterceptorResult(InterceptorState.FORCE_ON_EXCEPTION,
                    new CougarValidationException(ServerFaultCode.MandatoryNotDefined,
                        "Mandatory attributes not defined for parameter '"+parms[i].getName() + "'"));
              }
          } else {
                try {
                    ValidationUtils.validateMandatory(args[i]);
                } catch (IllegalArgumentException e) {
                    return new InterceptorResult(InterceptorState.FORCE_ON_EXCEPTION,
                            new CougarValidationException(ServerFaultCode.MandatoryNotDefined,
                                    "Embedded fields not defined for parameter '"+parms[i].getName() + "'", e));
                }
          }
    }
    return SUCCESS;
View Full Code Here

TOP

Related Classes of com.betfair.cougar.core.api.exception.CougarValidationException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.