user1540471
user1540471

Reputation: 431

Validation of data posted in Talend esb

I'm working on a route in Talend that should interogate an api and store the resulting data in a queue.

I have issues with the request to have 2 validations of data posted on api.

One of them is to have only digits and commas in string posted and the second is to have at most 200 numbers (ex: 123,34,35,780,01, ..... to have no more than 200 numbers between commas

A colleague suggest to use regular expresions and I found this expression ^[0-9]+(,[0-9]+)*$ for doing the first demand but I do not know how to use it in my route.

I use cREST and I do not know where to put this expression for doing the validation.

Can you help me?

Thanks,

Aurel

Upvotes: 0

Views: 234

Answers (2)

clanc9
clanc9

Reputation: 56

To access the exchange in a bean, add the following import import org.apache.camel.Exchange and set the first parameter of your bean method to be of class Exchange, as in public static Integer yourMethod(Exchange exch) {}.

Documentation at [https://camel.apache.org/manual/bean-binding.html].

Upvotes: 0

clanc9
clanc9

Reputation: 56

One possiblity is to put a cMessageRouter component after the cREST component. You can then pull a 'when trigger' and enter a predicate that will be evaluated to conditionally send the message to your queue. Assuming that your API returns a raw string (in which case you should make sure to set the Accept-Type of the cREST component to 'any') and using the Simple language, the
predicate could look like "${body} regex '[your regex]'". If the predicate evaluates to false, you can pull an 'otherwise trigger' from the cMessageRouter to send the message to a dead-letter queue, as shown below.

Note that you can have the cMessageRouter component evaluate multiple predicates and send the message to different destinations depending on the condition that is fulfilled.

Example of using cMessageRouter to conditionally route API responses

Upvotes: 0

Related Questions