[JBoss jBPM] - Re: How to invoke rules(drools) from a jBPM
by rinki
Below are the files:
1. File for invoking jbpm process
package com.sample.test;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.exe.ProcessInstance;
public class TestDroolsInvocation {
/**
* @param args
*/
public static void main(String[] args) {
ProcessDefinition definition = ProcessDefinition.parseXmlResource("JbpmDroolsExample/processdefinition.xml");
ProcessInstance instance = new ProcessInstance(definition);
instance.signal();
//instance.signal();
System.out.println("Ended!!!");
}
}
2. File where rules are invoked(Actionhandler)
package com.sample.action;
import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.exe.ExecutionContext;
import org.drools.RuleBase;
import org.drools.RuleBaseFactory;
import org.drools.WorkingMemory;
import org.drools.compiler.DrlParser;
import org.drools.compiler.PackageBuilder;
import org.drools.lang.descr.PackageDescr;
import org.drools.rule.Package;
import java.io.*;
public class FireRulesActionHandler implements ActionHandler {
private static final long serialVersionUID = 1L;
public static String ruleFile;
/**
* The FireRulesActionHandler gets variables from the Instance, and asserts
* them into the Rules Engine and invokes the rules.
*/
public void execute(ExecutionContext executionContext) throws Exception {
try {
//load up the rulebase
RuleBase ruleBase = readRule();
WorkingMemory workingMemory = ruleBase.newStatefulSession();
//go !
Message message = new Message();
message.setMessage( "Hello World" );
message.setStatus( Message.LikesCheese );
workingMemory.insert( message );
workingMemory.fireAllRules();
} catch (Throwable t) {
t.printStackTrace();
}
}
private static RuleBase readRule() throws Exception {
//read in the source
Reader source = new InputStreamReader( FireRulesActionHandler.class.getResourceAsStream("E:/jBPM/workspace/InvokingDrools/src/main/java/com/sample/rules/CheeseRules.drl"));
//Reader source = new InputStreamReader(FireRulesActionHandler.class.getResourceAsStream(ruleFile));
DrlParser parser = new DrlParser();
PackageDescr packageDescr = parser.parse(source);
// pre build the package
PackageBuilder builder = new PackageBuilder();
builder.addPackage(packageDescr);
Package pkg = builder.getPackage();
/*PackageBuilder builder = new PackageBuilder();
builder.addPackageFromDrl( source );
Package pkg = builder.getPackage();*/
//add the package to a rulebase (deploy the rule package).
RuleBase ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage( pkg );
return ruleBase;
}
public static class Message {
public static final int LikesCheese = 0;
public static final int GOODBYE = 1;
private String message;
private int status;
public String getMessage() {
return this.message;
}
public void setMessage(String message) {
this.message = message;
}
public int getStatus() {
return this.status;
}
public void setStatus( int status ) {
this.status = status;
}
}
}
3. CheeseRules.drl
#created on: Nov 4, 2008
package src.main.rules
import com.sample.action.FireRulesActionHandler.Message;
rule "Bob Likes Cheese"
when
m : Message( status == Message.LikesCheese, message : message )
then
System.out.println( message );
m.setMessage( "Bob enjoys eating cheese" );
m.setStatus( Message.GOODBYE );
update( m );
end
rule "GoodBye"
when
Message( status == Message.GOODBYE, message : message )
then
System.out.println( message );
end
Everything is present in jbpm project.
Regards,
Ruchika
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4186681#4186681
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4186681
17 years, 5 months
[JBoss jBPM] - call/ start bpel process from web application
by sw_bpel
hello,
i have created my own bpel process, deployed it use an ant script and tested it using soap ui. it seems that so far everything works fine.
now i have created an web application in eclipse (dynamic web project) and i want to call/ invoke/ start the bpel process from an servlet inside the web application. therefore i want to create a web service client in eclipse (new -> other -> web services -> web service client). i typed in the address of the bpel process wsdl
configuration:
- server: jboss v4.2
- web service runtime: apache axis
and clicked finish, but then i get the following error:
| IWAB0014E Unexpected exception occurred.
|
| java.lang.NullPointerException
| at org.eclipse.jst.ws.internal.axis.consumption.ui.task.Stub2BeanCommand.execute(Stub2BeanCommand.java:121)
| at org.eclipse.jst.ws.internal.axis.consumption.ui.task.ClientCodeGenOperation$ClientWSModifyOperation.execute(ClientCodeGenOperation.java:110)
| at org.eclipse.jst.ws.internal.axis.consumption.ui.task.ClientCodeGenOperation.execute(ClientCodeGenOperation.java:61)
| at org.eclipse.wst.command.internal.env.core.fragment.CommandFragmentEngine.runCommand(CommandFragmentEngine.java:419)
| at org.eclipse.wst.command.internal.env.core.fragment.CommandFragmentEngine.visitTop(CommandFragmentEngine.java:359)
| at org.eclipse.wst.command.internal.env.core.fragment.CommandFragmentEngine.moveForwardToNextStop(CommandFragmentEngine.java:254)
| at org.eclipse.wst.command.internal.env.ui.widgets.SimpleCommandEngineManager$6.run(SimpleCommandEngineManager.java:294)
| at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:369)
| at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:313)
| at org.eclipse.jface.wizard.WizardDialog.run(WizardDialog.java:934)
| at org.eclipse.wst.command.internal.env.ui.widgets.SimpleCommandEngineManager.runForwardToNextStop(SimpleCommandEngineManager.java:264)
| at org.eclipse.wst.command.internal.env.ui.widgets.WizardPageManager.runForwardToNextStop(WizardPageManager.java:91)
| at org.eclipse.wst.command.internal.env.ui.widgets.WizardPageManager.performFinish(WizardPageManager.java:262)
| at org.eclipse.wst.command.internal.env.ui.widgets.DynamicWizard.performFinish(DynamicWizard.java:380)
| at org.eclipse.jface.wizard.WizardDialog.finishPressed(WizardDialog.java:742)
| at org.eclipse.jface.wizard.WizardDialog.buttonPressed(WizardDialog.java:373)
| at org.eclipse.jface.dialogs.Dialog$2.widgetSelected(Dialog.java:618)
| at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:227)
| at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
| at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:938)
| at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3682)
| at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3293)
| at org.eclipse.jface.window.Window.runEventLoop(Window.java:820)
| at org.eclipse.jface.window.Window.open(Window.java:796)
| at org.eclipse.ui.actions.NewWizardAction.run(NewWizardAction.java:182)
| at org.eclipse.jface.action.Action.runWithEvent(Action.java:498)
| at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:546)
| at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:490)
| at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:402)
| at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
| at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:938)
| at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3682)
| at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3293)
| at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2389)
| at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2353)
| at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2219)
| at org.eclipse.ui.internal.Workbench$4.run(Workbench.java:466)
| at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:289)
| at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:461)
| at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
| at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:106)
| at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:169)
| at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:106)
| at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:76)
| at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:363)
| at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:176)
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
| at java.lang.reflect.Method.invoke(Unknown Source)
| at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:508)
| at org.eclipse.equinox.launcher.Main.basicRun(Main.java:447)
| at org.eclipse.equinox.launcher.Main.run(Main.java:1173)
|
if i do that procedure with other web services i works fine. can't i access the bpel process that way? what do i have to do, to start the bpel process form the servlet and to get the response of the process and present it in an jsp.
thanks for your help!!!
greetings stefan
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4186678#4186678
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4186678
17 years, 5 months
[JBoss jBPM] - How to invoke rules(drools) from a jBPM
by rinki
Hello,
I am using eclipse3.4, jbpm-jpdl-3.2.3, and drools-5.0.0.MR2-bin.
I was trying to invoke rules from from my jbpm project.
I am geting the below error:
8:21:31,500 [main] INFO JbpmConfiguration : using jbpm configuration resource 'jbpm.cfg.xml'
18:21:31,515 [main] DEBUG JbpmConfiguration : loading defaults in jbpm configuration
18:21:31,718 [main] DEBUG ObjectFactoryImpl : adding object info 'default.jbpm.context'
18:21:31,718 [main] DEBUG ObjectFactoryImpl : adding object info 'resource.hibernate.cfg.xml'
18:21:31,718 [main] DEBUG ObjectFactoryImpl : adding object info 'resource.business.calendar'
18:21:31,718 [main] DEBUG ObjectFactoryImpl : adding object info 'resource.default.modules'
18:21:31,718 [main] DEBUG ObjectFactoryImpl : adding object info 'resource.converter'
18:21:31,718 [main] DEBUG ObjectFactoryImpl : adding object info 'resource.action.types'
18:21:31,718 [main] DEBUG ObjectFactoryImpl : adding object info 'resource.node.types'
18:21:31,718 [main] DEBUG ObjectFactoryImpl : adding object info 'resource.parsers'
18:21:31,718 [main] DEBUG ObjectFactoryImpl : adding object info 'resource.varmapping'
18:21:31,718 [main] DEBUG ObjectFactoryImpl : adding object info 'resource.mail.templates'
18:21:31,734 [main] DEBUG ObjectFactoryImpl : adding object info 'jbpm.byte.block.size'
18:21:31,734 [main] DEBUG ObjectFactoryImpl : adding object info 'jbpm.task.instance.factory'
18:21:31,734 [main] DEBUG ObjectFactoryImpl : adding object info 'jbpm.variable.resolver'
18:21:31,734 [main] DEBUG ObjectFactoryImpl : adding object info 'jbpm.mail.smtp.host'
18:21:31,734 [main] DEBUG ObjectFactoryImpl : adding object info 'jbpm.mail.address.resolver'
18:21:31,734 [main] DEBUG ObjectFactoryImpl : adding object info 'jbpm.mail.from.address'
18:21:31,750 [main] DEBUG ObjectFactoryImpl : adding object info 'jbpm.job.executor'
18:21:31,750 [main] DEBUG JbpmConfiguration : loading specific configuration...
18:21:31,750 [main] DEBUG ObjectFactoryImpl : adding object info 'jbpmConfiguration'
18:21:31,765 [main] INFO StaleObjectLogConfigurer : stale object exceptions will be hidden from logging
18:21:31,859 [main] DEBUG JpdlParser$JpdlEntityResolver : resolving schema reference publicId(null) systemId(http://jbpm.org/jpdl-3.2.xsd)
18:21:31,859 [main] DEBUG JpdlParser$JpdlEntityResolver : providing input source to local 'jpdl-3.2.xsd' resource
18:21:32,140 [main] DEBUG GraphElement : event 'process-start' on 'ProcessDefinition(JbpmDroolsExample)' for 'Token(/)'
18:21:32,156 [main] DEBUG GraphElement : event 'before-signal' on 'StartState(start)' for 'Token(/)'
18:21:32,156 [main] DEBUG GraphElement : event 'node-leave' on 'StartState(start)' for 'Token(/)'
18:21:32,156 [main] DEBUG GraphElement : event 'transition' on 'Transition(148cc8c)' for 'Token(/)'
18:21:32,156 [main] DEBUG GraphElement : event 'node-enter' on 'Node(ship)' for 'Token(/)'
18:21:32,156 [main] DEBUG GraphElement : executing action 'action[fireRules]'
18:21:32,156 [main] DEBUG Token : token[0] is locked by token[0]
java.lang.NullPointerException
at java.io.Reader.(Reader.java:61)
at java.io.InputStreamReader.(InputStreamReader.java:55)
at com.sample.action.FireRulesActionHandler.readRule(FireRulesActionHandler.java:44)
at com.sample.action.FireRulesActionHandler.execute(FireRulesActionHandler.java:28)
at org.jbpm.graph.def.Action.execute(Action.java:122)
at org.jbpm.graph.def.GraphElement.executeAction(GraphElement.java:259)
at org.jbpm.graph.def.GraphElement.executeActions(GraphElement.java:215)
at org.jbpm.graph.def.GraphElement.fireAndPropagateEvent(GraphElement.java:185)
at org.jbpm.graph.def.GraphElement.fireEvent(GraphElement.java:169)
at org.jbpm.graph.def.Node.enter(Node.java:302)
at org.jbpm.graph.def.Transition.take(Transition.java:151)
at org.jbpm.graph.def.Node.leave(Node.java:393)
at org.jbpm.graph.node.StartState.leave(StartState.java:70)
at org.jbpm.graph.exe.Token.signal(Token.java:192)
at org.jbpm.graph.exe.Token.signal(Token.java:140)
at org.jbpm.graph.exe.ProcessInstance.signal(ProcessInstance.java:270)
at com.sample.test.TestDroolsInvocation.main(TestDroolsInvocation.java:17)
18:21:32,202 [main] DEBUG Token : token[0] is unlocked by token[0]
18:21:32,218 [main] DEBUG GraphElement : event 'node-leave' on 'Node(ship)' for 'Token(/)'
18:21:32,218 [main] DEBUG GraphElement : event 'transition' on 'Transition(6d084b)' for 'Token(/)'
18:21:32,218 [main] DEBUG GraphElement : event 'node-enter' on 'EndState(end)' for 'Token(/)'
18:21:32,218 [main] DEBUG GraphElement : event 'process-end' on 'ProcessDefinition(JbpmDroolsExample)' for 'Token(/)'
18:21:32,218 [main] DEBUG GraphElement : event 'after-signal' on 'StartState(start)' for 'Token(/)'
Ended!!!
Even when I am hard coding the .drl path its not being picked.
Any help will be greatly appreciated.
Regards,
Ruchika
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4186676#4186676
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4186676
17 years, 5 months