Petals-SE-Camel 1.4.0+

Features

The component SE Camel embeds the Apache Camel routing engine to execute enterprise integration patterns (EIP) in Petals.

Service Units can be written to describe, for a given provided Petals endpoint, how and where messages should be routed.

Even if it is recommended to route messages toward other Petals services, it is still always possible to exploit Camel transports to integrate with non-Petals external services.

This version must be installed on [Petals ESB 5.4.0]+
Previous service units are no more compliant with this component version and must be migrated. See Migrating service units developed for previous versions
Table of contents
Contributors
No contributors found for: authors on selected page(s)

Introduction

This implementation of the SE Camel uses Apache Camel version 4.0.3.

Routes can be defined using any of the JVM based DSL, as well as using the XML notation.
A Camel route always starts with a from declaration, a consumer, and often ends with one or many to declaration, producers.
Consumers and producers refers to service external to Camel using an URI: Petals services have their own URI scheme identified with petals.

For each provides section, exactly one route must be present and will be activated when a message is received.
Each route can call any service declared in a consumes section.

Consumes corresponds to an operation of a service and have a MEP defined.
Provides corresponds to a service defined with WSDL and for which every operation has one corresponding route.

The terminology used by Camel is apparently counter-intuitive to the one used in JBI terminology: a camel route consumes a service while an SU provides this same service.
This is because from the route point of view, messages arriving to the provided service are then consumed by the rule.
The SOA terminology is sometimes confusing: in the following we will use the general term service and operation interchangeably.

We show in the next section a general overview of a typical Camel Service Unit.

Overview of a Camel Service Unit at Runtime

Each SU has its own Camel context: the Camel context is the runtime entity responsible of executing the routes.
Routes in the same context can refer to each others when needed.

When a JBI exchange arrives for a provided service (an operation), it is transformed to a Camel exchange and dispatched to the route with a petals consumer (in the Camel terminology, i.e. with a from declaration using the petals URI scheme) the service.

When a Camel exchange is dispatched in a route to a petals producer (in the Camel terminology, i.e. with a to declaration using the petals URI scheme), it is transformed to a Petals exchange and sent to the corresponding consumes service.

For details on the transformation, see the section Petals to Camel to Petals below.

Overview of a Camel Service Unit at Implementation Time

Maven Project

When developing with Maven, the pom.xml file must contains the following kind of declarations:

<!-- ... -->

   <!-- We are producing a service unit -->
   <groupId>my.group</groupId>
   <artifactId>my-service-unit</artifactId>
   <version>1.0.0</version>
   <packaging>jbi-service-unit</packaging>

<!-- ... -->

   <dependencies>
      <!-- First a jbi-component dependency to the component (note that it won't provide anything in the classpath!) -->
      <dependency>
         <groupId>org.ow2.petals</groupId>
         <artifactId>petals-se-camel</artifactId>
         <version>1.1.0-SNAPSHOT</version>
         <type>jbi-component</type>
      </dependency>
      <!-- Then a dependency to camel, only if you plan to implement routes in Java -->
      <dependency>
         <groupId>org.apache.camel</groupId>
         <artifactId>camel-core</artifactId>
         <version>2.17.1</version>
         <!-- camel-core is provided by the component! -->
         <scope>provided</scope>
      </dependency>
      <!-- optionally, camel-petals provides some Java helpers in org.ow2.petals.camel.helpers -->
      <dependency>
         <groupId>org.ow2.petals</groupId>
         <artifactId>camel-petals</artifactId>
         <version>1.1.0-SNAPSHOT</version>
         <!-- camel-petals is provided by the component! -->
         <scope>provided</scope>
      </dependency>
      <!-- optionally, petals-se-camel-junit provides some Java testing helpers in org.ow2.petals.camel.junit -->
      <dependency>
         <groupId>org.ow2.petals</groupId>
         <artifactId>petals-se-camel-junit</artifactId>
         <version>1.1.0-SNAPSHOT</version>
         <scope>test</scope>
      </dependency>
      <!-- Maybe other dependencies if you relies on other camel extensions (for xml and java routes).
           Note: these extensions are NOT provided by the component and must thus be present with the (default) scope compile. -->
   </dependencies>

<!-- ... -->

   <build>
      <!-- Finally the petals maven plugins to generate JBI zip files -->
      <plugins>
         <plugin>
            <groupId>org.ow2.petals</groupId>
            <artifactId>maven-petals-plugin</artifactId>
         </plugin>
      </plugins>
   </build>

<!-- ... -->

The project structure will follow typical maven projects :

my-service-unit/
  + pom.xml
  + src/
    + main/
    + jbi/
      + jbi.xml
      + service.wsdl (none, one or several)
    + java/.../MyRoutes.java (none, one or several)
    + resources/myroutes.xml (none, one or several)

On top of the typical pom.xml, there must be at least one route implementation per operation of the provides, in a jar file or an xml file, a WSDL description for every provides service of the JBI descriptor and of course a JBI descriptor.

Service Unit Content

A Camel SU generated from the previous Maven projects, named my-service-unit-1.0.0.zip will contains the following elements:

my-service-unit-1.0.0.zip
  + META-INF/
    + jbi.xml
  + service.wsdl (none, one or several)
  + my-service-unit-1.0.0.jar

Note that the jar is the generated Jar Maven artefact, and it is included in the generated Zip artefact by the petals maven plugin.

A Camel Route

Here is an example of a Camel route defined in XML:

  <!-- we must use the http://camel.apache.org/schema/spring namespace so Camel can load the routes
       but Spring JARs are not required -->
  <routes xmlns="http://camel.apache.org/schema/spring">
    <route>
      <from uri="petals:incomingOrders" />
      <convertBodyTo type="java.lang.String" />
      <choice>
        <when>
          <simple>${body} contains '?xml'</simple>
          <unmarshal>
            <jaxb contextPath="org.fusesource.camel" />
          </unmarshal>
          <to uri="petals:orders" />
        </when>
        <otherwise>
          <unmarshal>
            <bindy packages="org.fusesource.camel" type="Csv" />
          </unmarshal>
          <to uri="petals:orders2" />
        </otherwise>
      </choice>
    </route>
  <routes>

TODO. make that a real example...

The only specificity for Petals of this route are the URIs used to identify the services consumed by the route (from element) and to which messages are then sent (to element).
The scheme reserved to petals is petals: it is followed by : and then the unique id identifying a service's operation.

The rest is typical Camel but some Camel processors are particularly useful to handle Petals exchange from within Camel, such as the jaxb marshaller/unmarshaller or the body conversion.
See the section Camel Routes below for details.

JBI Descriptor and WSDL definition

The JBI descriptor contains:

  • The services that are provided by this SU for which routes will handle messages, and
  • The services consumed by this SU that will be callable from the route.

In order to identify a service's operation, each of the operation, provided or consumed, must have a unique id.
Of course, a provided service will be only usable by from elements and consumed services by to elements.

<?xml version="1.0" encoding="UTF-8"?>
<jbi:jbi version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jbi="http://java.sun.com/xml/ns/jbi"
   xmlns:petalsCDK="http://petals.ow2.org/components/extensions/version-5" xmlns:petals-se-camel="http://petals.ow2.org/components/petals-se-camel/jbi/version-1.0"
   xmlns:hello="http://petals.ow2.org">

   <jbi:services binding-component="false">

      <jbi:provides interface-name="hello:HelloInterface" service-name="hello:HelloService" endpoint-name="autogenerate">
         <petalsCDK:wsdl>service.wsdl</petalsCDK:wsdl>
      </jbi:provides>

      <jbi:consumes interface-name="hello:HelloInterface" service-name="hello:HelloService">

         <!-- Mandatory CDK specific elements -->
         <petalsCDK:operation>hello:sayHello</petalsCDK:operation>
         <petalsCDK:mep>InOut</petalsCDK:mep>

         <!-- Mandatory Component specific elements -->
         <petals-se-camel:service-id>theConsumesId</petals-se-camel:service-id>
      </jbi:consumes>

      <!-- These are found in the jar packaged by Maven and included in the JBI Zip -->
      <petals-se-camel:xml-routes>routes.xml</petals-se-camel:xml-routes>
      <petals-se-camel:java-routes>org.test.ASimpleRoute</petals-se-camel:java-routes>

   </jbi:services>
</jbi:jbi>
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://petals.ow2.org" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
   xmlns:tns="http://petals.ow2.org" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:petals-camel-wsdl="http://petals.ow2.org/components/petals-se-camel/wsdl/version-1.0">
   <wsdl:types>
      <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://petals.ow2.org"
         elementFormDefault="unqualified" targetNamespace="http://petals.ow2.org" version="1.0">
         <xs:element name="sayHello" type="tns:sayHello" />
         <xs:element name="sayHelloResponse" type="tns:sayHelloResponse" />
         <xs:complexType name="sayHello">
            <xs:sequence>
               <xs:element minOccurs="0" name="arg0" type="xs:string" />
            </xs:sequence>
         </xs:complexType>
         <xs:complexType name="sayHelloResponse">
            <xs:sequence>
               <xs:element minOccurs="0" name="return" type="xs:string" />
            </xs:sequence>
         </xs:complexType>
      </xs:schema>
   </wsdl:types>
   <wsdl:message name="sayHelloResponse">
      <wsdl:part name="parameters" element="tns:sayHelloResponse" />
   </wsdl:message>
   <wsdl:message name="sayHello">
      <wsdl:part name="parameters" element="tns:sayHello" />
   </wsdl:message>
   <wsdl:portType name="HelloInterface">
      <wsdl:operation name="sayHello">
         <wsdl:input name="sayHello" message="tns:sayHello" />
         <wsdl:output name="sayHelloResponse" message="tns:sayHelloResponse" />
      </wsdl:operation>
   </wsdl:portType>
   <wsdl:binding name="HelloServiceBinding" type="tns:HelloInterface">
      <wsdl:operation name="sayHello">
         <petals-camel-wsdl:operation service-id="theProvidesId" />
      </wsdl:operation>
   </wsdl:binding>
   <wsdl:service name="HelloService">
      <wsdl:port name="autogenerate" binding="tns:HelloServiceBinding" />
   </wsdl:service>
</wsdl:definitions>

In these two snippets, the important parts are the elements with the namespace URI http://petals.ow2.org/components/petals-se-camel/jbi/version-1.0 for the JBI and http://petals.ow2.org/components/petals-se-camel/wsdl/version-1.0 for the WSDL.

The first one enables to define the service id for a consumes in the JBI: notice that the consumes must also have a MEP (or a default one (imposed by the Camel SE) is used, that is InOut) and an operation set.

The second one enables to define the service id for the operation of a provides in the binding section of the WSDL definition: again the operation must have an MEP set (or the default one (imposed by the WSDL specification) is used, that is Inout).

Finally, the services section of the JBI contains a list of routes to be loaded by the Camel SE.
Two types of route definitions can be used: java classes and XML files.
Java classes refer to classes that extends the Camel RouteBuilder abstract class, i.e. routes written with any of the JVM-based DSLs: Camel DSL Page.
XML files refer to routes defined used the XML DSL from Camel: Camel XML Examples.

Semantics of the Send operation (synchronicity, timeouts, etc)

By default, the execution is asynchronous: it means that if one of the processor or producer on the route needs to do blocking operations, the processing won't keep the CDK thread that received the message busy and it will continue execution when it is time to depending on the blocked processor.
This has no impact on how the routes are implemented, but in term of execution, it means that threads are not blocked and resources are often freed as soon as possible.
See Camel Asynchronous Routing Engine and Camel Asynchronous Processing for technical details.

Nevertheless, it is possible to force synchronous execution:

  • of a whole route either by adding the synchronous argument to the Camel from URI, or
  • of a service invocation when calling an external petals services using a to with the same argument.

It is also possible to have a timeout (both for synchronous and asynchronous mode) to specify how long we should wait before failing a service invocation done with to by using the timeout option.
Note: by default, it will use the value specified in the JBI consumes section and as usual, the value 0 means no timeout.

Petals to Camel to Petals

Petals (i.e. JBI) and Camel share many concepts to format exchanges.
They both have exchanges with a WSDL MEP, In, Out and Fault messages, as well as Errors.
The main difference is that Camel exchanges do not make mandatory the use of XML for the messages content and that they have no explicit status (the status of Camel exchange is inferred from their content).

An error seems to be present in Camel: the InOptionalOut MEP has the wrong URI (ending with in-optional-out instead of in-opt-out according to the WSDL specification).
Note: this will be fixed in Camel 2.16.x and will most certainly be included in version 1.0.0 of the SE.

From Petals to Camel

When a new exchange arrives on a provides endpoint, the following happen:

The JBI exchange is transformed to a Camel exchange.
Its properties are put (by reference) into the Camel exchange properties, prefixed by "PetalsOriginalProperty."
Its interface and service names, the endpoint, the operation name and the MEP are put into the Camel exchange properties "PetalsOriginalInterface" (as a QName), "PetalsOriginalService" (as a QName), "PetalsOriginalEndpoint" (as a ServiceEndpoint), "PetalsOriginalOperation" (as a QName), "PetalsOriginalPattern" (as an URI).
Its In normalized message is transformed to a Camel message.
Its properties are put into the Camel message headers (by reference).
Its attachments are put into the Camel message attachments (by reference).
The content of the normalized message (a Source object in Java, containing XML) is put in the body of the Camel message without change.

Service provider configuration

All needed information must be defined in the service-unit JBI descriptor. This JBI descriptor is configured through parameters divided in following groups:

  • JBI parameters that defines the service provider identification,
  • CDK parameters that are parameters driving the service provider implementation at CDK layer,
  • CDK interceptor parameters that are parameters driving interceptors at CDK layer,
  • Dedicated parameters that are parameters driving the service provider implementation at component layer.

Placeholder

A placeholder is a specific value that is resolved at runtime against a property available in the property file set at component level. It is mainly used in the service unit JBI descriptor to be able to configure your service providers and/or your service consumers.

<service-unit-parameter>${dgfip.quotient-familial.base-url}</service-unit-parameter>

Its syntax is: '${placeholder-name[:default-value]}',

  • if no property with name 'placeholder-name' exists in the component property file, the default value 'default-value' is used. If no default value is defined, the literal value '${placeholder-name}' is used,
  • if a placeholder name must contain the character ':' (colon), it must be escaped by the character '\', example: ${placeholder-name-with-\:-colon:default-value}',
  • if a placeholder default value must contain the character ':' (colon), it must be escaped by the character '\', example: ${placeholder-name:default-value-with-\:-colon}'.
  • the escape character can be escaped by itself.

Placeholders are not supported for each service unit parameter, check your documentation before to use them.
It is also possible to change a placeholder value at runtime reloading the component property file. It is not sufficient, the parameter associated to the placeholder must be changeable at runtime. So check component documentation to know that.

CDK parameters defining service provider implementation

The following parameters correspond to the CDK configuration of the service provider implementation.

The service provider is defined into the section 'provides' of the JBI descriptor, containing:

Parameter
Description
Default
Required
Support placeholders
interface-name
Interface name of the service provider. Must match the one defined in the WSDL.
-
Yes
No
service-name
Service name of the service provider. Must match the one defined in the WSDL.
-
Yes
No
endpoint-name
Endpoint name of the service provider. Must match the one defined in the WSDL. The value 'autogenerate' will force Petals ESB to generate an endpoint name as UUID at deployment time.
-
Yes
No
timeout
Timeout in milliseconds of a synchronous send. This parameter is used by the method sendSync(Exchange exchange) proposes by the CDK Listeners classes.
Set it to 0 for an infinite timeout.
30000
No
Yes
su-interceptors
Service unit interceptor configuration. See Service unit interceptor configuration.
-
No
No
exchange-properties
This sections defines the list of properties to set to the JBI exchange when processing a service.
-
No
No
message-properties
This sections defines the list of properties to set to the JBI message when processing a service.
-
No
No
validate-wsdl
Activate the validation of the WSDL when deploying a service unit.
true
No
No
forward-security-subject
Defines if the security subject will be forwarded from IN message to OUT message.
false
No
No
forward-message-properties
Defines if the message properties will be forwarded from IN message to OUT message.
false
No
No
forward-attachments
Defines if attachment will be forwarded from IN message to OUT message.
false
No
No
activate-flow-tracing
Enable ('true') or disable ('false') the flow tracing for this service provider. This value overrides the value defined at component level and can be overridden at incoming exchange level.
Value defined at component
No
Yes
wsdl
Path to the WSDL document describing services and operations exposed by the provided JBI endpoints defined in the SU.
The value of this parameter is :
  • an URL
  • a file relative to the root of the SU package
    If not specified, a basic WSDL description is automatically provided by the CDK.
-
Yes
No

CDK parameters driving interceptors

The following parameters drive interceptors at CDK layer.

Interceptors can be defined to inject some post or pre-processing in the service provider processing or service consumer processing.

Using interceptor is very sensitive and must be manipulated only by power users. A non properly coded interceptor engaged in a component can lead to uncontrolled behaviors, out of the standard process.

Example of an interceptor configuration:

<?xml version="1.0" encoding="UTF-8"?>
<jbi:jbi xmlns:jbi="http://java.sun.com/xml/ns/jbi" xmlns:petalsCDK="http://petals.ow2.org/components/extensions/version-5">
   <jbi:services>
      <jbi:provides|consumes>
         <!--...-->
         <petalsCDK:su-interceptors>
            <petalsCDK:send>
               <petalsCDK:interceptor name="myInterceptorName">
                  <petalsCDK:param name="myParamName">myParamValue</petalsCDK:param>
                  <petalsCDK:param name="myParamName2">myParamValue2</petalsCDK:param>
               </petalsCDK:interceptor>
            </petalsCDK:send>
            <petalsCDK:accept>
               <petalsCDK:interceptor name="myInterceptorName">
                  <petalsCDK:param name="myParamName">myParamValue</petalsCDK:param>
               </petalsCDK:interceptor>
            </petalsCDK:accept>
            <petalsCDK:send-response>
               <petalsCDK:Interceptor name="myInterceptorName">
                  <petalsCDK:param name="myParamName">myParamValue</petalsCDK:param>
               </petalsCDK:Interceptor>
            </petalsCDK:send-response>
            <petalsCDK:accept-response>
               <petalsCDK:Interceptor name="myInterceptorName">
                  <petalsCDK:param name="myParamName">myParamValue</petalsCDK:param>
               </petalsCDK:Interceptor>
            </petalsCDK:accept-response>
         </petalsCDK:su-interceptors>
         <!--...-->
      </jbi:provides|consumes>
      <!--...-->
   </jbi:services>
</jbi:jbi>

Interceptors configuration for SU (CDK)

Parameter Description Default Required
send Interceptor dedicated to send phase, for an exchange sent by a consumer - No
accept Interceptor dedicated to receive phase, for an exchange received by a provider - No
send-response Interceptor dedicated to send phase, for an exchange (a response) received by a consumer - No
accept-response Interceptor dedicated to receive phase, for an exchange sent (a response) by a provider - No
interceptor - name Logical name of the interceptor instance defined at component level, see CDK Component Interceptor configuration. - Yes
param[] - name The name of the parameter to use for the interceptor for this SU - No
param[] The value of the parameter to use for the interceptor for this SU - No

Dedicated configuration

No specific configuration exists.

From Camel to Petals

When an exchange is sent from Camel to Petals through a consumes endpoint, the following happen:

  • The Camel exchange is transformed to a JBI exchange.
  • Its properties prefixed by "PetalsProperty." are put (by reference) into the JBI exchange properties (without the prefix).
  • Its "In" message is transformed to a normalized message.
  • Its headers are put into the normalized exchange properties (by reference).
  • Its attachments are put into the normalized message attachments (by reference).
  • The body is transformed, using available Camel type converters, to a DOMSource object (or if it is already a Source, it stays as a Source) and put in the content of the normalized message.

The Camel's endpoint "to" is defined through an identifier ('service-id') refering to a service consumer definition in the service unit JBI descriptor.

Specifying the service consumer

The definition of the service consumer is declared in the service unit JBI descriptor, in a section "consumes".

All needed information must be defined in the service-unit JBI descriptor. This JBI descriptor is configured through parameters divided in following groups:

  • JBI parameters that defines the service provider identification,
  • CDK parameters that are parameters driving the service consumer implementation at CDK layer,
  • CDK interceptor parameters that are parameters driving interceptors at CDK layer,
  • Dedicated parameters that are parameters driving the service consumer implementation at component layer.

CDK parameters defining service provider implementation

The following parameters correspond to the CDK configuration of the service consumer implementation.

A service consumer is defined into the section 'consumes' of the JBI descriptor, containing:

Parameter
Description
Default
Required
Support placeholders
interface-name
Interface name of the service provider to invoke.
-
Yes
No
service-name
Service name of the service provider to invoke.
-
No
No
endpoint-name
Endpoint name of the service provider to invoke.
-
No
No
timeout
Timeout in milliseconds of a synchronous send. This parameter can be used in conjunction with the sendSync(Exchange exchange) method of the Listeners. Set 0 for an infinite timeout. 30000
No
Yes
operation
Operation to call on the service provider. If no operation is specified in the Message Exchange to send, this parameter will be used.
-
No
No
activate-flow-tracing
This parameter makes sens only for service consumer running on binding component.
-
-
-
propagate-flow-tracing-activation
Control whether the flow tracing activation state must be propagated to next flow steps or not. If 'true', the flow tracing activation state is propagated to the invoked service provider. This value overrides the value defined at component level. Value defined at component
No
Yes
su-interceptors
Service unit interceptor configuration. See Service unit interceptor configuration.
-
No
No
mep
Message exchange pattern to use.
-
Yes
No

CDK parameters driving interceptors

The following parameters drive interceptors at CDK layer.

Interceptors can be defined to inject some post or pre-processing in the service provider processing or service consumer processing.

Using interceptor is very sensitive and must be manipulated only by power users. A non properly coded interceptor engaged in a component can lead to uncontrolled behaviors, out of the standard process.

Example of an interceptor configuration:

<?xml version="1.0" encoding="UTF-8"?>
<jbi:jbi xmlns:jbi="http://java.sun.com/xml/ns/jbi" xmlns:petalsCDK="http://petals.ow2.org/components/extensions/version-5">
   <jbi:services>
      <jbi:provides|consumes>
         <!--...-->
         <petalsCDK:su-interceptors>
            <petalsCDK:send>
               <petalsCDK:interceptor name="myInterceptorName">
                  <petalsCDK:param name="myParamName">myParamValue</petalsCDK:param>
                  <petalsCDK:param name="myParamName2">myParamValue2</petalsCDK:param>
               </petalsCDK:interceptor>
            </petalsCDK:send>
            <petalsCDK:accept>
               <petalsCDK:interceptor name="myInterceptorName">
                  <petalsCDK:param name="myParamName">myParamValue</petalsCDK:param>
               </petalsCDK:interceptor>
            </petalsCDK:accept>
            <petalsCDK:send-response>
               <petalsCDK:Interceptor name="myInterceptorName">
                  <petalsCDK:param name="myParamName">myParamValue</petalsCDK:param>
               </petalsCDK:Interceptor>
            </petalsCDK:send-response>
            <petalsCDK:accept-response>
               <petalsCDK:Interceptor name="myInterceptorName">
                  <petalsCDK:param name="myParamName">myParamValue</petalsCDK:param>
               </petalsCDK:Interceptor>
            </petalsCDK:accept-response>
         </petalsCDK:su-interceptors>
         <!--...-->
      </jbi:provides|consumes>
      <!--...-->
   </jbi:services>
</jbi:jbi>

Interceptors configuration for SU (CDK)

Parameter Description Default Required
send Interceptor dedicated to send phase, for an exchange sent by a consumer - No
accept Interceptor dedicated to receive phase, for an exchange received by a provider - No
send-response Interceptor dedicated to send phase, for an exchange (a response) received by a consumer - No
accept-response Interceptor dedicated to receive phase, for an exchange sent (a response) by a provider - No
interceptor - name Logical name of the interceptor instance defined at component level, see CDK Component Interceptor configuration. - Yes
param[] - name The name of the parameter to use for the interceptor for this SU - No
param[] The value of the parameter to use for the interceptor for this SU - No

Dedicated configuration

Parameter Description Default Required
service-id The reference of the service consumer. This value is used, prefixed with 'petals:', in the Camel route's endpoint "to".
-
Yes

Override parameters of the service consumer directly from the Camel's route

One way to influence the service, endpoint, operation names and the MEP is to set parameters on the endpoint URI in the Camel route like this:

@Override
public void configure() throws Exception {
    from("petals:theProvidesId").to("petals:theConsumesId?serviceName={http://a.com/namespace}AService&endpointName=edpt-name&operation={http://a.com/namespace}anOperation&exchangePattern=InOut");
}

Of course each can be used alone or together, but the following rules always apply:

  • If a parameter is set in the Consumes, it can't be set in the Camel endpoint URI
  • endpointName can only be set if either the Consumes or the endpoint URI have a serviceName set

Using the MEP of the Camel exchange

Even though it's not the most recommended (because of its implicit nature), if no MEP is set neither on the Consumes or the Camel endpoint URI, then the MEP of the Camel exchange will be used.

Back to Camel from Petals

When an answer to an exchange sent to Petals arrives back to Camel through a consumes endpoint, the following happen:

  • The Camel exchange properties prefixed by "PetalsProperty." are updated from the JBI exchange properties (by reference).
  • If the exchange has the error status, the exception is put in the exchange.
  • If the exchange has a Fault, it is transformed to a Camel message (same process as before), the fault status is set on it and put as the exchange's Out.
  • If the exchange has an Out, it is transformed to a Camel message (same process as before) and put as the exchange's Out.

Back to Petals from Camel

When an answer to an exchange sent to Camel from Petals arrives back to Petals through a provides endpoint, the following happen:

  • The JBI exchange properties are updated (by reference) with the Camel exchange properties prefixed by "PetalsOriginalProperty." (without the prefix).
  • If the exchange has an Exception, the exception is put as the JBI exchange's error and its status is set to "error".
  • If the exchange has a Fault, it is transformed to a normalized message of type "fault" (same process as before) and put as the JBI exchange's Fault.
  • If the exchange has an "Out" and it is an "InOut" or an "InOptionalOut", it is transformed to a normalized message (same process as before) and put as the JBI exchange's Out.
  • If the exchange has no "Out" and it is an "InOut" exchange, its In message is transformed to a normalized message (same process as before) and put as the JBI exchange's Out.
  • In all the other cases, the exchange's status is changed to done.
Some Camel processors are made to work in-place with an "In" message without making an "Out" message: because of this practice (see http://camel.apache.org/using-getin-or-getout-methods-on-exchange.html), we have to make the assumption that an "InOptionalOut" Camel message MUST have an "Out" message for the exchange to be considered not done!
In other words: before sending an "InOptionalOut" message that has an "Out" message back to Petals, make sure that the answer is not in the "In" but in the "Out" message of the Camel exchange.

Manipulating JBI faults in a Camel route

Apache Camel does not support advanced manipulation of faults through their Exchange/Message API:

  • if a message is marked as being a fault (via Message.isFault), it won't be possible in a Camel route to process it as a normal message.
  • The route will simply stop its processing.
  • This is because Camel does not encourage a WSDL-oriented paradigm of defining exchanges like JBI do.

Hence, the Camel SE introduces some helpers (in camel-petals's PetalsRouteBuilder) to reand and mark messages as faults outside of the facilities provided by Camel.

Basically, static methods are available to test if an Exchange is failed or a Message is a fault, as well as to set them as fault.
They add an extra header to the exchange to mark the out message.
The message itself is just a message like any other.

The helpers also allow for stopping the routing when setting a fault, if desired.

Examples

Some examples are available with the SE.
They show how to define Java or XML-based Camel routes in a Petals SU.

They also illustrates the use of the route helpers available from camel-petals and of the junit helpers available from petals-se-camel-junit.

See https://github.com/petalslink/petals-se-camel/tree/master/samples.

Configuring the component

The component can be configured through the parameters of its JBI descriptor file. These parameters are divided in following groups:

  • JBI parameters that have not to be changed otherwise the component will not work,
  • CDK parameters that are parameters driving the processing of the CDK layer,
  • Dedicated parameters that are parameters specific to this component.

CDK parameters

The component configuration includes the configuration of the CDK. The following parameters correspond to the CDK configuration.

Parameter Description Default Scope*
acceptor-pool-size The size of the thread pool used to accept Message Exchanges from the NMR. Once a message is accepted, its processing is delegated to the processor pool thread. 1
Runtime
acceptor-retry-number Number of tries to submit a message exchange to a processor for processing before to declare that it cannot be processed. 40
Installation
acceptor-retry-wait Base duration, in milliseconds, to wait between two processing submission tries. At each try, the new duration is the previous one plus this base duration. 250
Installation
acceptor-stop-max-wait The max duration (in milliseconds) before, on component stop, each acceptor is stopped by force. 500
Runtime
processor-pool-size The size of the thread pool used to process Message Exchanges. Once a message is accepted, its processing is delegated to one of the thread of this pool. 10 Runtime
processor-max-pool-size The maximum size of the thread pool used to process Message Exchanges. The difference between this size and the processor-pool-size represents the dynamic threads that can be created and destroyed during overhead processing time.
50
Runtime
processor-keep-alive-time When the number of processors is greater than the core, this is the maximum time that excess idle processors will wait for new tasks before terminating, in seconds.
300
Runtime
processor-stop-max-wait The max duration (in milliseconds) of message exchange processing on stop phase (for all processors).
15000
Runtime
time-beetween-async-cleaner-runs The time (in milliseconds) between two runs of the asynchronous message exchange cleaner.
2000
Installation
properties-file Name of the file containing properties used as reference by other parameters. Parameters reference the property name using a placeholder in the following pattern ${myPropertyName}. At runtime, the expression is replaced by the value of the property.

The properties file can be reloaded using the JMX API of the component. The runtime configuration MBean provides an operation to reload these place holders. Check the service unit parameters that support this reloading.

The value of this parameter is :
  • an URL
  • a file relative to the PEtALS installation path
  • an absolute file path
  • an empty value to stipulate a non-using file.
- Installation
monitoring-sampling-period Period, in seconds, of a sample used by response time probes of the monitoring feature. 300 Installation
activate-flow-tracing Enable ('true') or disable ('false') the flow tracing. This value can be overridden at service consumer or service provider level, or at exchange level. true Runtime
propagate-flow-tracing-activation Control whether the flow tracing activation state must be propagated to next flow steps or not. If 'true', the flow tracing activation state is propagated. This value can be overridden at service consumer level. true Runtime
component-interceptors Component interceptor configuration. See CDK Component interceptor configuration. - See Maven Petals plugin to known how to inject component interceptor configuration in component configuration

* Definition of CDK parameter scopes:

  • Installation: The parameter can be set during the installation of the component, by using the installation MBean (see JBI specifications for details about the installation sequence). If the parameter is optional and has not been defined during the development of the component, it is not available at installation time.
  • Runtime: The paramater can be set during the installation of the component and during runtime. The runtime configuration can be changed using the CDK custom MBean named RuntimeConfiguration. If the parameter is optional and has not been defined during the development of the component, it is not available at installation and runtime times.

Interception configuration

Interceptors can be defined to inject some post or pre-processing in the component during service processing.

Using interceptor is very sensitive and must be manipulated only by power users. A non properly coded interceptor engaged in a component can lead to uncontrolled behaviors, out of the standard process.

Example of an interceptor configuration:

<?xml version="1.0" encoding="UTF-8"?>
<jbi:jbi xmlns:jbi="http://java.sun.com/xml/ns/jbi" xmlns:petalsCDK="http://petals.ow2.org/components/extensions/version-5" ...>
   <jbi:component>
      <!--...-->
      <petalsCDK:component-interceptors>
         <petalsCDK:interceptor active="true" class="org.ow2.petals.myInterceptor" name="myInterceptorName">
            <petalsCDK:param name="myParamName">myParamValue</petalsCDK:param>
            <petalsCDK:param name="myParamName2">myParamValue2</petalsCDK:param>
         </petalsCDK:interceptor>
      </petalsCDK:component-interceptors>
      <!--...-->
   </jbi:component>
</jbi:jbi>

Interceptors configuration for Component (CDK)

Parameter Description Default Required
interceptor - class Name of the interceptor class to implement. This class must extend the abstract class org.ow2.petals.component.common.interceptor.Interceptor. This class must be loadable from the component classloader, or in a dependent Shared Library classloader. - Yes
interceptor - name Logical name of the interceptor instance. It is referenced at service unit level to register this interceptor for services of the service unit. See SU Interceptor configuration. - Yes
interceptor - active If true, the Interceptor instance is activated for every SU deployed on the component.
If false, the Interceptor can be activated:
-by the InterceptorManager Mbean at runtime, to activate the interceptor for every deployed SU.
-by a SU configuration
- Yes
param[] - name The name of the parameter to use for the interceptor. - No
param[] The value of the parameter to use for the interceptor. - No

Dedicated configuration

No dedicated configuration parameter is available.

Monitoring the component

Using metrics

Several probes providing metrics are included in the component, and are available through the JMX MBean 'org.ow2.petals:type=custom,name=monitoring_<component-id>', where <component-id> is the unique JBI identifier of the component.

Common metrics

The following metrics are provided through the Petals CDK, and are common to all components:

Metrics, as MBean attribute Description Detail of the value Configurable
MessageExchangeAcceptorThreadPoolMaxSize The maximum number of threads of the message exchange acceptor thread pool integer value, since the last startup of the component yes, through acceptor-pool-size
MessageExchangeAcceptorThreadPoolCurrentSize The current number of threads of the message exchange acceptor thread pool. Should be always equals to MessageExchangeAcceptorThreadPoolMaxSize. instant integer value no
MessageExchangeAcceptorCurrentWorking The current number of working message exchange acceptors. instant long value no
MessageExchangeAcceptorMaxWorking The max number of working message exchange acceptors. long value, since the last startup of the component no
MessageExchangeAcceptorAbsoluteDurations The aggregated durations of the working message exchange acceptors since the last startup of the component. n-tuple value containing, in nanosecond:
  • the maximum duration,
  • the average duration,
  • the minimum duration.
no
MessageExchangeAcceptorRelativeDurations The aggregated durations of the working message exchange acceptors on the last sample. n-tuple value containing, in nanosecond:
  • the maximum duration,
  • the average duration,
  • the minimum duration,
  • the 10-percentile duration (10% of the durations are lesser than this value),
  • the 50-percentile duration (50% of the durations are lesser than this value),
  • the 90-percentile duration (90% of the durations are upper than this value).
no
MessageExchangeProcessorAbsoluteDurations The aggregated durations of the working message exchange processor since the last startup of the component. n-tuple value containing, in milliseconds:
  • the maximum duration,
  • the average duration,
  • the minimum duration.
no
MessageExchangeProcessorRelativeDurations The aggregated durations of the working message exchange processor on the last sample. n-tuple value containing, in milliseconds:
  • the maximum duration,
  • the average duration,
  • the minimum duration,
  • the 10-percentile duration (10% of the durations are lesser than this value),
  • the 50-percentile duration (50% of the durations are lesser than this value),
  • the 90-percentile duration (90% of the durations are upper than this value).
no
MessageExchangeProcessorThreadPoolActiveThreadsCurrent The current number of active threads of the message exchange processor thread pool instant integer value no
MessageExchangeProcessorThreadPoolActiveThreadsMax The maximum number of threads of the message exchange processor thread pool that was active integer value, since the last startup of the component no
MessageExchangeProcessorThreadPoolIdleThreadsCurrent The current number of idle threads of the message exchange processor thread pool instant integer value no
MessageExchangeProcessorThreadPoolIdleThreadsMax The maximum number of threads of the message exchange processor thread pool that was idle integer value, since the last startup of the component no
MessageExchangeProcessorThreadPoolMaxSize The maximum size, in threads, of the message exchange processor thread pool instant integer value yes, through http-thread-pool-size-max
MessageExchangeProcessorThreadPoolMinSize The minimum size, in threads, of the message exchange processor thread pool instant integer value yes, through http-thread-pool-size-min
MessageExchangeProcessorThreadPoolQueuedRequestsCurrent The current number of enqueued requests waiting to be processed by the message exchange processor thread pool instant integer value no
MessageExchangeProcessorThreadPoolQueuedRequestsMax The maximum number of enqueued requests waiting to be processed by the message exchange processor thread pool since the last startup of the component instant integer value no
ServiceProviderInvocations The number of service provider invocations grouped by:
  • interface name, as QName, the invoked service provider,
  • service name, as QName, the invoked service provider,
  • invoked operation, as QName,
  • message exchange pattern,
  • and execution status (PENDING, ERROR, FAULT, SUCCEEDED).
integer counter value since the last startup of the component no
ServiceProviderInvocationsResponseTimeAbs The aggregated response times of the service provider invocations since the last startup of the component grouped by:
  • interface name, as QName, the invoked service provider,
  • service name, as QName, the invoked service provider,
  • invoked operation, as QName,
  • message exchange pattern,
  • and execution status (PENDING, ERROR, FAULT, SUCCEEDED).
n-tuple value containing, in millisecond:
  • the maximum response time,
  • the average response time,
  • the minimum response time.
no
ServiceProviderInvocationsResponseTimeRel The aggregated response times of the service provider invocations on the last sample, grouped by:
  • interface name, as QName, the invoked service provider,
  • service name, as QName, the invoked service provider,
  • invoked operation, as QName,
  • message exchange pattern,
  • and execution status (PENDING, ERROR, FAULT, SUCCEEDED).
n-tuple value containing, in millisecond:
  • the maximum response time,
  • the average response time,
  • the minimum response time,
  • the 10-percentile response time (10% of the response times are lesser than this value),
  • the 50-percentile response time (50% of the response times are lesser than this value),
  • the 90-percentile response time (90% of the response times are lesser than this value).
no

Dedicated metrics

No dedicated metric is available.

Receiving alerts

Several alerts are notified by the component through notification of the JMX MBean 'org.ow2.petals:type=custom,name=monitoring_<component-id>', where <component-id> is the unique JBI identifier of the component.

To integrate these alerts with Nagios, see Receiving Petals ESB defects in Nagios.

Common alerts

Defect JMX Notification
A message exchange acceptor thread is dead
  • type: org.ow2.petals.component.framework.process.message.acceptor.pool.thread.dead
  • no user data
No more thread is available in the message exchange acceptor thread pool
  • type: org.ow2.petals.component.framework.process.message.acceptor.pool.exhausted
  • no user data
No more thread is available to run a message exchange processor
  • type: org.ow2.petals.component.framework.process.message.processor.thread.pool.exhausted
  • no user data

Dedicated alerts

No dedicated alert is available.

Business monitoring

MONIT traces

Each service provider implemented is able to log MONIT traces with following information:

  • on service provider invocation, when receiving an incoming request, with following attributes:
    • traceCode set to provideFlowStepBegin,
    • flowInstanceId set to the flow instance identifier retrieved from the incoming request,
    • flowStepId set to an UUID value,
    • flowStepInterfaceName set to the service provider interface name,
    • flowStepServiceName set to the service provider service name,
    • flowStepOperationName set to the operation of the invoked service provider,
    • flowStepEndpointName set to the service provider endpoint name,
    • flowPreviousStepId set to the step identifier of the previous step, retrieved from the incoming request.
  • on service provider termination, when returning the outgoing response, with following attributes:
    • traceCode set to provideFlowStepEnd or provideFlowStepFailure,
    • flowInstanceId set to the flow instance identifier retrieved from the incoming request,
    • flowStepId set to the flow step identifier defined on incoming request receipt.

Flow tracing activation

The flow tracing (ie. MONIT traces generation) is defined according to the property 'org.ow2.petals.monitoring.business.activate-flow-tracing' of the incoming JBI request. If the property does not exist, the parameter activate-flow-tracing of the service provider definition will be inspected. If no parameter is defined at service provider level, the component configuration parameter 'activate-flow-tracing' is used. Finally, by default, the flow tracing is enabled.

Flow tracing propagation

The flow tracing propagation from a service provider implemented with this component to another service provider is driven by the parameter propagate-flow-tracing-activation of the service consumer definition. If no parameter is defined at service consumer level, the component configuration parameter 'propagate-flow-tracing-activation' is used. Finally, by default, the flow tracing propagation is enabled.

Migration guide

Migrating service units developed for previous versions

To be deployed on this version of the Petals SE Camel, the Petals SE Camel service units must be migrated. Please follow the following chapters to know which changes must be applied.

From 1.3.x to 1.4.x

Please apply the following changes in your Petals SE Camel service unit to migrate them from Petals SE Camel 1.3.x to Petals SE Camel 1.4.x:

  • in your route definitions:
    • move Java EE package to Jakarta EE 9+ package:
      • javax.activation -> jakarta.activation
      • javax.mail -> jakarta.mail
      • javax.xml.bind -> jakarta.xml.bind
      • ...
    • the API MarshallingHelper.unmarshal(Message, Class<T>) has moved to MarshallingHelper.unmarshal(Exchange, Class<T>),
    • the API PetalsRouteBuilder.isJbiFault(Message) has moved to PetalsRouteBuilder.isJbiFault(Exchange),
    • to generate your beans from an XSD or WSDL definition, use the Maven plugin 'org.patrodyne.jvnet:hisrc-higherjaxb-maven-plugin' instead of 'org.jvnet.jaxb2.maven2:maven-jaxb2-plugin',
    • adjust your Java route definition to Apache Camel 4.0.x:
      • Replace the deprecated method 'exchange.getOut()' by 'exchange.getMessage()', except if you want to transform a fault received into an out message in such case the usage of 'exchange.getOut()' is required,
      • Prefer to use 'doTry()/doCatch()/doFinally()/end()' instead of 'isJbiFailed()' to catch exceptions,
  • in your unit tests:
    • move Java EE package to Jakarta EE 9+ package:
      • javax.activation -> jakarta.activation
      • javax.mail -> jakarta.mail
      • javax.xml.bind -> jakarta.xml.bind
      • ...
    • the API MarshallingHelper.unmarshal(Message, Class<T>) has moved to MarshallingHelper.unmarshal(Exchange, Class<T>),
    • to generate your beans from an XSD or WSDL definition, use the Maven plugin 'org.patrodyne.jvnet:hisrc-higherjaxb-maven-plugin' instead of 'org.jvnet.jaxb2.maven2:maven-jaxb2-plugin',
    • JUnit 5 is now required for your unit tests,
    • Rework your mocked endpoint definition with AdviceWith.adviceWith as something like:
      AdviceWith.adviceWith(context, "onlyoffice-wrapper-convert", builder -> {
          builder.interceptSendToEndpoint(CONVERTED_DOCUMENT_URL).skipSendToOriginalEndpoint()
             .to(MOCK_HTTP_DOWNLOAD_EDP);
      });
      
    • the assertion 'assertMockEndpointsSatisfied' is replaced by 'assertIsSatisfied'.

From 1.2.x to 1.3.x

Please apply the following changes in your Petals SE Camel service unit to migrate them from Petals SE Camel 1.2.x to Petals SE Camel 1.3.x:

  • in your route definitions and unit tests:
    • Placeholders are no more defined through Properties but through Placeholders,
    • the Petals SE Camel JUnit Framework package has been changed to 'org.ow2.petals.se.camel.junit' instead of 'org.ow2.petals.camel.junit'.
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.