Search in sources :

Example 1 with DataPullContext

use of com.homeaway.datapullclient.config.DataPullContext in project datapull by homeaway.

the class DataPullRequestProcessor method validateAndEnrich.

private String validateAndEnrich(String json) throws ProcessingException {
    JSONObject jsonString = new JSONObject(new JSONTokener(new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8))));
    try {
        DataPullContext context = DataPullContextHolder.getContext();
        if (context != null) {
            String authenticatedUser = context.getAuthenticatedUser();
            if (authenticatedUser != null) {
                jsonString.put("authenticated_user", authenticatedUser);
            }
        }
        inputJsonSchema.validate(jsonString);
        return jsonString.toString();
    } catch (ValidationException exception) {
        throw new ProcessingException("Json Validation failed " + exception.getMessage(), exception);
    }
}
Also used : JSONTokener(org.json.JSONTokener) ValidationException(org.everit.json.schema.ValidationException) JSONObject(org.json.JSONObject) ByteArrayInputStream(java.io.ByteArrayInputStream) DataPullContext(com.homeaway.datapullclient.config.DataPullContext) ProcessingException(com.homeaway.datapullclient.exception.ProcessingException)

Aggregations

DataPullContext (com.homeaway.datapullclient.config.DataPullContext)1 ProcessingException (com.homeaway.datapullclient.exception.ProcessingException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ValidationException (org.everit.json.schema.ValidationException)1 JSONObject (org.json.JSONObject)1 JSONTokener (org.json.JSONTokener)1