Altova FlowForce Server 2025 

Check if a Path Exists

Home Prev Top Next

This example shows you how to create a job which informs you if a path (to a file or directory) exists on the operating system. To achieve this goal, you will use a combination of built-in functions and expression functions. The job will be defined as a Web service, so that you can trigger it on demand, by accessing a URL from the browser. The job will take the path as an argument, and will return a string which informs whether the path supplied as argument exists on the operating system where FlowForce Server runs.

 

Prerequisites

Required licenses: FlowForce Server

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

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

 

Creating the job

1.Log on to FlowForce Server and navigate to a container where you have permission to create new jobs. For consistency with other examples, this tutorial uses the /public/Examples container—if you don't have this container yet, create it using the Create | Create Container command.

2.In the /public/Examples container, click Create, and then select Create job.

3.Add a job name ("CheckPath", in this example) and, optionally, a job description.

ExamplePathExists01

4.Under Job Input Parameters, click add, and add the parameter path, as shown below.

ExamplePathExists02

5.Add a new execution step which calls the builtin_function/system/shell/commandline function, and enter the shell command which checks for the existence of the file. Make sure to declare the result of this step, as shown below (in this example, we called it output).

ExamplePathExists03

On Windows, the shell command outputs "1" when the path exists and "0" when it does not exist. If FlowForce Server runs on a Unix system, adjust the command accordingly. Notice that the command embeds the FlowForce expression {path}. This expression references the input parameter defined in the previous step.

6.Under "Execution Steps", click the add button, and then select new Choose step. Then enter trim(content(stdout(output))) == '1' as condition expression. This expression consists of three nested functions: stdout, content, and trim. First, the stdout function gets the standard output of the result returned by the previous step. Then the content function converts the standard output to string. Finally, the trim function removes any leading or trailing spaces, carriage returns, or line feeds from the standard output. The result is then compared to "1" using the equality operator. If both values are equal, the path exists. Otherwise, the path does not exist.

7.Under the When clause, add an execution step as shown below. This execution step calls the builtin_function/system/compute-string function to build the string value that should be returned when the path exists. Notice that the value embeds the FlowForce expression {path}. This expression references the input parameter defined in a previous step.

ExamplePathExists04

8.Under the Otherwise clause, add an execution step as shown below. This execution step calls the builtin_function/system/compute-string function to build the string value that should be returned when the path does not exist. Notice that the value embeds the FlowForce expression {path}. This expression references the input parameter defined in a previous step.

ExamplePathExists05

9.Under Execution Result, declare the return type as string.

helloworld04

10.Under Service, click to select the Make this job available via HTTP check box, and enter CheckPathService as name of the service. For more information, see Exposing Jobs as Web Services.

fs_ex_checkpath_07

11.Under "Credentials", select an existing credential record or specify a local credential. For more information, see Credentials.

12.Click Save.

 

Running the job

To run the job, do one of the following:

 

Go to the Home page and 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/CheckPathService 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 on the Setup page, change the address accordingly.

If you set the optional Host name field of FlowForce Server on 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 you are asked for credentials when you access the Web service, supply the same credentials you use to log on to FlowForce Server.

 

Important

Supplying your FlowForce Server user credentials for HTTP authentication is only for testing purposes. For production, it is recommended to 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. For details, see How Permissions Work.

 

Since this job has arguments, you will be prompted to supply them when you access the Web service in the browser.

ExamplePathExists06

If the job executes successfully, the browser displays the output of the job, for example:

 

Path C:\ exists.

 

If the job fails, the browser displays a "Service execution failed" message. In this case, check the log of the job in FlowForce Server to identify the error, see Viewing the Job Log.

© 2018-2024 Altova GmbH