Patch: Better exception message for failed connects

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Patch: Better exception message for failed connects

Mark Doliner-3
I have the following bit of code which throws an SmbException:

> UniAddress address = UniAddress.getByName(domainController);
> NtlmPasswordAuthentication mycreds = new NtlmPasswordAuthentication(domain,
>     username, password);
> SmbSession.logon(address, mycreds);

The "message" field of this exception is set to the empty string.  It would be better if the message was set to SOMETHING.  The attached patch changes 1 line to make the message "Unable to establish connection with www.google.com."  A better alternative might be to use te.getMessage(), but that's something you'll have to decide.

For reference, here's the stacktrace given by smbException.printStackTrace():
jcifs.smb.SmbException:
jcifs.util.transport.TransportException
java.net.ConnectException: Connection refused: connect
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
        at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
        at java.net.Socket.connect(Socket.java:507)
        at java.net.Socket.connect(Socket.java:457)
        at java.net.Socket.<init>(Socket.java:365)
        at java.net.Socket.<init>(Socket.java:178)
        at jcifs.smb.SmbTransport.ssn139(SmbTransport.java:178)
        at jcifs.smb.SmbTransport.negotiate(SmbTransport.java:236)
        at jcifs.smb.SmbTransport.doConnect(SmbTransport.java:302)
        at jcifs.util.transport.Transport.run(Transport.java:217)
        at java.lang.Thread.run(Thread.java:595)
        at jcifs.util.transport.Transport.run(Transport.java:233)
        at java.lang.Thread.run(Thread.java:595)
        at jcifs.smb.SmbTransport.connect(SmbTransport.java:288)
        at jcifs.smb.SmbTree.treeConnect(SmbTree.java:129)
        at jcifs.smb.SmbSession.logon(SmbSession.java:161)
        at jcifs.smb.SmbSession.logon(SmbSession.java:154)
        at com.sas.djte.reporting.UserInfos.authenticate(UserInfos.java:49)

JCIFS is sleek, thanks for creating it!
-Mark

jcifs_better_exception_message_for_failed_connects.diff (892 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Patch: Better exception message for failed connects

Michael B Allen-4
On Wed, 15 Mar 2006 13:13:33 -0500
"Mark Doliner" <[hidden email]> wrote:

> I have the following bit of code which throws an SmbException:
>
> > UniAddress address = UniAddress.getByName(domainController);
> > NtlmPasswordAuthentication mycreds = new NtlmPasswordAuthentication(domain,
> >     username, password);
> > SmbSession.logon(address, mycreds);
>
> The "message" field of this exception is set to the empty string.  It would be better if the message was set to SOMETHING.  The attached patch changes 1 line to make the message "Unable to establish connection with www.google.com."  A better alternative might be to use te.getMessage(), but that's something you'll have to decide.
>
> For reference, here's the stacktrace given by smbException.printStackTrace():
> jcifs.smb.SmbException:
> jcifs.util.transport.TransportException
> java.net.ConnectException: Connection refused: connect

I added this to The List for consideration later.

Thanks,
Mike