Skip to content

Commit

Permalink
Fail fast during app start up
Browse files Browse the repository at this point in the history
  • Loading branch information
dima767 committed Oct 9, 2018
1 parent 145f18d commit b700f07
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package edu.internet2.tier.shibboleth.admin.ui.controller

import com.fasterxml.jackson.databind.ObjectMapper
import edu.internet2.tier.shibboleth.admin.ui.configuration.CustomAttributesConfiguration
import groovy.json.JsonOutput

import org.springframework.beans.factory.BeanInitializationException
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.core.io.ResourceLoader
Expand All @@ -19,6 +20,7 @@ import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR
* interface in terms of JSON schema.
*
* @author Dmitriy Kopylenko
* @author Bill Smith (wsmith@unicon.net)
*/
@RestController('/api/ui/MetadataSources')
@ConfigurationProperties('shibui')
Expand Down Expand Up @@ -64,5 +66,17 @@ class MetadataSourcesUiDefinitionController {
@PostConstruct
def init() {
jsonSchemaUrl = this.resourceLoader.getResource(this.metadataSourcesUiSchemaLocation).getURL()
//Detect malformed JSON schema early, during application start up and fail fast with useful exception message
try {
this.jacksonObjectMapper.readValue(this.jsonSchemaUrl, Map)
}
catch (Exception e) {
def msg = """
An error is detected during JSON parsing => [${e.message}]
**********************************************************
Offending resource => [${this.jsonSchemaUrl}]
"""
throw new BeanInitializationException(msg.toString(), e)
}
}
}

0 comments on commit b700f07

Please sign in to comment.