FeatureThe 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:
It is based on:
|
Table of contents
Contributors
No contributors found for: authors on selected page(s)
|
Exposing an external Restful Web Service as a JBI service endpoint
In provide mode, the component exposes an external Web Service in the JBI environment to send REST requests to the external Web Service.
Usage
The Petals BC REST component can expose an external Web Service as a JBI service endpoint by deploying a Service Unit on it:
Provides an external resource as a JBI service
When a message is received on a REST linked endpoint from the JBI environment, it is transformed into a REST message 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+Documents/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.
- if the HTTP status is catched by a configuration element 'on-http-status', the return depends on the message exchange pattern:
Configuration
With no description of the RESTful resource
All needed information must be defined in the service-unit. See Service Unit attributes to provide services for more information :
<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>
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.
With a WADL
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.
The Service Unit has to contain the following elements, packaged in the archive:
- The META-INF/jbi.xml descriptor file as described above,
- An optional imported WADL file describing the partner service.
With a WSDL 2.0
The address of the RESTful Web Service is found in the WSDL 2.0.
The REST operation corresponding to the JBI operation is found in the WSDL 2.0.
The HTTP method is defined in the WSDL 2.0 for the operation.
The Service Unit has to contain the following elements, packaged in the archive:
- The META-INF/jbi.xml descriptor file as described above,
- An optional imported WSDL 2.0 file describing the partner service.
Parameter
|
Description
|
Default
|
Required
|
---|---|---|---|
provides
|
Describe the JBI service that will be exposed into the JBI bus. Interface (QName), Service (QName) and Endpoint (String) attributes are required. | -
|
Yes
|
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:
|
-
|
Yes
|
||
uri | URI template of the external resource. Value of substitutable parameters are retrieved from XPath expressions given by 'xpath-param', or retrieved from JBI message properties. |
-
|
Yes*
|
||
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
|
||
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:
|
-
|
No
|
||
headers | Defines the HTTP headers to set on the REST request:
|
-
|
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. | -
|
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
|
||
response-body-as | Defined the body content type. By default, the body content-type is auto-detected according to the content-type of the HTTP response, but in few case it is necessary to specify it. Possible values are:
|
auto
|
No
|
||
on-http-status | Define how to process a given HTTP status:
|
-
|
No
|
||
form-data | Define the form data to put in a part of a multi-part HTTP request:
|
-
|
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
|
||
wadl | WADL which defines the partner service | -
|
Yes*
|
||
wsdl2 | WSDL2 which defines the partner service | -
|
Yes*
|
*Either uri and http-method extensions or wadl or wsdl2 must be present in a specific SU.
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 component consumes the JBI service:
Consumes a JBI service on a REST message
The service-name Service Unit extension value 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 operation is created differently from the operation present in the REST URI operation
- 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 petalsCDK:mep extension.
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. See Service Unit attributes to consume services for more information :
<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>
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.
Parameter
|
Description
|
Default
|
Required
|
---|---|---|---|
consumes
|
Refer JBI service to invoke into the JBI bus. You can define an explicit endpoint: interface (QName) / Service (QName) / Endpoint (String) attributes. Or define implicit endpoint, to let the container routing according to QOS configurations (HA...): -by Interface attribute (QName) -by Service attribute (QName) |
- | Yes |
Parameter
|
Description
|
Default
|
Required
|
Support placeholders
|
---|---|---|---|---|
mep
|
Message exchange pattern abbreviation. This parameter can be used in conjunction with the method of the CDK Listeners: createMessageExchange(Extensions extensions). This method returns a CDK Exchange corresponding to the type of the specified pattern. |
- | Yes
|
No
|
operation
|
Operation to call on a service. This parameter can be used in conjunction with the sending methods of the Listeners. If no operation is specified in the Message Exchange to send, this parameter will be used. | - | 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
|
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:
|
-
|
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'.
|
-
|
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:
|
-
|
Yes
|
Check sub-element
|
Service Unit descriptor
The service unit is configurable via its extensions in the jbi.xml file:
<jbi:jbi version="1.0" xmlns:jbi="http://java.sun.com/xml/ns/jbi" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cdk="http://petals.ow2.org/components/extensions/version-5" xmlns:rest="http://petals.ow2.org/components/rest/version-1" xmlns:inscription-cantine="http://municipalite.fr/demarches-administratives/inscription-cantine/1.0"> <jbi:services binding-component="true"> <jbi:consumes interface-name="inscription-cantine:inscriptionCantine"> <cdk:timeout /> <cdk:mep xsi:nil="true" /> <rest:service-base-path>/api</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>/demarches-administratives/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:xml-template> <!-- TODO: Should be removed. Not needed here --> <dummy /> </rest:xml-template> <!-- REST request part --> <rest:http-body-to-json-virtual-root>newResponse</rest:http-body-to-json-virtual-root> </rest:operation> <rest:operation name="inscription-cantine:validate"> <!-- REST request part --> <rest:http-method>PUT</rest:http-method> <rest:path-template>/demarches-administratives/cantine/{numero-demande}</rest:path-template> <rest:http-body-from-json-virtual-root>validate</rest:http-body-from-json-virtual-root> <rest:xml-template> <!-- TODO: Should be removed. Not needed here --> <dummy /> </rest:xml-template> <!-- REST request part --> <rest:http-body-to-json-virtual-root>validateResponse</rest:http-body-to-json-virtual-root> </rest:operation> </rest:mapping> </jbi:consumes> </jbi:services> </jbi:jbi>
Service Unit content
The Service Unit has to contain the following elements, packaged in an archive:
- The META-INF/jbi.xml descriptor file as described above
- XSLs required by transformations
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 :
|
- | Installation |
monitoring-sampling-period | Period, in seconds, of a sample used by response time probes of the monitoring feature. |
300 |
Installation |
Definition of CDK parameter scope :
- 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.
Interceptor
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 manipulate only by power users. An 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"?> <!--...--> <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> <!--...-->
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 can be referenced to add extended parameters by a 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 |
Component specific parameters
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 |
---|---|---|---|---|
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
|
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 ...
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:
|
no |
MessageExchangeAcceptorRelativeDurations | The aggregated durations of the working message exchange acceptors on the last sample. | n-tuple value containing, in nanosecond:
|
no |
MessageExchangeProcessorAbsoluteDurations | The aggregated durations of the working message exchange processor since the last startup of the component. | n-tuple value containing, in milliseconds:
|
no |
MessageExchangeProcessorRelativeDurations | The aggregated durations of the working message exchange processor on the last sample. | n-tuple value containing, in milliseconds:
|
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:
|
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:
|
n-tuple value containing, in millisecond:
|
no |
ServiceProviderInvocationsResponseTimeRel | The aggregated response times of the service provider invocations on the last sample, grouped by:
|
n-tuple value containing, in millisecond:
|
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 |
|
No more thread is available in the message exchange acceptor thread pool |
|
No more thread is available to run a message exchange processor |
|
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>1.2.0</version> <scope>test</scope> </dependency> ... </dependencies> ... </project>
The version 1.0.0+ of the framework is compliant with the Petals BC REST 1.1.0+. The version 1.1.0+ of the framework is compliant with the Petals BC REST 1.2.0+. The version 1.2.0+ of the framework is compliant with the Petals BC REST 1.3.0+. |
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,
- assertJBIRequestJSON: The result of the transformation from JBI to an HTTP request is expected as a JSON body similar to the given resource,
- assertJBIRequestXML: The result of the transformation from JBI to an HTTP request is expected as a XML 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).