July 30, 2023

cREST – Docs for ESB ESB 7.x

cREST

Provides integration with Apache CXF for connecting to JAX-RS
services.

cREST Standard properties

These properties are used to configure cREST running in the
Standard Job framework.

The Standard
cREST component belongs to the
Connectivity family.

Basic settings

API definition

Click […] to browse to the OAS/Swagger 2.0 file
to initialize your component endpoint, API mappings and documentation
from your API definition.

Endpoint

The service endpoint URL where the REST service is
provided. You can either specify an explicit port number, for example,
"http://localhost:8088/services/customers", or use the
default port of Talend and specify the relative path only, for example,
"/services/customers".

The default port is different depending on the build
type or where you run the service:

  • To run the service inside Talend Studio:
    8090
  • To run the service in a Talend Runtime Container: for HTTP 8040 is used for all services,
    and if HTTPS is enable on Talend Runtime the
    service is also exposed on 9001.
  • To run the service as a Microservice: 8065

Type

Select which type you want to use to provide the REST
service. Either Manual or resourceClass.

Manual: Determine the REST API
mapping manually in the table if cREST is used as a service provider, or set HTTP Method
and other parameters if the component is used as a service consumer.

resourceClass: Select this type to
provide the resource class which you want to export as the REST
service.

REST API Mapping

This table appears when the Manual service type is selected and cREST is used as a service provider.

Click [+] under the
table to add as many rows as needed to specify the HTTP request:

Output Flow: Specify the name of an
output flow.

HTTP Verb: Select a HTTP method
from GET, POST, PUT,
DELETE, OPTIONS and HEAD in the list.

URI pattern: Fill this field with
the REST URI that describes the resource.

Consumes: Select the format type of
the consume content that the component will use from XML or JSON, XML, JSON,
Form, Multipart, and Any
when HTTP Verb is POST or PUT.

Produces: Select the format type of
the produce content that the component will use from XML or JSON, XML, JSON,
HTML, Any when HTTP Verb
is GET, POST, PUT or
DELETE.

Bean class: Set the bean class when
the HTTP Verb is POST or PUT and the consume content format is XML or JSON, XML or JSON.

Resource Class

This field appears when the resourceClass service type is selected. Enter the name
of the resource class which you want to export as the REST service.

Operation

This field appears when the resourceClass service type is selected and cREST is used as the service consumer.
Enter the name of the operation.

Relative Path

This field appears when the Manual service type is selected and cREST is used as the service consumer.
Enter the relative path of the REST server to be invoked.

HTTP Method

This option appears when the Manual service type is selected and cREST is used as the service consumer.
Select a HTTP method fromGET,
POST, PUT, and DELETE in
the list.

Warning:

When using the POST method to create an
object, by default, the created object ID will not be get back
from the header. By default, the cREST
filters any header except system headers. To get the created
object ID, you need to set
javax.ws.rs.core.Response as the response
class.

Content Type

This option appears when the Manual service type is selected and cREST is used as the service consumer.

Select XML, JSON, or FORM according to the media type of the content to be
uploaded to the server end. This list appears only when you select the
POST or PUT in the HTTP
Method
list.

Accept Type

This field appears when the Manual service type is selected and cREST is used as the service consumer.

Select the media type the client end is prepared to accept
for the response from the server end. Available options are XML, JSON, and ANY.
When ANY is selected, the response
message can be of any type and will be transformed into a string. This
list does not appear when you select the DELETE method.

Response Class

This field appears when the Manual service type is selected and the cREST is used as the service consumer.
Enter the name of the response class.

Use Service Locator

Select this check box to enable the Service Locator.
Specify the service namespace and the service name in the corresponding
fields.

Enable the Service Activity
Monitoring

Select this check box to enable the Service Activity
Monitor.

Note that this option works in Runtime only. When running
the Route in the Studio, it is recommended to clear this check box.
Otherwise warnings will be thrown in the execution console.

Use Authentication

Select this check box to enable the authentication option.
Select the authentication type from:

  • HTTP Basic: The simplest technique for
    enforcing access controls to web resources using standard fields in
    the HTTP header.
  • SAML Token (ESB runtime only): An XML-based,
    open-standard data format for exchanging authentication and
    authorization data between an identity provider and a service
    provider.
  • Open
    ID Connect
    : An extension for OAuth2 which allows
    Clients to verify the identity of the End-User based on the
    authentication performed by an Authorization Server, as well as to
    obtain basic profile information about the End-User in an
    interoperable and REST-like manner.

When the cREST
component is used as consumer, enter a username and a password in the
corresponding fields as required. To enter the password, click the
[…] button next to the
password field, and then in the pop-up dialog box enter the password
between double quotes and click OK
to save the settings.

Use Authorization

This option is only available if you subscribed to Talend
Enterprise ESB solutions. It appears when SAML
Token (ESB runtime only)
is selected in the Use Authentication list.

When the cREST
component is used as the service provider, select this check box to
enable authorization.

When the cREST
component is used as the service consumer, select this check box to
invoke authorized call and specify the client’s role in the Role field.

Use Business Correlation

Select this check box to create a correlation ID in this
component.

You can specify a correlation ID in the Correlation Value field.

Advanced settings

Log messages

Select this check box to log the message exchanges in the
Route.

Expose Swagger specification

This option appears when cREST is used as a service provider, and is available
only when the Manual service type
is selected. Select this check box to expose the Swagger specification
and include the Swagger UI into the REST service, which provides an
online API Documentation in human-readable form and some basic test
features.

If the Route is running in the Studio, the Swagger specification will be
available at
http://127.0.0.1:8090/ENDPOINT/swagger.json and
http://127.0.0.1:8090/ENDPOINT/swagger.yaml. The
Swagger UI is not available.

If the Route is running in Talend Runtime, the Swagger specification will be available at
http://127.0.0.1:8040/services/ENDPOINT/swagger.json
and
http://127.0.0.1:8040/services/ENDPOINT/swagger.yaml.
The Swagger UI will be available at
http://127.0.0.1:8040/services/ENDPOINT/api-docs?url=/services/ENDPOINT/swagger.json.

If the Route is running as a ESB Microservice, the Swagger specification
will be available at
http://127.0.0.1:8065/services/ENDPOINT/swagger.json
and
http://127.0.0.1:8065/services/ENDPOINT/swagger.yaml.
The Swagger UI will be available at
http://127.0.0.1:8065/services/ENDPOINT/api-docs?url=/services/ENDPOINT/swagger.json.

For more information about how to build a Route to a ESB Microservice and
how to run the Microservice, see Talend Studio User
Guide.

Include Documentation into Swagger Spec

This option appears when cREST is used as a
service provider and the Expose Swagger
specification
check box is selected. Select this option
to add content in the Comment field of the
Documentation tab of this component into the
Swagger specification and the Swagger UI page.

For more information about the Documentation tab,
see Talend Studio
User Guide.

Arguments Set the optional arguments in the corresponding table. Click [+] as many times as required to add arguments
to the table. Then click the corresponding Value field and enter a value. See the site http://camel.apache.org/cxfrs.html for available
URI options.

Usage

Usage rule

cREST can be a start component in a
Route as the service provider, or middle or end component as the service
consumer.

Limitation

Due to license incompatibility, one or more JARs required to use
this component are not provided. You can install the missing JARs for this particular
component by clicking the Install button
on the Component tab view. You can also
find out and add all missing JARs easily on the Modules tab in the
Integration
perspective of your studio. You can find more details about how to install external modules in
Talend Help Center (https://help.talend.com)
.

Providing and consuming a REST service using cREST

This scenario applies only to Talend Open Studio for ESB, Talend Data Services Platform and Talend Data Fabric.

This scenario demonstrates how to use the cREST component to provide and consume a REST service. To do so, two Routes are
built, a service provider Route and a consumer Route. The service provider Route will be
accessible for requests and respond with some predefined customer information. The consumer
Route will send a request to the REST service.

Building the service provider Route

This Route provides a REST Web service using the cREST component. In this Route, a cBeanRegister component is used to set the customer information in a Java bean.
The bean is then called by a cSetBody as the response of
the service.

Dropping and linking the components

cREST_1.png

  1. From the Palette, drag and drop a
    cREST, a cSetBody, a cLog and a cBeanRegister component onto the design workspace.
  2. Link the cREST, cSetBody and cLog
    using the Row > Route connection.
  3. Label the components for better identification of their roles.

Configuring the components

  1. Double-click the cBeanRegister component to display its Basic settings view in the Component tab.

    cREST_2.png

  2. The cBeanRegister component
    registers a Java bean, in which the customer information is set with the firstName, lastName,
    city, and id
    values.

    In the Id field, enter “customers” to name the bean.
    Select the Customized
    option and enter the following code in the Code box to create two customers and set the firstName, lastName,
    city, and id
    values for each of
    them:
  3. Double-click the cREST
    component to display its Basic settings
    view in the Component tab.

    cREST_3.png

  4. The cREST component is used
    to provide the REST service.

    In the Endpoint field, type
    in the endpoint URL where the Web service will be provided, “http://localhost:8040/services/customers” in this example.
    From the Type list, select
    Manual to determine the REST API
    mapping manually.
    In the REST API mapping
    table, click [+] to add a row in the table.
    In the Output Flow field, enter getAllCustomers as the name of it. Select GET in the HTTP
    Verb
    list. Keep the default settings in the other
    columns.
  5. Double-click the cSetBody
    component to display its Basic settings
    view in the Component tab.

    cREST_4.png

  6. Select SIMPLE from the
    Dataformat list. In the Expression field, enter “ref:customers” to refer to the bean defined in the cBeanRegister component as the message body of the
    service response.
  7. Keep the default settings of the cLog component to log the message exchanges.

    cREST_5.png

  8. Press Ctrl+S to save your
    route.

Viewing code and executing the Route

  1. Click the Code tab at the
    bottom of the design workspace to have a look at the generated code.

    cREST_6.png

    As shown in the code, the Route is built from
    cREST_1, set message body in cSetBody_1 and then to cLog_1.
  2. Click the Run view to display it
    and click the Run button to launch the execution
    of your Route. You can also press F6 to execute
    it.

    RESULT: The service is successfully started. You can access it from
    a Web browser using the service endpoint URL. The customer information is shown in
    the browser.
    cREST_7.png

Building the service consumer Route

This Route will consume the REST service that is built in the provider
Route.

Arranging the flow of the message

cREST_8.png

  1. From the Palette, drag and drop
    a cTimer, a cREST, and a cLog component onto
    the design workspace.
  2. Link the cTimer, cREST and cLog
    using the Row > Route connection.
  3. Label the components for better identification of their roles.

Configuring how the message is processed

  1. Double-click the cTimer
    component to display its Basic settings
    view in the Component tab.

    cREST_9.png

  2. In the Repeat field, enter
    1 to generate the message exchange one time. Keep the
    default settings of the other options.
  3. Double-click the cREST
    component to display its Basic settings
    view in the Component tab.

    cREST_10.png

  4. This cREST component will
    consume the REST service built in the provider Route.

    In the Endpoint field, type
    in the URL of the service, “http://localhost:8040/services/customers” in this example.
    Select Manual from the
    Type list. In the Relative Path field, enter constant(“”). Select GET in the
    HTTP Method list. Keep the default
    settings of the other options.
  5. Keep the default settings of the cLog component to log the message exchanges.

    cREST_11.png

  6. Press Ctrl+S to save your
    route.

Executing the Route

  1. Click the Code tab at the
    bottom of the design workspace to have a look at the generated code.

    cREST_12.png

    As shown in the code, the Route is built from
    cTimer_1. The HTTP_PATH, HTTP_METHOD, and ACCEPT_CONTENT_TYPE are set in cREST_1. The message is then routed to cLog_1.
  2. Click the Run view to display it
    and click the Run button to launch the execution
    of your Route. You can also press F6 to execute
    it.

    RESULT: The customers information is displayed in the
    console.
    cREST_13.png


Document get from Talend https://help.talend.com
Thank you for watching.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x