Search in sources :

Example 1 with ServiceDefinitionDeploymentContributor

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;
}
Also used : ServiceDefinitionDeploymentContributor(org.apache.knox.gateway.deploy.impl.ServiceDefinitionDeploymentContributor) ServiceDeploymentContributor(org.apache.knox.gateway.deploy.ServiceDeploymentContributor) JAXBException(javax.xml.bind.JAXBException) FileNotFoundException(java.io.FileNotFoundException) UrlRewriteRulesDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) File(java.io.File) ServiceDefinition(org.apache.knox.gateway.service.definition.ServiceDefinition) FileInputStream(java.io.FileInputStream) HashSet(java.util.HashSet)

Aggregations

File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 HashSet (java.util.HashSet)1 JAXBContext (javax.xml.bind.JAXBContext)1 JAXBException (javax.xml.bind.JAXBException)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 ServiceDeploymentContributor (org.apache.knox.gateway.deploy.ServiceDeploymentContributor)1 ServiceDefinitionDeploymentContributor (org.apache.knox.gateway.deploy.impl.ServiceDefinitionDeploymentContributor)1 UrlRewriteRulesDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor)1 ServiceDefinition (org.apache.knox.gateway.service.definition.ServiceDefinition)1