7 Replies Latest reply on Apr 22, 2016 11:39 AM by dbrodski

    Adding a custom java FileSystemProvider to an ear / ejb

    dbrodski

      Hi everyone,

       

      I'm trying to implement a custom FileSystemProvider (one that can handle the vfs URIs from wildfly).

      The problem is that I cannot get the provider registered as a java service, is there any example how to do that?

      I'm using wildfly 9 (tried with wildfly 10, too) and an ear which only has an ejb for a java message queue for hornet.

       

      I already looked and tried to use the suggestions in the jiras:

      [WFLY-3971] Jar Services in META-INF/services are not loaded from static modules - JBoss Issue Tracker

      [WFLY-4205] Undertow not detecting @HandlesTypes If the implentation class is inside EAR/lib - JBoss Issue Tracker

      I tried to have the service inside the ejb and as a separate java lib with the same result. The examples in the bugs always use war files and not ejbs.

       

      I'm new to the whole ear/ejb things and an example or a hint would be really great.

      If I use the same lib inside a standalone java executable the service registration works, just not if it is used in the wildfly server.

      I added an example project and the source code to show my code.

       

      Thanks,

      David

        • 1. Re: Adding a custom java FileSystemProvider to an ear / ejb
          xdury

          Hi,

           

          I have more or less the same problem as you: I am trying to use a custom ClasspathFileSystemProvider in my application to make it easier to resolve resources in various XML apis (like URIResolver...).

           

          I have put the FQCN in META-INF/services/java.nio.file.spi.FileSystemProvider in the jar that contains my FS classes and this jar is embedded in a webapp (WEB-INF/lib).

           

          As soon as I try to resolve a Path with the classpath scheme, I get the following error: java.nio.file.FileSystemNotFoundException: Provider "classpath" not installed (although it works without any problem in unit tests).

           

          Did you find a solution?

           

          Thanks,

          Xavier

          • 2. Re: Adding a custom java FileSystemProvider to an ear / ejb
            dbrodski

            Hi,

             

            I could not fix it yet, at the moment I just filter it by hand and create the provider then by calling it directly.  I did not find any way to inject the module by hand, too.

            I'm thinking of creating a bug in Jira, since the other Jiras indicate that it should work / is working when using spring and somehow WEB-INF.

             

             

            Thanks,

            David

            • 3. Re: Adding a custom java FileSystemProvider to an ear / ejb
              xdury

              +1 for a JIRA

               

              I've tried to replace Paths.get(myUri) with something like FileSystems.newFileSystem(myUri, Collections.emptyMap(), Thread.currentThread().getContextClassLoader()).getPath(myUri.getSchemeSpecificPart()) but that does not work either and I get the following error: java.util.ServiceConfigurationError: java.nio.file.spi.FileSystemProvider: Provider com.sun.nio.zipfs.ZipFileSystemProvider not found.

               

              I suppose the ServiceLoader discovers all META-INF/services/java.nio.file.spi.FileSystemProvider and tries to load com.sun.nio.zipfs.ZipFileSystemProvider but this class is not visible to my application and the wildfly "sun.jdk" module.xml does not export classes from com.sun.nio.*

               

              Other people having the same problem:

               

              • 5. Re: Adding a custom java FileSystemProvider to an ear / ejb
                ctomc

                Xavier Dury wrote:

                 

                I've tried to replace Paths.get(myUri) with something like FileSystems.newFileSystem(myUri, Collections.emptyMap(), Thread.currentThread().getContextClassLoader()).getPath(myUri.getSchemeSpecificPart()) but that does not work either and I get the following error: java.util.ServiceConfigurationError: java.nio.file.spi.FileSystemProvider: Provider com.sun.nio.zipfs.ZipFileSystemProvider not found.

                If you add jboss-deployment-structure.xml to your deployment and add com/sun/nio/zipfs to addiational system paths does it work?

                • 6. Re: Adding a custom java FileSystemProvider to an ear / ejb
                  xdury

                  Tomaz Cerar wrote:

                   

                  Xavier Dury wrote:

                   

                  I've tried to replace Paths.get(myUri) with something like FileSystems.newFileSystem(myUri, Collections.emptyMap(), Thread.currentThread().getContextClassLoader()).getPath(myUri.getSchemeSpecificPart()) but that does not work either and I get the following error: java.util.ServiceConfigurationError: java.nio.file.spi.FileSystemProvider: Provider com.sun.nio.zipfs.ZipFileSystemProvider not found.

                  If you add jboss-deployment-structure.xml to your deployment and add com/sun/nio/zipfs to addiational system paths does it work?

                  Thanks, I added the following jboss-deployment-structure.xml and it was working with FileSystems.newFileSystem(...) :

                   

                  <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">

                      <deployment>

                          <dependencies>

                              <system export="true">

                                  <paths>

                                      <path name="com/sun/nio/zipfs" />

                                  </paths>

                              </system>

                          </dependencies>

                      </deployment>

                  </jboss-deployment-structure>

                  • 7. Re: Adding a custom java FileSystemProvider to an ear / ejb
                    dbrodski

                    Strangely I don't have any problems with the jre integrated zipfs. I do have the problem with a FileSystemProvider that is defined the ejb or in an additional lib. Adding a jboss-deployment-structure.xml to it did no help me, but maybe I do something wrong.