Skip to main content Skip to complementary content

How to validate a data record through the REST API using a Job

Availability-noteDeprecated

The following example shows how to use a Talend Job to validate a data record through the REST API and print out the response message accordingly.

The Job is composed of two components: tREST and tJavaRow:

  • tREST is used to send the HTTP request and get the response correspondingly.
  • tJavaRow is used to print out the response.

Download the Job file: tREST.zip.

Before you begin

  • The MDM server is up and running.
  • You have already launched Talend Studio.
  • You have already imported the MDM Demo Project.

Procedure

  1. From the Palette, drop two components tREST and tJavaRow on the workspace.
  2. Connect tREST to tJavaRow using a Row > Main link.
  3. Double-click tREST to open its Basic settings tab.
  4. In the URL field, enter the URL to access the MDM REST API service.
    In this example, it is http://localhost:8180/talendmdm/services/rest/data/Product/validate.
  5. From the HTTP Method list, select POST.
  6. Click the [+] button to add two lines in the HTTP Headers area to describe the content type of the HTTP request and specify the authorization information.
    In this example, provide the following name/value pairs:
    name value

    "Content-Type"

    "application/xml"

    "Authorization"

    "Basic YWRtaW5pc3RyYXRvcjphZG1pbmlzdHJhdG9y"

  7. In the HTTP Body area, enter the data record you want to validate against the master storage in XML format.
    In this example, the <root> element is used to enclose the data record.
  8. Double-click tJavaRow to open its Basic settings tab.
  9. In the Code area, enter your customized code.
    For example:
    System.out.println("\n##### An invalid record example #####\n");
    System.out.println(restResponse_tREST_1);
  10. Save and execute the Job.
    Since no Accept header is specified, the response returns the JSON content. The response shows that the data record is not valid and gives a message about why the data record did not pass the validation.

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – please let us know!