1 Reply Latest reply on Sep 15, 2013 5:32 AM by Claus Ibsen

    Problem with drools camel endpoint

    A Majewski Newbie

      In our project we trying to use Drools together with camel. We followed examples provided in the documentation as well as FuseByExample(https://github.com/FuseByExample/camel-drools-example). Today I found out that DroolProducer seems to be loosing all the headers after the Camel Exchange is passed vi drools endpoint. Then I looked into the source code.

       

       

      <code>

       

       

      package org.drools.camel.component;

       

      import java.util.Arrays;

       

      import org.apache.camel.Endpoint;

      import org.apache.camel.Exchange;

      import org.apache.camel.RuntimeCamelException;

      import org.apache.camel.impl.DefaultProducer;

      import org.drools.command.Command;

      import org.drools.command.impl.GenericCommand;

      import org.drools.command.runtime.BatchExecutionCommandImpl;

      import org.drools.core.util.StringUtils;

      import org.drools.grid.GridNode;

      import org.drools.runtime.CommandExecutor;

      import org.drools.runtime.ExecutionResults;

       

      public class DroolsExecuteProducer extends DefaultProducer {

       

          DroolsEndpoint de;

       

          public DroolsExecuteProducer(Endpoint endpoint,

                                       GridNode node) {

              super( endpoint );

              de = (DroolsEndpoint) endpoint;

          }

       

          public void process(Exchange exchange) throws Exception {

       

              Command<?> cmd = exchange.getIn().getBody( Command.class );

       

              if ( cmd == null ) {

                  throw new RuntimeCamelException( "Body of in message not of the expected type 'org.drools.command.Command' for uri" + de.getEndpointUri() );

              }

       

              if ( !(cmd instanceof BatchExecutionCommandImpl) ) {

                  cmd = new BatchExecutionCommandImpl( Arrays.asList( new GenericCommand< ? >[]{(GenericCommand<?>) cmd} ) );

              }

       

              CommandExecutor exec;

              ExecutionNodePipelineContextImpl droolsContext = exchange.getProperty( "drools-context",

                                                                                         ExecutionNodePipelineContextImpl.class );

              if ( droolsContext != null ) {

                  exec = droolsContext.getCommandExecutor();

              } else {

                  exec = de.getExecutor();

                  if ( exec == null ) {

                      String lookup = exchange.getIn().getHeader( DroolsComponent.DROOLS_LOOKUP,

                                                                      String.class );

                      if ( StringUtils.isEmpty( lookup ) && (cmd instanceof BatchExecutionCommandImpl) ) {

                          lookup = ((BatchExecutionCommandImpl) cmd).getLookup();

                      }

       

                      if ( de.getGridNode() != null && !StringUtils.isEmpty( lookup ) ) {

                          exec = de.getGridNode().get( lookup,

                                                           CommandExecutor.class );

                          if ( exec == null ) {

                              throw new RuntimeException( "ExecutionNode is unable to find ksession=" + lookup + " for uri" + de.getEndpointUri() );

                          }

                      } else {

                          throw new RuntimeException( "No ExecutionNode, unable to find ksession=" + lookup + " for uri" + de.getEndpointUri() );

                      }

                  }

              }

       

              if ( exec == null ) {

                  throw new RuntimeException( "No defined ksession for uri" + de.getEndpointUri() );

              }

       

              ExecutionResults results = exec.execute( (BatchExecutionCommandImpl) cmd );;

              exchange.getOut().setBody( results );

          }

      }

      </code>

       

      http://grepcode.com/file/repository.jboss.org/nexus/content/repositories/releases/org.drools/drools-camel/5.5.0.Final/or…

       

      It seems for me like a bug. My understanding of using an InOut exchange is that the headers from In exchange should be copied out exchange. Could somebody confirm if I am right? And if so I where can i raise a bug for it??