ModIProtocolManager.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.protocol.modipa.config;

  21. import java.util.Map;

  22. import org.openspcoop2.message.OpenSPCoop2Message;
  23. import org.openspcoop2.message.constants.ServiceBinding;
  24. import org.openspcoop2.protocol.basic.config.BasicManager;
  25. import org.openspcoop2.protocol.modipa.constants.ModICostanti;
  26. import org.openspcoop2.protocol.sdk.Busta;
  27. import org.openspcoop2.protocol.sdk.IProtocolFactory;
  28. import org.openspcoop2.protocol.sdk.ProtocolException;
  29. import org.openspcoop2.protocol.sdk.constants.FaultIntegrationGenericInfoMode;
  30. import org.openspcoop2.protocol.sdk.constants.TipoIntegrazione;
  31. import org.openspcoop2.protocol.sdk.registry.IRegistryReader;
  32. import org.openspcoop2.utils.BooleanNullable;
  33. import org.openspcoop2.utils.io.notifier.NotifierInputStreamParams;
  34. import org.openspcoop2.utils.transport.TransportRequestContext;
  35. import org.openspcoop2.utils.transport.TransportResponseContext;
  36. import org.openspcoop2.utils.transport.TransportUtils;
  37. import org.slf4j.Logger;

  38. /**
  39.  * Classe che implementa, in base al protocollo ModI, l'interfaccia {@link org.openspcoop2.protocol.sdk.config.IProtocolManager}
  40.  *
  41.  * @author Poli Andrea (apoli@link.it)
  42.  * @author $Author$
  43.  * @version $Rev$, $Date$
  44.  */
  45. public class ModIProtocolManager extends BasicManager {
  46.    
  47.     protected ModIProperties modipaProperties = null;
  48.     protected Logger logger = null;
  49.     public ModIProtocolManager(IProtocolFactory<?> protocolFactory) throws ProtocolException{
  50.         super(protocolFactory);
  51.         this.logger = this.getProtocolFactory().getLogger();
  52.         this.modipaProperties = ModIProperties.getInstance();
  53.     }
  54.    
  55.    
  56.    
  57.     /* *********** VALIDAZIONE/GENERAZIONE BUSTE ******************* */
  58.    
  59.     @Override
  60.     public boolean isGenerazioneListaEccezioniErroreProcessamento(){
  61.         return true; // l'eccezione viene utilizzata per produrre un errore applicativo e/o per impostare un codice nel soap fault
  62.     }
  63.    
  64.    
  65.    
  66.     /* *********** Fault della Porta (Protocollo, Porta Applicativa) ******************* */
  67.    
  68.     @Override
  69.     public boolean isGenerazioneDetailsFaultProtocollo_EccezioneValidazione(){
  70.         return this.modipaProperties.isGenerazioneDetailsSOAPFaultProtocolValidazione();
  71.     }
  72.    
  73.     @Override
  74.     public boolean isGenerazioneDetailsFaultProtocollo_EccezioneProcessamento(){
  75.         return this.modipaProperties.isGenerazioneDetailsSOAPFaultProtocolProcessamento();
  76.     }
  77.        
  78.     @Override
  79.     public boolean isGenerazioneDetailsFaultProtocolloConStackTrace(){
  80.         return this.modipaProperties.isGenerazioneDetailsSOAPFaultProtocolWithStackTrace();
  81.     }
  82.    
  83.     @Override
  84.     public boolean isGenerazioneDetailsFaultProtocolloConInformazioniGeneriche(){
  85.         return this.modipaProperties.isGenerazioneDetailsSOAPFaultProtocolConInformazioniGeneriche();
  86.     }
  87.    
  88.    
  89.    
  90.     /* *********** Fault della Porta (Integrazione, Porta Delegata) ******************* */
  91.    
  92.     @Override
  93.     public boolean isGenerazioneDetailsFaultIntegratione_erroreServer(){
  94.         return this.modipaProperties.isGenerazioneDetailsSOAPFaultIntegrationServerError();
  95.     }
  96.    
  97.     @Override
  98.     public boolean isGenerazioneDetailsFaultIntegratione_erroreClient(){
  99.         return this.modipaProperties.isGenerazioneDetailsSOAPFaultIntegrationClientError();
  100.     }
  101.    
  102.     @Override
  103.     public boolean isGenerazioneDetailsFaultIntegrationeConStackTrace(){
  104.         return this.modipaProperties.isGenerazioneDetailsSOAPFaultIntegrationWithStackTrace();
  105.     }
  106.    
  107.     @Override
  108.     public FaultIntegrationGenericInfoMode getModalitaGenerazioneInformazioniGeneriche_DetailsFaultIntegrazione(){
  109.         Boolean value = this.modipaProperties.isGenerazioneDetailsSOAPFaultIntegrazionConInformazioniGeneriche();
  110.         if(value==null){
  111.             return FaultIntegrationGenericInfoMode.SERVIZIO_APPLICATIVO;
  112.         }
  113.         else if(value){
  114.             return FaultIntegrationGenericInfoMode.ABILITATO;
  115.         }else{
  116.             return FaultIntegrationGenericInfoMode.DISABILITATO;
  117.         }
  118.     }
  119.    
  120.    
  121.    
  122.     /* *********** SOAP Fault della Porta (Generati dagli attori esterni) ******************* */
  123.    
  124.     @Override
  125.     public BooleanNullable isAggiungiDetailErroreApplicativo_FaultApplicativo() {
  126.         return this.modipaProperties.isAggiungiDetailErroreApplicativoSoapFaultApplicativo();
  127.     }

  128.     @Override
  129.     public BooleanNullable isAggiungiDetailErroreApplicativo_FaultPdD() {
  130.         return this.modipaProperties.isAggiungiDetailErroreApplicativoSoapFaultPdD();
  131.     }
  132.    
  133.    
  134.    
  135.     /* *********** INTEGRAZIONE ******************* */
  136.    
  137.     @Override
  138.     public Map<String, String> buildIntegrationProperties(Busta busta,
  139.             boolean isRichiesta, TipoIntegrazione tipoIntegrazione)
  140.             throws ProtocolException {
  141.        
  142.         return null;

  143.     }
  144.    
  145.     @Override
  146.     public OpenSPCoop2Message updateOpenSPCoop2MessageResponse(OpenSPCoop2Message msg, Busta busta,
  147.             NotifierInputStreamParams notifierInputStreamParams,
  148.             TransportRequestContext transportRequestContext, TransportResponseContext transportResponseContext,
  149.             IRegistryReader registryReader,
  150.             boolean integration) throws ProtocolException{
  151.        
  152.         if(integration) {
  153.             try {
  154.            
  155.                 boolean createCorrelationIdIfNotExists = false;
  156.                 if(msg!=null) {
  157.                     if(ServiceBinding.REST.equals(msg.getServiceBinding())) {
  158.                         createCorrelationIdIfNotExists = this.modipaProperties.isRestSecurityTokenPushCorrelationIdUseTransactionIdIfNotExists();
  159.                     }
  160.                     else {
  161.                         createCorrelationIdIfNotExists = this.modipaProperties.isSoapSecurityTokenPushCorrelationIdUseTransactionIdIfNotExists();
  162.                     }
  163.                 }
  164.                
  165.                 if(busta!=null && createCorrelationIdIfNotExists) {
  166.                     String asyncInteractionType = busta.getProperty(ModICostanti.MODIPA_BUSTA_EXT_PROFILO_INTERAZIONE_ASINCRONA_TIPO);
  167.                     if(ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_VALUE_PUSH.equals(asyncInteractionType)) {
  168.                         String asyncInteractionRole = busta.getProperty(ModICostanti.MODIPA_BUSTA_EXT_PROFILO_INTERAZIONE_ASINCRONA_RUOLO);
  169.                         if(ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_VALUE_RICHIESTA.equals(asyncInteractionRole)) {
  170.                            
  171.                             if(ServiceBinding.REST.equals(msg.getServiceBinding())) {
  172.                                 String headerCorrelationId = this.modipaProperties.getRestCorrelationIdHeader();
  173.                                 String correlationIdFound = msg.getTransportResponseContext().getHeaderFirstValue(headerCorrelationId);
  174.                                 if(correlationIdFound==null || "".equals(correlationIdFound)) {
  175.                                     TransportUtils.addHeader(msg.getTransportResponseContext().getHeaders(),headerCorrelationId, ModICostanti.MODIPA_BUSTA_EXT_PROFILO_INTERAZIONE_ASINCRONA_ID_CORRELAZIONE_AGGIUNTO_PER_CONSENTIRE_VALIDAZIONE_CONTENUTI);
  176.                                 }
  177.                             }
  178.                             else {
  179.                                 // TODO: add SOAPHeader
  180.                                 //       fino a che non viene implementata la validazione dell'header SOAP l'aggiunta non serve
  181.                             }
  182.                            
  183.                         }
  184.                     }
  185.                 }
  186.                
  187.             }catch(Exception e) {
  188.                 throw new ProtocolException(e.getMessage(),e);
  189.             }
  190.         }
  191.        
  192.         return super.updateOpenSPCoop2MessageResponse(msg, busta,
  193.                 notifierInputStreamParams,transportRequestContext,transportResponseContext,registryReader,integration);
  194.     }
  195.    
  196.    
  197.     /* *********** CONNETTORE ******************* */
  198.    
  199.     @Override
  200.     public boolean isSuccessfulHttpRedirectStatusCode(ServiceBinding serviceBinding) throws ProtocolException{
  201.         return ServiceBinding.REST.equals(serviceBinding);
  202.     }
  203.    
  204. }