Petals-BC-REST 1.1.0+

This version must be installed on Petals ESB 5.0.2+

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

Exposing an external Restful Web Service as a JBI service endpoint

In provide mode, the component exposes an external Web Service in the JBI environment to send REST requests to the external Web Service.

Usage

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

Provides an external resource as a JBI service

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

The REST request is created like this:

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

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

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

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

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

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

Configuration

With no description of the RESTful resource

All needed information must be defined in the service-unit. See Service Unit attributes to provide services for more information :

<jbi:jbi xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cdk5="http://petals.ow2.org/components/extensions/version-5"
   xmlns:jbi="http://java.sun.com/xml/ns/jbi" xmlns:rest="http://petals.ow2.org/components/rest/version-1"
   xmlns:ged="http://petals.ow2.org/bc/rest/unit-test/ged" version="1.0">
   <jbi:services binding-component="true">
      <jbi:provides interface-name="gerd:document" service-name="ged:documentService">
         <cdk5:timeout>30000</cdk5:timeout>
         <cdk5:wsdl>ged.wsdl</cdk5:wsdl>
         <rest:service-base-path>/sample-rest</rest:service-base-path>
         <rest:mapping>
            <rest:operation name="ged:consulter">
               <rest:http-method>GET</rest:http-method>
               <rest:http-body-type>NO_BODY</rest:http-body-type>
               <rest:uri>http://localhost:8088/library/{library}/documents/{reference}</rest:uri>
               <rest:xpath-param name="library">//*[local-name()='library']</rest:xpath-param>
               <rest:xpath-param name="reference">//*[local-name()='reference']</rest:xpath-param>
               <rest:authentication>
                  <rest:basic>
                     <rest:username><rest:constant>${username}</rest:constant></rest:username>
                     <rest:password><rest:constant>${password}</rest:constant></rest:password>
                  </rest:basic>
               </rest:authentication>
               <rest:on-http-status code="200">
                  <rest: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: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: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: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:xsl as-fault="true">documentInconnu-as-fault.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: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: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>

The Service Unit has to contain the following elements, packaged in the archive:

  • the META-INF/jbi.xml descriptor file as described above,
  • XSL files referenced in the JBI descriptor.

With a WADL

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

The Service Unit has to contain the following elements, packaged in the archive:

  • The META-INF/jbi.xml descriptor file as described above,
  • An optional imported WADL file describing the partner service.

With a WSDL 2.0

The address of the RESTful Web Service is found in the WSDL 2.0.
The REST operation corresponding to the JBI operation is found in the WSDL 2.0.
The HTTP method is defined in the WSDL 2.0 for the operation.

The Service Unit has to contain the following elements, packaged in the archive:

  • The META-INF/jbi.xml descriptor file as described above,
  • An optional imported WSDL 2.0 file describing the partner service.
Configuration of a Service Unit to provide a service (JBI)

Parameter Description
Default
Required
provides Describe the JBI service that will be exposed into the JBI bus. Interface (QName), Service (QName) and Endpoint (String) attributes are required. - Yes

Configuration of a Service Unit to provide a service (CDK)

Parameter Description
Default
Required
timeout Timeout in milliseconds of a synchronous send. This parameter is used by the method sendSync (Exchange exchange) proposes by the CDK Listeners classes.
Set it to 0 for an infinite timeout.
30000 No
exchange-properties This sections defines the list of properties to set to the JBI exchange when processing a service. - No
message-properties This sections defines the list of properties to set to the JBI message when processing a service. - No
validate-wsdl Activate the validation of the WSDL when deploying a service unit. true No
wsdl
Path to the WSDL document describing services and operations exposed by the provided JBI endpoints defined in the SU.
The value of this parameter is :
  • an URL
  • a file relative to the root of the SU package
    If not specified, a basic WSDL description is automaticaly provided by the CDK.
- No
forward-attachments
Defines if attachment will be forwarded from IN message to OUT message.
false No
forward-message-properties
Defines if the message properties will be forwarded from IN message to OUT message. false No
forward-security-subject
Defines if the security subject will be forwarded from IN message to OUT message. false No

Service Unit attributes to provide services

Attribute Description Default value Required
http-method HTTP method to use. Possible values are: GET, POST, PUT and DELETE.
Yes*
http-body-type Define which kind of HTTP body the resource is expecting:
  • NO_BODY: no HTTP body is expected,
  • XML: the HTTP body is filled with the incoming XML payload, possibly transformed by the XSL tansformation defined with 'xsl',
  • JSON: the HTTP body is filled with the incoming XML payload, possibly transformed by the XSL tansformation defined with 'xsl', converted into JSON,
  • POST_QUERY_STRING:
  • MULTIPART_FORMDATA: A multi-part HTTP request is built. Each part will be defined using 'form-data'.
Yes
uri URI template of the external resource.
Value of substitutable parameters are retrieved from XPath expressions given by 'xpath-param', or retrieved from JBI message properties.
Yes*
xpath-param Define how to retrieve an URI template parameter as an XPath expression executed on the incoming payload. The attribute name is the name of the parameter in the URI template, and the value is the XPath expression to apply.
Yes, if at least one parameter is included into the URI template
authentication Defines the authentication to set on the REST request.
<rest:authentication>
   <rest:basic>
      <rest:username><rest:constant>${username}</rest:constant></rest:username>
      <rest:password><rest:xpath>//*[local-name()='password']</rest:xpath></rest:password>
   </rest:basic>
</rest:authentication>

Available authentication are available:

  • 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.
No
headers Defines the HTTP headers to set on the REST request:
  • each header defines through a sub-element '<header />' for which the attribute 'name' is the name of the header,
  • the value to set is defined by the content of the sub-element '<header />':
    • '<constant />', the constant of this tag will be used as header value,
    • '<xpath />', the header value is extracted from the incoming payload by an XPath expression
      <rest:headers>
         <rest:header name="Accept"><rest:constant>application/xml</rest:constant><rest:header>
         <rest:header name="X-RequestDigest"><rest:xpath>/update/token</rest:xpath><rest:header>
      <rest:headers>
      
No
xsl A XSL style-sheet used to transform the incoming XML payload before to generate the HTTP body of the REST request. The result of this transformation will be used to be converted into JSON or to be set as XML payload.
No
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
No
form-data Define the form data to put in a part of a multi-part HTTP request:
  • the attribute 'name' define the name of the form data,
  • the sub-element 'extracted-by-xpath' defines the XPath expression applied on the incoming request to compute the value to set into the form data. If the result of the XPath expression is the content identifier of an attachment of the incoming request, the attribute 'as-attachment' drives the processing of the attachment: if 'true', the attachment content will be put into the form data, otherwise the content id will be put. If you want to put the XPath result as a form field value, use the value 'false'.
No
wadl WADL which defines the partner service
Yes*
wsdl2 WSDL2 which defines the partner service
Yes*

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

Exposing an internal JBI service endpoint as a RESTful Web Service

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

Usage

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

Consumes a JBI service on a REST message

The service-name Service Unit extension value will be used as service name.

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

The JBI message is created like this:

  • The JBI operation is created differently from the operation present in the REST URI operation
  • The JBI message content is created according to the HTTP method of the incoming REST request:
    • GET: The JBI message content is created from the REST URI path and parameters
    • 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)

Configuration

Configuration of a Service Unit to consume a service (JBI)

Parameter Description Default Required
consumes Refer JBI service to invoke into the JBI bus.
You can define an explicit endpoint: interface (QName) / Service (QName) / Endpoint (String) attributes.
Or define implicit endpoint, to let the container routing according to QOS configurations (HA...):
-by Interface attribute (QName)
-by Service attribute (QName)
- Yes


Configuration of a Service Unit to consume a service (CDK)

Parameter Description Default Required
mep Message exchange pattern abbreviation. This parameter can be used in conjunction with the method of the CDK Listeners: createMessageExchange(Extensions extensions).
This method returns a CDK Exchange corresponding to the type of the specified pattern.
- Yes
operation Operation to call on a service. This parameter can be used in conjunction with the sending methods of the Listeners. If no operation is specified in the Message Exchange to send, this parameter will be used. - No
timeout Timeout in milliseconds of a synchronous send. This parameter can be used in conjunction with the sendSync(Exchange exchange) method of the Listeners. Set 0 for an infinite timeout. 30000 No


Service Unit attributes to consume services

Attribute Description Default value Required
service-name Web Service name to expose.  
No

Service Unit descriptor

The service unit is configurable via its extensions in the jbi.xml file:


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

Monitoring the component

Using metrics

Several probes providing metrics are included in the component, and are available through the JMX MBean 'org.ow2.petals:type=custom,name=monitoring_<component-id>', where <component-id> is the unique JBI identifier of the component.

Common metrics

The following metrics are provided through the Petals CDK, and are common to all components:

Metrics, as MBean attribute Description Detail of the value Configurable
MessageExchangeAcceptorThreadPoolMaxSize The maximum number of threads of the message exchange acceptor thread pool integer value, since the last startup of the component yes, through acceptor-pool-size
MessageExchangeAcceptorThreadPoolCurrentSize The current number of threads of the message exchange acceptor thread pool. Should be always equals to MessageExchangeAcceptorThreadPoolMaxSize. instant integer value no
MessageExchangeAcceptorCurrentWorking The current number of working message exchange acceptors. instant long value no
MessageExchangeAcceptorMaxWorking The max number of working message exchange acceptors. long value, since the last startup of the component no
MessageExchangeAcceptorAbsoluteDurations The aggregated durations of the working message exchange acceptors since the last startup of the component. n-tuple value containing, in nanosecond:
  • the maximum duration,
  • the average duration,
  • the minimum duration.
no
MessageExchangeAcceptorRelativeDurations The aggregated durations of the working message exchange acceptors on the last sample. n-tuple value containing, in nanosecond:
  • the maximum duration,
  • the average duration,
  • the minimum duration,
  • the 10-percentile duration (10% of the durations are lesser than this value),
  • the 50-percentile duration (50% of the durations are lesser than this value),
  • the 90-percentile duration (90% of the durations are upper than this value).
no
MessageExchangeProcessorAbsoluteDurations The aggregated durations of the working message exchange processor since the last startup of the component. n-tuple value containing, in milliseconds:
  • the maximum duration,
  • the average duration,
  • the minimum duration.
no
MessageExchangeProcessorRelativeDurations The aggregated durations of the working message exchange processor on the last sample. n-tuple value containing, in milliseconds:
  • the maximum duration,
  • the average duration,
  • the minimum duration,
  • the 10-percentile duration (10% of the durations are lesser than this value),
  • the 50-percentile duration (50% of the durations are lesser than this value),
  • the 90-percentile duration (90% of the durations are upper than this value).
no
MessageExchangeProcessorThreadPoolActiveThreadsCurrent The current number of active threads of the message exchange processor thread pool instant integer value no
MessageExchangeProcessorThreadPoolActiveThreadsMax The maximum number of threads of the message exchange processor thread pool that was active integer value, since the last startup of the component no
MessageExchangeProcessorThreadPoolIdleThreadsCurrent The current number of idle threads of the message exchange processor thread pool instant integer value no
MessageExchangeProcessorThreadPoolIdleThreadsMax The maximum number of threads of the message exchange processor thread pool that was idle integer value, since the last startup of the component no
MessageExchangeProcessorThreadPoolMaxSize The maximum size, in threads, of the message exchange processor thread pool instant integer value yes, through http-thread-pool-size-max
MessageExchangeProcessorThreadPoolMinSize The minimum size, in threads, of the message exchange processor thread pool instant integer value yes, through http-thread-pool-size-min
MessageExchangeProcessorThreadPoolQueuedRequestsCurrent The current number of enqueued requests waiting to be processed by the message exchange processor thread pool instant integer value no
MessageExchangeProcessorThreadPoolQueuedRequestsMax The maximum number of enqueued requests waiting to be processed by the message exchange processor thread pool since the last startup of the component instant integer value no
ServiceProviderInvocations The number of service provider invocations grouped by:
  • interface name, as QName, the invoked service provider,
  • service name, as QName, the invoked service provider,
  • invoked operation, as QName,
  • message exchange pattern,
  • and execution status (PENDING, ERROR, FAULT, SUCCEEDED).
integer counter value since the last startup of the component no
ServiceProviderInvocationsResponseTimeAbs The aggregated response times of the service provider invocations since the last startup of the component grouped by:
  • interface name, as QName, the invoked service provider,
  • service name, as QName, the invoked service provider,
  • invoked operation, as QName,
  • message exchange pattern,
  • and execution status (PENDING, ERROR, FAULT, SUCCEEDED).
n-tuple value containing, in millisecond:
  • the maximum response time,
  • the average response time,
  • the minimum response time.
no
ServiceProviderInvocationsResponseTimeRel The aggregated response times of the service provider invocations on the last sample, grouped by:
  • interface name, as QName, the invoked service provider,
  • service name, as QName, the invoked service provider,
  • invoked operation, as QName,
  • message exchange pattern,
  • and execution status (PENDING, ERROR, FAULT, SUCCEEDED).
n-tuple value containing, in millisecond:
  • the maximum response time,
  • the average response time,
  • the minimum response time,
  • the 10-percentile response time (10% of the response times are lesser than this value),
  • the 50-percentile response time (50% of the response times are lesser than this value),
  • the 90-percentile response time (90% of the response times are lesser than this value).
no

Dedicated metrics

No dedicated metric is available.

Receiving alerts

Several alerts are notified by the component through notification of the JMX MBean 'org.ow2.petals:type=custom,name=monitoring_<component-id>', where <component-id> is the unique JBI identifier of the component.

To integrate these alerts with Nagios, see Receiving Petals ESB defects in Nagios.

Common alerts

Defect JMX Notification
A message exchange acceptor thread is dead
  • type: org.ow2.petals.component.framework.process.message.acceptor.pool.thread.dead
  • no user data
No more thread is available in the message exchange acceptor thread pool
  • type: org.ow2.petals.component.framework.process.message.acceptor.pool.exhausted
  • no user data
No more thread is available to run a message exchange processor
  • type: org.ow2.petals.component.framework.process.message.processor.thread.pool.exhausted
  • no user data

Dedicated alerts

No dedicated alert is available.

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