View Source

{section}
{column}

{warning}This version must be installed on [Petals ESB 5.3.0|petalsesb530:Petals ESB 5.3.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 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:
* Eclipse Jetty v9.4.11.v20180605 (http://www.eclipse.org/jetty/),
* [Apache HTTP Asynchronous Client|https://hc.apache.org/httpcomponents-asyncclient-4.1.x/index.html] v4.1.4, patched with:
** [Apache HTTP Core|https://hc.apache.org/httpcomponents-core-4.4.x/index.html] v4.4.14,
** [Apache HTTP Core|https://hc.apache.org/httpcomponents-core-4.4.x/index.html] NIO v4.4.14,
* Jersey v2.33 (https://jersey.github.io/),
* Staxon v1.3 (https://github.com/beckchr/staxon),
* Java JWT v0.9.1 (https://github.com/jwtk/jjwt).

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

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

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

{include:0 CDK SU Provide Configuration 5.8.0}

h4. CDK parameters driving interceptors
The following parameters drive interceptors at CDK layer.

{include:0 CDK SU Interceptor configuration 5.8.0}

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

{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: 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. | {center}-{center} | {center}Yes{center} |
| 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}'.
{tip}
Example: {code}<rest:uri>https://${placeholder.host}:${placeholder.port}/api/library/{placeholder.library.id}/document/{document-id}/chapters</rest:uri></rest:post-query>{code}
{tip} | {center}-{center} | {center}Yes\*{center} |
| 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. | {center}{{ignore}}{center} | {center}No{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} |
| 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.
{tip}
Example: {code}<rest:post-query>grant_type=client_credentials&amp;validity_period={placeholder.ttl}</rest:post-query>{code}
{tip} | {center}-{center} | {center}Yes, if '{{http-body-type}}' is set to '{{POST_QUERY_STRING}}'{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. 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. | {center}-{center} | {center}No{center} |
| 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. | {center}false{center} | {center}No{center} |
| 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}}',
{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-http-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,
* 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.

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,
* 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.
{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 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. | {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}}',
** 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}}'. | {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} |
{table-plus}

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

{code}
service-unit.zip
+ META-INF
- jbi.xml (as defined above)
- service.wsdl (optional)
- stylesheet-1.xsl
- stylesheet-2.xsl
{code}

h4. Example

{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}

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

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

{include:0 CDK SU Provide Configuration 5.8.0}

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

{table-plus}
|| Attribute || Description || Default value || Required ||
| wadl | WADL which defines the partner service | {center}-{center} | {center}Yes\*{center} |
{table-plus}

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

{code}
service-unit.zip
+ META-INF
- jbi.xml (as defined above)
- service.wsdl (recommended)
- resource.wadl
{code}

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

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

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

{include:0 CDK SU BC Consume Configuration 5.8.0}

{note}
The parameter '{{mep}}' of the section '{{consumes}}' is not used. It must be set to 'null': {code:lan=xml}<cdk:mep xsi:nil="true" />{code}
The MEP is selected from the exchange pattern defined in the service provider contract (ie. WSDL of the service provider).
{note}

{note}
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.
{note}

h3. CDK parameters driving interceptors
The following parameters drive interceptors at CDK layer.

{include:0 CDK SU Interceptor configuration 5.8.0}

h3. Dedicated configuration

{anchor:service-unit-attributes-consume}
{table-plus}
|| Attribute || Description || Default value || Required || Support of placeholders ||
| {{http-method}} | HTTP method to use. Possible values are: GET, PATCH, POST, PUT and DELETE. | {center}-{center} | {center}Yes{center} | {center}Not applicable{center} |
| {{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+)}. | {center}-{center} | {center}Yes{center} | {center}Yes{center} |
| {{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}}'.
{tip}
each URI parameter is available as XSL parameter (without namespace).
{tip} | {center}-{center} | {center}No{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} | {center}Not applicable{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} | {center}Not applicable{center} |
| {{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,
{tip}
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:
* each URI parameter is available without namespace,
* 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,
* in case of error response, two additional parameters are set:
** '\{http://petals.ow2.org/bc/rest/xsl/param/output/1.0/placeholders\}error-message' that contains the error message,
** '\{http://petals.ow2.org/bc/rest/xsl/param/output/1.0/placeholders\}error-stack-trace' filled with the error stack trace.
{tip}
** 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.
{tip}
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.
{tip}
* 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. | {center}-{center} | {center}Yes{center}| {center}Check sub-element{center} |

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

{code}
service-unit.zip
+ META-INF
- jbi.xml (as defined above)
- stylesheet-1.xsl
- stylesheet-2.xsl
{code}

h3. Example

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

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.8.0}

h2. Interception configuration
{include:0 CDK Component Interceptor configuration 5.8.0}

h2. Dedicated configuration

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} |
{table-plus}

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 ||
| max-connection-per-route | Default max number of connections per target host, used to establish a connection to the remote external resource. | {center}2{center} | {center}No{center} | {center}Installation{center} |
| 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} |
{table-plus}

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

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. Business monitoring

h2. MONIT traces

{include:0 CDK BC Business Monitoring Traces 5.8.0}

h2. Flow tracing activation

{include:0 CDK BC Provides Business Monitoring Flow Tracing Activation 5.8.0}

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.

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.8.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>2.2.0</version>
<scope>test</scope>
</dependency>
...
</dependencies>
...
</project>
{code}

{warning}
See the [Compatibility Matrix|petalsesb:Compatibility Matrix] to known the version of the BC Rest Junit framework compliant with your version of the BC Rest.
{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,
* {{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.

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