private void createAndBuildKieServices(DroolsResource[] resources) throws KieBuildException {
this.kieServices = KieServices.Factory.get();
this.kfs = newKieFileSystem();
for (DroolsResource resource : resources) {
log.info("Resource: " + resource.getType() + ", path type="
+ resource.getPathType() + ", path=" + resource.getPath());
switch (resource.getPathType()) {
case CLASSPATH:
this.kfs.write(ResourceFactory.newClassPathResource(resource.getPath()));
break;
case FILE:
this.kfs.write(ResourceFactory.newFileResource(resource.getPath()));
break;
case URL:
UrlResource urlResource = (UrlResource) ResourceFactory
.newUrlResource(resource.getPath());
if (resource.getUsername() != null) {
log.info("Setting authentication for: " + resource.getUsername());
urlResource.setBasicAuthentication("enabled");
urlResource.setUsername(resource.getUsername());
urlResource.setPassword(resource.getPassword());
}
this.kfs.write(urlResource);
break;
default:
throw new IllegalArgumentException(
"Unable to build this resource path type.");
}
}
KieBuilder kieBuilder = kieServices.newKieBuilder(kfs).buildAll();
if (kieBuilder.getResults().hasMessages(Level.ERROR)) {
List<Message> errors = kieBuilder.getResults().getMessages(Level.ERROR);
StringBuilder sb = new StringBuilder("Errors:");
for (Message msg : errors) {
sb.append("\n " + prettyBuildMessage(msg));
}
throw new KieBuildException(sb.toString());
}
log.info("KieServices built: " + toString());
}