Results 1 to 10 of 10
  1. #1
    tm_sss is offline Member
    Join Date
    Nov 2009
    Posts
    2
    Rep Power
    0

    Default Accessing the lowest exception message

    Hi all,

    I'm relatively new to Java (4 hrs in) and I've managed to get an SFTP implementation working. However, in trying to break it, I realised that the component (Zehon) that I'm using, raises exceptions with messages that aren't as descriptive as the library it is calling Jsch.

    Java Code:
    04/11/2009 2:12:51 PM org.apache.commons.vfs.VfsLog info
    INFO: Using "C:\DOCUME~1\trentm\LOCALS~1\Temp\vfs_cache" as temporary files store.
    org.apache.commons.vfs.FileSystemException: Could not connect to SFTP server at "sftp://temp:***@sftpserver/".
    com.zehon.exception.FileTransferException: org.apache.commons.vfs.FileSystemException: Could not connect to SFTP server at "sftp://temp:***@sftpserver/".
      at com.zehon.FileTransferClient.resourceExist(FileTransferClient.java:576)
      at com.zehon.FileTransferClient.folderExists(FileTransferClient.java:551)
      at com.zehon.sftp.SFTPClient.folderExists(SFTPClient.java:803)
      at SFTP.IdfJSFTP.jSFTPPut(IdfJSFTP.java:69)
      at SFTP.IdfJSFTP.main(IdfJSFTP.java:26)
    Caused by: org.apache.commons.vfs.FileSystemException: Could not connect to SFTP server at "sftp://temp:***@sftpserver/".
      at org.apache.commons.vfs.provider.sftp.SftpFileProvider.doCreateFileSystem(SftpFileProvider.java:99)
      at org.apache.commons.vfs.provider.AbstractOriginatingFileProvider.getFileSystem(AbstractOriginatingFileProvider.java:103)
      at org.apache.commons.vfs.provider.AbstractOriginatingFileProvider.findFile(AbstractOriginatingFileProvider.java:82)
      at org.apache.commons.vfs.provider.AbstractOriginatingFileProvider.findFile(AbstractOriginatingFileProvider.java:66)
      at org.apache.commons.vfs.impl.DefaultFileSystemManager.resolveFile(DefaultFileSystemManager.java:692)
      at org.apache.commons.vfs.impl.DefaultFileSystemManager.resolveFile(DefaultFileSystemManager.java:620)
      at com.zehon.FileTransferClient.getFileObject(FileTransferClient.java:741)
      at com.zehon.FileTransferClient.resourceExist(FileTransferClient.java:573)
      ... 4 more
    Caused by: org.apache.commons.vfs.FileSystemException: Could not connect to SFTP server at "sftpserver".
      at org.apache.commons.vfs.provider.sftp.SftpClientFactory.createConnection(SftpClientFactory.java:214)
      at org.apache.commons.vfs.provider.sftp.SftpFileProvider.doCreateFileSystem(SftpFileProvider.java:90)
      ... 11 more
    Caused by: com.jcraft.jsch.JSchException: Auth fail
      at com.jcraft.jsch.Session.connect(Session.java:452)
    Unknown Exception
      at com.jcraft.jsch.Session.connect(Session.java:150)
      at org.apache.commons.vfs.provider.sftp.SftpClientFactory.createConnection(SftpClientFactory.java:210)
      ... 12 more
    The message I want to return is actually the line:
    Caused by: com.jcraft.jsch.JSchException: Auth fail

    How do I access that?

    Regards,
    TM

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    843
    Rep Power
    6

    Default

    just if u want to print only the exact messages.

    say

    try
    {
    ur code will be here
    }
    catch(Exception ex)
    {
    System.out.println(ex);//it prints the eception caused by in single line

    }//try-catch
    Ramya:cool:

  3. #3
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    getCause recursively until you get the one you want?

  4. #4
    rsvedula is offline Member
    Join Date
    Nov 2009
    Posts
    1
    Rep Power
    0

    Default

    I am trying to use zehon but get a error

    "at org.apache.commons.vfs.impl.DefaultFileSystemManag er.setupComponent(DefaultFileSystemManager.java:42 9)
    at org.apache.commons.vfs.impl.DefaultFileSystemManag er.setReplicator(DefaultFileSystemManager.java:388 )
    at org.apache.commons.vfs.impl.StandardFileSystemMana ger.init(StandardFileSystemManager.java:100)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:324)
    at org.apache.commons.vfs.VFS.createManager(VFS.java: 89)
    at org.apache.commons.vfs.VFS.getManager(VFS.java:51)
    at com.zehon.FileTransferClient.getFileObject(FileTra nsferClient.java:729)
    at com.zehon.FileTransferClient.resourceExist(FileTra nsferClient.java:573)"

    I am not able to figure out the issue?

    Any inputs please?

  5. #5
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Did you read Masi's response? What code did you write to implement that suggestion?

  6. #6
    tm_sss is offline Member
    Join Date
    Nov 2009
    Posts
    2
    Rep Power
    0

    Default

    masijade,

    Thanks for the tip. Worked the charm.

    For anyone looking for the same type of thing. To implement I assigned the getCause() of the exception to a Throwable type variable, then evaluated the results.

    Java Code:
    Throwable chain = e.getCause();
        
    while (chain != null) {
      chain = chain.getCause();
    
      if (chain == null) break;
      lastMessage = chain.getMessage();
      
    }
    Regards,
    TM

  7. #7
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Make it generic and write a method called getCauseOfType that takes two parameters. The one is the Exception and the other is the type of exception one is looking for. Put that in an Exceptions class and file it under your utility functions project.

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    This is one of those instances where recursion might be a neater solution, but that's just me being awkward...:)

  9. #9
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Quote Originally Posted by Tolls View Post
    This is one of those instances where recursion might be a neater solution, but that's just me being awkward...:)
    Mine is recursively implemented too ...

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

Similar Threads

  1. QuickSort highest lowest Situation
    By Tenn in forum New To Java
    Replies: 17
    Last Post: 05-06-2009, 05:37 AM
  2. find the greatest and lowest number in 2D array
    By le_albina@hotmail.com in forum New To Java
    Replies: 2
    Last Post: 03-31-2009, 12:09 AM
  3. Error Message:Invocation Target Exception
    By Deepa in forum New To Java
    Replies: 1
    Last Post: 11-27-2008, 08:43 AM
  4. Display Message Without Throwing Exception
    By kailashchandra in forum JavaServer Faces (JSF)
    Replies: 0
    Last Post: 09-27-2008, 10:05 AM
  5. Getting Exception message into a String
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-04-2008, 10:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •