Altova FlowForce Server 2024 

Validate XML with Error Logging

Home Prev Top Next

This example shows you how to create a job which validates an XML file against a schema. If the job fails due to any reason, the error details will be written to a log file. For validation, we will use the valxml-withxsd function of RaptorXML Server running under FlowForce Server management. Note that, for the error logging part, the technique illustrated in this example is not dependent on RaptorXML Server and can be applied to other job types.

 

Note:The RaptorXML Server functions become available in FlowForce Server after RaptorXML Server is installed.

 

In this example, the job will be defined as a Web service, so that you can trigger it on demand, by accessing a URL from the browser. You can also add to the job a timer (or file system) trigger, similar to how this is done in other examples. You could even add to the same job a combination of a trigger and a Web service. This way, the job will run not only as defined by the trigger rules, but also on demand, when the Web service is called.

 

Prerequisites

Required licenses: FlowForce Server, RaptorXML (or RaptorXML+XBRL) Server

The FlowForce Web Server and FlowForce Server services must be listening at the configured network address and port

Your FlowForce Server user account has permissions to one of the containers (by default, the /public container used in this example is accessible to any authenticated user).

The job created in this example generates a log file every time when it runs. Therefore, on the operating system where FlowForce Server runs, you must have rights to create files in some directory (this example uses the C:\FlowForceExamples\ValidateXml directory).

 

Demo files used

The XML file validated in this example is available in the RaptorXML Server installation folder, at the following path: C:\Program Files\Altova\RaptorXMLServer2024\examples\NanonullOrg.xml.

 

On a 64-bit Windows running 32-bit RaptorXML Server, the path is C:\Program Files (x86)\Altova\RaptorXMLServer2024\examples\NanonullOrg.xml, unless you installed RaptorXML Server in a different folder.

 

You could also use any other XML file for validation.

 

Creating the job

1.Log in to the FlowForce Server Web administration interface and open the /public/Examples container. The public/Examples container should already exist if you followed the previous examples; otherwise, create it using the Create | Create Container command.

2.Click Create Job. Next, enter a name and, optionally, a description for the job you are creating. This example uses "ValidateXml" as job name.

fs_valxml_example_01

3.Under "Job Input Parameters", click the add button and create a new parameter of type "string as file", for example:

fs_valxml_example_02

4.Under "Execution Steps", click the add button, and then select new error/success handling step.

fs_valxml_example_03

5.Under "Execute with error/success handling", click the add button, and choose to add a new execution step, with the following settings:

 

Execute function

Browse for the /RaptorXML/valxml-withxsd function.

Parameters

Next to the XML File parameter, click ff-setTo and select the inputFile job input parameter declared earlier.

 

6.Under the "On error" condition, click the add button and choose to add a new execution step, with the following settings:

 

Execute function

Browse for the /system/compute function.

Parameters

Set the value of Expression to:

 

as-file(stdout(failed-step()))

 

The parts between curly braces are two FlowForce expressions. This expression gets the output, converts it to a stream and then writes it to a file on the disk:

 

The failed-step function returns the result of the failing step. This is an abstract FlowForce type that, in order to become more useful, must be supplied as argument to the exitcode, stderr , or error-message functions, see below.

The stdout function gets the standard output from the result, as a stream, assuming that there is standard output.

The as-file function creates a file from the stream. The path will be specified in a subsequent step.

Assign this step's result to

Enter a value which will uniquely identify the result of this job, for example, MyResult. By doing this, you are declaring this value as a variable, so that you can use it in a subsequent step.

 

7.Click the add button to add a new execution step after the previous one, with the following settings:

 

Execute function

Browse for the /system/filesystem/copy function.

Parameters

Next to the Source parameter, click ff-setTo and select the MyResult variable declared earlier.

 

Next to the Target parameter, type the path where the log will be saved (in this example, the path is C:\FlowForceExamples\ValidateXml\error.log).

 

Select the check box next to the Overwrite parameter. The log file is generated each time the job runs, so this ensures that the job does not fail when the log file already exists.

 

Set the Working Directory parameter to C:\FlowForceExamples\ValidateXml.

 

The "On Error" branch of the job should now look as follows:

fs_valxml_example_04

8.Under "Service", select the Make this job available via HTTP check box, and enter ValidateXmlService as name of the service.

9.Under "Credentials", select an existing credential record or specify a local credential. For details, see Credentials.

10.Click Save.

 

Running the job

To run the job, do one of the following:

 

Go to Home, and then click Show all active triggers and services. Next, click the job's URL displayed in the "Info" column.

Enter http://127.0.0.1:4646/service/ValidateXmlService in the browser's address bar. Note that this URL works only if the FlowForce Server service listens at the default host address and port name. If you have defined other host and port settings in the Configuration page, change the address accordingly.

If you set the optional Host name field of FlowForce Server from the Setup Page, you can execute the web service call directly from the job configuration page, by clicking the fs_ic_call_ws button adjacent to the Make this job available via HTTP check box. The button is not displayed otherwise.

 

If prompted for credentials when accessing the Web service, supply the same credentials you use to log on to FlowForce Server.

 

Supplying your FlowForce Server user credentials for HTTP authentication is only for testing purposes. For production, it is recommended that you create a new FlowForce user, grant the Service - Use permission to this user on the container where the job is, and then access the Web service with the corresponding user account. To disable HTTP authentication and make the Web service public, grant the Service - Use permission to the user Anonymous, see How Permissions Work.

 

Since this job was configured to expect a parameter as input, the browser displays a form where you can enter the path to the XML file that is to be validated.

fs_valxml_example_05

Enter an XML file path in the text box (for example, C:\Program Files\Altova\RaptorXMLServer2024\examples\NanonullOrg.xml), and click Submit.

 

If the job executes successfully (that is, if it returns the exit code 0), the browser displays the standard output of the job, for example:

 

file:///C:/Program%20Files/Altova/RaptorXMLServer/examples/NanonullOrg.xml: runtime="16ms" result="OK"

 

If the job returns an exit code other than 0 (for example, due to an incorrect path, validation errors, and so on), the browser displays a "Service execution failed" message and the output is written to the C:\FlowForceExamples\ValidateXml\error.log file. In the event that the log file was not generated, check the job log to identify the error. It may be the case, for example, that the /system/filesystem/copy function has failed because you have no permission to write to the target path.

© 2018-2024 Altova GmbH