[jcifs] smb protocol handler

Marc Hoffmann marc.hoffmann at mountainminds.com
Tue Dec 24 23:26:49 EST 2002


Hi Mike,

my name is Marc Hoffmann, working with Fujitsu EST GmbH, located in Munich.
The company uses JCIFS for a while internally in one of their Java APIs (see
conversation with Uwe Specht regarding closed pipes).


PROBLEM

The new URL design of version 0.7 introduces Java's powerful extension
mechanism for new protocol types, but has also a serious impact on system
properties and class loading (see e.g. "MalformedURLException" threads).
Especially in the context of application servers this adds deployment
hassles. Moreover, if necessary modifications of the security settings or
system libraries are not possible this could become a "show stopper".


SUGGESTION

Therefore I would like to suggest making the registration of the URL handler
optional. It could explicitly triggered by an application by invoking a
static method like "Config.registerSmbURLHandler()".

To grant backward capability (concerning deployment) and allow standard
deployment of e.g. web applications the internal JCIFS implementation should
not rely on the registration of an URLStreamHandler.


IMPLEMENTATION

The 0.7.0b10 implementation could easily be changed to work without the need
of the registered smb protocol. The basic idea is to explicitly pass the
proper URLStreamHandler directly to the internally used java.net.URL
constructors. Some testing proofed that the MalformedURLException does not
happen, even if no system property is set and the jcifs.jar is located in
the WEB-INF/lib of a web application only.

I made the following modifications (source files attached):

1. Provide an internally used singleton instance of jcifs.smb.Handler:

  static final URLStreamHandler SMB_HANDLER = new Handler();

2. Replace all URL constructors in SmbFile with the URL(URL context, String
spec, URLStreamHandler handler) version, e.g.

    public SmbFile( SmbFile context, String name ) throws
MalformedURLException, UnknownHostException {
        this( context.isWorkgroup0() ?
            new URL(null, "smb://" + name, Handler.SMB_HANDLER) :
            new URL( context.url, name, Handler.SMB_HANDLER),
context.auth );
    }

3. In the files SmbFileInputStream, SmbFileOutputStream, SmbNamedPipe
replace "new SmbFile(new URL(urlstring))" by "new SmbFile(urlstring)".

This modification would certainly avoid many error situations, especially
for users who upgrade from older jcifs versions and do not use java.net.URL
to identify resources at all.

Best Regard,
marc

-------------- next part --------------
A non-text attachment was scrubbed...
Name: SmbFile.java
Type: application/octet-stream
Size: 68381 bytes
Desc: not available
Url : http://lists.samba.org/archive/jcifs/attachments/20021224/afee0bf2/SmbFile.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SmbNamedPipe.java
Type: application/octet-stream
Size: 7445 bytes
Desc: not available
Url : http://lists.samba.org/archive/jcifs/attachments/20021224/afee0bf2/SmbNamedPipe.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SmbFileInputStream.java
Type: application/octet-stream
Size: 5917 bytes
Desc: not available
Url : http://lists.samba.org/archive/jcifs/attachments/20021224/afee0bf2/SmbFileInputStream.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SmbFileOutputStream.java
Type: application/octet-stream
Size: 6185 bytes
Desc: not available
Url : http://lists.samba.org/archive/jcifs/attachments/20021224/afee0bf2/SmbFileOutputStream.obj


More information about the jcifs mailing list