Re: [rules-users] Sending requests to the Drools Execution Server from an external source

2012-01-06 Thread JeffMax
I am not sure, have you looked in the log file of the drools server
(catalina.out if you are running on tomcat)? Also have you configured the
server to consume JSON rather than XML?


On Fri, Jan 6, 2012 at 1:26 PM, kofibentum [via Drools] 
ml-node+s46999n3638561...@n3.nabble.com wrote:

 Thanks a lot for your post. It works for me. But why does curl not return
 any message when I post the folowing json formatted command:

  curl  -v -H Content-Type: text/plain --data
 {\batch-execution\:{\commands\:[{\insert\:{\out-identifier\:\message\,\object\:{\org.test.Message\:{\text\:\Hello\,{\fire-all-rules\:\\}]}}
 http://localhost:8080/drools-server/kservice/rest/execute

 --
  If you reply to this email, your message will be added to the discussion
 below:

 http://drools.46999.n3.nabble.com/Sending-requests-to-the-Drools-Execution-Server-from-an-external-source-tp1776466p3638561.html
  To unsubscribe from Sending requests to the Drools Execution Server from
 an external source, click 
 herehttp://drools.46999.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_codenode=1776466code=amVmZm1heEBnbWFpbC5jb218MTc3NjQ2NnwxNDc1NzMzMzc4
 .
 NAMLhttp://drools.46999.n3.nabble.com/template/NamlServlet.jtp?macro=macro_viewerid=instant_html%21nabble%3Aemail.namlbase=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.InstantMailNamespacebreadcrumbs=instant+emails%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml



--
View this message in context: 
http://drools.46999.n3.nabble.com/Sending-requests-to-the-Drools-Execution-Server-from-an-external-source-tp1776466p3638618.html
Sent from the Drools: User forum mailing list archive at Nabble.com.___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Sending requests to the Drools Execution Server from an external source

2012-01-06 Thread JeffMax
It has been a while since I worked with this and it may have been updated.
This might not be your issue but I my camel-server.xml looks like this,
note that the converters and aliases tags are not necessary, but if you
find yourself needing an xstream alias or convert, that is where you would
configure them. I would check your server log file too.

  dataFormats
   xstream id=xstream-json driver=json
   converters
   /converters
   aliases
   /aliases
   /xstream
  /dataFormats

  route
 from uri=cxfrs://bean://rsServer/
 policy ref=droolsPolicy
unmarshal ref=xstream-json /
to uri=drools:node1/ksession1 /
marshal ref=xstream-json /
 /policy
 /route



On Fri, Jan 6, 2012 at 2:03 PM, kofibentum [via Drools] 
ml-node+s46999n3638652...@n3.nabble.com wrote:

 Yes I am using tomcat 6. Can you point me to the part of the documentation
 that has instructions for configuring the server to consume json? I have
 not come across that yet.

 --
  If you reply to this email, your message will be added to the discussion
 below:

 http://drools.46999.n3.nabble.com/Sending-requests-to-the-Drools-Execution-Server-from-an-external-source-tp1776466p3638652.html
  To unsubscribe from Sending requests to the Drools Execution Server from
 an external source, click 
 herehttp://drools.46999.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_codenode=1776466code=amVmZm1heEBnbWFpbC5jb218MTc3NjQ2NnwxNDc1NzMzMzc4
 .
 NAMLhttp://drools.46999.n3.nabble.com/template/NamlServlet.jtp?macro=macro_viewerid=instant_html%21nabble%3Aemail.namlbase=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.InstantMailNamespacebreadcrumbs=instant+emails%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml



--
View this message in context: 
http://drools.46999.n3.nabble.com/Sending-requests-to-the-Drools-Execution-Server-from-an-external-source-tp1776466p3638685.html
Sent from the Drools: User forum mailing list archive at Nabble.com.___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] RuleFlow only calling first RuleFlowGroup when called through drools-server

2011-02-18 Thread JeffMax

This is actually a problem with using Drools Flow in stateless sessions in
general, regardless of the Drools-Server.

See this post for details:
http://drools-java-rules-engine.46999.n3.nabble.com/Drools-Flow-within-Stateless-Session-in-Drools-5-1-td2094451.html#a2105016

This may be fixed in the trunk. I am not sure.
-- 
View this message in context: 
http://drools-java-rules-engine.46999.n3.nabble.com/RuleFlow-only-calling-first-RuleFlowGroup-when-called-through-drools-server-tp2514244p2527194.html
Sent from the Drools - User mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] RuleFlow only calling first RuleFlowGroup when called through drools-server

2011-02-18 Thread JeffMax

My experience has been (and I believe the expected behavior of stateful
sessions) is that the state of your working memory will not be cleaned up
between flow executions. If,for example, one flow execution inserts a new
fact into working memory, then a subsequent flow execution would see that
fact in working memory.

For my requirements, which was to use Drools-Server as a stateless, request
- response server, with no shared state between requests, it was necessary
to use a stateless session.

- Jeff
-- 
View this message in context: 
http://drools-java-rules-engine.46999.n3.nabble.com/RuleFlow-only-calling-first-RuleFlowGroup-when-called-through-drools-server-tp2514244p2527353.html
Sent from the Drools - User mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Drools Flow within Stateless Session in Drools 5.1

2011-01-03 Thread JeffMax

Hi,

I have spoken with the Drools developers and they are aware of the problem
and are going to fix it. In my previous post, I mentioned that if you
comment out the line:

wm.setRuleFlowEventSupport(this.ruleFlowEventSupport );

in the function newWorkingMemory() within the file
StatelessKnowledgeSessionImpl.java, it will solve the problem (but
potentially cause others.) 

The reason commenting out that line solves the problem is that the default
constructor for a StatefulKnowledgeSession (which StatelessKnowledgeSession
wraps) sets a Rule Flow event listener which is actually responsible for
making Rule Flows work within Expert. It listens for when a Rule Flow group
is empty, and sends the proper signals for advancing to the next Rule Flow
group. The line in question above is meant to allow any custom Rule Flow
group listeners you might have set on the StatelessSession to work on the
temporary StatefulSession used internally, but unfortunately, it erases the
one set in the StatefulKnowledgeSession constructor that Flow needs to work. 

As I said, I have reported this issue. If you comment out the line, the main
functionality will work (as far as I am able to determine), however no
custom Rule Flow events will work. The real fix will be to merge the two
objects. 

Hope this helped,

Jeff
-- 
View this message in context: 
http://drools-java-rules-engine.46999.n3.nabble.com/Drools-Flow-within-Stateless-Session-in-Drools-5-1-tp2094451p2187696.html
Sent from the Drools - User mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Drools Flow within Stateless Session in Drools 5.1

2010-12-17 Thread JeffMax

Hi,

I have investigated this a little further. Since a stateless session uses a
stateful session internally, I compared the code in the stateless session
implementation that instantiates a stateful session to the regular stateful
session instantiation code. 

In the file StatelessKnowledgeSessionImpl.java, there is a function called
newWorkingMemory(), with the following code:

StatefulKnowledgeSessionImpl ksession = new StatefulKnowledgeSessionImpl(
wm,

  
new KnowledgeBaseImpl( this.ruleBase ) );
 
 ((Globals) wm.getGlobalResolver()).setDelegate(
this.sessionGlobals );
 wm.setKnowledgeRuntime( ksession );
 wm.setWorkingMemoryEventSupport(
this.workingMemoryEventSupport );
 wm.setAgendaEventSupport( this.agendaEventSupport
);
 wm.setRuleFlowEventSupport(
this.ruleFlowEventSupport );

I noticed that if I comment out the last line that calls
setRuleFlowEventSupport, both stateless and stateful sessions work the same
with the test case I described in this post. Does anyone have any idea why
this would be, or what other effects not calling that function will have? 

The background on this is that I am implementing a decision support web
service, where each request is independent. I am interested in the
difference between using a stateless session, and just creating a new
stateful session for each request.

Thanks,

Jeff
-- 
View this message in context: 
http://drools-java-rules-engine.46999.n3.nabble.com/Drools-Flow-within-Stateless-Session-in-Drools-5-1-tp2094451p2105016.html
Sent from the Drools - User mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


[rules-users] Drools Flow within Stateless Session in Drools 5.1

2010-12-15 Thread JeffMax

I am seeing some odd behavior where it seems that inference is not working
when trying to use a flow process within a stateless knowledge session. I
have tried to do the same thing in both stateful and stateless, and the
behavior is different.  It appears that if one rule inserts a fact in its
right hand side that causes another rule in a different flow-group to become
activated, the rule-flow (which should progress to the next flow group) will
not allow that rule to fire if the session is stateless. It is possible I am
confused about how a rule-flow evaluates or the order in which it evaluates
with respect to inference, but it is working as I expected in a stateful
session.

An example:

I have a simple rule flow with two flow-groups, group1 and group2. They are
connected one after the other
in a file with id TestFlow

start-group1 - group2 - end

I then have a simple rules file:

declare Fact1
  num: int
end

declare Fact2
  num: int
end

rule Rule1
ruleflow-group group1
when
Fact1()
then 
System.out.print(FIRING 1);
insert(new Fact2());

end

rule Your Second Rule
ruleflow-group group2
when
Fact2()
then 
System.out.print(FIRING 2);
end


When used in a stateful session, both rules will fire and print their
respective output. In a stateless, the second rule will never fire. To
execute this test, I am using the same code against both a stateless and
stateful session:

FactType fact = kbase.getFactType(org.test, Fact1);
Object one = fact.newInstance();
List cmds = new ArrayList();
cmds.add(CommandFactory.newInsert(one));
cmds.add(CommandFactory.newStartProcess(TestFlow));
cmds.add(CommandFactory.newFireAllRules()); // Only need this in stateful
ksession.execute(CommandFactory.newBatchExecution(cmds));

Does anyone have any suggestions? 
Thanks, 
Jeff

-- 
View this message in context: 
http://drools-java-rules-engine.46999.n3.nabble.com/Drools-Flow-within-Stateless-Session-in-Drools-5-1-tp2094451p2094451.html
Sent from the Drools - User mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


[rules-users] Sending requests to the Drools Execution Server from an external source

2010-10-26 Thread JeffMax

I am just posting this to share my experience setting up the Drools Execution
Server for making requests from a non-Java based service (from the
perspective of a programmer without much Spring, CXF, or Camel experience).

The Drools Execution Server is packaged as a WAR file that can be run in any
Java servlet container (Tomcat/Jetty/JBOSS.) One important thing to know
about it right now is that as of version 5.1, most tutorials out there
except on the Drools Documentation are no longer correct. It used to use a
.properties file and a URL based on the name of the knowledge engine, this
is no longer true. 
I will try to explain how (with quite a bit of hand-waving and wild
guessing) how it works in this tutorial. I would welcome anyone that
understands how Camel and this integration truly works to correct or provide
more useful details on anything I mention here. 

First, to get it running on tomcat:

Unzip the war file and place it in the webapps directory of Tomcat. There is
one thing you have to check (at least for Tomcat):
1) In camel-server.xml, change the line that says address=/kservice/rest
to just address=/rest. The reason for this is that in the web.xml for
the server, kservice is used as the url pattern for  CXF servlet.:

servlet
servlet-nameCXFServlet/servlet-name
display-nameCXF Servlet/display-name
servlet-class
org.apache.cxf.transport.servlet.CXFServlet
/servlet-class
load-on-startup1/load-on-startup
/servlet

servlet-mapping
servlet-nameCXFServlet/servlet-name
url-pattern/kservice/*/url-pattern
/servlet-mapping

If you leave this the way it is, to get to your services, you will need to
go to kservice/kservice/, which is a little redundant. 

With this being done, you should be able to go to
http://localhost:8080/drools-server/kservice/ in your browser and see a list
of services that are available.

The new version of Drools Server uses Apache CXF (a web framework that is an
implementation of JAX-RS), Spring, and Apache Camel. I do not fully
understand how it works, but the basics are that you use the Spring
Container which allows you to declaratively create your objects (or beans)
via xml configuration files (Spring is a huge framework, that was just an
over simplification of how it is being used in this context).  From there
you use CXF to expose a URL which will be used as the endpoint for your
service. Camel grabs the data from this endpoint, and forwards it your
drools session, and then returns the response back out.

Lets look at how this happens in the config (camel-server.xml):

The CXF tag looks like this:

  cxf:rsServer id=rsServer  
address=/rest
serviceClass=org.drools.jax.rs.CommandExecutorImpl
   cxf:providers
   bean class=org.drools.jax.rs.CommandMessageBodyReader/
   /cxf:providers
  /cxf:rsServer  

We see here, it is exposing at /rest a web service that is serviced by the
class CommandExecuctorImpl (there is also that CommandMessageBodyReader, I
do not know exactly what it does)
A quick look into the source for CommandExecutorImpl, we see that it is
class that uses the CXF annotations (that is part of CXF, using annotations
to expose methods as web services) to expose 
the execute method at /execute, to consume text/plain (which was the
source of some of my trouble, see below) through an HTTP POST.  You can also
see that this method is not actually meant to be called because the only
thing that it does is raise an exception stating that fact.


public class CommandExecutorImpl implements CommandExecutor {

public CommandExecutorImpl() {

}

public CommandExecutorImpl(boolean restFlag) {

}   

@POST()
@Path(/execute)
@Consumes(text/plain)
@Produces(text/plain)   
public T T execute(CommandT command) {
throw new UnsupportedOperationException( This should never be
called, as it's handled by camel );
}
}

I believe this is where Camel comes in. Again in the Spring configuration
(camel-server.xml) we have:

  !-- Leave this, as it's needed to make Camel drools aware --
  bean id=droolsPolicy class=org.drools.camel.component.DroolsPolicy /  

  camelContext id=camel xmlns=http://camel.apache.org/schema/spring;
!-- 
 ! Routes incoming messages from end point id=rsServer.
 ! Example route unmarshals the messages with xstream and executes
against ksession1.
 ! Copy and paste this element, changing marshallers and the 'to' uri,
to target different sessions, as needed.
 !--
 
route
   from uri=cxfrs://bean://rsServer/
   policy ref=droolsPolicy
   unmarshal ref=xstream /   
   to uri=drools:node1/ksession1 /
   marshal ref=xstream /
   /policy
/route

  /camelContext

We can see here that we