use of org.orcid.core.exception.InvalidJSONException in project ORCID-Source by ORCID.
the class JSONInputValidator method validate2_1APIJSONInput.
public void validate2_1APIJSONInput(Object obj) {
Class<?> clazz = obj.getClass();
JAXBSource source = null;
if (!SCHEMA_LOCATIONS_2_1_API.containsKey(clazz)) {
LOGGER.error("Cannot validate " + clazz.getName());
return;
}
try {
source = new JAXBSource(CONTEXTS_2_1_API.get(clazz), obj);
VALIDATORS_2_1_API.get(clazz).validate(source);
} catch (SAXException e) {
Map<String, String> params = new HashMap<>();
params.put("error", e.getCause().getCause().getMessage());
throw new InvalidJSONException(params);
} catch (Exception e) {
throw new ApplicationException(e);
}
}
use of org.orcid.core.exception.InvalidJSONException in project ORCID-Source by ORCID.
the class JSONInputValidator method validateJSONInput.
public void validateJSONInput(Object obj) {
Class<?> clazz = obj.getClass();
JAXBSource source = null;
if (!canValidate(clazz)) {
LOGGER.error("Cannot validate " + clazz.getName());
return;
}
try {
source = new JAXBSource(CONTEXTS.get(clazz), obj);
VALIDATORS.get(clazz).validate(source);
} catch (SAXException e) {
Map<String, String> params = new HashMap<>();
params.put("error", e.getCause().getCause().getMessage());
throw new InvalidJSONException(params);
} catch (Exception e) {
throw new ApplicationException(e);
}
}
use of org.orcid.core.exception.InvalidJSONException in project ORCID-Source by ORCID.
the class OrcidJacksonJaxbJsonProviderPretty method readFrom.
/**
* This adds a validation step when converting JSON into ORCID models.
*/
@Override
public Object readFrom(Class<Object> arg0, Type arg1, Annotation[] arg2, MediaType arg3, MultivaluedMap<String, String> arg4, InputStream arg5) throws IOException {
Object o = null;
try {
o = super.readFrom(arg0, arg1, arg2, arg3, arg4, arg5);
} catch (JsonMappingException e) {
Map<String, String> params = new HashMap<>();
params.put("error", e.getMessage());
throw new InvalidJSONException(params);
}
if (jsonInputValidator.canValidate(o.getClass())) {
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
String apiVersion = (String) requestAttributes.getAttribute(ApiVersionFilter.API_VERSION_REQUEST_ATTRIBUTE_NAME, RequestAttributes.SCOPE_REQUEST);
if (apiVersion != null && apiVersion.equals("2.1")) {
jsonInputValidator.validate2_1APIJSONInput(o);
} else {
jsonInputValidator.validateJSONInput(o);
}
}
return o;
}
Aggregations