IntegrationManagerException.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.skeleton;


  21. import javax.xml.bind.annotation.XmlElement;
  22. import javax.xml.bind.annotation.XmlTransient;

  23. import org.openspcoop2.core.config.ServizioApplicativo;
  24. import org.openspcoop2.core.id.IDServizioApplicativo;
  25. import org.openspcoop2.core.id.IDSoggetto;
  26. import org.openspcoop2.message.OpenSPCoop2SoapMessage;
  27. import org.openspcoop2.pdd.config.ConfigurazionePdDManager;
  28. import org.openspcoop2.pdd.config.OpenSPCoop2Properties;
  29. import org.openspcoop2.protocol.basic.Costanti;
  30. import org.openspcoop2.protocol.engine.builder.DateBuilder;
  31. import org.openspcoop2.protocol.sdk.Eccezione;
  32. import org.openspcoop2.protocol.sdk.IProtocolFactory;
  33. import org.openspcoop2.protocol.sdk.ProtocolException;
  34. import org.openspcoop2.protocol.sdk.builder.ProprietaErroreApplicativo;
  35. import org.openspcoop2.protocol.sdk.config.IProtocolManager;
  36. import org.openspcoop2.protocol.sdk.constants.CodiceErroreCooperazione;
  37. import org.openspcoop2.protocol.sdk.constants.CodiceErroreIntegrazione;
  38. import org.openspcoop2.protocol.sdk.constants.ErroreCooperazione;
  39. import org.openspcoop2.protocol.sdk.constants.ErroreIntegrazione;
  40. import org.openspcoop2.protocol.sdk.constants.IntegrationFunctionError;
  41. import org.openspcoop2.protocol.utils.ErroriProperties;
  42. import org.openspcoop2.utils.date.DateManager;
  43. import org.openspcoop2.utils.date.DateUtils;

  44. /**
  45.  * <p>Java class for IntegrationManagerException complex type.
  46.  *
  47.  * <p>The following schema fragment specifies the expected content contained within this class.
  48.  *
  49.  * <pre>
  50.  * &lt;complexType name="IntegrationManagerException">
  51.  *   &lt;complexContent>
  52.  *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
  53.  *       &lt;sequence>
  54.  *         &lt;element name="codiceEccezione" type="{http://www.w3.org/2001/XMLSchema}string"/>
  55.  *         &lt;element name="descrizioneEccezione" type="{http://www.w3.org/2001/XMLSchema}string"/>
  56.  *         &lt;element name="identificativoFunzione" type="{http://www.w3.org/2001/XMLSchema}string"/>
  57.  *         &lt;element name="identificativoPorta" type="{http://www.w3.org/2001/XMLSchema}string"/>
  58.  *         &lt;element name="oraRegistrazione" type="{http://www.w3.org/2001/XMLSchema}string"/>
  59.  *         &lt;element name="tipoEccezione" type="{http://www.w3.org/2001/XMLSchema}string"/>
  60.  *       &lt;/sequence>
  61.  *     &lt;/restriction>
  62.  *   &lt;/complexContent>
  63.  * &lt;/complexType>
  64.  * </pre>
  65.  *
  66.  *
  67.  */

  68. /**
  69.  * Contiene la definizione di una eccezione lanciata dal servizio IntegrationManager
  70.  *
  71.  * @author Poli Andrea (apoli@link.it)
  72.  * @author Tronci Fabio (tronci@link.it)
  73.  * @author Nardi Lorenzo (nardi@link.it)
  74.  * @author $Author$
  75.  * @version $Rev$, $Date$
  76.  */


  77. @javax.xml.bind.annotation.XmlType(name = "IntegrationManagerException", namespace="http://services.pdd.openspcoop2.org", propOrder = {
  78.     "codiceEccezione",
  79.     "descrizioneEccezione",
  80.     "identificativoFunzione",
  81.     "identificativoPorta",
  82.     "oraRegistrazione",
  83.     "tipoEccezione"
  84. })
  85. @javax.xml.ws.WebFault(name = "IntegrationManagerException", targetNamespace = "http://services.pdd.openspcoop2.org")

  86. public class IntegrationManagerException extends Exception implements java.io.Serializable {

  87.     /**
  88.      *
  89.      */
  90.     private static final long serialVersionUID = 4100781617691120752L;
  91.    
  92.     public static final String ECCEZIONE_PROTOCOLLO = "EccezioneProtocollo";
  93.     public static final String ECCEZIONE_INTEGRAZIONE = "EccezioneIntegrazione";
  94.    
  95.     /** Variabili */

  96.     private String codiceEccezione;
  97.     private String descrizioneEccezione;
  98.     private String identificativoFunzione;
  99.     private String identificativoPorta;
  100.     private String oraRegistrazione;
  101.     private String tipoEccezione;
  102.    
  103.     private CodiceErroreIntegrazione codiceErroreIntegrazione;
  104.     private CodiceErroreCooperazione codiceErroreCooperazione;
  105.     private ProprietaErroreApplicativo proprietaErroreAppl;
  106.    
  107.    
  108.     private void _setCode(String codErrore, IntegrationFunctionError functionError, ErroriProperties erroriProperties) throws ProtocolException {
  109.         if(Costanti.isTRANSACTION_ERROR_STATUS_ABILITATO()){
  110.             this.codiceEccezione = codErrore;
  111.         }
  112.         else {
  113.             String govwayType = erroriProperties.getErrorType(functionError);
  114.             this.codiceEccezione = govwayType;
  115.         }
  116.     }
  117.     private static String _getDescription(String descrErrore, IntegrationFunctionError functionError, ErroriProperties erroriProperties) {
  118.         try {
  119.             boolean genericDetails = false;
  120.             if(erroriProperties.isForceGenericDetails(functionError)) {
  121.                 genericDetails = true;
  122.             }
  123.             if (Costanti.isTRANSACTION_FORCE_SPECIFIC_ERROR_DETAILS()) {
  124.                 genericDetails = false;
  125.             }
  126.            
  127.             if(genericDetails){
  128.                 String govwayDetails = erroriProperties.getGenericDetails(functionError);
  129.                 return govwayDetails;
  130.             }
  131.             else {
  132.                 return descrErrore;
  133.             }
  134.         }catch(ProtocolException pExc) {
  135.             return descrErrore; // errore non dovrebbe succedere
  136.         }
  137.     }
  138.     private void _setDescription(String descrErrore, IntegrationFunctionError functionError, ErroriProperties erroriProperties) throws ProtocolException {
  139.         this.descrizioneEccezione = _getDescription(descrErrore, functionError, erroriProperties);
  140.     }
  141.    
  142.     public IntegrationManagerException(OpenSPCoop2SoapMessage message, String faultCode, String faultString, IDSoggetto identitaPdD, String identificativoFunzione) throws Exception {
  143.        
  144.         Object govwayPrefixCodeInContextProperty = message.getContextProperty(org.openspcoop2.message.constants.Costanti.ERRORE_GOVWAY_PREFIX_CODE);
  145.         Object govwayCodeInContextProperty = message.getContextProperty(org.openspcoop2.message.constants.Costanti.ERRORE_GOVWAY_CODE);
  146.         //Object govwayDetailsInContextProperty = message.getContextProperty(org.openspcoop2.message.constants.Costanti.ERRORE_GOVWAY_DETAILS);
  147.        
  148.         String govwayPrefixInternalErrorCode = null;
  149.         String govwayInternalErrorCode = null;
  150.         if(govwayPrefixCodeInContextProperty!=null && govwayCodeInContextProperty!=null){
  151.             govwayPrefixInternalErrorCode = (String) govwayPrefixCodeInContextProperty;
  152.             govwayInternalErrorCode = (String) govwayCodeInContextProperty;
  153.        
  154.             if(Costanti.isTRANSACTION_ERROR_STATUS_ABILITATO()){
  155.                 this.codiceEccezione = govwayInternalErrorCode;
  156.             }
  157.             else {
  158.                 if(faultCode.startsWith(org.openspcoop2.message.constants.Costanti.SOAP11_FAULT_CODE_CLIENT+org.openspcoop2.message.constants.Costanti.SOAP11_FAULT_CODE_SEPARATOR)) {
  159.                     this.codiceEccezione = faultCode.substring((org.openspcoop2.message.constants.Costanti.SOAP11_FAULT_CODE_CLIENT+org.openspcoop2.message.constants.Costanti.SOAP11_FAULT_CODE_SEPARATOR).length());
  160.                 }
  161.                 else if(faultCode.startsWith(org.openspcoop2.message.constants.Costanti.SOAP11_FAULT_CODE_SERVER+org.openspcoop2.message.constants.Costanti.SOAP11_FAULT_CODE_SEPARATOR)) {
  162.                     this.codiceEccezione = faultCode.substring((org.openspcoop2.message.constants.Costanti.SOAP11_FAULT_CODE_SERVER+org.openspcoop2.message.constants.Costanti.SOAP11_FAULT_CODE_SEPARATOR).length());
  163.                 }
  164.                 else {
  165.                     this.codiceEccezione = faultCode;
  166.                 }
  167.             }
  168.            
  169.             if(org.openspcoop2.protocol.basic.Costanti.PROBLEM_RFC7807_GOVWAY_CODE_PREFIX_PROTOCOL.equals(govwayPrefixInternalErrorCode)){
  170.                 this.setTipoEccezione(IntegrationManagerException.ECCEZIONE_PROTOCOLLO);
  171.             }
  172.             else {
  173.                 this.setTipoEccezione(IntegrationManagerException.ECCEZIONE_INTEGRAZIONE);
  174.             }
  175.            
  176.             this.setDescrizioneEccezione(faultString);
  177.            
  178.             this.setOraRegistrazione(DateUtils.getSimpleDateFormatMs().format(DateManager.getDate()));
  179.            
  180.             this.setIdentificativoPorta(identitaPdD.getCodicePorta());
  181.            
  182.             this.setIdentificativoFunzione(identificativoFunzione);
  183.         }
  184.         else {
  185.             throw new Exception("Not exists internal error code");
  186.         }

  187.     }
  188.    

  189.     public IntegrationManagerException(IProtocolFactory<?> protocolFactory,ErroreIntegrazione errore,
  190.             IntegrationFunctionError functionError, ErroriProperties erroriProperties) {
  191.         this(protocolFactory,errore,IntegrationManagerException.ECCEZIONE_INTEGRAZIONE,null,
  192.                 functionError, erroriProperties);
  193.     }
  194.     public IntegrationManagerException(IProtocolFactory<?> protocolFactory,ErroreIntegrazione errore,IDServizioApplicativo servizioApplicativo,
  195.             IntegrationFunctionError functionError, ErroriProperties erroriProperties) {
  196.         this(protocolFactory,errore,IntegrationManagerException.ECCEZIONE_INTEGRAZIONE,servizioApplicativo,
  197.                 functionError, erroriProperties);
  198.     }
  199.     private IntegrationManagerException(IProtocolFactory<?> protocolFactory,ErroreIntegrazione errore,String tipo,IDServizioApplicativo servizioApplicativo,
  200.             IntegrationFunctionError functionError, ErroriProperties erroriProperties) {
  201.         super( _getDescription(errore.getDescrizioneRawValue(), functionError, erroriProperties) );
  202.         try{
  203.             this.initProprietaBase(protocolFactory, tipo, servizioApplicativo);
  204.             this.codiceErroreIntegrazione = errore.getCodiceErrore();
  205.             String cod = null;
  206.             String desc = null;
  207.             if(protocolFactory!=null){
  208.                 cod = protocolFactory.createTraduttore().toString(errore.getCodiceErrore(),
  209.                         this.proprietaErroreAppl.getFaultPrefixCode(), this.proprietaErroreAppl.isFaultAsGenericCode());
  210.                 desc = errore.getDescrizione(protocolFactory);
  211.             }
  212.             else{
  213.                 cod = errore.getCodiceErrore().getCodice()+"";
  214.                 desc = errore.getDescrizioneRawValue();
  215.             }
  216.             this._setCode(cod, functionError, erroriProperties);
  217.             this._setDescription(desc, functionError, erroriProperties);
  218.         }catch(Exception e){
  219.             throw new RuntimeException(e.getMessage(), e);
  220.         }
  221.     }
  222.    

  223.     public IntegrationManagerException(IProtocolFactory<?> protocolFactory,ErroreCooperazione errore,
  224.             IntegrationFunctionError functionError, ErroriProperties erroriProperties) {
  225.         this(protocolFactory,errore,IntegrationManagerException.ECCEZIONE_PROTOCOLLO,null,
  226.                 functionError, erroriProperties);
  227.     }
  228.     public IntegrationManagerException(IProtocolFactory<?> protocolFactory,ErroreCooperazione errore,IDServizioApplicativo servizioApplicativo,
  229.             IntegrationFunctionError functionError, ErroriProperties erroriProperties) {
  230.         this(protocolFactory,errore,IntegrationManagerException.ECCEZIONE_PROTOCOLLO,servizioApplicativo,
  231.                 functionError, erroriProperties);
  232.     }
  233.     private IntegrationManagerException(IProtocolFactory<?> protocolFactory,ErroreCooperazione errore,String tipo,IDServizioApplicativo servizioApplicativo,
  234.             IntegrationFunctionError functionError, ErroriProperties erroriProperties)  {
  235.         super( _getDescription(errore.getDescrizioneRawValue(), functionError, erroriProperties) );
  236.         try{
  237.             this.initProprietaBase(protocolFactory, tipo, servizioApplicativo);
  238.             this.codiceErroreCooperazione = errore.getCodiceErrore();
  239.             String cod = protocolFactory.createTraduttore().toString(errore.getCodiceErrore());
  240.             String desc = errore.getDescrizione(protocolFactory);
  241.             this._setCode(cod, functionError, erroriProperties);
  242.             this._setDescription(desc, functionError, erroriProperties);
  243.         }catch(Exception e){
  244.             throw new RuntimeException(e.getMessage(), e);
  245.         }
  246.     }
  247.    
  248.    
  249.    
  250.     public IntegrationManagerException(IProtocolFactory<?> protocolFactory,Eccezione errore,
  251.             IntegrationFunctionError functionError, ErroriProperties erroriProperties)  {
  252.         this(protocolFactory,errore,IntegrationManagerException.ECCEZIONE_PROTOCOLLO,null,
  253.                 functionError, erroriProperties);
  254.     }
  255.     public IntegrationManagerException(IProtocolFactory<?> protocolFactory,Eccezione errore,IDServizioApplicativo servizioApplicativo,
  256.             IntegrationFunctionError functionError, ErroriProperties erroriProperties) {
  257.         this(protocolFactory,errore,IntegrationManagerException.ECCEZIONE_PROTOCOLLO,servizioApplicativo,
  258.                 functionError, erroriProperties);
  259.     }
  260.     private IntegrationManagerException(IProtocolFactory<?> protocolFactory,Eccezione errore,String tipo,IDServizioApplicativo servizioApplicativo,
  261.             IntegrationFunctionError functionError, ErroriProperties erroriProperties) {
  262.         super( _getDescription(getDescrizione(errore,protocolFactory), functionError, erroriProperties) );
  263.         try{
  264.             this.initProprietaBase(protocolFactory, tipo, servizioApplicativo);
  265.             this.codiceErroreCooperazione = errore.getCodiceEccezione();
  266.             String cod = protocolFactory.createTraduttore().toString(errore.getCodiceEccezione());
  267.             String desc = errore.getDescrizione(protocolFactory);
  268.             this._setCode(cod, functionError, erroriProperties);
  269.             this._setDescription(desc, functionError, erroriProperties);
  270.         }catch(Exception e){
  271.             throw new RuntimeException(e.getMessage(), e);
  272.         }
  273.     }
  274.     private static String getDescrizione(Eccezione errore,IProtocolFactory<?> protocolFactory){
  275.         try{
  276.             return errore.getDescrizione(protocolFactory);
  277.         }catch(Exception e){
  278.             throw new RuntimeException(e.getMessage(),e);
  279.         }
  280.     }

  281.    
  282.     public IntegrationManagerException() { }
  283.    
  284.    
  285.     private void initProprietaBase(IProtocolFactory<?> protocolFactory,String tipoEccezione, IDServizioApplicativo servizioApplicativo) throws ProtocolException {
  286.         this.oraRegistrazione = DateBuilder.getDate_Format(null);
  287.         this.identificativoFunzione = IntegrationManager.ID_MODULO;
  288.         this.tipoEccezione = tipoEccezione;
  289.         OpenSPCoop2Properties openspcoopProperties = OpenSPCoop2Properties.getInstance();
  290.         openspcoopProperties = OpenSPCoop2Properties.getInstance();
  291.         try{
  292.             IProtocolManager pm = null;
  293.             if(protocolFactory!=null){
  294.                 pm = protocolFactory.createProtocolManager();
  295.             }
  296.             this.proprietaErroreAppl = openspcoopProperties.getProprietaGestioneErrorePD(pm);
  297.         }catch(Exception e){
  298.             // ignore
  299.         }
  300.         if(servizioApplicativo!=null){
  301.             try{
  302.                 ConfigurazionePdDManager configPdDReader = ConfigurazionePdDManager.getInstance();
  303.                 ServizioApplicativo sa = configPdDReader.getServizioApplicativo(servizioApplicativo, null);
  304.                 configPdDReader.aggiornaProprietaGestioneErrorePD(this.proprietaErroreAppl,sa);
  305.             }catch(Exception e){
  306.                 //OpenSPCoopLogger.getLoggerOpenSPCoopCore().error("Aggiornamento gestione errore PD servizio applicativo in IntegrationManagerException.init dell'IntegrationManager  SA["+servizioApplicativo+"] non riuscito");
  307.             }
  308.         }
  309.         String protocol = null;
  310.         if(protocolFactory!=null){
  311.             protocol = protocolFactory.getProtocol();
  312.         }
  313.         this.identificativoPorta = openspcoopProperties.getIdentificativoPortaDefault(protocol, null);
  314.     }

  315.     @XmlTransient
  316.     public CodiceErroreIntegrazione getCodiceErroreIntegrazione() {
  317.         return this.codiceErroreIntegrazione;
  318.     }  
  319.     @XmlTransient
  320.     public CodiceErroreCooperazione getCodiceErroreCooperazione() {
  321.         return this.codiceErroreCooperazione;
  322.     }
  323.    

  324.     @XmlElement(required = true, nillable = true)
  325.     public void setDescrizioneEccezione(String descrizione){
  326.         this.descrizioneEccezione = descrizione;
  327.     }
  328.    
  329.     public String getDescrizioneEccezione(){
  330.         return this.descrizioneEccezione;
  331.     }
  332.    
  333.     @XmlElement(required = true, nillable = true)
  334.     public void setTipoEccezione(String tipo){
  335.         this.tipoEccezione = tipo;
  336.     }
  337.    
  338.     public String getTipoEccezione(){
  339.         return this.tipoEccezione;
  340.     }
  341.    
  342.     @XmlElement(required = true, nillable = true)
  343.     public void setOraRegistrazione(String ora){
  344.         this.oraRegistrazione = ora;
  345.     }

  346.     public String getOraRegistrazione(){
  347.         return this.oraRegistrazione;
  348.     }
  349.    
  350.     @XmlElement(required = true, nillable = true)
  351.     public void setIdentificativoPorta(String id){
  352.         this.identificativoPorta = id;
  353.     }
  354.    
  355.     public String getIdentificativoPorta(){
  356.         return this.identificativoPorta;
  357.     }
  358.    
  359.     @XmlElement(required = true, nillable = true)
  360.     public void setIdentificativoFunzione(String id){
  361.         this.identificativoFunzione = id;
  362.     }
  363.    
  364.     public String getIdentificativoFunzione(){
  365.         return this.identificativoFunzione;
  366.     }

  367.     @XmlElement(required = true, nillable = true)
  368.     public void setCodiceEccezione(String codice){
  369.         this.codiceEccezione = codice;
  370.     }

  371.     public String getCodiceEccezione(){
  372.         return this.codiceEccezione;
  373.     }

  374.     protected ProprietaErroreApplicativo getProprietaErroreApplicativo(){
  375.         return this.proprietaErroreAppl;
  376.     }
  377.    

  378.     // I seguenti transient method servono per evitare il warning:
  379.     // WARN  JAXBSchemaInitializer:595 - propOrder in @XmlType doesn't define all schema elements :
  380.     // [codiceEccezione, descrizioneEccezione, identificativoFunzione, identificativoPorta, oraRegistrazione, tipoEccezione]
  381.    
  382.     @Override
  383.     @XmlTransient
  384.     public StackTraceElement[] getStackTrace() {
  385.         return super.getStackTrace();
  386.     }
  387.    
  388.     @Override
  389.     @XmlTransient
  390.     public String getMessage() {
  391.         return super.getMessage();
  392.     }
  393.    
  394.     @Override
  395.     @XmlTransient
  396.     public String getLocalizedMessage() {
  397.         return super.getLocalizedMessage();
  398.     }
  399.    
  400.     @Override
  401.     @XmlTransient
  402.     public synchronized Throwable getCause() {
  403.         return super.getCause();
  404.     }
  405.    

  406. }