Petals-BC-REST 2.4.0+

This version must be installed on Petals ESB 5.3.0+

Feature

The REST component is a Binding Component (BC) which enables to interact with external RESTful Web Services and to expose JBI services as RESTful Web Services.

In provider role, when a JBI MessageExchange is sent to a ServiceEndpoint (mapped to a Web Service), it is transformed into a REST message and sent to the linked external Web Service. In consumer role, when a REST message is received on an exposed Web Service, it is transformed into a JBI MessageExchange and sent to the corresponding JBI ServiceEndpoint.

The REST component provides the following features:

  • Expose Restful Web Services as JBI Services
  • Expose Restful Web Services as JBI Services using a WADL (TBC)
  • Expose Restful Web Services as JBI Services using a WSDL 2.0 (TBC)
  • Expose JBI Services as Restful Web Services

It is based on:

REST is a style of software architecture not a standard. If you want more details about REST, you can consult the Wikipedia page: http://en.wikipedia.org/wiki/Representational_State_Transfer
Contributors
No contributors found for: authors on selected page(s)

Exposing an external Restful Web Service as a JBI service endpoint

In service provider mode, the component exposes an external REST resource as a service in the JBI environment. It will convert service invocations into REST requests to the associated external resources.

Usage

The Petals BC REST component can expose a set of external REST resources as a JBI service endpoint by deploying a service-unit on it.

When a message is received on a REST linked endpoint from the JBI environment, it is transformed into a REST request and sent to the resource server.

The REST request is created like this:

  • The REST URI is created from the address extension, the JBI operation and JBI message content (The JBI message content must contains the information about the path, the matrix and query parameters),
  • The HTTP headers are set according to the provided configuration,
  • The HTTP body is created differently according the HTTP method to used:
    • GET/DELETE: There is no HTTP body
    • POST: The HTTP body is also created differently according the JBI message content:
      • The JBI message content contains only a reference to a JBI attachment: The HTTP body is created from a JBI attachment (binary data)
      • The JBI message content does not contains a reference to a JBI attachment: The HTTP body is created from the JBI message content (form parameters)
    • PUT: The HTTP body is created from a JBI attachment.

For example the following JBI message will produces the URI http://localhost:8088/library/My%20Documents/documents/6/metadata:

<consulter xmlns="http://petals.ow2.org/bc/rest/unit-test/ged">
    <library>My Documents</library>
    <reference>6</reference>
</consulter>

The external resource is called and the REST response is processed and returned to the JBI environment.

The REST response is transformed into a JBI message like this:

  • In case of normal response (HTTP status as 20x), the JBI output message content and attachment are created differently according the Content-Type HTTP header:
    • XML content types: The JBI message content is created from the HTTP body. If a configuration element 'on-http-status' is defined for the HTTP status 20x, the XML of the HTTP body is transformed with the associated XSL,
    • JSON content types: The JBI message content is created from the JSON body converted into a basic XML. If a configuration element 'on-http-status' is defined for the HTTP status 20x, the basic XML is transformed with the associated XSL,
    • Non XML content types: The JBI message content is a reference (cf SOAP) to a JBI attachment which contains the HTTP body.
  • In case of error (HTTP status different from 20x) a JBI error is created, the JBI output message is built according to the following rules:
    • if the HTTP status is catched by a configuration element 'on-http-status', the return depends on the message exchange pattern:
      • 'InOnly', a status DONE is returned,
      • 'RobustInOnly', a fault generated from the given XSL is returned,
      • 'InOut', a fault or normal response, both generated from the given XSL, is returned according to the value of the attribute 'as-fault',
    • if the HTTP status is not catched by a configuration element 'on-http-status', a status 'ERROR' is returned.

Configuration

With no description of the RESTful resource

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.

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

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

Attribute Description Default value Required
http-method HTTP method to use. Possible values are: GET, POST, PUT and DELETE.
-
Yes*
http-body-type Define which kind of HTTP body the resource is expecting:
  • NO_BODY: no HTTP body is expected,
  • XML: the HTTP body is filled with the incoming XML payload, possibly transformed by the XSL tansformation defined with 'xsl',
  • JSON: the HTTP body is filled with the incoming XML payload, possibly transformed by the XSL tansformation defined with 'xsl', converted into JSON,
  • POST_QUERY_STRING: the HTTP body is filled with URL-encoded form data. The form datas are provided through the parameter 'post-query',
  • MULTIPART_FORMDATA: A multi-part HTTP request is built. Each part will be defined using 'form-data',
  • ATTACHMENT: the attachment of the incoming JBI request is used as HTTP request body. By default the header 'Content-Type' of the HTTP request is initialized with the attachment MIME type.
-
Yes
uri URI template of the external resource.
Value of substitutable parameters are retrieved first from XPath expressions given by 'xpath-param', next retrieved from JBI message properties, and finally retrieved from placeholders. A placeholder can be also used with its classic expression '${placeholder-name}'.
Example:
<rest:uri>https://${placeholder.host}:${placeholder.port}/api/library/{placeholder.library.id}/document/{document-id}/chapters</rest:uri></rest:post-query>
-
Yes*
cookie-policy The cookie policy applied on HTTP connection reuse:
  • ignore: All cookies are ignored,
  • netscape: The Netscape cookie draft compliant policy,
  • standard: The RFC 6265 compliant policy (interoprability profile),
  • standard-strict: // The RFC 6265 compliant policy (strict profile),
  • compatibility: A higher degree of compatibility with common cookie management of popular HTTP agents for non-standard (Netscape style) cookies.
ignore
No
buffer-request if the request should be buffered to be sent, mostly useful with authentication methods that requires multiple retries.
false
No
trust-all-certificates Do not fail if an HTTPS connection uses an untrusted certificate (self-signed, expired, etc). DO NOT USE IN PRODUCTION.
false
No
post-query The URI template defining form data to put as URL-encoded into the HTTP body.
Value of substitutable parameters are retrieved first from XPath expressions given by 'xpath-param', next retrieved from JBI message properties, and finally retrieved from placeholders.
Example:
<rest:post-query>grant_type=client_credentials&amp;validity_period={placeholder.ttl}</rest:post-query>
-
Yes, if 'http-body-type' is set to 'POST_QUERY_STRING'
xpath-param Define how to retrieve an URI template parameter as an XPath expression executed on the incoming payload. The attribute name is the name of the parameter in the URI template, and the value is the XPath expression to apply.
-
Yes, if at least one parameter is included into the URI template
authentication Defines the authentication to set on the REST request.
<rest:authentication>
   <rest:basic>
      <rest:username><rest:constant>${username}</rest:constant></rest:username>
      <rest:password><rest:xpath>//*[local-name()='password']</rest:xpath></rest:password>
   </rest:basic>
</rest:authentication>

Available authentication are:

  • Basic authentication, using '<basic />', and having following parameters:
    • <username />: the username to use
      • '<constant />', the username is a constant, placeholders are supported,
      • '<xpath />', the username value is extracted from the incoming payload by an XPath expression.
    • <password />: the password to use
      • '<constant />', the password is a constant, placeholders are supported,
      • '<xpath />', the password value is extracted from the incoming payload by an XPath expression.
  • JWT (Java Web Token) based authentication, using '<jwt />', and having following parameters:
    • <claim />: defines a list of claims to include in the token
      • <name />: the claim name
        • '<constant />', the claim name is a constant, placeholders are supported,
        • '<xpath />', the claim name is extracted from the incoming payload by an XPath expression,
      • <value />: the claim value
        • '<constant />', the claim value is a constant, placeholders are supported,
        • '<xpath />', the claim value is extracted from the incoming payload by an XPath expression,
    • <compress-with />: defines a compression algorithm. Available values are: DEF (JWA standard deflate compression algorithm) or GZIP (gzip compression algorithm),
    • <sign-with />: defines the token signature (algorithm and key):
      • algorithm: attribute defining the signature algorithm. All algorithms accepted by library io.jsonwebtoken:jjwt:0.6.0 are supported.
      • <key-file-url />: URL of the key file to use to sign the token. Placeholders are accepted in the key URL definition.
  • NTLM authentication, using '<ntlm />', and having following parameters:
    • <username />: the username to use
      • '<constant />', the username is a constant, placeholders are supported,
      • '<xpath />', the username value is extracted from the incoming payload by an XPath expression.
    • <password />: the password to use
      • '<constant />', the password is a constant, placeholders are supported,
      • '<xpath />', the password value is extracted from the incoming payload by an XPath expression.
    • <domain />: the Windows domain of the user to use
      • '<constant />', the domain is a constant, placeholders are supported,
      • '<xpath />', the domain value is extracted from the incoming payload by an XPath expression.
-
No
headers Defines the HTTP headers to set on the REST request:
  • each header defines through a sub-element '<header />' for which the attribute 'name' is the name of the header,
  • the value to set is defined by the content of the sub-element '<header />':
    • '<constant />', the constant of this tag will be used as header value,
    • '<xpath />', the header value is extracted from the incoming payload by an XPath expression
      <rest:headers>
         <rest:header name="Accept"><rest:constant>application/xml</rest:constant><rest:header>
         <rest:header name="X-RequestDigest"><rest:xpath>/update/token</rest:xpath><rest:header>
      <rest:headers>
      
-
No
xsl A XSL style-sheet used to transform the incoming XML payload before to generate the HTTP body of the REST request. The result of this transformation will be used to be converted into JSON or to be set as XML payload. The component placeholders are available as parameters from namespace '{{ http://petals.ow2.org/bc/rest/xsl/param/output/1.0/placeholders

}}'. The parameter name is the placeholder name, and its value the placeholder value.

-
No
xsl/@is-json-result If true, the output of the XSL transforming the incoming XML payload will be considered as JSON to put in the HTTP body of the REST request.
false
No
on-http-status Define how to process a given HTTP status:
  • the attribute code is the list of HTTP codes separated by '|' for which this processing must be applied,
  • the sub-elements 'out', 'fault' or 'error define conditional transformations to apply on the HTTP body response if exists. The first condition evaluted to 'true' determine the transformation that will be applied. The result of the transformation will be used as OUT response, fault or error. Several conditional transformations can be defined:
    • the attribute 'order-id' permits to order condition evaluations,
    • the attribute 'process-http-response-as' defines how the HTTP response body must be processed. By default, the body content-type is auto-detected according to the content-type of the HTTP response. Possible values are:
      • auto (default value): The body content type is auto-detected from the HTTP response content-type,
      • xml: The body contains XML that will be put be put in the service provider response as a XML payload,
      • json: The body contains JSON that will be put be put in the service provider response as a XML payload,
      • attachment: The body will be put in the service provider response as an attachment.
    • the sub-element 'condition' defines the condition to evaluate. Now, only XPath conditions are supported through the sub-element 'xpath',
    • the sub-element 'transformation' defines the transformation to apply if the condition matches. Now, only XSL transformations are supported through the sub-element 'xsl',
      If the HTTP body response is a XML or JSON payload, it is used as XML to be transformed according to the current on-http-status definition. Several XSL parameters are set to be used in the XSL transformation:

      If the HTTP body response is not a XML or JSON payload, the IN message payload is used to be transformed according to the current on-htt-status definition. Several XSL parameters are set to be used in the XSL transformation:

  • the sub-elements 'otherwise-out', 'otherwise-fault' or 'otherwise-error define the default transformation to apply when no condition transformation matches the HTTP body response. The result of the transformation will be used as OUT response, fault or error. Only one default transformation can be defined:
    • the attribute 'process-http-response-as' defines how the HTTP response body must be processed. By default, the body content-type is auto-detected according to the content-type of the HTTP response. Possible values are:
      • auto (default value): The body content type is auto-detected from the HTTP response content-type,
      • xml: The body contains XML that will be put be put in the service provider response as a XML payload,
      • json: The body contains JSON that will be put be put in the service provider response as a XML payload,
      • attachment: The body will be put in the service provider response as an attachment.
    • the sub-element 'transformation' defines the transformation to apply if the condition matches. Now, only XSL transformations are supported through the sub-element 'xsl'. The available XSL parameters available are the same as the ones for 'out', 'fault' and 'error,
  • if no default transformation is defined:
    • if the HTTP code returned is 20X:
      • if the exchange is an InOut exchange, the HTTP body is put as OUT message,
      • otherwise (the exchange is InOnly or RobustInOnly), the status DONE is returned,
    • otherwise, a status ERROR is returned.
-
No
form-data Define the form data to put in a part of a multi-part HTTP request:
  • the attribute 'name' define the name of the form data,
  • the sub-element 'extracted-by-xpath' defines the XPath expression applied on the incoming request to compute the value to set into the form data:
    • if the result of the XPath expression is the content identifier of an attachment of the incoming request, the attribute 'as-attachment' drives the processing of the attachment: if 'true', the attachment content will be put into the form data, otherwise the content id will be put. If you want to put the XPath result as a form field value, use the value 'false',
    • if the result of the XPath expression is a list of element, a form data will be generated for each element with its value as form data value,
    • if the result of the XPath expression is a simple value, it will be used as form data value.
  • the sub-element 'attachment-name' can be used to transmitted an attachment name to the REST server. This sub-element has only sens with an attachment form data. The attachment name can be defined as a constant value through the sub-element 'constant' or as a XPath expression through the sub-element 'xpath'.
-
No
http-body-to-json-multiple-pi This parameter drives the conversion of XML to JSON. See https://github.com/beckchr/staxon/wiki/Factory-Configuration

false
No
http-body-from-json-multiple-pi This parameter drives the conversion of JSON to XML. See https://github.com/beckchr/staxon/wiki/Factory-Configuration

false
No
http-body-to-json-virtual-root This parameter drives the conversion of XML to JSON. See https://github.com/beckchr/staxon/wiki/Factory-Configuration

-
No
http-body-from-json-virtual-root This parameter drives the conversion of JSON to XML. See https://github.com/beckchr/staxon/wiki/Factory-Configuration

-
No
http-body-to-json-auto-array This parameter drives the conversion of XML to JSON. See https://github.com/beckchr/staxon/wiki/Factory-Configuration

false
No
http-body-to-json-auto-primitive This parameter drives the conversion of XML to JSON. See https://github.com/beckchr/staxon/wiki/Factory-Configuration

false
No
http-body-to-json-pretty-print This parameter drives the conversion of XML to JSON. See https://github.com/beckchr/staxon/wiki/Factory-Configuration

false
No
http-body-to-json-ns-declarations This parameter drives the conversion of XML to JSON. See https://github.com/beckchr/staxon/wiki/Factory-Configuration

false
No
namespace-mapping This parameter drives the conversion of XML to JSON. The prefix is defined by attribute prefix. See https://github.com/beckchr/staxon/wiki/Factory-Configuration

-
No

Service unit content

The service unit has to contain the following elements, packaged in the archive:

  • the META-INF/jbi.xml descriptor file as described above,
  • it is also highly recommended to provide a WSDL description for service provider embeded in the service-unit,
  • XSL files referenced in the JBI descriptor.
service-unit.zip
  + META-INF
    - jbi.xml (as defined above)
    - service.wsdl (optional)
  - stylesheet-1.xsl
  - stylesheet-2.xsl

Example

<jbi:jbi xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cdk5="http://petals.ow2.org/components/extensions/version-5"
   xmlns:jbi="http://java.sun.com/xml/ns/jbi" xmlns:rest="http://petals.ow2.org/components/rest/version-1"
   xmlns:ged="http://petals.ow2.org/bc/rest/unit-test/ged" version="1.0">
   <jbi:services binding-component="true">
      <jbi:provides interface-name="gerd:document" service-name="ged:documentService">
         <cdk5:timeout>30000</cdk5:timeout>
         <cdk5:wsdl>ged.wsdl</cdk5:wsdl>
         <rest:service-base-path>/sample-rest</rest:service-base-path>
         <rest:mapping>
            <rest:operation name="ged:consulter">
               <rest:http-method>GET</rest:http-method>
               <rest:http-body-type>NO_BODY</rest:http-body-type>
               <rest:uri>http://localhost:8088/library/{library}/documents/{reference}</rest:uri>
               <rest:xpath-param name="library">//*[local-name()='library']</rest:xpath-param>
               <rest:xpath-param name="reference">//*[local-name()='reference']</rest:xpath-param>
               <rest:authentication>
                  <rest:basic>
                     <rest:username><rest:constant>${username}</rest:constant></rest:username>
                     <rest:password><rest:constant>${password}</rest:constant></rest:password>
                  </rest:basic>
               </rest:authentication>
               <rest:on-http-status code="200">
                  <rest:otherwise-out>
                     <rest:transformation>
                        <rest:xsl>200-consulter.xsl</rest:xsl>
                     </rest:transformation>
                  </rest:otherwise-out>
               </rest:on-http-status>
               <rest:on-http-status code="404">
                  <rest:otherwise-fault>
                     <rest:transformation>
                        <rest:xsl>404.xsl</rest:xsl>
                     </rest:transformation>
                  </rest:otherwise-fault>
               </rest:on-http-status>
            </rest:operation>
            <rest:operation name="ged:get-metadata">
               <rest:http-method>GET</rest:http-method>
               <rest:http-body-type>NO_BODY</rest:http-body-type>
               <rest:uri>http://localhost:8088/library/{library}/documents/{reference}/metadata</rest:uri>
               <rest:xpath-param name="library">//*[local-name()='library']</rest:xpath-param>
               <rest:xpath-param name="reference">//*[local-name()='reference']</rest:xpath-param>
               <rest:authentication>
                  <rest:basic>
                     <rest:username><rest:constant>${username}</rest:constant></rest:username>
                     <rest:password><rest:constant>${password}</rest:constant></rest:password>
                  </rest:basic>
               </rest:authentication>
               <rest:headers>
                  <rest:header name="Accept">
                     <rest:constant>application/json</rest:constant>
                  </rest:header>
               </rest:headers>
               <rest:json-xml-mapping-convention>MAPPED_CONVENTION</rest:json-xml-mapping-convention>
               <rest:on-http-status code="200">
                  <rest:otherwise-out>
                     <rest:transformation>
                        <rest:xsl>200-metadata.xsl</rest:xsl>
                     </rest:transformation>
                  </rest:otherwise-out>
               </rest:on-http-status>
               <rest:on-http-status code="404">
                  <rest:otherwise-fault>
                     <rest:transformation>
                        <rest:xsl>404.xsl</rest:xsl>
                     </rest:transformation>
                  </rest:otherwise-fault>
               </rest:on-http-status>
            </rest:operation>
            <rest:operation name="edm:reset-metadatas">
               <rest:http-method>PUT</rest:http-method>
               <rest:http-body-type>JSON</rest:http-body-type>
               <rest:uri>http://localhost:8080/library/{library}/document/{reference}/metadata</rest:uri>
               <rest:xpath-param name="library">//*[local-name()='library']</rest:xpath-param>
               <rest:xpath-param name="reference">//*[local-name()='reference']</rest:xpath-param>
               <rest:authentication>
                  <rest:basic>
                     <rest:username><rest:xpath>//*[local-name()='username']</rest:xpath></rest:username>
                     <rest:password><rest:xpath>//*[local-name()='password']</rest:xpath></rest:password>
                  </rest:basic>
               </rest:authentication>
               <rest:xsl>reset-metadatas-via-json-in.xsl</rest:xsl>
               <rest:http-body-to-json-virtual-root>metadatas</rest:http-body-to-json-virtual-root>
               <rest:http-body-to-json-multiple-pi>true</rest:http-body-to-json-multiple-pi>
               <rest:http-body-to-json-auto-array>true</rest:http-body-to-json-auto-array>
               <rest:on-http-status code="404">
                  <rest:otherwise-fault>
                     <rest:transformation>
                        <rest:xsl>documentInconnu-as-fault.xsl</rest:xsl>
                     </rest:transformation>
                  </rest:otherwise-fault>
               </rest:on-http-status>
            </rest:operation>
            <rest:operation name="edm:archiver">
               <rest:http-method>POST</rest:http-method>
               <rest:http-body-type>MULTIPART_FORMDATA</rest:http-body-type>
               <rest:uri>http://localhost:8080/library/{library}/document</rest:uri>
               <rest:xpath-param name="library">//*[local-name()='library']</rest:xpath-param>
               <rest:authentication>
                  <rest:basic>
                     <rest:username><rest:xpath>//*[local-name()='username']</rest:xpath></rest:username>
                     <rest:password><rest:xpath>//*[local-name()='password']</rest:xpath></rest:password>
                  </rest:basic>
               </rest:authentication>
               <rest:form-data name="file" as-attachment="true">
                  <rest:extracted-by-xpath>
                     substring-after(//*[local-name()='document']/*[local-name()='Include']/@href, 'cid:')
                  </rest:extracted-by-xpath>
                  <rest:attachment-name>
                     <rest:xpath>//*[local-name()='document']/*[local-name()='nom']</rest:xpath>
                  </rest:attachment-name>
               </rest:form-data>
               <rest:on-http-status code="200">
                  <rest:otherwise-out>
                     <rest:transformation>
                        <rest:xsl>archiver-200.xsl</rest:xsl>
                     </rest:transformation>
                  </rest:otherwise-out>
               </rest:on-http-status>
               <rest:on-http-status code="404">
                  <rest:otherwise-fault>
                     <rest:transformation>
                        <rest:xsl>unknownLibrary-as-fault.xsl</rest:xsl>
                     </rest:transformation>
                  </rest:otherwise-fault>
               </rest:on-http-status>
            </rest:operation>
         </rest:mapping>
      </jbi:consumes>
   </jbi:services>
</jbi:jbi>

With a WADL

Using a WADL file simplifies the implementation of the service provider:

  • the address of the RESTful Web Service is found in the WADL.
  • the REST operation corresponding to the JBI operation is found in the WADL.
  • the HTTP method is defined in the WADL for the operation.

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,
  • Dedicated parameters that are parameters driving the service provider implementation at component layer.

CDK parameters

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

Dedicated configuration

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

Attribute Description Default value Required
wadl WADL which defines the partner service
-
Yes*

Service unit content

The service unit has to contain the following elements, packaged in the archive:

  • the META-INF/jbi.xml descriptor file as described above,
  • it is also highly recommended to provide a WSDL description for service provider embedded in the service-unit,
  • a WADL file describing the partner service.
service-unit.zip
  + META-INF
    - jbi.xml (as defined above)
  - service.wsdl (recommended)
  - resource.wadl

Exposing an internal JBI service endpoint as a RESTful Web Service

In consumer mode, the component exposes an internal JBI service outside the bus to transfer incoming REST requests to the internal service.

Usage

The petals-bc-rest component can listen incoming REST messages and send messages to a JBI service endpoint by deploying a Service Unit on it.

The value of the service-unit extension '{{service-name }}' will be used as service name.

When a REST message is handled by the component, it is transformed into a JBI Message and sent to the JBI service endpoint configured in the Service Unit.

The JBI message is created like this:

  • The JBI service operation invoked is selected from the HTTP methode and path of the REST request,
  • The JBI message content is created according to the HTTP method of the incoming REST request:
    • GET: The JBI message content is created from the REST URI path and parameters
    • PATCH: The JBI message content is created according to the Content-Type HTTP header:
      • XML content types: The JBI message content is created from the HTTP body (there is no JBI attachment created). A XSL transformation can be applied if needed.
      • JSON content types: The JSON content is converted into XML (there is no JBI attachment created). A XSL transformation can be applied if needed.
    • POST: The JBI message content is also created differently according to the Content-Type HTTP header:
      • Non XML content types: The JBI message content is a reference (cf SOAP) to a JBI attachment which contains the HTTP body
      • XML content types: The JBI message content is created from the HTTP body (there is no JBI attachment created). A XSL transformation can be applied if needed.
      • JSON content types: The JSON content is converted into XML (there is no JBI attachment created). A XSL transformation can be applied if needed.
    • PUT/DELETE: There is no JBI message content
  • A JBI attachment is created according to the HTTP method of the incoming REST request:
    • GET/DELETE/PATCH: There is no JBI attachment created
    • POST: A JBI attachment is created from the HTTP body if the Content-Type HTTP header contains a non XML content type.
    • PUT: A JBI attachment is created from the HTTP body
  • The HTTP headers are added to the the protocol header JBI message property
  • The MEP is defined by the exchange pattern defined in the service provider contract (ie. WSDL of the service provider).

A WADL is available at the following URL: (TBC)
A WSDL 2.0 is available at the following URL: (TBC)

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 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 consumer 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
Enable ('true') or disable ('false') the flow tracing for this service consumer. This value overrides the value defined at component level and can be overridden at incoming exchange level. Value defined at component level
No
Yes
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

The parameter 'mep' of the section 'consumes' is not used. It must be set to 'null':
<cdk:mep xsi:nil="true" />

The MEP is selected from the exchange pattern defined in the service provider contract (ie. WSDL of the service provider).

The configuration of the flow tracing (ie. value of parameter 'activate-flow-tracing') can be overidden on REST resource invocation setting the HTTP header 'org.ow2.petals.monitoring.activate-flow-tracing':
  • not set: the parameter 'activate-flow-tracing' configured at service unit level is applied,
  • 'true': the flow tracing is activated,
  • 'false': the flow tracing is deactivated.

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


Attribute Description Default value Required Support of placeholders
http-method HTTP method to use. Possible values are: GET, PATCH, POST, PUT and DELETE.
-
Yes
Not applicable
path-template URI template of the resource exposed. Java regular expressions are supported into parameter part of URI template as following:
  • /blah/{ver:v[12]}/ep,
  • /{id : (\d+)}.
-
Yes
Yes
incoming-payload If set, a transformation will be applied on XML extracted from HTTP body (eventually resulting from JSON conversion). Only XSL transformation is supported through the sub-element 'xsl'.
each URI parameter is available as XSL parameter (without namespace).
-
No
No
http-body-from-json-multiple-pi This parameter drives the conversion of JSON to XML. See https://github.com/beckchr/staxon/wiki/Factory-Configuration

false
No
Not applicable
http-body-from-json-virtual-root This parameter drives the conversion of JSON to XML. See https://github.com/beckchr/staxon/wiki/Factory-Configuration

-
No
Not applicable
on-jbi-response Defines the REST response that will be generated according to the JBI service response:
  • the sub-elements 'on-out', 'on-fault' or 'on-error' define conditional transformations to apply on the service provider response, fault or error. The first condition evaluated to 'true' determine the transformation that will be applied. The result of the transformation will be used as HTTP response. Several conditional transformations can be defined:
    • the attribute 'order-id' permits to order condition evaluations,
    • the sub-element 'condition' defines the condition to evaluate. Now, only XPath conditions are supported through the sub-element 'xpath'. XPath condition supports placeholders,
    • the sub-element 'transformation' defines a preliminar transformation to apply on the XML payload of the response service if the condition matches, before to eventually be converted into JSON through the declaration 'http-response'. Now, only XSL transformations are supported through the sub-element 'xsl'. Placeholders are supported neither to define XSL stylesheet nor into the XSL stylesheet,
      If the service response has no XML payload, the XML payload of the service request is used to be transformed instead of the service response XML payload.

      Several XSL parameters are set to be used in the XSL transformation:

    • the sub-element 'http-response' defines the transformation to apply if the condition matches to generate the HTTP REST response:
      • the attribute 'http-code' defines the HTTP code returned. Placeholder not supported,
      • the attribute 'http-body-is-empty' defines if the body of the HTTP response must be empty. The default value is 'false' except for 'on-error' and 'on-default-error' for which the default value will be 'true' if no transformation is defined with 'transformation',
      • headers can be added through sub-elements 'header'. The header name is provided through attribute 'name'. Header name does not support placeholder, but they are supported at header value level,
      • the sub-element http-body-to-json-multiple-pi drives the conversion of XML to JSON. See https://github.com/beckchr/staxon/wiki/Factory-Configuration

        . Default value: false, placeholder not supported,

      • the sub-element http-body-to-json-virtual-root drives the conversion of XML to JSON. See https://github.com/beckchr/staxon/wiki/Factory-Configuration

        . No default virtual root, placeholder not supported,

      • the sub-element http-body-to-json-auto-array drives the conversion of XML to JSON. See https://github.com/beckchr/staxon/wiki/Factory-Configuration

        . Default value: false, placeholder not supported,

      • the sub-element http-body-to-json-auto-primitive drives the conversion of XML to JSON. See https://github.com/beckchr/staxon/wiki/Factory-Configuration

        . Default value: false, placeholder not supported,

      • the sub-element http-body-to-json-pretty-print drives the conversion of XML to JSON. See https://github.com/beckchr/staxon/wiki/Factory-Configuration

        . Default value: false, placeholder not supported,

      • the sub-element http-body-to-json-ns-declarations drives the conversion of XML to JSON. See https://github.com/beckchr/staxon/wiki/Factory-Configuration

        . Default value: false, placeholder not supported.

        The content type of the HTTP response is defined according to the header 'Accept' of the incoming HTTP REST request. The content-type used for the HTTP response is the first one contained in the header value and compliant with XML or JSON.
  • the sub-elements 'on-default-out' defines the default HTTP response to generate on a nominal response of service provider when no condition matches it,
  • the sub-elements 'on-default-fault' defines the default HTTP response to generate on a fault returned by the service provider when no condition matches it,
  • the sub-elements 'on-default-error' defines the default HTTP response to generate on an error returned by the service provider when no condition matches it.
-
Yes
Check sub-element

Service unit content

The service unit has to contain the following elements, packaged in the archive:

  • the META-INF/jbi.xml descriptor file as described above,
  • XSL files referenced in the JBI descriptor.
service-unit.zip
  + META-INF
    - jbi.xml (as defined above)
    - stylesheet-1.xsl
    - stylesheet-2.xsl

Example

<jbi:jbi version="1.0" ..>
   <jbi:services binding-component="true">
      <jbi:consumes interface-name="inscription-cantine:inscriptionCantine">
         <cdk:timeout>${municipalite.timeout.clt-services.qf}</cdk:timeout>
         <cdk:mep xsi:nil="true" />

         <rest:service-base-path>/api/demarches-administratives</rest:service-base-path>
         <rest:mapping>
            <rest:operation name="inscription-cantine:new">
               <!-- REST request part -->
               <rest:http-method>POST</rest:http-method>
               <rest:path-template>/demande-cantine</rest:path-template>
               <rest:http-body-from-json-virtual-root>new</rest:http-body-from-json-virtual-root>
               <rest:incoming-payload>
                  <rest:transformation>
                     <rest:xsl>new-request.xsl</rest:xsl>
                  </rest:transformation>
               </rest:incoming-payload>

               <!-- REST response part -->
               <rest:on-jbi-response>
                  <rest:on-default-out>
                     <rest:http-response http-code="201">
                        <rest:header name="Access-Control-Allow-Origin">
                           <rest:constant>*</rest:constant>
                        </rest:header>
                        <rest:header name="Access-Control-Allow-Headers">
                           <rest:constant>Origin, X-Requested-With, Content-Type, Accept</rest:constant>
                        </rest:header>
                        <rest:http-body-to-json-virtual-root>newResponse</rest:http-body-to-json-virtual-root>
                     </rest:http-response>
                  </rest:on-default-out>
                  <rest:on-default-error>
                     <rest:http-response http-code="500" />
                  </rest:on-default-error>
               </rest:on-jbi-response>
            </rest:operation>
            <rest:operation name="inscription-cantine:validate">
               <!-- REST request part -->
               <rest:http-method>PUT</rest:http-method>
               <rest:path-template>/demande-cantine/{numero-demande}</rest:path-template>
               <rest:http-body-from-json-virtual-root>validate</rest:http-body-from-json-virtual-root>
               <rest:incoming-payload>
                  <rest:transformation>
                     <rest:xsl>validate-request.xsl</rest:xsl>
                  </rest:transformation>
               </rest:incoming-payload>
               
               <!-- REST response part -->
               <rest:on-jbi-response>
                  <rest:on-default-out>
                     <rest:http-response http-code="202">
                        <rest:http-body-to-json-virtual-root>validateResponse</rest:http-body-to-json-virtual-root>
                     </rest:http-response>
                  </rest:on-default-out>
                  <rest:on-fault order-id="0">
                     <rest:condition>
                        <rest:xpath>boolean(//*[local-name()='inscriptionInconnue'])</rest:xpath>
                     </rest:condition>
                     <rest:http-response http-code="404" />
                  </rest:on-fault>
                  <rest:on-fault order-id="1">
                     <rest:condition>
                        <rest:xpath>boolean(//*[local-name()='inscriptionDejaValidee'])</rest:xpath>
                     </rest:condition>
                     <rest:http-response http-code="409" />
                  </rest:on-fault>
                  <rest:on-default-error>
                     <rest:http-response http-code="500" />
                  </rest:on-default-error>
               </rest:on-jbi-response>
            </rest:operation>
            <rest:operation name="flowable-integration:getProcessInstances">
               <!-- REST request part -->
               <rest:http-method>GET</rest:http-method>
               <rest:path-template>/usager-demandeur/{usager-demandeur}</rest:path-template>
               <rest:http-body-from-json-virtual-root>getProcessInstances</rest:http-body-from-json-virtual-root>
               <rest:xml-template>
                  <flowable-integration:getProcessInstances>
                     <flowable-integration:process-definition-identifier>inscriptionCantine</flowable-integration:process-definition-identifier>
                     <flowable-integration:variables>
                        <flowable-integration:variable name="citizen">{usager-demandeur}</flowable-integration:variable>
                     </flowable-integration:variables>
                  </flowable-integration:getProcessInstances>
               </rest:xml-template>
               
               <!-- REST response part -->
               <rest:on-jbi-response>
                  <rest:on-default-out>
                     <rest:transformation>
                        <rest:xsl>demandes-usager.xsl</rest:xsl>
                     </rest:transformation>
                     <rest:http-response http-code="200">
                        <rest:header name="Access-Control-Allow-Origin">
                           <rest:constant>*</rest:constant>
                        </rest:header>
                        <rest:header name="Access-Control-Allow-Headers">
                           <rest:constant>Origin, X-Requested-With, Content-Type, Accept</rest:constant>
                        </rest:header>
                        <rest:http-body-to-json-auto-array>true</rest:http-body-to-json-auto-array>
                     </rest:http-response>
                  </rest:on-default-out>
                  <rest:on-default-error>
                     <rest:http-response http-code="500">
                        <rest:header name="Access-Control-Allow-Origin">
                           <rest:constant>*</rest:constant>
                        </rest:header>
                        <rest:header name="Access-Control-Allow-Headers">
                           <rest:constant>Origin, X-Requested-With, Content-Type, Accept</rest:constant>
                        </rest:header>
                     </rest:http-response>
                  </rest:on-default-error>
               </rest:on-jbi-response>
            </rest:operation>
         </rest:mapping>
      </jbi:consumes>
   </jbi:services>
</jbi:jbi>

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,
  • and parameters dedicated to the REST part:
    • embedded REST server,
    • embedded REST client.
<jbi:jbi xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:petalsCDK="http://petals.ow2.org/components/extensions/version-5"
   xmlns:jbi="http://java.sun.com/xml/ns/jbi" version="1.0"
   xmlns:rest="http://petals.ow2.org/components/rest/version-1">

   <jbi:component type="binding-component">
      ...
      <petalsCDK:acceptor-pool-size />
      <petalsCDK:acceptor-retry-number />
      <petalsCDK:acceptor-retry-wait />
      <petalsCDK:acceptor-stop-max-wait />
      <petalsCDK:processor-pool-size />
      <petalsCDK:processor-max-pool-size />
      <petalsCDK:processor-keep-alive-time />
      <petalsCDK:processor-stop-max-wait />
      <petalsCDK:time-beetween-async-cleaner-runs />
      <petalsCDK:properties-file />
      <petalsCDK:monitoring-sampling-period />
      ...
      <rest:http-host />
      <rest:http-port>8086</rest:http-port>
      <rest:connection-timeout />
      <rest:read-timeout />
      ...
   </jbi:component>
</jbi:jbi>

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

These parameters drive features proposed by the component and configure the REST part:

  • the embedded REST server,
  • the embedded REST client.

Parameters of the embedded REST server

Parameter Description Default Required Scope
http-host The interface(s) on which the component listens incoming REST requests
All interfaces
No
Installation
http-port The TCP port on which the component listens incoming REST requests
8086
No
Installation

Parameters of the embedded REST client

Parameter Description Default Required Scope
max-connection-per-route Default max number of connections per target host, used to establish a connection to the remote external resource.
2
No
Installation
connection-timeout Timeout, in milliseconds, used to establish a connection to the remote external resource.
60s
No
Installation
read-timeout Timeout, in milliseconds, used to receive the response of a remote external resource.
60s
No
Installation

The maximum number of total open connections is defined accordingly the Petals CDK parameter 'processor-max-pool-size'.

Logging

Logging of the embedded HTTP server

The traces of the embedded HTTP server "Jetty" are activated through the logging configuration file of Petals ESB. The root logger for Jetty is org.eclipse.jetty:

...
org.eclipse.jetty.level=INFO
...

Logging of the embedded HTTP client

The traces of the embedded HTTP client "Apache HTTP client" are activated through the logging configuration file of Petals ESB. The root logger for Apache HTTP client is org.apache.http. You will find more information about Apache HTTP client loggers here: https://hc.apache.org/httpcomponents-client-ga/logging.html

...
org.apache.http.level=INFO
...

Business monitoring

MONIT traces

Each service provider exposed in Petals ESB 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 external service provider invocation, when sending a request to the external service provider, with following attributes:
    • traceCode set to provideExtFlowStepBegin,
    • flowInstanceId set to the flow instance identifier retrieved from the incoming request,
    • flowStepId set to an UUID value,
    • flowPreviousStepId set to the step identifier of the previous step that is the internal processing of the incoming request into the BC.
  • on external service provider termination, when receiving the outgoing response of the external service provider, with following attributes:
    • traceCode set to provideExtFlowStepEnd or provideExtFlowStepFailure,
    • flowInstanceId set to the flow instance identifier retrieved from the incoming request,
    • flowStepId set to the flow step identifier defined for the external service provider invocation.
  • 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 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.

On service consumer side, the flow tracing can be enabled ('true') or disabled ('false') per request using the HTTP header org.ow2.petals.monitoring.activate-flow-tracing. If not defined, the flow tracing will be activated according to the service consumer definition.

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.

Unit testing

The unit testing can occur at several levels in your Rest service unit:

  • on the provider side:
    • to check the operation definition in the JBI descriptor
    • to check the compliance of the JBI descriptor with the WSDL content,
    • to unit test your XSL transformations.

A dedicated framework is available as an extension of JUnit providing facilities:

  • to validate your WSDL:
    • in a WSDL point of view,
    • checking the compliance of the JBI descriptor with the WSDL content,
  • to validate your JBI descriptor:
    • checking syntax of the XPath expressions,
  • to verify generated response from HTTP response.

This dedicated framework is provided by the Maven artifact org.ow2.petals:petals-bc-rest-junit:

<project>
   ...
   <dependencies>
      ...
      <dependency>
         <groupId>org.ow2.petals</groupId>
         <artifactId>petals-bc-rest-junit</artifactId>
         <version>2.2.0</version>
         <scope>test</scope>
      </dependency>
      ...
   </dependencies>
   ...
</project>
See the Compatibility Matrix to known the version of the BC Rest Junit framework compliant with your version of the BC Rest.

Checking the compliance of the JBI descriptor with WSDL content

The unit test framework contains an assertion 'assertWsdlCompliance' to verify easily the compliance of your JBI descriptor with the WSDL content. As the WSDL is parsed, it's syntax is also verified:

import static org.ow2.petals.binding.rest.junit.Assert.assertWsdlCompliance;

public class WsdlValidatorTest {

    @Test
    public void validateJbiAgainstWsdl() throws Exception {

        assertWsdlCompliance();
    }

}

The WSDL file to verify is extracted from the JBI descriptor content.

Unit-testing your operation definitions

The unit test framework contains several assertions to verify transformation of HTTP response:

  • assertJBIOutResponse: The result of the HTTP response is expected as an OUT message similar to the given resource,
  • assertJBIFault: The result of the HTTP response is expected as a fault similar to the given resource,
  • assertJBIStatus: The result of the HTTP response is expected as the given status,
  • assertJBIRequestEmpty: The result of the transformation from JBI to a HTTP request is expected as a given HTTP URI and no HTTP body,
  • assertJBIRequestJSON: The result of the transformation from JBI to a HTTP request is expected as a given HTTP URI and a JSON body similar to the given resource,
  • assertJBIRequestXML: The result of the transformation from JBI to a HTTP request is expected as a given HTTP URI and a XML body similar to the given resource,
  • assertJBIRequestForm: The result of the transformation from JBI to a HTTP request is expected as a given HTTP URI and an URL-encoded form data as HTTP body similar to the given resource.
import static org.ow2.petals.binding.rest.junit.Assert.assertJBIFault;
import static org.ow2.petals.binding.rest.junit.Assert.assertJBIOutResponse;
...
import org.ow2.petals.binding.rest.junit.rule.ServiceOperationUnderTest;
...

    @ClassRule
    public static final ServiceOperationUnderTest OPERATION_UNDER_TEST = new ServiceOperationUnderTest(
            OP_GET_METADATA_BY_JSON);

    @Test
    public void nominal() throws Exception {
        assertJBIOutResponse("get-metadata-expected-nominal-response.xml", OPERATION_UNDER_TEST,
                HttpStatus.SC_OK, null, "get-metadata-nominal-http-body.json",
                MediaType.APPLICATION_JSON_TYPE, null);
    }

    @Test
    public void nometadata() throws Exception {
        assertJBIOutResponse("get-metadata-expected-no-metadata-response.xml", OPERATION_UNDER_TEST,
                HttpStatus.SC_OK, null, "get-metadata-no-metadata-http-body.json",
                MediaType.APPLICATION_JSON_TYPE, null);
    }

    @Test
    public void unexistingDocument() throws Exception {

        assertJBIFault("get-metadata-expected-fault-unexisting-document.xml", OPERATION_UNDER_TEST,
                HttpStatus.SC_NOT_FOUND, null, null, null, "get-metadata-by-json-request.xml", null);
    }
}

In the service unit JBI descriptor, the response transformations are described for each operation. The JUnit rule ServiceOperationUnderTest represents one of these operations, and the response transformation processing is the same than the one of the component. This JUnit rule is used to execute the transformation on a given HTTP response through assertions assertJBIOutResponse or assertJBIFault. For each assertion, the transformation result is compared to the content of the given resource. Following part of the HTTP response used as input of the transformation can be set:

  • the HTTP status,
  • a resource name containing the HTTP body,
  • the content type of the HTTP body,
  • a resource name containing the JBI IN message payload,
  • URI parameters.

See the Javadoc for more details on parameters.

Know problems

Handshake error invoking external resources through HTTPS

Problem:
In some cases, invoking external resources through HTTPS, you can get a connection reset by peer because of a handshake error. This problem can occur on Java 7 (previous to 1.7.0_91-b15) with a SSL certificate with a key size upper to 1024 bits.

Solution:
Run Petals ESB with a more recent Java 7 version (1.7.0_91-b15 or upper) or with Java 8 (any version).

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.