Questo contenuto non è disponibile nella lingua selezionata.

Appendix C. Camel Integration


C.1. Example Configuration for Camel Integration

Users running JBoss BRMS with Camel inside a application server need to bundle their own web app to avoid conflicts between the dependencies of different versions of CXF on the classpath.
The web app should include the following files in the Drools-camel-server/src/main/resources/ directory:
  • beans.xml
  • camel-server.xml
  • knowledge-server.xml
  • soap-wsdl
  • test.drl

Example C.1. beans.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"
    default-autowire="byName">


  <!-- loads the kbases and ksessions into the ApplicationContext -->
  <import resource="classpath:knowledge-services.xml" />

  <!-- Builds the routes that makes the ksessesions available as services -->
  <import resource="classpath:camel-server.xml" />

</beans>

Copy to Clipboard Toggle word wrap

Example C.2. camel-server.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:cxf="http://camel.apache.org/schema/cxf"
       xmlns:jaxrs="http://cxf.apache.org/jaxrs"
       xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
">

  <import resource="classpath:META-INF/cxf/cxf.xml" />
  <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

  <!--
! If you are running on JBoss you will need to copy a camel-jboss.jar into the lib and set this classloader configuration
| http://camel.apache.org/camel-jboss.html
<bean id="jbossResolver" class="org.apache.camel.jboss.JBossPackageScanClassResolver"/>
-->

  <!--
! Define the server end point.
! Copy and paste this element, changing id and the address, to expose services on different urls.
! Different Camel routes can handle different end point paths.
-->
  <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>

  <cxf:cxfEndpoint id="soapServer"
            address="/soap"
             serviceName="ns:CommandExecutor"
             endpointName="ns:CommandExecutorPort"
          wsdlURL="soap.wsdl"
          xmlns:ns="http://soap.jax.drools.org/" >
    <cxf:properties>
      <entry key="dataFormat" value="MESSAGE"/>
      <entry key="defaultOperationName" value="execute"/>
    </cxf:properties>
  </cxf:cxfEndpoint>

  <!-- 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>

    <route>
      <from uri="cxf://bean://soapServer"/>
      <policy ref="droolsPolicy">
        <unmarshal ref="xstream" />
        <to uri="drools:node1/ksession1" />
        <marshal ref="xstream" />
      </policy>
    </route>

  </camelContext>

</beans>

Copy to Clipboard Toggle word wrap

Example C.3. knowledge-server.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:drools="http://drools.org/schema/drools-spring"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://drools.org/schema/drools-spring http://drools.org/schema/drools-spring-1.3.0.xsd">

  <drools:grid-node id="node1"/>

  <drools:kbase id="kbase1" node="node1">
    <drools:resources>
      <drools:resource type="DRL" source="classpath:test.drl"/>
    </drools:resources>
  </drools:kbase>

  <drools:ksession id="ksession1" type="stateless" kbase="kbase1" node="node1"/>

</beans>         

Copy to Clipboard Toggle word wrap

Example C.4. soap-wsdl

         
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="CommandExecutor" targetNamespace="http://soap.jax.drools.org/" xmlns:ns1="http://cxf.apache.org/bindings/xformat" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://soap.jax.drools.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <wsdl:types>
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://soap.jax.drools.org/" xmlns:tns="http://soap.jax.drools.org/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="execute" type="tns:execute"/>
<xsd:complexType name="execute">
<xsd:sequence>
<xsd:element minOccurs="0" name="arg0"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="executeResponse" type="tns:executeResponse"/>
<xsd:complexType name="executeResponse">
<xsd:sequence>
<xsd:element minOccurs="0" name="return" type="xsd:anyType"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
  </wsdl:types>
  <wsdl:message name="execute">
    <wsdl:part element="tns:execute" name="parameters">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="executeResponse">
    <wsdl:part element="tns:executeResponse" name="parameters">
    </wsdl:part>
  </wsdl:message>
  <wsdl:portType name="CommandExecutorPortType">
    <wsdl:operation name="execute">
      <wsdl:input message="tns:execute" name="execute">
    </wsdl:input>
      <wsdl:output message="tns:executeResponse" name="executeResponse">
    </wsdl:output>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="CommandExecutorSoapBinding" type="tns:CommandExecutorPortType">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="execute">
      <soap:operation soapAction="" style="document"/>
      <wsdl:input name="execute">
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output name="executeResponse">
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="CommandExecutor">
    <wsdl:port binding="tns:CommandExecutorSoapBinding" name="CommandExecutorPort">
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>         

Copy to Clipboard Toggle word wrap
An example test.drl is provided for testing purposes.

Example C.5. test.drl

/*
 * Copyright 2010 JBoss Inc
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.test

declare Message
   text : String
end

query "get All Messages"
    $m : Message()
end

rule "echo" dialect "mvel"
when
   $m : Message()
then
    $m.text = "echo:" + $m.text;
end         

Copy to Clipboard Toggle word wrap
The web app should also include a web.xml file in the Drools-camel-server/src/main/webapp/WEB-INF/ directory:

Example C.6. web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:beans.xml</param-value>
  </context-param>

  <listener>
    <listener-class>
      org.springframework.web.context.ContextLoaderListener
    </listener-class>
  </listener>

  <servlet>
    <display-name>CXF Servlet</display-name>
    <servlet-name>CXFServlet</servlet-name>
    <servlet-class>
      org.apache.cxf.transport.servlet.CXFServlet
    </servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>CXFServlet</servlet-name>
    <url-pattern>/kservice/*</url-pattern>
  </servlet-mapping>

  <session-config>
    <session-timeout>10</session-timeout>
  </session-config>
</web-app>         

Copy to Clipboard Toggle word wrap
For further details about Apache Camel, please refer to the Apache Camel Documentation

Torna in cima
Red Hat logoGithubredditYoutubeTwitter

Formazione

Prova, acquista e vendi

Community

Informazioni sulla documentazione di Red Hat

Aiutiamo gli utenti Red Hat a innovarsi e raggiungere i propri obiettivi con i nostri prodotti e servizi grazie a contenuti di cui possono fidarsi. Esplora i nostri ultimi aggiornamenti.

Rendiamo l’open source più inclusivo

Red Hat si impegna a sostituire il linguaggio problematico nel codice, nella documentazione e nelle proprietà web. Per maggiori dettagli, visita il Blog di Red Hat.

Informazioni su Red Hat

Forniamo soluzioni consolidate che rendono più semplice per le aziende lavorare su piattaforme e ambienti diversi, dal datacenter centrale all'edge della rete.

Theme

© 2025 Red Hat