From 81991b42deb3e24a5d45f2d6812fdd1859fecb61 Mon Sep 17 00:00:00 2001 From: Björn Hagemeister Date: Wed, 1 Oct 2014 14:42:34 +0200 Subject: Made exception handling more local to code. --- .../filetransfer/ThriftConnection.java | 149 ++++++++++----------- 1 file changed, 68 insertions(+), 81 deletions(-) diff --git a/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java b/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java index 614fb24..e88019c 100644 --- a/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java +++ b/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java @@ -71,22 +71,52 @@ public class ThriftConnection { log.error("Client was null!"); return null; } - List crcSums = null; - try { - crc = new CrcFile(crcPath); - log.info("Made CRCFile from " + crcPath); - log.info("crc.getCrcSums( ).size = " + crc.getCrcSums().size()); - // log.info( "crc.getMasterSum() : " + crc.getMasterSum() ); - // for ( int i = 0; i < crc.getCrcSums().size() - 1; i++ ) { - // log.info( "crc.getCRCSum() : " + crc.getCRCSum( i ) ); - // } - crcSums = crc.getCrcSums(); - return theClient - .submitImage(sSD.sessionId, imDat, crcSums); - } catch (FileNotFoundException e) { - log.debug("crcFile " + crcPath + " not found."); - return theClient - .submitImage(sSD.sessionId, imDat, crcSums); + } catch (UnrecoverableKeyException e) { + log.error("UnrecoverableKeyException", e); + } catch (InvalidKeyException e) { + log.error("InvalidKeyException", e); + } catch (NoSuchAlgorithmException e) { + log.error("NoSuchAlgorithmException", e); + } catch (CertificateException e) { + log.error("CertificateException", e); + } catch (FileNotFoundException e) { + log.error("FileNotFoundException", e); + } catch (KeyStoreException e) { + log.error("KeyStoreException", e); + } catch (SignatureException e) { + log.error("SignatureException", e); + } catch (IOException e) { + log.error("IOException", e); + } + List crcSums = null; + try { + crc = new CrcFile(crcPath); + log.info("Made CRCFile from " + crcPath); + log.info("crc.getCrcSums( ).size = " + crc.getCrcSums().size()); + // log.info( "crc.getMasterSum() : " + crc.getMasterSum() ); + // for ( int i = 0; i < crc.getCrcSums().size() - 1; i++ ) { + // log.info( "crc.getCRCSum() : " + crc.getCRCSum( i ) ); + // } + crcSums = crc.getCrcSums(); + } catch (FileNotFoundException e) { + log.debug("crcFile " + crcPath + " not found."); + } catch (IOException e) { + log.error("IOException", e); + } + try { + return theClient + .submitImage(sSD.sessionId, imDat, crcSums); + } catch (AuthorizationException e) { + if (e.isSetNumber() + && e.getNumber().equals( + AuthorizationError.NOT_AUTHENTICATED)) { + // SessionID is not valid + // TODO: Code for new SSID + } else if (e.getNumber().equals(AuthorizationError.NO_PERMISSION)) { + // not yet implemented. + + } else { + e.printStackTrace(); } } catch (ImageDataException e) { if (e.isSetNumber() @@ -116,45 +146,8 @@ public class ThriftConnection { } else { e.printStackTrace(); } - } catch (AuthorizationException e) { - if (e.isSetNumber() - && e.getNumber().equals( - AuthorizationError.NOT_AUTHENTICATED)) { - // SessionID is not valid - // TODO: Code for new SSID - } else if (e.getNumber().equals(AuthorizationError.NO_PERMISSION)) { - // not yet implemented. - - } else { - e.printStackTrace(); - } - } catch (UnrecoverableKeyException e) { - log.error("UnrecoverableKeyException"); - e.printStackTrace(); - } catch (InvalidKeyException e) { - log.error("InvalidKeyException"); - e.printStackTrace(); - } catch (NoSuchAlgorithmException e) { - log.error("NoSuchAlgorithmException"); - e.printStackTrace(); - } catch (CertificateException e) { - log.error("CertificateException"); - e.printStackTrace(); - } catch (FileNotFoundException e) { - log.error("FileNotFoundException"); - e.printStackTrace(); - } catch (KeyStoreException e) { - log.error("KeyStoreException"); - e.printStackTrace(); - } catch (SignatureException e) { - log.error("SignatureException"); - e.printStackTrace(); - } catch (IOException e) { - log.error("IOException"); - e.printStackTrace(); } catch (TException e) { - log.error("TException"); - e.printStackTrace(); + log.error("TException", e); } return null; } @@ -162,7 +155,7 @@ public class ThriftConnection { /***********************************************************************************************/ /** * Method for getting DonwloadInfos. Calls getConnection if client was null. - * You need to spezifie all Blocks you want to have in an List. + * You need to specify all Blocks you want to have in an List. * * @return returns 'null' if there is a problem. */ @@ -174,6 +167,25 @@ public class ThriftConnection { log.error("Client was null!"); return null; } + } catch (UnrecoverableKeyException e) { + log.error("UnrecoverableKeyException", e); + } catch (InvalidKeyException e) { + log.error("InvalidKeyException", e); + } catch (NoSuchAlgorithmException e) { + log.error("NoSuchAlgorithmException", e); + } catch (CertificateException e) { + log.error("CertificateException", e); + } catch (FileNotFoundException e) { + log.error("FileNotFoundException", e); + } catch (KeyStoreException e) { + log.error("KeyStoreException", e); + } catch (SignatureException e) { + log.error("SignatureException", e); + } catch (IOException e) { + log.error("IOException", e); + } + + try { return theClient.getImage(sSD.sessionId, imDat.guid); } catch (ImageDataException e) { log.debug("In catch - blog of thrift connection"); @@ -205,33 +217,8 @@ public class ThriftConnection { } else { e.printStackTrace(); } - } catch (UnrecoverableKeyException e) { - log.error("UnrecoverableKeyException"); - e.printStackTrace(); - } catch (InvalidKeyException e) { - log.error("InvalidKeyException"); - e.printStackTrace(); - } catch (NoSuchAlgorithmException e) { - log.error("NoSuchAlgorithmException"); - e.printStackTrace(); - } catch (CertificateException e) { - log.error("CertificateException"); - e.printStackTrace(); - } catch (FileNotFoundException e) { - log.error("FileNotFoundException"); - e.printStackTrace(); - } catch (KeyStoreException e) { - log.error("KeyStoreException"); - e.printStackTrace(); - } catch (SignatureException e) { - log.error("SignatureException"); - e.printStackTrace(); - } catch (IOException e) { - log.error("IOException"); - e.printStackTrace(); } catch (TException e) { - log.error("TException"); - e.printStackTrace(); + log.error("TException", e); } return null; } -- cgit v1.2.3-55-g7522