OutResponseHandler.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.core.handlers.transazioni;

  21. import org.openspcoop2.core.constants.Costanti;
  22. import org.openspcoop2.pdd.config.OpenSPCoop2Properties;
  23. import org.openspcoop2.pdd.core.handlers.HandlerException;
  24. import org.openspcoop2.pdd.core.handlers.OutResponseContext;
  25. import org.openspcoop2.pdd.core.transazioni.Transaction;
  26. import org.openspcoop2.pdd.core.transazioni.TransactionContext;
  27. import org.openspcoop2.pdd.core.transazioni.TransactionDeletedException;
  28. import org.openspcoop2.pdd.core.transazioni.TransactionNotExistsException;

  29. /**    
  30.  * OutResponseHandler
  31.  *
  32.  * @author Poli Andrea (poli@link.it)
  33.  * @author $Author$
  34.  * @version $Rev$, $Date$
  35.  */
  36. public class OutResponseHandler extends LastPositionHandler implements  org.openspcoop2.pdd.core.handlers.OutResponseHandler{

  37.     @Override
  38.     public void invoke(OutResponseContext context) throws HandlerException {
  39.        
  40.         OpenSPCoop2Properties op2Properties = OpenSPCoop2Properties.getInstance();
  41.         if(op2Properties.isTransazioniEnabled()==false) {
  42.             return;
  43.         }
  44.        
  45.         String idTransazione = (String) context.getPddContext().getObject(Costanti.ID_TRANSAZIONE);
  46.        
  47.         //System.out.println("------------- OutResponseHandler ("+idTransazione+")("+context.getTipoPorta().getTipo()+") -------------------");
  48.        
  49.         //if(context.getIntegrazione()!=null)
  50.         //  System.out.println("GESTIONE STATELESS OutResponseHandler ["+context.getIntegrazione().isGestioneStateless()+"] ["+context.getTipoPorta()+"]");
  51.         // NOTA: se l'integrazione e' null o l'indicazione se la gestione stateless e' null, significa che la PdD non e' ancora riuscita
  52.         // a capire che tipo di gestione deve adottare. Queste transazioni devono essere sempre registrate perche' riguardano cooperazioni andate in errore all'inizio,
  53.         // es. Porta Delegata non esistente, busta malformata....
  54.         if(context.getIntegrazione()!=null &&
  55.                 context.getIntegrazione().isGestioneStateless()!=null &&
  56.                 !context.getIntegrazione().isGestioneStateless()){
  57.             if(op2Properties.isTransazioniStatefulEnabled()==false){
  58.                 throw new HandlerException("Gestione delle transazioni stateful non abilita");
  59.             }
  60.         }
  61.        
  62.         Transaction tr = null;
  63.         try{
  64.        
  65.             tr = TransactionContext.getTransaction(idTransazione);
  66.            
  67.             tr.setDataUscitaRisposta(context.getDataElaborazioneMessaggio());
  68.             //System.out.println("SET DATA ("+context.getDataElaborazioneMessaggio().toString()+")");
  69.        
  70.         }catch(TransactionDeletedException e){
  71.             throw new HandlerException(e);
  72.             // Non dovrebbe avvenire in questo handler
  73.         }catch(TransactionNotExistsException e){
  74.             throw new HandlerException(e);
  75.             // Non dovrebbe avvenire in questo handler
  76.         }
  77. //      catch(HandlerException e){
  78. //          throw e;
  79. //      }
  80.         catch(Exception e){
  81.             throw new HandlerException(e);
  82.         }

  83.     }


  84. }