GVExample ValidateRemoteXMLFiles
Contents
Description
The flow is designed to show how GreenVulcano® ESB manages the files present in a Remote file system and how can perform a validation of an xml file. It is executed following these steps:
- Reading XML files from a remote directory of inputs via FTP (TextXML/input)
- Validating the read files using a predefined schema
- Coping valid and invalid files in two separated directories (TextXML/validated and TextXML/discarded)
- Saving a file <filename>.result with the <filename> validation error message
VulCon Configuration
The implementation is the same of services ValidateXMLFiles and ValidateSingleXMLFile. It consists of two services that perform the following tasks:
- ValidateRemoteXMLFiles: Enumerates the files to be validated
- ValidateSingleRemoteXMLFile: Validates and moves each single file
The difference between these services is in the operations to be performed. The following table shows the operations used for each service, divided by scope:
Scope | ValidateXMLFiles/ValidateSingleXMLFile | ValidateRemoteXMLFiles/ValidateSingleRemoteXMLFile |
---|---|---|
Scanning XML files | fsmonitor-call | fsmonitor-call |
Reading a file | filereader-call | remotemanager-call |
Moving a file | filemanager-call | remotemanager-call |
Writing a file | filewriter-call | remotemanager-call |
To configure this service, the steps are as follows:
- Definition of systems, Channels and Operations
- Definition of Services
- Flow implementation
Definition of Systems, Channels and Operations
For the definition of the system go to the VulCon core view and insert the System GVESB (if not present). Define the Channel TEST_CHANNEL_REMOTE_FILE with the following operations:
- fsmonitor-call: This operation allows to analyse the directory "path" and return an XML report with the list of files that verify the regular expression "file-mask" ("*. \ xml") in the given directory. Set its attributes as:
Attribute | Value |
---|---|
name | ScanXMLFiles |
RemoteFileSystemMonitor/path | /home/test_user/TestXML/input |
FileFilter/file-mask | .*\.xml |
FileFilter/file-type | files-only |
ResultFilter/existing | true |
InMemoryMonitorStatus | dumpStatus="false" |
FTPManager | autoConnect="false" hostType="UNIX" hostname="localhost" password="{3DES}pl1YKFjWlqMfdTIbxY17Mg==" port="3021" type="remote-manager" username="test_user" |
- This operation also imposes some properties into the output GVBuffer, if files with the indicated conditions exist:
- GVFSM_REPORT_CREATED setted to "true"
- GVFSM_EXISTING_FILES number of file presents
- remotemanager-call: This operation allows to move the file, which name is present into the GVBuffer property "FILE_NAME" from the directory "input" to the directory which name is present into the GVBuffer property "TARGET". The directory of destination depends on the property "TARGET" value that worflow gives when imposes it to "validated" if the XML file is correct, or "discarded" if don't. Set its attributes as:
Attribute | Value |
---|---|
name | MoveFile |
FTPManager | autoConnect="false" hostType="UNIX" hostname="localhost" password="{3DES}pl1YKFjWlqMfdTIbxY17Mg==" port="3021" type="remote-manager" username="test_user" |
RemoteCommands/RemoteMoveCommand | isCritical="true" newName="ognl{{property['TARGET']}}/ognl{{property['FILE_NAME']}}" oldName="input/ognl{{property['FILE_NAME']}}" targetPath="/home/test_user/TestXML" |
- remotemanager-call: This operation allows to download the file which name is defined in the property "FILE_NAME" into the "remotePath" directory. The file content will be charged in GVBuffer.object field as array of bytes. Set its attributes as:
Attribute | Value |
---|---|
name | ReadFile |
FTPManager | autoConnect="false" hostType="UNIX" hostname="localhost" password="{3DES}pl1YKFjWlqMfdTIbxY17Mg==" port="3021" type="remote-manager" username="test_user" |
RemoteCommands/RemoteDownloadCommand | isCritical="true" remoteFilePattern="ognl{{property['FILE_NAME']}}" remotePath="/home/test_user/TestXML/input" toGVBufferExpression="setObject(new java.lang.String(#input))" |
- remotemanager-call: This operation allows to upload the file which name is defined concatenating the property "FILE_NAME" with the string ".result", into the "remotePath" directory. The file content will be present into the "fromGVBufferExpression" field. Set its attributes as:
Attribute | Value |
---|---|
name | WriteStatusFile |
FTPManager | autoConnect="false" hostType="UNIX" hostname="localhost" password="{3DES}pl1YKFjWlqMfdTIbxY17Mg==" port="3021" type="remote-manager" username="test_user" |
RemoteCommands/RemoteUploadCommand | fromGVBufferExpression="getObject().getBytes()" isCritical="true" remotePath="/home/test_user/TestXML/discarded" sourceFilePattern="ognl{{property['FILE_NAME']}}.result" |
Definition of Services
To define a Service for reading the files present into a directory, use the voice "Wizard new Service" (right clicking the Services element) with the following parameters:
Attribute | value |
---|---|
Service name | ValidateXMLFiles |
Scenario | Synchronous- Synchronous |
Client | GVESB |
Server (Participant) | system = "GVESB" channel = "TEST_CHANNEL_FILE" request operation = "ScanXMLFiles" |
The Wizard will create a flow which has to be modified successively.
Analogously, use the "Wizard New Service" for creating the service for the validation of each single XML file present in the input directory, using the following parameters:
Attribute | value |
---|---|
Service name | ValidateSingleXMLFile |
Scenario | Synchronous-Synchronous |
Client | GVESB |
Server (Participant) | system = "GVESB" channel = "TEST_CHANNEL_FILE" request operation = "ReadFile" |
The Wizard will create a flow that must be modified successively.
Flow implementation
To define the flow for the service ValidateXMLFiles, design it as it is shown in the picture:
In this first flow all files present into the directory "dir_scanner" are read, and for each one, the service ValidateSingleXMLFile will be invoked validating it.
The following table shows the parameters to be defined for each flow operation:
Attribute | value |
---|---|
Conditions/GVBufferCondition | condition="CheckNumFiles" Property:
|
GVOperationNode | id="dir_scanner" id-system="GVESB" input="input" next-node-id="check_files" op-type="call" operation-name="ScanXMLFiles" output="files" |
GVNodeCheck | default-id="end_nofile" id="check_files" input="files" on-exception-id="end_notok" op-type="check" |
GVNodeCheck/GVRouting | condition="CheckNumFiles" next-node-id="iterate_file_list |
GVIteratorOperationNode | id="iterate_file_list" collection-dp="fileNamesCollectionDP" input="files" next-node-id="end_ok" op-type="call" output="single-file" |
GVIteratorOperationNode/CoreCall | change-log-context="true" id-service="ValidateSingleXMLFile" id-system="GVESB" operation="Request |
GVEndNode | id="end_ok" op-type="end" output="files" |
GVEndNode | id="end_notok" op-type="end" output="files" |
To define the flow for ValidateSingleXMLFile Service, design the flow as it is seen from the picture:
In this flow the file in input is read, validated using a specific XSD and, depending on the result, the file will be moved in other directory or a new file will be created with the result of the failed validation.
The workflow will be invoked passing into the GVBuffer.object of input an element "File" chosen from the generated XML report of the ScanXMLFiles operation.
The following table shows the parameters to be defined for each flow operation:
Attribute | value |
---|---|
first-node | fillProperties |
ChangeGVBufferNode | id="fillProperties" input="node" |
ChangeGVBufferNode/ChangeGVBuffer | OGNLScript: property[‘FILE_NAME’]=@it.greenvulcano.configuration.XMLConfig@get(object,’@name’) |
GVOperationNode | id="read_validate_file" id-system="GVESB" |
GVOperationNode/OutputServices | xml-validation-service:
xml-validation-call:
|
GVNodeCheck | default-id="validation_ok" id="check_validate" |
ChangeGVBufferNode | id="validation_ok" input="input" |
ChangeGVBufferNode | id="validation_ok"
input="input" next-node-id="move_file" clear-data="false” |
GVOperationNode | OGNLScript: property['TARGET'] = 'validated' id="move_file" |
ChangeGVBufferNode | id="validation_failed"
input="input" next-node-id="write_status" clear-data="false" |
GVOperationNode | OGNLScript: property['TARGET'] = 'discarded', setObject( + #environment.get('payload')) id="write_status" |
GVEndNode | end-business-process="yes" id="end" |