Search in sources :

Example 1 with UrlResource

use of org.drools.core.io.impl.UrlResource in project drools by kiegroup.

the class ChangeSetTest method testBasicAuthentication.

@Test
public void testBasicAuthentication() throws SAXException, IOException {
    KnowledgeBuilderConfigurationImpl conf = new KnowledgeBuilderConfigurationImpl();
    XmlChangeSetReader xmlReader = new XmlChangeSetReader(conf.getSemanticModules());
    xmlReader.setClassLoader(ChangeSetTest.class.getClassLoader(), ChangeSetTest.class);
    String str = "";
    str += "<change-set ";
    str += "xmlns='http://drools.org/drools-5.0/change-set' ";
    str += "xmlns:xs='http://www.w3.org/2001/XMLSchema-instance' ";
    str += "xs:schemaLocation='http://drools.org/drools-5.0/change-set http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-api/src/main/resources/change-set-1.0.0.xsd' >";
    str += "    <add> ";
    str += "        <resource source='http://localhost:8081/jboss-brms/org.kie.guvnor.Guvnor/package/defaultPackage/LATEST' type='PKG' basicAuthentication='enabled' username='admin' password='pwd'/>";
    str += "    </add> ";
    str += "</change-set>";
    StringReader reader = new StringReader(str);
    ChangeSet changeSet = xmlReader.read(reader);
    assertEquals(1, changeSet.getResourcesAdded().size());
    UrlResource resource = (UrlResource) ((List) changeSet.getResourcesAdded()).get(0);
    assertEquals("http://localhost:8081/jboss-brms/org.kie.guvnor.Guvnor/package/defaultPackage/LATEST", resource.getURL().toString());
    assertEquals("enabled", resource.getBasicAuthentication());
    assertEquals("admin", resource.getUsername());
    assertEquals("pwd", resource.getPassword());
    assertEquals(ResourceType.PKG, resource.getResourceType());
}
Also used : KnowledgeBuilderConfigurationImpl(org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl) UrlResource(org.drools.core.io.impl.UrlResource) StringReader(java.io.StringReader) XmlChangeSetReader(org.drools.core.xml.XmlChangeSetReader) ChangeSet(org.kie.internal.ChangeSet) Test(org.junit.Test)

Example 2 with UrlResource

use of org.drools.core.io.impl.UrlResource in project drools by kiegroup.

the class ChangeSetTest method testXmlParser.

@Test
public void testXmlParser() throws SAXException, IOException {
    KnowledgeBuilderConfigurationImpl conf = new KnowledgeBuilderConfigurationImpl();
    XmlChangeSetReader xmlReader = new XmlChangeSetReader(conf.getSemanticModules());
    xmlReader.setClassLoader(ChangeSetTest.class.getClassLoader(), ChangeSetTest.class);
    String str = "";
    str += "<change-set ";
    str += "xmlns='http://drools.org/drools-5.0/change-set' ";
    str += "xmlns:xs='http://www.w3.org/2001/XMLSchema-instance' ";
    str += "xs:schemaLocation='http://drools.org/drools-5.0/change-set http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-api/src/main/resources/change-set-1.0.0.xsd' >";
    str += "    <add> ";
    str += "        <resource source='http://www.domain.com/test.drl' type='DRL' />";
    str += "        <resource source='http://www.domain.com/test.xls' type='DTABLE' >";
    str += "            <decisiontable-conf worksheet-name='sheet10' input-type='XLS' />";
    str += "        </resource>";
    str += "    </add> ";
    str += "</change-set>";
    StringReader reader = new StringReader(str);
    ChangeSet changeSet = xmlReader.read(reader);
    assertEquals(2, changeSet.getResourcesAdded().size());
    UrlResource resource = (UrlResource) ((List) changeSet.getResourcesAdded()).get(0);
    assertEquals("http://www.domain.com/test.drl", resource.getURL().toString());
    assertEquals(ResourceType.DRL, resource.getResourceType());
    resource = (UrlResource) ((List) changeSet.getResourcesAdded()).get(1);
    assertEquals("http://www.domain.com/test.xls", resource.getURL().toString());
    assertEquals(ResourceType.DTABLE, resource.getResourceType());
    DecisionTableConfiguration dtConf = (DecisionTableConfiguration) resource.getConfiguration();
    assertEquals(DecisionTableInputType.XLS, dtConf.getInputType());
}
Also used : KnowledgeBuilderConfigurationImpl(org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl) UrlResource(org.drools.core.io.impl.UrlResource) DecisionTableConfiguration(org.kie.internal.builder.DecisionTableConfiguration) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) List(java.util.List) XmlChangeSetReader(org.drools.core.xml.XmlChangeSetReader) ChangeSet(org.kie.internal.ChangeSet) Test(org.junit.Test)

Example 3 with UrlResource

use of org.drools.core.io.impl.UrlResource in project drools by kiegroup.

the class ResourceHandler method start.

public Object start(String uri, String localName, Attributes attrs, ExtensibleXmlParser parser) throws SAXException {
    parser.startElementBuilder(localName, attrs);
    final Collection collection = (Collection) parser.getParent();
    String src = attrs.getValue("source");
    String type = attrs.getValue("type");
    String basicAuthentication = attrs.getValue("basicAuthentication");
    String username = attrs.getValue("username");
    String password = attrs.getValue("password");
    String name = attrs.getValue("name");
    String description = attrs.getValue("description");
    String categories = attrs.getValue("categories");
    emptyAttributeCheck(localName, "source", src, parser);
    emptyAttributeCheck(localName, "type", type, parser);
    InternalResource resource = null;
    if (src.trim().startsWith("classpath:")) {
        resource = new ClassPathResource(src.substring(src.indexOf(':') + 1), parser.getClassLoader());
    } else {
        resource = new UrlResource(src);
        ((UrlResource) resource).setBasicAuthentication(basicAuthentication);
        ((UrlResource) resource).setUsername(username);
        ((UrlResource) resource).setPassword(password);
    }
    resource.setResourceType(ResourceType.getResourceType(type));
    resource.setSourcePath(name);
    resource.setDescription(description);
    resource.setCategories(categories);
    return resource;
}
Also used : InternalResource(org.drools.core.io.internal.InternalResource) UrlResource(org.drools.core.io.impl.UrlResource) Collection(java.util.Collection) ClassPathResource(org.drools.core.io.impl.ClassPathResource)

Aggregations

UrlResource (org.drools.core.io.impl.UrlResource)3 StringReader (java.io.StringReader)2 KnowledgeBuilderConfigurationImpl (org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl)2 XmlChangeSetReader (org.drools.core.xml.XmlChangeSetReader)2 Test (org.junit.Test)2 ChangeSet (org.kie.internal.ChangeSet)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 ClassPathResource (org.drools.core.io.impl.ClassPathResource)1 InternalResource (org.drools.core.io.internal.InternalResource)1 DecisionTableConfiguration (org.kie.internal.builder.DecisionTableConfiguration)1