dCache / nfs4j

Pure Java NFSv3 and NFSv4.2 implementation
Other
240 stars 76 forks source link

support parsing exports directly from a stream (at the cost of no rescans if read from stream) #31

Closed radai-rosenblatt closed 9 years ago

radai-rosenblatt commented 9 years ago

allow parsing the exports "file" directly from a stream.

this is needed as a work around to something like this issue - http://bugs.java.com/bugdatabase/view_bug.do?bug_id=7156873

specifically, if you use onejar packaging, and try something like:

exportFile = new ExportFile(this.getClass().getClassLoader().getResource("exports").toURI());

(where "exports" is packaged inside the jar), you will get this:

Exception in thread "main" java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.simontuffs.onejar.Boot.run(Boot.java:340)
    at com.simontuffs.onejar.Boot.main(Boot.java:166)
Caused by: java.nio.file.FileSystemNotFoundException
    at com.sun.nio.zipfs.ZipFileSystemProvider.getFileSystem(ZipFileSystemProvider.java:171)
    at com.sun.nio.zipfs.ZipFileSystemProvider.getPath(ZipFileSystemProvider.java:157)
    at java.nio.file.Paths.get(Paths.java:143)
    at org.dcache.nfs.ExportFile.parse(ExportFile.java:65)
    at org.dcache.nfs.ExportFile.<init>(ExportFile.java:54)
    at org.dcache.simplenfs.SimpleNfsServer.<init>(SimpleNfsServer.java:38)
    at org.dcache.simplenfs.App.main(App.java:23)
    ... 6 more

with this commit you can do this:

exportFile = new ExportFile(new InputStreamReader(this.getClass().getClassLoader().getResourceAsStream("exports")))
radai-rosenblatt commented 9 years ago

on further thought the cause of the original exception probably isnt exactly the jdk bug i linked to (since its marked as solved in the jdk i'm running), but something similar cause by onejar's packaging (jars within jars)

kofemann commented 9 years ago

Che the unit test. There have similar thing:

_exportFile = new ExportFile(ClassLoader.getSystemResource("org/dcache/nfs/exports").toURI());

radai-rosenblatt commented 9 years ago

any URI will fail if the resource is 2 jars deep (inside a *.jar inside a onejar)

dcache-ci commented 9 years ago

Can one of the admins verify this patch?

kofemann commented 9 years ago

ok to test

kofemann commented 9 years ago

Thanks!

mksahakyan commented 7 years ago

retest this please