diff options
Diffstat (limited to 'UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/DiskRepoConfigFileService.java')
-rw-r--r-- | UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/DiskRepoConfigFileService.java | 72 |
1 files changed, 43 insertions, 29 deletions
diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/DiskRepoConfigFileService.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/DiskRepoConfigFileService.java index c2a30f0..7c05ced 100644 --- a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/DiskRepoConfigFileService.java +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/DiskRepoConfigFileService.java @@ -32,7 +32,7 @@ import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; /** - * Implementation of {@code ConfigFileService} using disk repository + * Implementation of {@code ConfigFileService} using disk repository. * * @author kmalbari * @@ -40,34 +40,48 @@ import org.springframework.web.client.RestTemplate; @Component public class DiskRepoConfigFileService implements ConfigFileService { - private final Logger LOGGER = LoggerFactory.getLogger(this.getClass()); - - @Autowired - private DiskRepoConfiguration diskRepoConfiguration; - - private RestTemplate restTemplate = new RestTemplate(); - - private URI uri = null; + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Autowired + private DiskRepoConfiguration diskRepoConfiguration; + + private RestTemplate restTemplate; + + private URI uri = null; - /* (non-Javadoc) - * @see org.onap.universalvesadapter.service.ConfigFileService#readConfigFile(java.lang.String) - */ - @Override - public String readConfigFile(String fileName) throws ConfigFileReadException { - LOGGER.debug("Reading config file for " + fileName); - if(null == uri){ - try { - uri = new URI(diskRepoConfiguration.getFileRepositoryUrl()+fileName); - LOGGER.debug("Read URI for " + fileName); - } catch (URISyntaxException exception) { - throw new ConfigFileReadException("Unable to read config file for file " - + fileName + "\n Reason : " + exception.getMessage()); - } - } - LOGGER.debug("Calling file repo service for URI" + uri); - ResponseEntity<String> fileDataEntity = restTemplate.getForEntity(uri, String.class); - LOGGER.debug("Call completed successfully"); - return fileDataEntity.getBody(); - } + /* (non-Javadoc) + * @see org.onap.universalvesadapter.service.ConfigFileService#readConfigFile(java.lang.String) + */ + @Override + public String readConfigFile(String fileName) throws ConfigFileReadException { + logger.debug("Reading config file for " + fileName); + if (null == uri) { + try { + uri = new URI(diskRepoConfiguration.getFileRepositoryUrl() + fileName); + logger.debug("Read URI for " + fileName); + } catch (URISyntaxException exception) { + throw new ConfigFileReadException("Unable to read config file for file " + + fileName + "\n Reason : " + exception.getMessage(), exception); + } + } + logger.debug("Calling file repo service for URI" + uri); + ResponseEntity<String> fileDataEntity = getRestTemplate().getForEntity(uri, String.class); + logger.debug("Call completed successfully"); + return fileDataEntity.getBody(); + } + + /** + * Instantiates the instance if null and returns it. + * + * @return {@code RestTemplate} instance + */ + private RestTemplate getRestTemplate(){ + + if (null == restTemplate) { + restTemplate = new RestTemplate(); + } + + return restTemplate; + } } |