[jboss-svn-commits] JBL Code SVN: r34260 - in labs/jbossrules/trunk/drools-docs/drools-docs-integration/src/main/docbook/en-US/Chapter-Camel: Section-Introduction and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Jul 28 11:14:41 EDT 2010


Author: lucazamador
Date: 2010-07-28 11:14:40 -0400 (Wed, 28 Jul 2010)
New Revision: 34260

Modified:
   labs/jbossrules/trunk/drools-docs/drools-docs-integration/src/main/docbook/en-US/Chapter-Camel/Section-API/Section-CamelRoutesCreation.xml
   labs/jbossrules/trunk/drools-docs/drools-docs-integration/src/main/docbook/en-US/Chapter-Camel/Section-API/Section-SendingMessagesExchanges.xml
   labs/jbossrules/trunk/drools-docs/drools-docs-integration/src/main/docbook/en-US/Chapter-Camel/Section-Introduction/Section-Introduction.xml
Log:
JBRULES-2524 Camel/Spring/OSGi integration documentation
-drools camel documentation updated

Modified: labs/jbossrules/trunk/drools-docs/drools-docs-integration/src/main/docbook/en-US/Chapter-Camel/Section-API/Section-CamelRoutesCreation.xml
===================================================================
--- labs/jbossrules/trunk/drools-docs/drools-docs-integration/src/main/docbook/en-US/Chapter-Camel/Section-API/Section-CamelRoutesCreation.xml	2010-07-28 15:01:04 UTC (rev 34259)
+++ labs/jbossrules/trunk/drools-docs/drools-docs-integration/src/main/docbook/en-US/Chapter-Camel/Section-API/Section-CamelRoutesCreation.xml	2010-07-28 15:14:40 UTC (rev 34260)
@@ -1,24 +1,29 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <section version="5.0"
          xsi:schemaLocation="http://docbook.org/ns/docbook http://www.docbook.org/xml/5.0/xsd/docbook.xsd http://www.w3.org/1999/xlink http://www.docbook.org/xml/5.0/xsd/xlink.xsd"
-         xml:base="../../" xmlns="http://docbook.org/ns/docbook" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xlink="http://www.w3.org/1999/xlink"
-         xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:ns="http://docbook.org/ns/docbook">
+         xml:base="../../" xmlns="http://docbook.org/ns/docbook"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xmlns:xs="http://www.w3.org/2001/XMLSchema"
+         xmlns:xlink="http://www.w3.org/1999/xlink"
+         xmlns:xi="http://www.w3.org/2001/XInclude"
+         xmlns:ns="http://docbook.org/ns/docbook">
   <title>Camel Routes creation</title>
 
   <para>This is the most powerful feature of this integration, because of the
   very large library of <link
   xlink:href="http://camel.apache.org/component.html">Components</link>
-  provided by Camel to build pipelines.</para>
+  provided by Camel to build pipelines. If you check the Camel Components you
+  can see how many integration possibilities are added now to Camel, and if
+  this component doesn’t exists you can create this by your own.</para>
 
   <note>
     <para>A Camel Component is a factory of Endpoint instances</para>
   </note>
 
-  <para>The declaration of a Drools Endpoint needs a few parameters, as shown
-  below:</para>
+  <para>The first step is know how create a Drools endpoint, which has the
+  next syntax</para>
 
-  <para>drools:{0}/{1}?dataFormat={2}</para>
+  <programlisting>drools:{0}/{1}</programlisting>
 
   <para>{0} : Execution Node identifier that was registered in the
   CamelContext</para>
@@ -26,29 +31,107 @@
   <para>{1} : Knowledge Session identifier that was registered in the
   Execution Node with identifier {0}</para>
 
-  <para>{2} : XML command transformer that is going to be used. Currently, we
-  provide three implementations: drools-xstream, drools-jaxb and
-  drools-json.</para>
-
   <para></para>
 
-  <para>The most important thing in this section is to know how to create your
-  Drools Endpoint, best shown in an example:</para>
+  <para>Now that you know how define a drools endpoint, you can create your
+  routes and add them to the Camel Context</para>
 
   <programlisting role="JAVA">RouteBuilder rb = new RouteBuilder() {
    public void configure() throws Exception {
-      from("direct:with-session-xstream").to("drools:sm/ksession1?dataFormat=drools-xstream");
+      from("direct:test-with-session").policy(new DroolsPolicy()).unmarshal("xstream").to("drools:node/ksession1").marshal("xstream");
    }
 };
 camelContext.addRoutes(rb);</programlisting>
 
-  <para>In this example we created a simple route with a <link
+  <para><note>
+       <para>Camel Drools Policy is used to add Drools support in Camel, what it does is to add interceptors into the camel route to create
+       Camel Processors on the fly and modify the internal navigation route.</para>
+    </note>In this example we created a simple route with a <link
   xlink:href="http://camel.apache.org/direct.html">Direct Endpoint</link> as
   the input and a Drools Endpoint as the output. A Direct input allow us to
   send the commands directly to the next endpoint in the route, invoking their
   consumer, which in this case will process the XML command.</para>
 
-  <note>
-    <para>Bear in mind that when you send a XML command to a route, the format must the same as the dataFormat transformer used in the route creation.</para>
-  </note>
+  <para>But there are several ways to create Drools endpoints, and different
+  configurations to support extra features</para>
+
+  <para></para>
+
+  <section>
+    <title>Programmatically</title>
+
+    <itemizedlist>
+      <listitem>
+        <para>Processing the commands objects directly</para>
+
+        <programlisting>from("direct:test-with-session").to("drools://node/ksession1");</programlisting>
+      </listitem>
+
+      <listitem>
+        <para>Processing the commands in a XML representation, using XStream
+        or JSON as the marshaller/unmarshaller</para>
+
+        <programlisting>from("direct:test-with-session").policy(new DroolsPolicy()).unmarshal("xstream").to("drools:node/ksession1").marshal("xstream");</programlisting>
+
+        <note>
+           <para>To use JSON just change the unmarshall() and marshall() parameter to “json”</para>
+        </note>
+      </listitem>
+
+      <listitem>
+        <para>Using a custom XStream Data Format with your own XStream
+        Converters</para>
+
+        <programlisting>org.apache.camel.model.dataformat.XStreamDataFormat xstreamDataFormat = new org.apache.camel.model.dataformat.XStreamDataFormat();
+xstreamDataFormat.setConverters(Arrays.asList(new String[]{PersonConverter.class.getName()}));
+
+Map dataFormats = new HashMap();
+dataFormats.put("custom-xstream",xstreamDataFormat);
+camelContext.setDataFormats(dataFormats);
+
+from("direct:test-no-session-custom").policy(new DroolsPolicy()).unmarshal("custom-xstream").to("drools:node").marshal("custom-xstream");</programlisting>
+      </listitem>
+
+      <listitem>
+        <para>Using JAXB as the marshaller/unmarshaller</para>
+
+        <programlisting>JaxbDataFormat def = new JaxbDataFormat();
+def.setPrettyPrint(true);
+// Set the package names to be registered by JAXB
+def.setContextPath("org.drools.model:org.drools.pipeline.camel");
+
+from("direct:test-with-session").policy(new DroolsPolicy()).unmarshal(def).to("drools:node/ksession1").marshal(def);</programlisting>
+      </listitem>
+    </itemizedlist>
+  </section>
+
+  <section>
+    <title>Using Spring</title>
+
+    <itemizedlist>
+      <listitem>
+        <para>Simple configuration with XStream</para>
+
+        <para><programlisting>&lt;bean id="droolsPolicy" class="org.drools.camel.component.DroolsPolicy" /&gt;
+  &lt;camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"&gt;
+  &lt;route&gt;
+    &lt;from uri="direct:entryPoint"/&gt;
+    &lt;policy ref="droolsPolicy"&gt;
+      &lt;unmarshal ref="xstream" /&gt;
+      &lt;to uri="drools:node1/ksession1" /&gt;
+      &lt;marshal ref="xstream" /&gt;
+    &lt;/policy&gt;
+  &lt;/route&gt;
+&lt;/camelContext&gt;</programlisting></para>
+      </listitem>
+    </itemizedlist>
+
+    <note>
+       <para>Using spring we can create the same configurations that in the programmatically way.</para>
+    </note>
+
+    <para><note>
+         <para>As you can see, in all this examples we are using Direct Endpoints as the main entry point, but you can use any others of the available Camel Components.</para>
+      </note></para>
+  </section>
 </section>

Modified: labs/jbossrules/trunk/drools-docs/drools-docs-integration/src/main/docbook/en-US/Chapter-Camel/Section-API/Section-SendingMessagesExchanges.xml
===================================================================
--- labs/jbossrules/trunk/drools-docs/drools-docs-integration/src/main/docbook/en-US/Chapter-Camel/Section-API/Section-SendingMessagesExchanges.xml	2010-07-28 15:01:04 UTC (rev 34259)
+++ labs/jbossrules/trunk/drools-docs/drools-docs-integration/src/main/docbook/en-US/Chapter-Camel/Section-API/Section-SendingMessagesExchanges.xml	2010-07-28 15:14:40 UTC (rev 34260)
@@ -1,9 +1,12 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <section version="5.0"
          xsi:schemaLocation="http://docbook.org/ns/docbook http://www.docbook.org/xml/5.0/xsd/docbook.xsd http://www.w3.org/1999/xlink http://www.docbook.org/xml/5.0/xsd/xlink.xsd"
-         xml:base="../../" xmlns="http://docbook.org/ns/docbook" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xlink="http://www.w3.org/1999/xlink"
-         xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:ns="http://docbook.org/ns/docbook">
+         xml:base="../../" xmlns="http://docbook.org/ns/docbook"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xmlns:xs="http://www.w3.org/2001/XMLSchema"
+         xmlns:xlink="http://www.w3.org/1999/xlink"
+         xmlns:xi="http://www.w3.org/2001/XInclude"
+         xmlns:ns="http://docbook.org/ns/docbook">
   <title>Sending messages exchanges</title>
 
   <para>In order to send messages to a Camel Endpoint we need to create a
@@ -18,15 +21,26 @@
   <programlisting role="JAVA">String xml = "&lt;xml&gt;example&lt;/xml&gt;";
 template.requestBody("direct:with-session-xstream", xml);</programlisting>
 
-  <note>
-    <para>When we use commands created with JAXB we need to use a special
-    method to send the JaxbContext to our route. This will be explained in
-    more detail in the Using JAXB section.</para>
-  </note>
-
   <para></para>
 
   <section>
+    <title>Without marshallers</title>
+
+    <para>If you don't want to use marshallers to send the messages, you can
+    send the Commands objects directly but remember that all your own objects
+    must be serializable.</para>
+
+    <para><programlisting>Person person = new Person();
+person.setName("darth");
+InsertObjectCommand cmd = (InsertObjectCommand) CommandFactory.newInsert(person, "vader");
+ExecutionResults response = (ExecutionResults) template.requestBody("direct:test-with-session", cmd);</programlisting></para>
+
+    <note>
+    <para>Remember that to send commands in this way you don't have to create the route using a Drools Policy.</para>
+    </note>
+  </section>
+
+  <section>
     <title>Using XStream</title>
 
     <para>Using XStream To create XML commands with XStream we use the
@@ -72,8 +86,6 @@
     KnowledgeBuilder. In the following example we are going to use a POJO Java
     model and a XSD to duplicate the same model representation.</para>
 
-    <para></para>
-
     <orderedlist>
       <listitem>
         <para>JAXBContext creation:</para>
@@ -85,29 +97,37 @@
 xjcOpts.setSchemaLanguage( Language.XMLSCHEMA );
 JaxbConfiguration jaxbConfiguration = KnowledgeBuilderFactory.newJaxbConfiguration( xjcOpts, "xsd" );
 kbuilder.add( ResourceFactory.newClassPathResource("person.xsd", getClass()), ResourceType.XSD, jaxbConfiguration);</programlisting>
-        <para>Then
-        you need to add your knowledge resources into the kbuilder and create
-        your KnowledgeBase. These steps are the same as those in the Drools
-        Expert documentation. Finally, we are going to create the
+
+        <para>Then you need to add your knowledge resources into the kbuilder
+        and create your KnowledgeBase. These steps are the same as those in
+        the Drools Expert documentation. Finally, we are going to create the
         JAXBContext</para>
 
-        <programlisting role="JAVA">// Add object model to classes array
-List&lt;String&gt; classesName = new ArrayList&lt;String&gt;();
-classesName.add("org.drools.model.AddressType");
-classesName.add("org.drools.model.ObjectFactory");
-classesName.add("org.drools.model.Person");
+        <programlisting role="JAVA">JAXBContext jaxbContext = null;
+JaxbDataFormat def = new JaxbDataFormat();
+def.setPrettyPrint(true);
+// Set the package names to be registered by JAXB
+def.setContextPath("org.drools.model:org.drools.pipeline.camel");
 
+// create a jaxbContext for the test to use outside of Camel.
+StatefulKnowledgeSession ksession1 = (StatefulKnowledgeSession) node.get(DirectoryLookupFactoryService.class).lookup("ksession1");
+KnowledgeBase kbase = ksession1.getKnowledgeBase();
+ClassLoader originalCl = Thread.currentThread().getContextClassLoader();
 try {
-   jaxbContext = KnowledgeBuilderHelper.newJAXBContext( classesName.toArray(new String[classesName.size()]), kbase );
-}
-catch (Exception e) {
-   LOG.info("Errors while creating JAXB Context.", e);
-   throw new RuntimeException(e);
+    Thread.currentThread().setContextClassLoader(((ReteooRuleBase) ((KnowledgeBaseImpl) kbase).getRuleBase()).getRootClassLoader());
+    def = DroolsPolicy.augmentJaxbDataFormatDefinition(def);
+    org.apache.camel.converter.jaxb.JaxbDataFormat jaxbDataformat = (org.apache.camel.converter.jaxb.JaxbDataFormat) def.getDataFormat(this.context.getRoutes().get(0).getRouteContext());
+    jaxbContext = jaxbDataformat.getContext();
+} catch (JAXBException e) {
+    throw new RuntimeException(e);
+} finally {
+    Thread.currentThread().setContextClassLoader(originalCl);
 }</programlisting>
       </listitem>
 
       <listitem>
         <para>BatchExecutionCommand marshalling</para>
+
         <programlisting role="JAVA">StringWriter xmlReq = new StringWriter();
 Marshaller marshaller = jaxbContext.createMarshaller();
 marshaller.setProperty("jaxb.formatted.output", true);
@@ -117,12 +137,8 @@
       <listitem>
         <para>Sending the commands through the ProducerTemplate</para>
 
-        <para>In this step we need to use another ProducerTemplate method
-        called requestBodyAndHeader() because the Drools Component needs to
-        know which JAXBContext must use to unmarshall the XML.</para>
-
         <programlisting role="JAVA">String xml = xmlReq.toString();
-byte[] xmlOutput = (byte[]) template.requestBodyAndHeader("direct:test-with-session", xmlReq.toString(), "jaxb-context", jaxbContext);</programlisting>
+byte[] xmlOutput = (byte[]) template.requestBodyAndHeader("direct:test-with-session", xmlReq.toString());</programlisting>
       </listitem>
 
       <listitem>
@@ -139,7 +155,8 @@
     <para></para>
 
     <note>
-      <para>The XML output conversion is not required, but is recommended to have a more legible data output.</para>
+      <para>The XML output conversion is not required, but is recommended to
+      have a more legible data output.</para>
     </note>
 
     <para></para>

Modified: labs/jbossrules/trunk/drools-docs/drools-docs-integration/src/main/docbook/en-US/Chapter-Camel/Section-Introduction/Section-Introduction.xml
===================================================================
--- labs/jbossrules/trunk/drools-docs/drools-docs-integration/src/main/docbook/en-US/Chapter-Camel/Section-Introduction/Section-Introduction.xml	2010-07-28 15:01:04 UTC (rev 34259)
+++ labs/jbossrules/trunk/drools-docs/drools-docs-integration/src/main/docbook/en-US/Chapter-Camel/Section-Introduction/Section-Introduction.xml	2010-07-28 15:14:40 UTC (rev 34260)
@@ -1,9 +1,12 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <section version="5.0"
          xsi:schemaLocation="http://docbook.org/ns/docbook http://www.docbook.org/xml/5.0/xsd/docbook.xsd http://www.w3.org/1999/xlink http://www.docbook.org/xml/5.0/xsd/xlink.xsd"
-         xml:base="../../" xmlns="http://docbook.org/ns/docbook" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xlink="http://www.w3.org/1999/xlink"
-         xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:ns="http://docbook.org/ns/docbook">
+         xml:base="../../" xmlns="http://docbook.org/ns/docbook"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xmlns:xs="http://www.w3.org/2001/XMLSchema"
+         xmlns:xlink="http://www.w3.org/1999/xlink"
+         xmlns:xi="http://www.w3.org/2001/XInclude"
+         xmlns:ns="http://docbook.org/ns/docbook">
   <title>Introduction</title>
 
   <para>The Apache Camel integration allows us to interact with a Drools
@@ -22,8 +25,11 @@
   send the execution result to another entry point. To name a few, JMS
   queue/Atom Feed/Mina connection/a Mail/etc. As you can see, this brings a
   more powerful interoperability mechanism to integrate your application with
-  Drools</para>
+  Drools.</para>
 
+  <para>Actually Drools is using Camel 2.4.0 that allows a more strong
+  internal integration between them.</para>
+
   <section>
     <title>Architecture</title>
 



More information about the jboss-svn-commits mailing list