use of org.apache.knox.gateway.deploy.impl.ServiceDefinitionDeploymentContributor in project knox by apache.
the class ServiceDefinitionsLoader method loadServiceDefinitions.
public static Set<ServiceDeploymentContributor> loadServiceDefinitions(File servicesDir) {
Set<ServiceDeploymentContributor> contributors = new HashSet<>();
if (servicesDir.exists() && servicesDir.isDirectory()) {
try {
JAXBContext context = JAXBContext.newInstance(ServiceDefinition.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
for (File file : getFileList(servicesDir)) {
try {
FileInputStream inputStream = new FileInputStream(file);
ServiceDefinition definition = (ServiceDefinition) unmarshaller.unmarshal(inputStream);
// look for rewrite rules as a sibling (for now)
UrlRewriteRulesDescriptor rewriteRulesDescriptor = loadRewriteRules(file.getParentFile());
contributors.add(new ServiceDefinitionDeploymentContributor(definition, rewriteRulesDescriptor));
log.addedServiceDefinition(definition.getName(), definition.getRole(), definition.getVersion());
} catch (FileNotFoundException e) {
log.failedToFindServiceDefinitionFile(file.getAbsolutePath(), e);
}
}
} catch (JAXBException e) {
log.failedToLoadServiceDefinition(SERVICE_FILE_NAME, e);
}
}
return contributors;
}
Aggregations