Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Module Resource Files Not Found When Using FileSystemHelper.readJson #552

Open
1 task done
halber opened this issue Aug 20, 2024 · 0 comments
Open
1 task done
Labels
bug Something isn't working needs triage This issue needs to be investigated and confirmed as a valid

Comments

@halber
Copy link
Contributor

halber commented Aug 20, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

When using the io.neonbee.internal.helper.FileSystemHelper.readJson method to load resource files within a NeonBee module, the resource file cannot be found. This occurs because the FileSystemHelper.readJson method relies on Vert.x's internal file resolver, which uses the application ClassLoader. The application ClassLoader is only aware of resource files within the NeonBee core, not those in the module's resources.

Expected Behavior

The FileSystemHelper.readJson method should be able to locate and load resource files from within the module’s resources when called from a NeonBee module.

Steps To Reproduce

  1. Create a NeonBee module with its own resources, such as a JSON file (somefile.json).
  2. Use the FileSystemHelper.readJson method in the module to attempt to load the JSON file from the module's resources.
  3. Observe that the file cannot be found, and an error is thrown.

Environment

- NeonBee: 0.37.0

Relevant log output

No response

Anything else?

A workaround involves manually loading the resource file using the module's ClassLoader, as shown in the following code snippet:

Future.future(promise -> {
    InputStream resourceAsStream = this.getClass().getClassLoader()
            .getResourceAsStream("somefile.json");

    try (BufferedReader reader = new BufferedReader(new InputStreamReader(resourceAsStream, StandardCharsets.UTF_8))) {
        StringBuilder stringBuilder = new StringBuilder();
        String line;
        while ((line = reader.readLine()) != null) {
            stringBuilder.append(line);
        }
        promise.complete(new JsonObject(stringBuilder.toString()));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
})
@halber halber added bug Something isn't working needs triage This issue needs to be investigated and confirmed as a valid labels Aug 20, 2024
@halber halber changed the title [Bug]: [Bug]: Module Resource Files Not Found When Using FileSystemHelper.readJson Aug 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage This issue needs to be investigated and confirmed as a valid
Projects
None yet
Development

No branches or pull requests

1 participant