|
Key
This line was removed.
This word was removed. This word was added.
This line was added.
|
Changes (17)
View Page Historyh2. Usage
The petals-bc-rest 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 Web Service 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 Web Service. resource server.
The REST request is created like this:
For example the following JBI message:
{code:lang=xml}
{code:lang=xml}
<consulter xmlns="http://petals.ow2.org/bc/rest/unit-test/ged">
<library>My Documents</library>
<reference>6</reference>
</consulter>
<library>My Documents</library>
<reference>6</reference>
</consulter>
{code}
produces the URI [http://weather.yahooapis.com/].... {{http://localhost:8088/library/My+Documents/documents/6/metadata}}
The external Web Service 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 error (HTTP status different from 20x) a JBI fault error is created.
* The JBI 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,
** JSON content types: The JBI message content is created from the JSON body converted into XML,
** JSON content types: The JBI message content is created from the JSON body converted into XML,
** 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)
* The HTTP headers are added to the protocol header JBI message property
h3. With no description of the RESTful resource
h3. With no description of the RESTful Web Service
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: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:operation>
</rest:mapping>
</jbi:consumes>
</jbi:services>
</jbi:jbi>
{code}
{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: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:operation>
</rest:mapping>
</jbi:consumes>
</jbi:services>
</jbi:jbi>
{code}
The address of the RESTful Web Service is defined in the address extension of the deployed Service Unit.
The HTTP method is defined in the http-method SU extension.
The HTTP method is defined in the http-method SU extension.
h3. With a WADL
{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 ||
| address | Address of the external Web Service to send JBI messages to. | | {center}Yes\*{center} |
{table-plus}
|| Attribute || Description || Default value || Required ||
| address | Address of the external Web Service to send JBI messages to. | | {center}Yes\*{center} |
| http-method | HTTP method to use. \\
\\
Possible values are: GET for the HTTP method GET, POST for the HTTP method POST, PUT for the HTTP method PUT and DELETE for the HTTP method DELETE. \\ | | {center}Yes\*{center} |
\\
Possible values are: GET for the HTTP method GET, POST for the HTTP method POST, PUT for the HTTP method PUT and DELETE for the HTTP method DELETE. \\ | | {center}Yes\*{center} |
| http-method | HTTP method to use. Possible values are: GET, POST, PUT and DELETE. | - | {center}Yes\*{center} |
| wadl | WADL which defines the partner service | | {center}Yes\*{center} |
| wsdl2 | WSDL2 which defines the partner service | | {center}Yes\*{center} |
| wsdl2 | WSDL2 which defines the partner service | | {center}Yes\*{center} |