Java Files.listFiles() issue

We are working on creating a utility to take the backup of configs from the IS/instances/default/packages. Code is written in a way that we iterate through all the packages/config folder and then copy the content inside the config folder to a separate directory. This code is working on local system where installed components are IS 10.11 and JDK 11.The same code is not working on our server (LINUX) where the installed components are IS 10.5 and JDK 8.

**Note: We have already checked the permission of the folder that we are trying to access.**
**permission for user, group and owner are same i.e. Read, write and execute.**
File[] allFilesOfSource = file_tempSource.listFiles();

here
file_tempSource: is a path to a packageName/config folder which is of File Type in java.
i am using the listFiles() method to get the content of that folder. Its returning null. The same code is working on my local system.
allFilesOfSource will store the content of the config folder i.e .cnf or any other type of config file with their proper path.

Please let us know if anything else we can do to fix this issue.

1 Like

Hi Ameya,

are you trying to implement this for your custom packages or for pre-installed webMethods-packages?

Is there any entry in the logs why the listFiles is returning null?

For the latter case I consider this counter-productive as these configs are only changed in very rare circumstances and will be backed up during application of new Fixes for these packages (luckily).

When it is related to custom packages, I would prefer creating a dedicated subdirectory under IS/instances/default/config as this one will be automatically backed up during initialization of IS instance (to IS/instances/default/config/backup).
Pathes inside the logic of code implementation are relative to IS/instances/default.

Having the config inside the package can lead to deployment issues when they contain environment specific settings (for i.e. DEV/QA/PROD).

Regards,
Holger

2 Likes

@Ameya_Andurekar2 ,
Holger makes some very valid points, I would also like to understand the need to write a custom utility in this case.
Looking at the problem from purely a technical standpoint, the java doc for File.listFiles() mentions that it can return null when the path is not valid or there is an IOError. File (Java Platform SE 7 ) .

A few things you can try

  1. Confirm the path you are trying to list files
  2. I’m assuming you are running this code from a java service. You can pass the same path to public service pub.file:listFiles and see it it works , you will have to modify the fileAccessControl.cnf first.

This could likely be a java problem and not specific to Integration Server.

-NP

1 Like

Hello Holger,

Thank you for your response. Actually i have already written a regex to exclude the Wm packages from the configs that are need to backed up. So basically i am trying to copy the configs of the custom packages. The target directory where i am saving these backup files is inside IS/instances/ConfigBackup folder.
Also, the same code is working on my local system with OS as windows. I am not sure if any other parameters are need to be taken care of with respect to LINUX.

Note: We are trying to create this backup utility because our project is working on the configuration based approach. If anything goes wrong in the config, then it causes a lot of work.

Hi Ameya,

nothing against that configuration based approach, but the question in this case will be where to place these configs.
As pointed out above I prefer placing them in dedicated custom subdirectories under instances/default/config, as they will be backed up automatically every time the IS finishes its startup sequence successfully (see line “Config file directory saved” in the logs for reference).

Remember to specify all pathes as relative pathes to instances/default as a base dir and use the unix-like path separator /.
This will also work on Windows (java handles this internally).

Regards,
Holger

1 Like

using the built-in service pub.file:listFiles inside java code has resolved the issue.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.