View Source

{section}
{column}

{warning}This version must be installed on Petals ESB 5.0.2+{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 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
* The headers present in the protocol header JBI message property are added to the HTTP headers.

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.
In all cases, the HTTP headers are added to the protocol header JBI message property.

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:on-http-status code="200">
<rest:xsl>200-consulter.xsl</rest:xsl>
</rest:on-http-status>
<rest:on-http-status code="404">
<rest:xsl as-fault="true">404.xsl</rest:xsl>
</rest:on-http-status>
</rest:operation>
<rest:operation name="ged: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:json-xml-mapping-convention>MAPPED_CONVENTION</rest:json-xml-mapping-convention>
<rest:on-http-status code="200">
<rest:xsl>200-metadata.xsl</rest:xsl>
</rest:on-http-status>
<rest:on-http-status code="404">
<rest:xsl as-fault="true">404.xsl</rest:xsl>
</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: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:form-data>
<rest:on-http-status code="200">
<rest:xsl>archiver-200.xsl</rest:xsl>
</rest:on-http-status>
<rest:on-http-status code="404">
<rest:xsl as-fault="true">unknownLibrary-as-fault.xsl</rest:xsl>
</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}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,
* JSON: the HTTP body is filled with the incoming XML payload converted into JSON,
* POST_QUERY_STRING:
* MULTIPART_FORMDATA: A multi-part HTTP request is built. Each part will be defined using '{{form-data}}'. | - | {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}Yes\*{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}Yes, if at least one parameter is included into the URI template{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-element '{{xsl}}' is the XSL generating the content of the reply to return,
** the reply type (fault or normal response) is defined according to the value of the attribute '{{as-fault}}'. The default reply type is a normal reply,
** the XSL can accept following global parameters according to the following cases:
*** generating a fault: The XML to transform is the incoming payload. Parameters of the URI called are available as XSL global parameters. The name of the XSL global parameter is the name of the URI parameter,
*** generating a normal reply from an XML or JSON response: The XML to transform is the XML returned by the resource or resulting of the JSON conversion. The incoming payload is available through the XSL global parameter '{{{http://petals.ow2.org/bc/rest/xsl/param/output/1.0}incoming-request}}',
*** generating a normal reply from an attachment response: The XML to transform is the incoming payload, and the content id of the attachment set in the JBI response message is available through the XSL global parameter '{{\{http://petals.ow2.org/bc/rest/xsl/param/output/1.0\}content-id}}'. | - | {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}}'. | - | {center}No{center} |
| wadl | WADL which defines the partner service | - | {center}Yes\*{center} |
| wsdl2 | WSDL2 which defines the partner service | - | {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. 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.