Re: [rules-users] Insert a fact into drools server from a web application or java application
I have progressed with this a little further, however I am wondering if anyone know of an end to end example using drools server and jsp web interfaces to display what is in the knowledge base and add to the knowledge base... I got the httpclient to work, but I am looking for what the suggested design pattern and best practices are for using drools server with the web. -- View this message in context: http://drools.46999.n3.nabble.com/Insert-a-fact-into-drools-server-from-a-web-application-or-java-application-tp3214229p3278773.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] Insert a fact into drools server from a web application or java application
I got the 5.2 drools-server working with xstream. You can see my code here: http://drools.46999.n3.nabble.com/rules-users-how-to-invoke-rest-service-on-drools-server-with-serialized-objects-td3179834.html at the time of that post, i hadn't figured out how to get the return objects. this post covers how to do that: http://drools.46999.n3.nabble.com/drools-server-empty-response-body-td3192475.html -- View this message in context: http://drools.46999.n3.nabble.com/Insert-a-fact-into-drools-server-from-a-web-application-or-java-application-tp3214229p3244021.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] Insert a fact into drools server from a web application or java application
Thank You I had been looking at your post actually, trying to understand the difference between the two technologies... I will take a look at the xstream and will post if I figure out what the issue is with the jaxb... -- View this message in context: http://drools.46999.n3.nabble.com/Insert-a-fact-into-drools-server-from-a-web-application-or-java-application-tp3214229p3244078.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] Insert a fact into drools server from a web application or java application
I was looking at you code and I was wondering if there is a reason that you did not use the new httpcomponents for the httpclient? -- View this message in context: http://drools.46999.n3.nabble.com/Insert-a-fact-into-drools-server-from-a-web-application-or-java-application-tp3214229p3244182.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] Insert a fact into drools server from a web application or java application
Well after modifying some of the code that you gave and setting the drools server back to using xstream... so basically, the exact code that I posted but with the xstream marshaller... the code works... so I am very confused with what the deal is with the jaxb situation I would think maybe that it has something to do with how to configure the drools server for jaxb correctly??? -- View this message in context: http://drools.46999.n3.nabble.com/Insert-a-fact-into-drools-server-from-a-web-application-or-java-application-tp3214229p3244282.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] Insert a fact into drools server from a web application or java application
So you did not create the classes defining the XML structure from an XMl schema using xjc? You might get around this by adding, to each package where one of those files is located, a file called jaxb.index containing a newline separated list of class names relative to the very same containing package. So, if you have a class a.b.c.Doo, the jaxb.index in a.b.c contains a line Foo. See the javadoc for javax.xml.bind.JAXBContext. Try to marshal your object locally by creating a JAXBContext, a Marshaller from it, and marshal to System.out. -W On 6 August 2011 00:13, kkelleyjr karl.kelley...@gmail.com wrote: Thank you for the response... Unfortunately, I have read this and still kinda lost on what any of that means... Is there an example with drools that I can look at to help me see this a little better? -- View this message in context: http://drools.46999.n3.nabble.com/Insert-a-fact-into-drools-server-from-a-web-application-or-java-application-tp3214229p3229963.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 ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Insert a fact into drools server from a web application or java application
Thank you for the response... Unfortunately, I have read this and still kinda lost on what any of that means... Is there an example with drools that I can look at to help me see this a little better? -- View this message in context: http://drools.46999.n3.nabble.com/Insert-a-fact-into-drools-server-from-a-web-application-or-java-application-tp3214229p3229963.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] Insert a fact into drools server from a web application or java application
The error message suggests to me that there is no class ObjectFactory, or not where it ought to be, for JAXB to be happy. If you JAXB-annotate your Java classes by hand, you'll also have to write an ObjectFactory.java. A little info can be found in my JAXB tutorialhttp://jaxb.java.net/tutorial/section_6_2_4-The-Object-Factory-XmlRegistry-XmlElementDecl.html#The%20Object%20Factory:%20XmlRegistry,%20XmlElementDecl. Also, you could apply xjc to an XML Schema to learn how it's done ;-) -W On 2 August 2011 19:11, kkelleyjr karl.kelley...@gmail.com wrote: Update: So I have the following as code that I found in a blog by salaboy... ListString myDomainClasses = new ArrayListString(); myDomainClasses.add(com.test.TestFact); // I need to create a JAXB context including my domain classes // to be able to create a JAXB representation to send to the server JAXBContext jaxbContext = DroolsJaxbContextHelper.createDroolsJaxbContext(myDomainClasses, null); TestFact test = new TestFact(); // Once I get my object I need to create // some commands to execute on the server // Here I include a reference to the session that // I define in my Knowledge Context Profile ListCommand listOCommand = new ArrayListCommand(); listOCommand.add(new InsertObjectCommand(test, testFact)); BatchExecutionCommand cmd = CommandFactory.newBatchExecution(listOCommand, ksession1); // Once I get all I need to send to the server, // I need to use the JAXB context // to obtain the JAXB representation. StringWriter xmlReq = new StringWriter(); javax.xml.bind.Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(jaxb.formatted.output, true); marshaller.marshal(cmd, xmlReq); // I create a HTTPClient to interact with the // server via REST (HTTP POST) DefaultHttpClient httpClient = new DefaultHttpClient(); HttpParams params = new BasicHttpParams(); params.setParameter(ClientPNames.DEFAULT_HOST, localhost); //Print the JAXB xml that we will send to the server System.out.println(xmlReq.toString()); // Send the Commands JAXB representation to the server for execution HttpPost postMethod = new HttpPost(http://localhost:8080/MyService/kservice/rest/execute;); HttpParams p = new BasicHttpParams(); p.setParameter(command, xmlReq.toString()); postMethod.setParams(p); HttpResponse response = httpClient.execute(postMethod); System.out.println(response); Now I had to change a few things from the blog but it should be basically the same as the post... I get the following exception... 1872701 [http-8080-1] ERROR processor.DefaultErrorHandler - Failed delivery for exchangeId: 839c6b11-3c2a-4106-9118-56417edfbab1. Exhausted after delivery attempt: 1 caught: java.io.IOException: null doesnt contain ObjectFactory.class or jaxb.index java.io.IOException: null doesnt contain ObjectFactory.class or jaxb.index at org.apache.camel.util.IOHelper.createIOException(IOHelper.java:80) at org.apache.camel.util.IOHelper.createIOException(IOHelper.java:72) at org.apache.camel.converter.jaxb.JaxbDataFormat.unmarshal(JaxbDataFormat.java:151) at org.apache.camel.processor.UnmarshalProcessor.process(UnmarshalProcessor.java:51) Thanks for any advice on this matter... -- View this message in context: http://drools.46999.n3.nabble.com/Insert-a-fact-into-drools-server-from-a-web-application-or-java-application-tp3214229p3219571.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 ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Insert a fact into drools server from a web application or java application
Update: So I have the following as code that I found in a blog by salaboy... ListString myDomainClasses = new ArrayListString(); myDomainClasses.add(com.test.TestFact); // I need to create a JAXB context including my domain classes // to be able to create a JAXB representation to send to the server JAXBContext jaxbContext = DroolsJaxbContextHelper.createDroolsJaxbContext(myDomainClasses, null); TestFact test = new TestFact(); // Once I get my object I need to create // some commands to execute on the server // Here I include a reference to the session that // I define in my Knowledge Context Profile ListCommand listOCommand = new ArrayListCommand(); listOCommand.add(new InsertObjectCommand(test, testFact)); BatchExecutionCommand cmd = CommandFactory.newBatchExecution(listOCommand, ksession1); // Once I get all I need to send to the server, // I need to use the JAXB context // to obtain the JAXB representation. StringWriter xmlReq = new StringWriter(); javax.xml.bind.Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(jaxb.formatted.output, true); marshaller.marshal(cmd, xmlReq); // I create a HTTPClient to interact with the // server via REST (HTTP POST) DefaultHttpClient httpClient = new DefaultHttpClient(); HttpParams params = new BasicHttpParams(); params.setParameter(ClientPNames.DEFAULT_HOST, localhost); //Print the JAXB xml that we will send to the server System.out.println(xmlReq.toString()); // Send the Commands JAXB representation to the server for execution HttpPost postMethod = new HttpPost(http://localhost:8080/MyService/kservice/rest/execute;); HttpParams p = new BasicHttpParams(); p.setParameter(command, xmlReq.toString()); postMethod.setParams(p); HttpResponse response = httpClient.execute(postMethod); System.out.println(response); Now I had to change a few things from the blog but it should be basically the same as the post... I get the following exception... 1872701 [http-8080-1] ERROR processor.DefaultErrorHandler - Failed delivery for exchangeId: 839c6b11-3c2a-4106-9118-56417edfbab1. Exhausted after delivery attempt: 1 caught: java.io.IOException: null doesnt contain ObjectFactory.class or jaxb.index java.io.IOException: null doesnt contain ObjectFactory.class or jaxb.index at org.apache.camel.util.IOHelper.createIOException(IOHelper.java:80) at org.apache.camel.util.IOHelper.createIOException(IOHelper.java:72) at org.apache.camel.converter.jaxb.JaxbDataFormat.unmarshal(JaxbDataFormat.java:151) at org.apache.camel.processor.UnmarshalProcessor.process(UnmarshalProcessor.java:51) Thanks for any advice on this matter... -- View this message in context: http://drools.46999.n3.nabble.com/Insert-a-fact-into-drools-server-from-a-web-application-or-java-application-tp3214229p3219571.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
[rules-users] Insert a fact into drools server from a web application or java application
Ok, I have read the documentation like a million times. I have looked at all the examples. Yet I still can not figure out how to add a fact to the drools server ksession1 from a web application or a java application. I have got the server to work. I have even got the soapUI to work. now I want to add a fact from my own client. My issue is that I need to add a facts that has maps and list in the pojo. how can I just add the pojo to the ksession1? Is there an example that is out there that I have not found? It seems simple, but I just do not understand... can someone provide some additional help, please? -- View this message in context: http://drools.46999.n3.nabble.com/Insert-a-fact-into-drools-server-from-a-web-application-or-java-application-tp3214229p3214229.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