ConnectorException.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */

  20. package org.openspcoop2.pdd.services.connector;

  21. import java.io.IOException;

  22. import org.openspcoop2.utils.Utilities;

  23. /**
  24.  * Contiene la definizione di una eccezione lanciata dai NodeReceiver e NodeSender
  25.  *
  26.  * @author Poli Andrea (apoli@link.it)
  27.  * @author $Author$
  28.  * @version $Rev$, $Date$
  29.  */


  30. public class ConnectorException extends Exception {

  31.     /**
  32.      * serialVersionUID
  33.      */
  34.     private static final long serialVersionUID = 1L;
  35.    
  36.     public ConnectorException() {
  37.     }
  38.     public ConnectorException(String msg) {
  39.         super(msg);
  40.     }
  41.    
  42.     public ConnectorException(Throwable cause) {
  43.         super(cause);
  44.     }

  45.     public ConnectorException(String message, Throwable cause) {
  46.         super(message, cause);
  47.     }
  48.    
  49.     private String getInnerMessage(){
  50.         try{
  51.              if(Utilities.existsInnerException(this, java.net.SocketException.class)){
  52.                  Throwable t = Utilities.getInnerException(this, java.net.SocketException.class);
  53.                  if(t!=null){
  54.                      String msg = t.getMessage();
  55.                      if(msg!=null && !"".equals(msg) && !"null".equals(msg)){
  56.                          return msg;
  57.                      }
  58.                  }
  59.              }
  60.              else if(Utilities.existsInnerException(this, java.nio.channels.ClosedChannelException.class)){
  61.                  Throwable t = Utilities.getInnerException(this, java.nio.channels.ClosedChannelException.class);
  62.                  if(t!=null){
  63.                      String msg = t.getMessage();
  64.                      if(msg!=null && !"".equals(msg) && !"null".equals(msg)){
  65.                          return msg;
  66.                      }
  67.                  }
  68.              }
  69.              else {
  70.                  Throwable t = Utilities.getLastInnerException(this);
  71.                  if(t!=null && t instanceof IOException) {
  72.                      String msg = t.getMessage();
  73.                      if(msg!=null && !"".equals(msg) && !"null".equals(msg)){
  74.                          return msg;
  75.                      }
  76.                  }
  77.              }
  78.         }catch(Throwable t){
  79.             //t.getMessage(); // per debug
  80.         }
  81.         return null;
  82.     }
  83.    
  84.      @Override
  85.     public String getMessage() {
  86.         String msg = this.getInnerMessage();
  87.         if(msg!=null){
  88.             return msg;
  89.         }
  90.         return super.getMessage();
  91.     }
  92.     @Override
  93.     public String toString() {
  94.         String msg = this.getInnerMessage();
  95.         if(msg!=null){
  96.             return msg;
  97.         }
  98.         return super.toString();
  99.     }
  100. }