As a follow-up, this is how we do it:
public void loadKnowledgeAgent(String packageName)
{
final String sourceMethod = "loadKnowledgeAgent";
KnowledgeAgentConfiguration aconf =
KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
aconf.setProperty("drools.agent.scanDirectories", "true");
aconf.setProperty("drools.agent.scanResources", "true");
aconf.setProperty("drools.agent.newInstance", "true");
aconf.setProperty("monitorChangeSetEvents", "true");
try
{
if (packageName == null)
return;
String xml = getDroolsChangeSet(packageName);
if (xml == null || xml.isEmpty())
{
log.severe("Could not load Drools Package: " + packageName);
return;
}
xml = xml.replace("type='PKG'", "type='PKG'
basicAuthentication='enabled' " + "username='" + getDroolsUid()
+ "' password='"
+ getDroolsPwd() + "'");
xml = xml.replace("
http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-api/src/...
+ "change-set-1.0.0.xsd", "");
KnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();
KnowledgeAgent kAgent = KnowledgeAgentFactory.newKnowledgeAgent(packageName,
kBase, aconf);
StringReader sr = new StringReader(xml);
try
{
log.info("Adding Package: " + packageName);
final org.drools.io.Resource resource =
ResourceFactory.newReaderResource(sr);
if (resource == null)
log.severe("\n\n\n Package " + packageName + " cannot init
ReaderResource.\n\n\n" + xml + "\n\n\n");
kAgent.applyChangeSet(resource);
kAgent.addEventListener(new AgentEventListener(packageName));
kAgents.put(packageName, kAgent);
setRuleColumns(packageName);
}
finally
{
sr.close();
}
}
catch (Throwable e)
{
log.throwing(sourceClass, sourceMethod, e);
mail.throwing("Error processing package: " + packageName, e);
}
}
Since you are already downloading the ChangeSet.xml yourself, I left that code out.
getDroolsChangeSet() is the function we use to download the changeset xml, and return it
as a string. We don't bother with an xml parser to change the changeset, we just use
a simple string replacement since we don't have any scenarios in our environment where
we would need to use an XML parser to do this.
This is very old code, so there is probably a better way now.
From: rules-users-bounces(a)lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org] On
Behalf Of Prasad
Sent: Monday, July 23, 2012 12:58 PM
To: rules-users(a)lists.jboss.org
Subject: Re: [rules-users] Changset Authentication through code
Thanks for the reply, Armand.
We are also planning to go with a similar approach where in we
download the XML from guvnor, modify it and then proceed with Agents.
On 7/24/12, Armand Welsh [via Drools]
<[hidden email]</user/SendEmail.jtp?type=node&node=4018845&i=0>>
wrote:
We are using guvnor in a similar way, and we download the xml from guvnor,
then modify the xml and initiate the process with locally provided
credentials.
-----Original Message-----
From: [hidden email]</user/SendEmail.jtp?type=node&node=4018845&i=1>
[mailto:[hidden email]</user/SendEmail.jtp?type=node&node=4018845&i=2>] On
Behalf Of Prasad
Sent: Monday, July 23, 2012 4:13 AM
To: [hidden email]</user/SendEmail.jtp?type=node&node=4018845&i=3>
Subject: [rules-users] Changset Authentication through code
Hi,
We are trying to apply authentication on an URL ChangeSet Resource and it
looks that doesn't work.
However authentication works if we specify in a local change set xml file.
We need to connect to guvnor to get the change set via authentication
instead of using a local change set XML file.
Please let me know if this possible or a change set XML created local is
the
only way.
--
View this message in context:
http://drools.46999.n3.nabble.com/Changset-Authentication-through-code-tp...
Sent from the Drools: User forum mailing list archive at
Nabble.com.
_______________________________________________
rules-users mailing list
[hidden email]</user/SendEmail.jtp?type=node&node=4018845&i=4>
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
[hidden email]</user/SendEmail.jtp?type=node&node=4018845&i=5>
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
If you reply to this email, your message will be added to the discussion
below:
http://drools.46999.n3.nabble.com/Changset-Authentication-through-code-tp...
To unsubscribe from Changset Authentication through code, visit
________________________________
View this message in context: Re: [rules-users] Changset Authentication through
code<http://drools.46999.n3.nabble.com/Changset-Authentication-through...
Sent from the Drools: User forum mailing list
archive<http://drools.46999.n3.nabble.com/Drools-User-forum-f47000.htm... at
Nabble.com.