-
Notifications
You must be signed in to change notification settings - Fork 2
RFE: Enhance vertx file resolving in wildfly extension
We have one Vert.x instance in WildFly with this extension installed, which has a global FileResolver
used to resolve files in a Vert.x context, the resolver uses the ClassLoader from the associated Vert.x context to load the resources. The contexts are global, so when you use APIs invoking FileResolver.resolveFile(String fileName)
from a verticle, it works good because the ModuleClassLoader of the deployment is bound to the veticle context which is created when the verticle is deployed, but if you use APIs like vertx.filesystem().readFile()
from non vertx context, like in Servlet or EJB, it may lead to wrong ClassLoader used, because the global FileResolver will pick a vertx context and use the ClassLoader from it.
The ability of changing ClassLoader of the context is under discussion, but before it is done, we can have a way around this by a implementing a FileResolver which uses a customized ClassLoader to be able to load resources from all deployments if the deployment configures itself exposed.
- The ability of loading resources from exposed deployments is disabled by default
The recommended way of using Vert.x APIs in this extension is using Verticle, and use Eventbus in EE codes to communicate with vert.x following it's way. There is no resolving issue using Verticle.
If you want to use APIs that depend on file resolving in EE codes directly, and you have multiple war deployments, you need to enable this to be able to load resources from multiple vertx deployments.
WARNING: if you consider security of loading resources from different deployemnts, please do NOT enable this and write your vert.x codes in verticles.
- Enable it by a system property
You can enable it by specifying a system property: vertx.classloading.multipe
to true
.
Once it is enabled, you can specify the resources to be exposed in your deployment.
- Expose the resources by specifying it in the deployment descriptor.
We have a defined deployment descriptor called vertx-deployment.json
in either at WEB-INF/
or META-INF/
, the fields to be added are:
-
expose: true|false
# defaults tofalse
exposed-resources: [list of resources]
The full example is like:
{
"deployments": [
{
"verticle-class": "org.wildfly.extension.vertx.test.mini.deployment.TestVerticle",
"deploy-options": {}
}
],
"expose": true,
"exposed-resources": [
"/public/*",
"/protected/exception.html"
]
}
- Set the value of
expose
totrue
means you are willing to expose some resources to global access, you need to defineexposed-resources
for which resources to be exposed. - Set the value of
exposed-resources
to make the specified resources exposed, empty list won't expose anything, so you need to define exposed-resources explicitly.
You can specify single resource item, or resources with a prefix, like: /public/*