You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Syte Beimin <sb...@betterbe.com> on 2016/08/18 15:19:28 UTC

Supporting the Java Service Provider Interface in order to use a custom NIO.2 FileSystem implementation

Hello,

For a while now I've been attempting to get a webapp working that uses
a custom NIO.2 FileSystem implementation (
https://github.com/Upplication/Amazon-S3-FileSystem-NIO2). It seems
like the Service Provider Interface isn't working when the war is
deployed in tomcat resulting in a
 java.nio.file.ProviderNotFoundException when
FileSystems.newFileSystem() is called for and URI like
"s3://access_key:secret_key@s3.amazonaws.com/bucket".

All googling and code debugging seems to point at 
java.nio.file.spi.FileSystemProvider.loadInstalledProviders()

Specifically 
ServiceLoader<FileSystemProvider> sl =
ServiceLoader.load(FileSystemProvider.class,
ClassLoader.getSystemClassLoader());

This attempts to find all resources (inside jars in the classpath) that
match "/META-INF/services/java.nio.file.spi.FileSystemProvider"

Generally, in the Eclipse IDE, this works like a charm but once
deployed in tomcat the FileSystemProviders aren't found. Might this
point towards an issue with tomcat's custom ClassLoader strategy?

Has anyone else run into problems with this and perhaps found a
fix/workaround? Or did I miss anything in my hunt for a solution?



Kind regards,

Syte

PS: Software versions used:
Tomcat Version: Apache Tomcat/7.0.57
JVM Version: 1.7.0_80-b15
JVM Vendor: Oracle Corporation

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Supporting the Java Service Provider Interface in order to use a custom NIO.2 FileSystem implementation

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Syte.

On 8/18/16 11:19 AM, Syte Beimin wrote:
> Hello,
> 
> For a while now I've been attempting to get a webapp working that
> uses a custom NIO.2 FileSystem implementation ( 
> https://github.com/Upplication/Amazon-S3-FileSystem-NIO2). It
> seems like the Service Provider Interface isn't working when the
> war is deployed in tomcat resulting in a 
> java.nio.file.ProviderNotFoundException when 
> FileSystems.newFileSystem() is called for and URI like 
> "s3://access_key:secret_key@s3.amazonaws.com/bucket".
> 
> All googling and code debugging seems to point at 
> java.nio.file.spi.FileSystemProvider.loadInstalledProviders()
> 
> Specifically ServiceLoader<FileSystemProvider> sl = 
> ServiceLoader.load(FileSystemProvider.class, 
> ClassLoader.getSystemClassLoader());
> 
> This attempts to find all resources (inside jars in the classpath)
> that match
> "/META-INF/services/java.nio.file.spi.FileSystemProvider"
> 
> Generally, in the Eclipse IDE, this works like a charm but once 
> deployed in tomcat the FileSystemProviders aren't found. Might
> this point towards an issue with tomcat's custom ClassLoader
> strategy?
> 
> Has anyone else run into problems with this and perhaps found a 
> fix/workaround? Or did I miss anything in my hunt for a solution?

Based solely upon what you have posted here, I would expect that
you'll need to:

1. Place your s3fs.jar in Tomcat's bin/ directory
2. Explicitly set the CLASSPATH in bin/setenv.sh to point to bin/s3fs.ja
r

That may kick things off for you.

Note that if you try to load your custom NIO.2 FileSystem
implementation from out of a WAR file, you are very *very* likely to
cause a ClassLoader-pinning leak where your application can never
really fully un-deploy and cleanup its resources. If you follow my two
steps above, that should not happen (because the classes won't be
loaded from a disposable ClassLoader).

- -chris
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBCAAGBQJXthS+AAoJEBzwKT+lPKRYka0QAK+kBqaDVey/MT+N2tc8QL7x
toSsd1WJhi9mGi0pl9mKuNuGJ6KO4DjUC9n42VKrUoYxH+g9i+5huEEWNsXz8XkM
4oK4Mv4m+zaPIYAiZLxRuCFXZv7Qe5lZCjYotfYdLGfgGh+PkAGjcK3C28mIL6PP
DVGOZxi0ZRPDTj7Gl6Tyg05gBHBRnicYTofW63/gms7DFyDYmTJI83giewgr3Ooy
B4l5GNkyBPYMJ4CIwPZLX+s5ciKWXYS+IlD8bBwxewK+MnOrPr9GKfwUIUhD63kx
1XratRl4vGXtjFVeXJOcA+OqRwzF6sV+lycTmZz+rNkeSo+llJBoI4RgNT4W/HBT
XIvyB+12Se8/bYmSoqZh1YXjhgEyyBr9rdvFXpSKwjDNSWIMT7GzLpj2tkvIHhME
fmy0yxW2sz4PE2G3lVbYwgkB7Psxe2m4NabXZtG+rknjnTvQyhhQf9QHyquyyJxL
iMJDh+LXCFrggLhMq5UrR/YtZwqqvk15HDi0P/+m7BgX1urQhz4bsNd4PYt8i8k0
OUimFnxhX+TljG+K4hJ02ZwdmEmF5ijRgcxVaIVWS86KhO9blh4etYkrH9DgZSqJ
8+H6meTYKsLbIAR26fQbSibFpuNMoEjgjUhFYRZ2NK1sOzlRnt4OhFz1bySMGHbg
mvufYV8i0KD2UmHMhLOi
=fPMQ
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org