View Source

{section}
{column}

{warning}This version must be installed on [Petals ESB 5.1.0|petalsesb510:Petals ESB 5.1.0]+{warning}

h1. 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 is based on Jersey and Axis2 (TBD). It 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


{info}
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]
{info}
{column}
{column:width=25%}
{panel:title=Table of contents}{toc}{panel}
{panel:title=Contributors}{contributors:order=name|mode=list}{panel}
{column}
{section}

h1. 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.

h2. Usage

The Petals BC REST component can expose an external Web Service as a JBI service endpoint by deploying a Service Unit on it:

{center}

*Provides an external resource as a JBI service*
{center}

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}}:
{code:lang=xml}
<consulter xmlns="http://petals.ow2.org/bc/rest/unit-test/ged">
<library>My Documents</library>
<reference>6</reference>
</consulter>
{code}

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.

h2. Configuration

h3. With no description of the RESTful resource

All needed information must be defined in the service-unit. See [Service Unit attributes to provide services|#service-unit-attributes-provide] for more information :
{code:xml}
<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>
{code}

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.

h3. 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.

h3. 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.

{include:0 CDK SU Provide Configuration}

{anchor:service-unit-attributes-provide}
{center}{*}Service Unit attributes to provide services{*}{center}
{table-plus}
|| Attribute || Description || Default value || Required ||
| http-method | HTTP method to use. Possible values are: GET, POST, PUT and DELETE. | {center}-{center} | {center}Yes\*{center} |
| 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:
* 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. | {center}-{center} | {center}Yes{center} |
| 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. | {center}-{center} | {center}Yes\*{center} |
| buffer-request | if the request should be buffered to be sent, mostly useful with authentication methods that requires multiple retries. | {center}{{false}}{center} | {center}No{center} |
| trust-all-certificates | Do not fail if an HTTPS connection uses an untrusted certificate (self-signed, expired, etc). DO NOT USE IN PRODUCTION. | {center}{{false}}{center} | {center}No{center} |
| 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. | {center}-{center} | {center}Yes, if at least one parameter is included into the URI template{center} |
| authentication | Defines the authentication to set on the REST request.
{code}
<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>
{code}
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|https://github.com/jwtk/jjwt] 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. | {center}-{center} | {center}No{center} |
| 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
{code}
<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>
{code} | {center}-{center} | {center}No{center} |
| 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. | {center}-{center} | {center}No{center} |
| 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}}: The body content type is auto-detected from the HTTP response content-type,
* {{xml}}: The body contains XML,
* {{json}}: The body contains JSON,
* {{attachment}}: The body is an attachment. | {center}{{auto}}{center} | {center}No{center} |
| on-http-status | Define how to process a given HTTP status:
* the attribute {{code}} is the HTTP code associated to this processing,
* 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 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}}',
{tip}
If the HTTP body response is a XML or JSON payload, it is used as XML to be transformed according to the current {{on-htt-status}} definition. Several XSL parameters are set to be used in the XSL transformation:
* the IN message payload can be loaded by the XSL through a variable using the XSL statement: {{<xsl:variable name="inPayload" select="document('petals-bc-rest:in-payload')"/>}}
* each URI parameter is available without namespace,
* the HTTP response status is available as parameters '{{http-status-code}}' and '{{http-status-reason}}' from namespace '{{http://petals.ow2.org/bc/rest/xsl/param/output/1.0}}',
* the headers of the HTTP response are available as parameters from namespace '{{http://petals.ow2.org/bc/rest/xsl/param/output/1.0/headers}}'. The parameter name is the HTTP header name, and its value the HTTP header value.

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 content identifier of the attachment is available as parameter '{{content-id}}' from namespace '{{http://petals.ow2.org/bc/rest/xsl/param/output/1.0}}',
* the HTTP response status is available as parameters '{{http-status-code}}' and '{{http-status-reason}}' from namespace '{{http://petals.ow2.org/bc/rest/xsl/param/output/1.0}}',
* the headers of the HTTP response are available as parameters from namespace '{{http://petals.ow2.org/bc/rest/xsl/param/output/1.0/headers}}'. The parameter name is the HTTP header name, and its value the HTTP header value,
* each URI parameter is available without namespace,
{tip}
* 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 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 avaiable 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. | {center}-{center} | {center}No{center} |
| 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}}'.
* 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}}'. | {center}-{center} | {center}No{center} |
| http-body-to-json-multiple-pi | This parameter drives the conversion of XML to JSON. See https://github.com/beckchr/staxon/wiki/Factory-Configuration | {center}false{center} | {center}No{center} |
| http-body-from-json-multiple-pi | This parameter drives the conversion of JSON to XML. See https://github.com/beckchr/staxon/wiki/Factory-Configuration | {center}false{center} | {center}No{center} |
| http-body-to-json-virtual-root | This parameter drives the conversion of XML to JSON. See https://github.com/beckchr/staxon/wiki/Factory-Configuration | {center}-{center} | {center}No{center} |
| http-body-from-json-virtual-root | This parameter drives the conversion of JSON to XML. See https://github.com/beckchr/staxon/wiki/Factory-Configuration | {center}-{center} | {center}No{center} |
| http-body-to-json-auto-array | This parameter drives the conversion of XML to JSON. See https://github.com/beckchr/staxon/wiki/Factory-Configuration | {center}false{center} | {center}No{center} |
| http-body-to-json-auto-primitive | This parameter drives the conversion of XML to JSON. See https://github.com/beckchr/staxon/wiki/Factory-Configuration | {center}false{center} | {center}No{center} |
| http-body-to-json-pretty-print | This parameter drives the conversion of XML to JSON. See https://github.com/beckchr/staxon/wiki/Factory-Configuration | {center}false{center} | {center}No{center} |
| http-body-to-json-ns-declarations | This parameter drives the conversion of XML to JSON. See https://github.com/beckchr/staxon/wiki/Factory-Configuration | {center}false{center} | {center}No{center} |
| 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 | {center}-{center} | {center}No{center} |
| wadl | WADL which defines the partner service | {center}-{center} | {center}Yes\*{center} |
| wsdl2 | WSDL2 which defines the partner service | {center}-{center} | {center}Yes\*{center} |
{table-plus}

\*Either {{uri}} and {{http-method}} extensions or {{wadl}} or {{wsdl2}} must be present in a specific SU.

h1. 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.

h2. 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:


{center}

*Consumes a JBI service on a REST message*
{center}

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
** POST: The JBI message content is also created differently according 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)
** 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: 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)

h2. Configuration

{include:0 CDK SU Consume Configuration}
\\
{center}{*}Service Unit attributes to consume services{*}{center}
{table-plus}
|| Attribute || Description || Default value || Required ||
| service-name | Web Service name to expose. | | {center}No{center} |
{table-plus}

h3. Service Unit descriptor

The service unit is configurable via its extensions in the jbi.xml file:
{code:lang=xml}
{code}

h3. 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

h1. 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.

{code:lang=xml}
<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>
{code}

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

{include:0 CDK Component Configuration Table 5.6.0}
{include:0 CDK Parameter scope}
{include:0 CDK Component Interceptor configuration}

h2. Component specific parameters

These parameters drive features proposed by the component and configure the REST part:
* the embedded REST server,
* the embedded REST client.

h3. Parameters of the embedded REST server
{table-plus}
|| {color:#333333}Parameter{color} || {color:#333333}Description{color} || {color:#333333}Default{color} || {color:#333333}Required{color} || Scope ||
| http-host | The interface(s) on which the component listens incoming REST requests | {center}All interfaces{center} | {center}No{center} | {center}Installation{center} |
| http-port | The TCP port on which the component listens incoming REST requests | {center}8086{center} | {center}No{center} | {center}Installation{center} |

h3. Parameters of the embedded REST client
{table-plus}
|| {color:#333333}Parameter{color} || {color:#333333}Description{color} || {color:#333333}Default{color} || {color:#333333}Required{color} || Scope ||
| connection-timeout | Timeout, in milliseconds, used to establish a connection to the remote external resource. | {center}60s{center} | {center}No{center} | {center}Installation{center} |
| read-timeout | Timeout, in milliseconds, used to receive the response of a remote external resource. | {center}60s{center} | {center}No{center} | {center}Installation{center} |

h1. Logging

h2. 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}}:
{code}
...
org.eclipse.jetty.level=INFO
...
{code}

h2. 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
{code}
...
org.apache.http.level=INFO
...
{code}

h1. Monitoring the component

h2. 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.

h3. Common metrics

{include:0 CDK Component Monitoring Metrics 5.6.0}

h3. Dedicated metrics

No dedicated metric is available.

h2. 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.

{tip}To integrate these alerts with Nagios, see [petalsesbsnapshot:Receiving Petals ESB defects in Nagios].{tip}

h3. Common alerts

{include:0 CDK Component Monitoring Alerts 5.6.0}

h3. Dedicated alerts

No dedicated alert is available.

{anchor:Unit_Testing}
h1. 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}}:
{code:xml}
<project>
...
<dependencies>
...
<dependency>
<groupId>org.ow2.petals</groupId>
<artifactId>petals-bc-rest-junit</artifactId>
<version>1.0.0</version>
<scope>test</scope>
</dependency>
...
</dependencies>
...
</project>
{code}

{warning}The version 1.0.0+ of the framework is compliant with the Petals BC REST 1.1.0+.{warning}

h2. 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:
{code:lang=java}
import static org.ow2.petals.binding.rest.junit.Assert.assertWsdlCompliance;

public class WsdlValidatorTest {

@Test
public void validateJbiAgainstWsdl() throws Exception {

assertWsdlCompliance();
}

}
{code}

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

h2. 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,

{code:lang=java}
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);
}
}
{code}

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.

h1. Know problems

h2. 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).