Pattern Validation

In WebSphere ESB, you can do schema validation of messages by setting the validation checkbox on various mediation primitives. Alternatively, you can use code (perhaps in a custom mediation, for example) similar to the following:

BOInstanceValidator boValidator = (BOInstanceValidator) new ServiceManager().locateService("com/ibm/websphere/bo/BOInstanceValidator");

boolean isItValid = boValidator.validate(myDataObject, anEmptyList);

(both of these methods use the same underlying mechanism).

However, there are some limitations to this approach: for example, pattern restrictions aren’t supported on derived types. In that case, you can always do that part of the validation manually, using code such as the following:

boolean valid = java.util.regex.Pattern.matches(myregexpattern, dataObject.getString("myfield"));

Of course, that does require some knowledge of the structure of the Data Object in question and the patterns that apply to it.

Thanks to Kevin Yang and Chris Markes for help with this tip.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: