ConnettoreMsg.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.connettori;

  21. import java.util.Date;
  22. import java.util.Iterator;
  23. import java.util.List;
  24. import java.util.Map;

  25. import org.openspcoop2.core.config.InvocazioneCredenziali;
  26. import org.openspcoop2.core.config.Property;
  27. import org.openspcoop2.core.config.driver.DriverConfigurazioneException;
  28. import org.openspcoop2.core.config.driver.DriverConfigurazioneNotFound;
  29. import org.openspcoop2.core.constants.CostantiConnettori;
  30. import org.openspcoop2.core.id.IDAccordo;
  31. import org.openspcoop2.core.id.IDPortaApplicativa;
  32. import org.openspcoop2.core.transazioni.TransazioneApplicativoServer;
  33. import org.openspcoop2.message.OpenSPCoop2Message;
  34. import org.openspcoop2.pdd.config.ConfigurazionePdDManager;
  35. import org.openspcoop2.pdd.config.ForwardProxy;
  36. import org.openspcoop2.pdd.core.PdDContext;
  37. import org.openspcoop2.pdd.core.controllo_traffico.PolicyTimeoutConfig;
  38. import org.openspcoop2.pdd.core.handlers.OutRequestContext;
  39. import org.openspcoop2.pdd.core.token.PolicyNegoziazioneToken;
  40. import org.openspcoop2.pdd.logger.MsgDiagnostico;
  41. import org.openspcoop2.protocol.sdk.Busta;
  42. import org.openspcoop2.protocol.sdk.BustaRawContent;
  43. import org.openspcoop2.protocol.sdk.IProtocolFactory;
  44. import org.openspcoop2.protocol.sdk.ProtocolException;
  45. import org.openspcoop2.protocol.sdk.ProtocolMessage;
  46. import org.openspcoop2.protocol.sdk.builder.ProprietaManifestAttachments;
  47. import org.openspcoop2.protocol.sdk.constants.FaseSbustamento;
  48. import org.openspcoop2.protocol.sdk.constants.RuoloMessaggio;
  49. import org.openspcoop2.protocol.sdk.state.IState;
  50. import org.openspcoop2.protocol.sdk.state.RequestInfo;
  51. import org.openspcoop2.utils.transport.TransportRequestContext;

  52. /**
  53.  * Classe utilizzata per rappresentare le informazioni utilizzata da un generico connettore.
  54.  *
  55.  * @author Poli Andrea (apoli@link.it)
  56.  * @author $Author$
  57.  * @version $Rev$, $Date$
  58.  */

  59. public class ConnettoreMsg  {


  60.     /* ********  F I E L D S  P R I V A T I  ******** */

  61.     /** Tipo di Connettore */
  62.     private String tipoConnector;
  63.     /** Messaggio da spedire */
  64.     private OpenSPCoop2Message request;
  65.     /** Proprieta' del connettore */
  66.     private java.util.Map<String,String> properties;
  67.     /** Errore generato con un prefisso del connettore */
  68.     protected boolean generateErrorWithConnectorPrefix = true;

  69.     /** Indicazione su di un eventuale sbustamento SOAP */
  70.     private boolean sbustamentoSoap;
  71.     /** Indicazione su di un eventuale sbustamento delle informazioni di protocollo */
  72.     private boolean sbustamentoInformazioniProtocollo;
  73.     /** Proprieta' di trasporto che deve utilizzare il connettore */
  74.     private Map<String, List<String>> propertiesTrasporto;
  75.     /** Proprieta' urlBased che deve utilizzare il connettore */
  76.     private Map<String, List<String>> propertiesUrlBased;
  77.     /** Tipo di Autenticazione */
  78.     private String tipoAutenticazione;
  79.     /** Credenziali per l'autenticazione */
  80.     private InvocazioneCredenziali credenziali;
  81.     /** Busta */
  82.     private Busta busta;
  83.     /** Identificativo Modulo che utilizza il connettore */
  84.     private String idModulo;
  85.     /** ProtocolFactory */
  86.     private IProtocolFactory<?> protocolFactory;
  87.     /** Attributi per lo sbustamento del protocollo */
  88.     private boolean gestioneManifest = false;
  89.     private ProprietaManifestAttachments proprietaManifestAttachments = null;
  90.     /** Eventuale header sbustato contenente le informazioni di protocollo */
  91.     private BustaRawContent<?> soapProtocolInfo = null;
  92.     /** Informazione sulla modalita LocalForward */
  93.     private boolean localForward = false;
  94.     /** Indicazione se il messaggio in consegna riguarda una richiesta o una risposta
  95.      * Il set di questo field, potrĂ  essere usato per la risposta di una invocazione sincrona con consegna su I.M. */
  96.     private RuoloMessaggio ruoloMessaggio = RuoloMessaggio.RICHIESTA;
  97.     /** Policy Token */
  98.     private PolicyNegoziazioneToken policyNegoziazioneToken;
  99.     private PolicyTimeoutConfig policyTimeoutConfig;
  100.    
  101.     /** OutRequestContext */
  102.     private OutRequestContext outRequestContext;
  103.     /** MessaggioDiagnostico */
  104.     private MsgDiagnostico msgDiagnostico;
  105.     /** IState */
  106.     private IState state;
  107.    
  108.     private TransazioneApplicativoServer transazioneApplicativoServer;
  109.     private IDPortaApplicativa idPortaApplicativa;
  110.     private Date dataConsegnaTransazioneApplicativoServer;
  111.    
  112.     private ForwardProxy forwardProxy;
  113.    
  114.     private IDAccordo idAccordo;
  115.    
  116.     private String urlInvocazionePorta;
  117.    
  118.     private Boolean forceSendContent = null;




  119.     /* ********  C O S T R U T T O R E  ******** */
  120.     /**
  121.      * Costruttore.
  122.      *
  123.      *
  124.      */
  125.     public ConnettoreMsg(){}
  126.     /**
  127.      * Costruttore.
  128.      *
  129.      * @param type Tipo di Connettore
  130.      * @param r Messaggio di Richiesta
  131.      * @param p Proprieta' del Connettore
  132.      *
  133.      */
  134.     public ConnettoreMsg(String type,OpenSPCoop2Message r,
  135.             Property[] p){
  136.         java.util.Map<String,String> pr = new java.util.HashMap<>();
  137.         if(p!=null){
  138.             for(int i=0; i<p.length; i++){
  139.                 if(p[i]!=null){
  140.                     pr.put(p[i].getNome(),p[i].getValore());
  141.                 }
  142.             }
  143.         }
  144.         this.tipoConnector = type;
  145.         this.request = r;
  146.         this.properties = pr;
  147.     }
  148.     /**
  149.      * Costruttore.
  150.      *
  151.      * @param type Tipo di Connettore
  152.      * @param r Messaggio di Richiesta
  153.      * @param p Proprieta' del Connettore
  154.      *
  155.      */
  156.     public ConnettoreMsg(String type,OpenSPCoop2Message r,
  157.             java.util.Map<String,String> p){
  158.         this(type,r,p,false,null,null,true);
  159.     }
  160.     /**
  161.      * Costruttore.
  162.      *
  163.      * @param type Tipo di Connettore
  164.      * @param r Messaggio di Richiesta
  165.      * @param p Proprieta' del Connettore
  166.      * @param sb Indicazione su di un eventuale sbustamento SOAP
  167.      * @param tipoAuth Tipo di Autenticazione associata al connettore
  168.      * @param cr Credenziali Associate al connettore
  169.      *
  170.      */
  171.     public ConnettoreMsg(String type,OpenSPCoop2Message r,
  172.             Property[] p,boolean sb,
  173.             String tipoAuth,InvocazioneCredenziali cr,
  174.             boolean isRichiesta){
  175.         this(type,r,new java.util.HashMap<>() ,sb,tipoAuth,cr,isRichiesta);

  176.         java.util.Map<String,String> pr = new java.util.HashMap<>();
  177.         if(p!=null){
  178.             for(int i=0; i<p.length; i++){
  179.                 if(p[i]!=null){
  180.                     pr.put(p[i].getNome(),p[i].getValore());
  181.                 }
  182.             }
  183.         }
  184.         this.properties = pr;
  185.     }
  186.     /**
  187.      * Costruttore.
  188.      *
  189.      * @param type Tipo di Connettore
  190.      * @param r Messaggio di Richiesta
  191.      * @param p Proprieta' del Connettore
  192.      * @param sb Indicazione su di un eventuale sbustamento SOAP
  193.      * @param tipoAuth Tipo di Autenticazione associata al connettore
  194.      * @param cr Credenziali Associate al connettore
  195.      *
  196.      */
  197.     public ConnettoreMsg(String type,OpenSPCoop2Message r,
  198.             java.util.Map<String,String> p,boolean sb,
  199.             String tipoAuth,InvocazioneCredenziali cr,
  200.             boolean isRichiesta){

  201.         this.tipoConnector = type;
  202.         this.request = r;
  203.         this.properties = p;
  204.         this.sbustamentoSoap = sb;
  205.         this.tipoAutenticazione = tipoAuth;
  206.         this.credenziali = cr;
  207.     }



  208.    

  209.     /* ********  S E T T E R   ******** */
  210.    
  211.     /**
  212.      * Imposta il tipo di connettore.
  213.      *
  214.      * @param tipo Tipo di Connettore.
  215.      *
  216.      */    
  217.     public void setTipoConnettore(String tipo) {
  218.         this.tipoConnector = tipo;
  219.     }
  220.     /**
  221.      * Imposta il messaggio da spedire.
  222.      *
  223.      * @param r Messaggio da Spedire
  224.      *
  225.      */  
  226.     public void setRequestMessage(OpenSPCoop2Message r) {
  227.         this.request = r;
  228.     }
  229.     /**
  230.      * Imposta le proprieta' del connettore.
  231.      *
  232.      * @param p Proprieta' del Connettore
  233.      *
  234.      */  
  235.     public void setConnectorProperties(java.util.Map<String,String> p) {
  236.         this.properties = p;
  237.     }
  238.     /**
  239.      * Imposta l'indicazione su di un eventuale sbustamento SOAP.
  240.      *
  241.      * @param sb indicazione su di un eventuale sbustamento SOAP.
  242.      *
  243.      */    
  244.     public void setSbustamentoSOAP(boolean sb) {
  245.         this.sbustamentoSoap = sb;
  246.     }
  247.    
  248.     /**
  249.      * Imposta il tipo di autenticazione associato al connettore
  250.      *
  251.      * @param tipoAuth tipo di autenticazione.
  252.      *
  253.      */
  254.     public void setAutenticazione(String tipoAuth){
  255.         this.tipoAutenticazione = tipoAuth;
  256.     }
  257.     /**
  258.      * Imposta le credenziali associate all'autenticazione utilizzata dal connettore
  259.      *
  260.      * @param cr Credenziali
  261.      *
  262.      */
  263.     public void setCredenziali(InvocazioneCredenziali cr){
  264.         this.credenziali = cr;
  265.     }
  266.    
  267.     public void setGenerateErrorWithConnectorPrefix(boolean generateErrorWithConnectorPrefix) {
  268.         this.generateErrorWithConnectorPrefix = generateErrorWithConnectorPrefix;
  269.     }
  270.    
  271.     public void setIdAccordo(IDAccordo id) {
  272.         this.idAccordo = id;
  273.     }
  274.    
  275.     public void setUrlInvocazionePorta(String urlInvocazionePorta) {
  276.         this.urlInvocazionePorta = urlInvocazionePorta;
  277.     }
  278.    
  279.     public void forceSendContent() {
  280.         this.forceSendContent = true;
  281.     }


  282.     /* ********  G E T T E R   ******** */

  283.     /**
  284.      * Ritorna il tipo di connettore.
  285.      *
  286.      * @return Tipo di Connettore.
  287.      *
  288.      */    
  289.     public String getTipoConnettore() {
  290.         return this.tipoConnector;
  291.     }
  292.     /**
  293.      * Ritorna il messaggio da spedire.
  294.      *
  295.      * @return Messaggio da Spedire
  296.      *
  297.      */  
  298.     private boolean sbustamentoProtocolInfoEffettuato = false;
  299.     private boolean checkPresenzaHeaderPrimaSbustamento = false;
  300.     public void setCheckPresenzaHeaderPrimaSbustamento(boolean checkPresenzaHeaderPrimaSbustamento) {
  301.         this.checkPresenzaHeaderPrimaSbustamento = checkPresenzaHeaderPrimaSbustamento;
  302.     }
  303.     public OpenSPCoop2Message getRequestMessage(RequestInfo requestInfo, PdDContext pddContext) throws ProtocolException {
  304.         if(!this.localForward && this.sbustamentoInformazioniProtocollo && !this.sbustamentoProtocolInfoEffettuato){
  305.             boolean protocolloPresente = true;
  306.             if(this.checkPresenzaHeaderPrimaSbustamento){
  307.                 try{
  308.                     protocolloPresente = this.protocolFactory.createValidazioneSintattica(this.state).
  309.                         verifyProtocolPresence(this.outRequestContext.getTipoPorta(), this.busta.getProfiloDiCollaborazione(), this.ruoloMessaggio, this.request);
  310.                 }catch(Exception e){}
  311.             }
  312.             if(protocolloPresente){
  313.                 org.openspcoop2.protocol.engine.builder.Sbustamento sbustatore =
  314.                         new org.openspcoop2.protocol.engine.builder.Sbustamento(this.protocolFactory,this.state);
  315.                     ProtocolMessage protocolMessage = sbustatore.sbustamento(this.request,pddContext,
  316.                             this.busta,
  317.                             this.ruoloMessaggio,this.gestioneManifest,this.proprietaManifestAttachments,
  318.                             FaseSbustamento.PRE_CONSEGNA_RICHIESTA, requestInfo);
  319.                     if(protocolMessage!=null) {
  320.                         this.soapProtocolInfo = protocolMessage.getBustaRawContent();
  321.                         this.request = protocolMessage.getMessage(); // updated
  322.                     }
  323.                     this.sbustamentoProtocolInfoEffettuato = true;
  324.             }
  325.         }
  326.         return this.request;
  327.     }
  328.     public TransportRequestContext getTransportRequestContext() {
  329.         if(this.request!=null) {
  330.             return this.request.getTransportRequestContext();
  331.         }
  332.         return null;
  333.     }
  334.    
  335.     /**
  336.      * Ritorna le proprieta' del connettore.
  337.      *
  338.      * @return Proprieta' del Connettore
  339.      *
  340.      */  
  341.     public java.util.Map<String,String> getConnectorProperties() {
  342.         return this.properties;
  343.     }
  344.     /**
  345.      * Ritorna l'indicazione su di un eventuale sbustamento SOAP.
  346.      *
  347.      * @return indicazione su di un eventuale sbustamento SOAP.
  348.      *
  349.      */    
  350.     public boolean isSbustamentoSOAP() {
  351.         return this.sbustamentoSoap;
  352.     }
  353.    
  354.     /**
  355.      * Ritorna il tipo di autenticazione associato al connettore
  356.      *
  357.      * @return tipo di autenticazione.
  358.      *
  359.      */
  360.     public String getAutenticazione(){
  361.         return this.tipoAutenticazione;
  362.     }
  363.     /**
  364.      * Ritorna le credenziali associate all'autenticazione utilizzata dal connettore
  365.      *
  366.      * @return Credenziali
  367.      *
  368.      */
  369.     public InvocazioneCredenziali getCredenziali(){
  370.         return this.credenziali;
  371.     }
  372.     /**
  373.      * @return the propertiesTrasporto
  374.      */
  375.     public Map<String, List<String>> getPropertiesTrasporto() {
  376.         return this.propertiesTrasporto;
  377.     }
  378.     /**
  379.      * @return the propertiesUrlBased
  380.      */
  381.     public Map<String, List<String>> getPropertiesUrlBased() {
  382.         return this.propertiesUrlBased;
  383.     }
  384.     /**
  385.      * @param propertiesTrasporto the propertiesTrasporto to set
  386.      */
  387.     public void setPropertiesTrasporto(Map<String, List<String>> propertiesTrasporto) {
  388.         this.propertiesTrasporto = propertiesTrasporto;
  389.     }
  390.     /**
  391.      * @param propertiesUrlBased the propertiesUrlBased to set
  392.      */
  393.     public void setPropertiesUrlBased(Map<String, List<String>> propertiesUrlBased) {
  394.         this.propertiesUrlBased = propertiesUrlBased;
  395.     }
  396.     /**
  397.      * @return the busta
  398.      */
  399.     public Busta getBusta() {
  400.         return this.busta;
  401.     }
  402.     /**
  403.      * @param busta the busta to set
  404.      */
  405.     public void setBusta(Busta busta) {
  406.         this.busta = busta;
  407.     }

  408.     public String getIdModulo() {
  409.         return this.idModulo;
  410.     }
  411.     public void setIdModulo(String idModulo) {
  412.         this.idModulo = idModulo;
  413.     }
  414.    
  415.     public boolean isSbustamentoInformazioniProtocollo() {
  416.         return this.sbustamentoInformazioniProtocollo;
  417.     }
  418.     public void setSbustamentoInformazioniProtocollo(
  419.             boolean sbustamentoInformazioniProtocollo) {
  420.         this.sbustamentoInformazioniProtocollo = sbustamentoInformazioniProtocollo;
  421.     }
  422.     public RuoloMessaggio getRuoloMessaggio() {
  423.         return this.ruoloMessaggio;
  424.     }
  425.     public void setRuoloMessaggio(RuoloMessaggio ruoloMessaggio) {
  426.         this.ruoloMessaggio = ruoloMessaggio;
  427.     }
  428.     public void setProtocolFactory(IProtocolFactory<?> protocolFactory) {
  429.         this.protocolFactory = protocolFactory;
  430.     }
  431.    
  432.     public void setGestioneManifest(boolean gestioneManifest) {
  433.         this.gestioneManifest = gestioneManifest;
  434.     }
  435.     public void setProprietaManifestAttachments(
  436.             ProprietaManifestAttachments proprietaManifestAttachments) {
  437.         this.proprietaManifestAttachments = proprietaManifestAttachments;
  438.     }
  439.     public BustaRawContent<?> getSoapProtocolInfo() {
  440.         return this.soapProtocolInfo;
  441.     }
  442.     public boolean isLocalForward() {
  443.         return this.localForward;
  444.     }
  445.     public void setLocalForward(boolean localForward) {
  446.         this.localForward = localForward;
  447.     }
  448.     public OutRequestContext getOutRequestContext() {
  449.         return this.outRequestContext;
  450.     }
  451.     public void setOutRequestContext(OutRequestContext outRequestContext) {
  452.         this.outRequestContext = outRequestContext;
  453.     }
  454.     public MsgDiagnostico getMsgDiagnostico() {
  455.         return this.msgDiagnostico;
  456.     }
  457.     public void setMsgDiagnostico(MsgDiagnostico msgDiagnostico) {
  458.         this.msgDiagnostico = msgDiagnostico;
  459.     }
  460.     public IState getState() {
  461.         return this.state;
  462.     }
  463.     public void setState(IState state) {
  464.         this.state = state;
  465.     }
  466.     public boolean isGenerateErrorWithConnectorPrefix() {
  467.         return this.generateErrorWithConnectorPrefix;
  468.     }

  469.     public PolicyNegoziazioneToken getPolicyNegoziazioneToken() {
  470.         return this.policyNegoziazioneToken;
  471.     }
  472.     public void setPolicyNegoziazioneToken(PolicyNegoziazioneToken policyNegoziazioneToken) {
  473.         this.policyNegoziazioneToken = policyNegoziazioneToken;
  474.     }
  475.     public void initPolicyGestioneToken(ConfigurazionePdDManager configPdDManager, RequestInfo requestInfo) throws DriverConfigurazioneException, DriverConfigurazioneNotFound {
  476.         if(this.properties!=null && !this.properties.isEmpty()) {
  477.             Iterator<String> en = this.properties.keySet().iterator();
  478.             while (en.hasNext()) {
  479.                 String propertyName = en.next();
  480.                 if(CostantiConnettori.CONNETTORE_TOKEN_POLICY.equals(propertyName)) {
  481.                     String tokenPolicy = this.properties.get(propertyName);
  482.                     if(tokenPolicy!=null && !"".equals(tokenPolicy)) {
  483.                         boolean forceNoCache = true;
  484.                         this.policyNegoziazioneToken = configPdDManager.getPolicyNegoziazioneToken(!forceNoCache, tokenPolicy, requestInfo);
  485.                     }
  486.                 }
  487.             }
  488.         }
  489.     }
  490.    
  491.     public PolicyTimeoutConfig getPolicyTimeoutConfig() {
  492.         return this.policyTimeoutConfig;
  493.     }
  494.     public void setPolicyTimeoutConfig(PolicyTimeoutConfig policyConfig) {
  495.         this.policyTimeoutConfig = policyConfig;
  496.     }
  497.    
  498.     public TransazioneApplicativoServer getTransazioneApplicativoServer() {
  499.         return this.transazioneApplicativoServer;
  500.     }
  501.     public void setTransazioneApplicativoServer(TransazioneApplicativoServer transazioneApplicativoServer) {
  502.         this.transazioneApplicativoServer = transazioneApplicativoServer;
  503.     }
  504.     public IDPortaApplicativa getIdPortaApplicativa() {
  505.         return this.idPortaApplicativa;
  506.     }
  507.     public void setIdPortaApplicativa(IDPortaApplicativa idPortaApplicativa) {
  508.         this.idPortaApplicativa = idPortaApplicativa;
  509.     }
  510.     public Date getDataConsegnaTransazioneApplicativoServer() {
  511.         return this.dataConsegnaTransazioneApplicativoServer;
  512.     }
  513.     public void setDataConsegnaTransazioneApplicativoServer(Date dataConsegnaTransazioneApplicativoServer) {
  514.         this.dataConsegnaTransazioneApplicativoServer = dataConsegnaTransazioneApplicativoServer;
  515.     }
  516.    
  517.     public ForwardProxy getForwardProxy() {
  518.         return this.forwardProxy;
  519.     }
  520.     public void setForwardProxy(ForwardProxy forwardProxy) {
  521.         this.forwardProxy = forwardProxy;
  522.     }
  523.    
  524.     public IDAccordo getIdAccordo() {
  525.         return this.idAccordo;
  526.     }
  527.    
  528.     public String getUrlInvocazionePorta() {
  529.         return this.urlInvocazionePorta;
  530.     }
  531.    
  532.     public boolean isForceSendContent() {
  533.         return this.forceSendContent!=null ? this.forceSendContent.booleanValue() : false;
  534.     }
  535. }