webMethods 10.2 | Service Development Help | Performing Data Validation | Performing Validation from within a Java Service
 
Performing Validation from within a Java Service
You can use built-in services pub.schema:validate and pub.schema:validatePipeline to perform validation from within a Java service. In the following example, the pub.schema:validate service is used to validate the results of the pub.xml:xmlNodeToDocument service against a specification for an OAG purchase order.
.
.
.
 
IData validInput;
IData dtrResult;
.
.
.
 
// initialize the folder and document type name to point to a document
// type that exists on the server
String ifc = "OAG.PO"
String rec = "purchaseOrder"
 
// put the result from the xmlNodeToDocument service (i.e, the object to
// be validated) into the key named <object>
IDataCursor validCursor = validInput.getCursor();
IDataCursor dtrCursor = drtResult.getCursor();
 
if (dtrCursor.first("boundNode")) {
// assumption here that there's data at the current cursor position
validCursor.insertAfter( "object", dtrCursor.getValue() );
}
 
dtrCursor.destroy();
 
// set <conformsTo> parameter to point to the document type to validate
// against this document type must exist on the server.
validCursor.insertAfter( "conformsTo", ifc+":"+rec );
 
 
// set the <maxErrors> parameter to the number of allowed validation
// errors
validCursor.insertAfter( "maxErrors", "1000" );
validCursor.destroy();

// invoke pub.schema.validate to validate contents of <object>
IData validResult = context.invoke("pub.schema", "validate", validInput);

// check <isValid> to see whether <object> is valid and process
// accordingly
IDataCursor validCursor = validResult.getCursor();
if(validCursor.first("isValid"))
{
if (IDataUtil.getString(validCursor).equals("false"))
{
IData [] vr = IDataUtil.getIDataArray(validCursor, "errors");
System.out.println ( vr.length+" ERROR(s) found with example");
for (int j=0; j < vr.length; j++ )
{
System.out.println( vr[j].toString() );
}
}
}
validCursor.destroy();
. . .
 
For additional information about pub.schema:validate and pub.schema:validatePipeline, see the Schema services in the webMethods Integration Server Built-In Services Reference.
Performing Data Validation
Blueprints or Models Against which Data is Validated
Performing Input/Output Validation
Performing Pipeline Validation
Performing Document Validation
Performing XML Validation in Integration Server
Validation Errors
Validation Exceptions

Copyright © 2017-2018 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.
Innovation Release