UrlInvocazioneAPI.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.config;

  21. import java.io.Serializable;
  22. import java.util.ArrayList;
  23. import java.util.Collections;
  24. import java.util.HashMap;
  25. import java.util.List;
  26. import java.util.Map;

  27. import org.openspcoop2.core.config.ConfigurazioneUrlInvocazione;
  28. import org.openspcoop2.core.config.ConfigurazioneUrlInvocazioneRegola;
  29. import org.openspcoop2.core.config.constants.CostantiConfigurazione;
  30. import org.openspcoop2.core.config.constants.RuoloContesto;
  31. import org.openspcoop2.core.config.constants.StatoFunzionalita;
  32. import org.openspcoop2.core.config.driver.DriverConfigurazioneException;
  33. import org.openspcoop2.core.constants.CostantiLabel;
  34. import org.openspcoop2.core.id.IDSoggetto;
  35. import org.openspcoop2.message.constants.ServiceBinding;
  36. import org.openspcoop2.protocol.engine.constants.Costanti;
  37. import org.openspcoop2.protocol.manifest.Context;
  38. import org.openspcoop2.protocol.manifest.WebEmptyContext;
  39. import org.openspcoop2.protocol.sdk.IProtocolFactory;
  40. import org.openspcoop2.protocol.utils.PorteNamingUtils;
  41. import org.openspcoop2.utils.Utilities;
  42. import org.openspcoop2.utils.regexp.RegExpNotFoundException;
  43. import org.openspcoop2.utils.regexp.RegularExpressionEngine;

  44. /**
  45.  * UrlInvocazioneAPI
  46.  *
  47.  * @author Poli Andrea (apoli@link.it)
  48.  * @author $Author$
  49.  * @version $Rev$, $Date$
  50.  */
  51. public class UrlInvocazioneAPI implements Serializable {

  52.     /**
  53.      *
  54.      */
  55.     private static final long serialVersionUID = 1L;
  56.    
  57.     private String baseUrl;
  58.     private String context;
  59.    
  60.     public String getBaseUrl() {
  61.         return this.baseUrl;
  62.     }
  63.     public void setBaseUrl(String baseUrl) {
  64.         this.baseUrl = baseUrl;
  65.     }
  66.     public String getContext() {
  67.         return this.context;
  68.     }
  69.     public void setContext(String context) {
  70.         this.context = context;
  71.     }
  72.     public String getUrl() {
  73.         if(this.baseUrl==null) {
  74.             return null;
  75.         }
  76.         return Utilities.buildUrl(this.baseUrl, this.context);
  77.     }

  78.    
  79.    
  80.    
  81.     // *** STATIC UTILITIES **
  82.    
  83.     public static UrlInvocazioneAPI getConfigurazioneUrlInvocazione(ConfigurazioneUrlInvocazione configurazioneUrlInvocazione,
  84.             IProtocolFactory<?> protocolFactory, RuoloContesto ruolo, ServiceBinding serviceBinding,
  85.             String interfaceName, IDSoggetto soggettoOperativo,
  86.             List<String> tags, String canale) throws DriverConfigurazioneException{
  87.         return getConfigurazioneUrlInvocazione(configurazioneUrlInvocazione,
  88.                 protocolFactory, ruolo, serviceBinding,
  89.                 interfaceName, soggettoOperativo,
  90.                 tags, canale, true);
  91.     }
  92.    
  93.     public static UrlInvocazioneAPI getConfigurazioneUrlInvocazione(ConfigurazioneUrlInvocazione configurazioneUrlInvocazione,
  94.             IProtocolFactory<?> protocolFactory, RuoloContesto ruolo, ServiceBinding serviceBinding,
  95.             String interfaceName, IDSoggetto soggettoOperativo,
  96.             List<String> tags, String canale, boolean analizeProxyPassRules) throws DriverConfigurazioneException{
  97.        
  98.         if(configurazioneUrlInvocazione==null) {
  99.             configurazioneUrlInvocazione = new ConfigurazioneUrlInvocazione();
  100.             initConfigurazioneProtocolloUrlInvocazione(configurazioneUrlInvocazione);
  101.         }
  102.        
  103.         // normalizzo interfaceName
  104.         String interfaceNameNormalizzata = interfaceName;
  105.         if(interfaceNameNormalizzata!=null) {
  106.             try {
  107.                 PorteNamingUtils utils = new PorteNamingUtils(protocolFactory);
  108.                 if( RuoloContesto.PORTA_DELEGATA.equals(ruolo) ) {
  109.                     interfaceNameNormalizzata = utils.normalizePD(interfaceName);
  110.                 }
  111.                 else {
  112.                     interfaceNameNormalizzata = utils.normalizePA(interfaceName);
  113.                 }
  114.             }catch(Exception e){
  115.                 protocolFactory.getLogger().debug("Normalizzazione interface name '"+interfaceName+"' non riuscita: "+e.getMessage(),e);
  116.             }
  117.         }
  118.        
  119.         // Regola di default
  120.         ConfigurazioneUrlInvocazioneRegola regolaDefault = getConfigurazioneUrlInvocazioneDefault(configurazioneUrlInvocazione, protocolFactory, ruolo, serviceBinding, interfaceNameNormalizzata); // default
  121.        
  122.         // Colleziono regole compatibili
  123.         ConfigurazioneUrlInvocazioneRegola regola = null;
  124.         if(analizeProxyPassRules) {
  125.             Map<String, ConfigurazioneUrlInvocazioneRegola> regole = new HashMap<>();
  126.             for (ConfigurazioneUrlInvocazioneRegola check : configurazioneUrlInvocazione.getRegolaList()) {
  127.                 String paddedNumber = String.format("%010d", check.getPosizione());
  128.                 regole.put(paddedNumber, check);
  129.             }
  130.             if(regole.size()>0) {
  131.                 List<String> posizioni = new ArrayList<>();
  132.                 posizioni.addAll(regole.keySet());
  133.                 Collections.sort(posizioni);
  134.                 for (String posizione : posizioni) {
  135.                     ConfigurazioneUrlInvocazioneRegola check = regole.get(posizione);
  136.                     try {
  137.                         /**System.out.println("ESAMINO REGOLA ALLA POSIZIONE '"+posizione+"'");*/
  138.                         String contesto = getContext(protocolFactory, ruolo, serviceBinding, interfaceNameNormalizzata);
  139.                         if(isMatchRegolaUrlInvocazione(check, protocolFactory, ruolo, serviceBinding, contesto, soggettoOperativo)) {
  140.                             regola = processMatchRegolaUrlInvocazione(check, contesto,
  141.                                     tags, canale); // risolve eventuale match di espressioni regolari.
  142.                             break;
  143.                         }  
  144.                     }catch(Exception e) {
  145.                         protocolFactory.getLogger().error("Errore durante il processamento della regola-"+posizione+" '"+check.getNome()+"': "+e.getMessage(),e);
  146.                     }
  147.                 }
  148.             }
  149.         }
  150.         if(regola==null) {
  151.             regola = regolaDefault;
  152.         }
  153.        
  154.         UrlInvocazioneAPI url = new UrlInvocazioneAPI();
  155.         if(regola.getBaseUrl()!=null) {
  156.             url.setBaseUrl(regola.getBaseUrl());
  157.         }
  158.         else {
  159.             if( RuoloContesto.PORTA_DELEGATA.equals(ruolo) && configurazioneUrlInvocazione.getBaseUrlFruizione()!=null ) {
  160.                 url.setBaseUrl(configurazioneUrlInvocazione.getBaseUrlFruizione());
  161.             }
  162.             else {
  163.                 url.setBaseUrl(configurazioneUrlInvocazione.getBaseUrl());
  164.             }
  165.         }
  166.         url.setContext(regola.getContestoEsterno());
  167.        
  168.         return url;
  169.     }
  170.    
  171.     private static void initConfigurazioneProtocolloUrlInvocazione(ConfigurazioneUrlInvocazione configurazioneUrlInvocazione) throws DriverConfigurazioneException {
  172.         try {
  173.             if(configurazioneUrlInvocazione.getBaseUrl()==null) {
  174.                 configurazioneUrlInvocazione.setBaseUrl(CostantiConfigurazione.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_URL_INVOCAZIONE_PREFIX);
  175.             }
  176.            
  177.         }catch(Exception e) {
  178.             throw new DriverConfigurazioneException(e.getMessage(),e);
  179.         }
  180.     }
  181.    
  182.     private static ConfigurazioneUrlInvocazioneRegola getConfigurazioneUrlInvocazioneDefault(ConfigurazioneUrlInvocazione configurazioneUrlInvocazione,
  183.             IProtocolFactory<?> protocolFactory, RuoloContesto ruolo, ServiceBinding serviceBinding, String interfaceNameNormalizzata) throws DriverConfigurazioneException {
  184.    
  185.         try {
  186.            
  187.             if(configurazioneUrlInvocazione!=null) {
  188.                 // nop
  189.             }
  190.            
  191.             ConfigurazioneUrlInvocazioneRegola regola = new ConfigurazioneUrlInvocazioneRegola();
  192.             regola.setNome(CostantiConfigurazione.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_URL_INVOCAZIONE_DEFAULT_RULE_NAME);
  193.             regola.setPosizione(-1); // non serve, verrĂ  usata questa regola
  194.             regola.setStato(StatoFunzionalita.ABILITATO);
  195.             regola.setDescrizione(CostantiConfigurazione.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_URL_INVOCAZIONE_DEFAULT_RULE_DESCRIPTION);
  196.             regola.setRegexpr(false);
  197.             regola.setRegola(""); // non serve, verrĂ  usata questa regola per produrre la url di invocazione
  198.            
  199.             regola.setContestoEsterno(getContext(protocolFactory, ruolo, serviceBinding, interfaceNameNormalizzata));
  200.            
  201.             regola.setBaseUrl(null); // viene usata quella di default
  202.             regola.setProtocollo(protocolFactory.getProtocol());
  203.             regola.setRuolo(ruolo);
  204.             if(serviceBinding!=null) {
  205.                 regola.setServiceBinding(ServiceBinding.REST.equals(serviceBinding) ? org.openspcoop2.core.config.constants.ServiceBinding.REST : org.openspcoop2.core.config.constants.ServiceBinding.SOAP);
  206.             }      
  207.            
  208.             return regola;

  209.         }catch(Exception e) {
  210.             throw new DriverConfigurazioneException(e.getMessage(),e);
  211.         }
  212.     }
  213.    
  214.     private static boolean isMatchRegolaUrlInvocazione(ConfigurazioneUrlInvocazioneRegola check,
  215.             IProtocolFactory<?> protocolFactory, RuoloContesto ruolo, ServiceBinding serviceBinding,
  216.             String contesto, IDSoggetto soggettoOperativoInterfaccia) throws DriverConfigurazioneException {
  217.        
  218.         if(StatoFunzionalita.DISABILITATO.equals(check.getStato())) {
  219.             return false;
  220.         }
  221.        
  222.         if(check.getProtocollo()!=null) {
  223.             if(protocolFactory==null) {
  224.                 return false;
  225.             }
  226.             if(!check.getProtocollo().equals(protocolFactory.getProtocol())) {
  227.                 return false;
  228.             }
  229.         }
  230.        
  231.         if(check.getRuolo()!=null) {
  232.             if(ruolo==null) {
  233.                 return false;
  234.             }
  235.             if(!check.getRuolo().equals(ruolo)) {
  236.                 return false;
  237.             }  
  238.         }
  239.        
  240.         if(check.getServiceBinding()!=null) {
  241.             if(serviceBinding==null) {
  242.                 return false;
  243.             }
  244.             if(!check.getServiceBinding().name().equals(serviceBinding.name())) {
  245.                 return false;
  246.             }  
  247.         }
  248.        
  249.         if(check.getSoggetto()!=null && check.getSoggetto().getTipo()!=null && check.getSoggetto().getNome()!=null) {
  250.             if(soggettoOperativoInterfaccia==null) {
  251.                 return false;
  252.             }
  253.             try {
  254.                 if(!check.getSoggetto().toIDSoggetto().equals(soggettoOperativoInterfaccia)) {
  255.                     return false;
  256.                 }
  257.             }catch(Exception e) {
  258.                 throw new DriverConfigurazioneException(e.getMessage(),e);
  259.             }
  260.         }
  261.        
  262.         if(contesto==null) {
  263.             return false;
  264.         }
  265.         if(check.isRegexpr()) {
  266.             try {
  267.                 boolean isMatch = RegularExpressionEngine.isMatch(contesto, check.getRegola());
  268.                 if(isMatch) {
  269.                     return true;
  270.                 }
  271.                 if(contesto.startsWith("/") && contesto.length()>1) {
  272.                     isMatch = RegularExpressionEngine.isMatch(contesto.substring(1), check.getRegola());
  273.                     if(isMatch) {
  274.                         return true;
  275.                     }
  276.                 }
  277.                 return false;
  278.             }catch(RegExpNotFoundException notFound) {
  279.                 return  false;
  280.             }catch(Exception e) {
  281.                 throw new DriverConfigurazioneException(e.getMessage(),e);
  282.             }
  283.         }
  284.         else {
  285.             String contestDaVerificare = contesto;
  286.             if(contesto.startsWith("/")) {
  287.                 if(!check.getRegola().startsWith("/")) {
  288.                     if(contesto.length()==1) {
  289.                         contestDaVerificare = "";
  290.                     }
  291.                     else {
  292.                         contestDaVerificare = contestDaVerificare.substring(1);
  293.                     }
  294.                 }
  295.             }
  296.             else {
  297.                 if(check.getRegola().startsWith("/")) {
  298.                     contestDaVerificare = "/"+contestDaVerificare;
  299.                 }
  300.             }
  301.             return contestDaVerificare.startsWith(check.getRegola());
  302.         }
  303.     }
  304.    
  305.     private static ConfigurazioneUrlInvocazioneRegola processMatchRegolaUrlInvocazione(ConfigurazioneUrlInvocazioneRegola regolaParam, String contestoParam,
  306.             List<String> tags, String canale) throws DriverConfigurazioneException {
  307.        
  308.         ConfigurazioneUrlInvocazioneRegola regola = (ConfigurazioneUrlInvocazioneRegola) regolaParam.clone();
  309.        
  310.         if(regola.isRegexpr()) {
  311.             try {
  312.                 String contestoDaUsarePerVerifica = contestoParam;
  313.                 boolean isMatch = RegularExpressionEngine.isMatch(contestoDaUsarePerVerifica, regola.getRegola());
  314.                 if(!isMatch &&
  315.                     contestoDaUsarePerVerifica.startsWith("/") && contestoDaUsarePerVerifica.length()>1) {
  316.                     contestoDaUsarePerVerifica = contestoDaUsarePerVerifica.substring(1);
  317.                 }
  318.                
  319.                 List<String> list = null;
  320.                 try {
  321.                     list = RegularExpressionEngine.getAllStringMatchPattern(contestoDaUsarePerVerifica, regola.getRegola());
  322.                 }catch(RegExpNotFoundException notFound) {
  323.                     if(!RegularExpressionEngine.isMatch(contestoDaUsarePerVerifica, regola.getRegola())) {
  324.                         throw notFound; // altrimenti l'espressione regolare ha un match senza perĂ²  avere condizioni () per estrarre informazioni tramite gruppi.
  325.                     }
  326.                 }
  327.                 String newContesto = regola.getContestoEsterno();
  328.                 if(newContesto==null) {
  329.                     newContesto = "";
  330.                 }
  331.                 String baseUrl = regola.getBaseUrl();
  332.                 if(list!=null) {
  333.                     for (int i = 0; i < list.size(); i++) {
  334.                         String found = list.get(i);
  335.                         if(found==null) {
  336.                             found = "";
  337.                         }
  338.                        
  339.                         String key = "${"+i+"}";
  340.                         while(newContesto.contains(key)) {
  341.                             newContesto = newContesto.replace(key, found);
  342.                         }
  343.                         if(baseUrl!=null) {
  344.                             while(baseUrl.contains(key)) {
  345.                                 baseUrl = baseUrl.replace(key, found);
  346.                             }  
  347.                         }
  348.                     }
  349.                 }
  350.                                
  351.                 regola.setContestoEsterno(newContesto);
  352.                 regola.setBaseUrl(baseUrl);
  353.             }
  354.             /**catch(RegExpNotFoundException notFound) { NON dovrebbe succedere, gestito prima con l'if
  355.                 return  null;
  356.             }*/
  357.             catch(Exception e) {
  358.                 throw new DriverConfigurazioneException(e.getMessage(),e);
  359.             }
  360.         }
  361.        
  362.         // tags
  363.         if(tags!=null && !tags.isEmpty()) {
  364.            
  365.             String newContesto = regola.getContestoEsterno();
  366.             if(newContesto==null) {
  367.                 newContesto = "";
  368.             }
  369.             String baseUrl = regola.getBaseUrl();
  370.            
  371.             for (int i = 0; i < tags.size(); i++) {
  372.                 String found = tags.get(i);
  373.                 if(found==null) {
  374.                     found = "";
  375.                 }
  376.                
  377.                 if(i==0) {
  378.                     String key = "${tag}";
  379.                     while(newContesto.contains(key)) {
  380.                         newContesto = newContesto.replace(key, found);
  381.                     }
  382.                     if(baseUrl!=null) {
  383.                         while(baseUrl.contains(key)) {
  384.                             baseUrl = baseUrl.replace(key, found);
  385.                         }  
  386.                     }
  387.                 }
  388.                
  389.                 String key = "${tag["+i+"]}";
  390.                 while(newContesto.contains(key)) {
  391.                     newContesto = newContesto.replace(key, found);
  392.                 }
  393.                 if(baseUrl!=null) {
  394.                     while(baseUrl.contains(key)) {
  395.                         baseUrl = baseUrl.replace(key, found);
  396.                     }  
  397.                 }
  398.             }
  399.            
  400.             regola.setContestoEsterno(newContesto);
  401.             regola.setBaseUrl(baseUrl);
  402.         }
  403.        
  404.         // canale
  405.         if(canale!=null) {
  406.             String newContesto = regola.getContestoEsterno();
  407.             if(newContesto==null) {
  408.                 newContesto = "";
  409.             }
  410.             String baseUrl = regola.getBaseUrl();
  411.            
  412.             String key = "${canale}";
  413.             while(newContesto.contains(key)) {
  414.                 newContesto = newContesto.replace(key, canale);
  415.             }
  416.             if(baseUrl!=null) {
  417.                 while(baseUrl.contains(key)) {
  418.                     baseUrl = baseUrl.replace(key, canale);
  419.                 }  
  420.             }
  421.                
  422.             regola.setContestoEsterno(newContesto);
  423.             regola.setBaseUrl(baseUrl);
  424.         }
  425.        
  426.         return regola;
  427.        
  428.        
  429.     }
  430.    
  431.    
  432.     private static String getContext(IProtocolFactory<?> protocolFactory, RuoloContesto ruolo, ServiceBinding serviceBinding, String interfaceNameNormalizzata) throws DriverConfigurazioneException {
  433.    
  434.         try {
  435.             boolean trasparente = false;
  436.             if(protocolFactory!=null) {
  437.                 trasparente = Costanti.TRASPARENTE_PROTOCOL_NAME.equals(protocolFactory.getProtocol());
  438.             }
  439.             boolean forceContextWithoutBinding = false;
  440.             if(trasparente) {
  441.                 forceContextWithoutBinding = true; // altrimenti vengono usati api-rest e api-soap
  442.             }
  443.            
  444.             String contextWithoutBinding = null;
  445.             String contextWithRestBinding = null;
  446.             String contextWithSoapBinding = null;
  447.             if(protocolFactory!=null && protocolFactory.getManifest().getWeb().getEmptyContext()!=null) {
  448.                 WebEmptyContext ctx = protocolFactory.getManifest().getWeb().getEmptyContext();
  449.                 if(ctx.getBinding()==null) {
  450.                     if(contextWithoutBinding==null) {
  451.                         contextWithoutBinding = "";
  452.                     }
  453.                 }
  454.                 else if(org.openspcoop2.protocol.manifest.constants.ServiceBinding.REST.equals(ctx.getBinding())) {
  455.                     if(contextWithRestBinding==null) {
  456.                         contextWithRestBinding = "";
  457.                     }
  458.                 }
  459.                 else if(org.openspcoop2.protocol.manifest.constants.ServiceBinding.SOAP.equals(ctx.getBinding()) &&
  460.                     contextWithSoapBinding==null) {
  461.                     contextWithSoapBinding = "";
  462.                 }
  463.             }
  464.             if(protocolFactory!=null && protocolFactory.getManifest().getWeb().sizeContextList()>0) {
  465.                 for (Context ctx : protocolFactory.getManifest().getWeb().getContextList()) {
  466.                     if(ctx.getBinding()==null) {
  467.                         if(contextWithoutBinding==null) {
  468.                             contextWithoutBinding = ctx.getName();
  469.                         }
  470.                     }
  471.                     else if(org.openspcoop2.protocol.manifest.constants.ServiceBinding.REST.equals(ctx.getBinding())) {
  472.                         if(contextWithRestBinding==null) {
  473.                             contextWithRestBinding = ctx.getName();
  474.                         }
  475.                     }
  476.                     else if(org.openspcoop2.protocol.manifest.constants.ServiceBinding.SOAP.equals(ctx.getBinding()) &&
  477.                         contextWithSoapBinding==null) {
  478.                         contextWithSoapBinding = ctx.getName();
  479.                     }
  480.                 }
  481.             }
  482.            
  483.             // Assegno i contesti se non trovati altri.
  484.             if(contextWithRestBinding==null || (forceContextWithoutBinding && contextWithoutBinding!=null)) {
  485.                 contextWithRestBinding = contextWithoutBinding;
  486.             }
  487.             if(contextWithSoapBinding==null || (forceContextWithoutBinding && contextWithoutBinding!=null)) {
  488.                 contextWithSoapBinding = contextWithoutBinding;
  489.             }
  490.             if(contextWithoutBinding==null) {
  491.                 throw new DriverConfigurazioneException("Contesto senza uno specifico binding non indicato");
  492.             }
  493.            
  494.             String contestoEsterno = null;
  495.             if(serviceBinding!=null) {
  496.                 switch (serviceBinding) {
  497.                 case REST:
  498.                     contestoEsterno = RuoloContesto.PORTA_DELEGATA.equals(ruolo) ?
  499.                             CostantiConfigurazione.getDefaultValueParametroConfigurazioneProtocolloPrefixUrlInvocazionePd(contextWithRestBinding) :
  500.                             CostantiConfigurazione.getDefaultValueParametroConfigurazioneProtocolloPrefixUrlInvocazionePa(contextWithRestBinding);
  501.                     break;
  502.                 case SOAP:
  503.                     contestoEsterno = RuoloContesto.PORTA_DELEGATA.equals(ruolo) ?
  504.                             CostantiConfigurazione.getDefaultValueParametroConfigurazioneProtocolloPrefixUrlInvocazionePd(contextWithSoapBinding) :
  505.                             CostantiConfigurazione.getDefaultValueParametroConfigurazioneProtocolloPrefixUrlInvocazionePa(contextWithSoapBinding);
  506.                     break;
  507.                 }
  508.             }
  509.             else {
  510.                 contestoEsterno = RuoloContesto.PORTA_DELEGATA.equals(ruolo) ?
  511.                         CostantiConfigurazione.getDefaultValueParametroConfigurazioneProtocolloPrefixUrlInvocazionePd(contextWithoutBinding) :
  512.                         CostantiConfigurazione.getDefaultValueParametroConfigurazioneProtocolloPrefixUrlInvocazionePa(contextWithoutBinding);
  513.             }
  514.            
  515.             if(contestoEsterno!=null) {
  516.                 if(CostantiLabel.TRASPARENTE_PROTOCOL_NAME.equalsIgnoreCase(protocolFactory.getProtocol())) {
  517.                     if(RuoloContesto.PORTA_APPLICATIVA.equals(ruolo)) {
  518.                         if(contestoEsterno.endsWith("in/")) {
  519.                             contestoEsterno = contestoEsterno.substring(0, contestoEsterno.length()-"in/".length());
  520.                         }
  521.                         else if(contestoEsterno.endsWith("in")) {
  522.                             contestoEsterno = contestoEsterno.substring(0, contestoEsterno.length()-"in".length());
  523.                         }
  524.                     }
  525.                 }
  526.                 else if(CostantiLabel.SDI_PROTOCOL_NAME.equalsIgnoreCase(protocolFactory.getProtocol()) &&
  527.                     RuoloContesto.PORTA_DELEGATA.equals(ruolo)) {
  528.                     if(contestoEsterno.endsWith("out/")) {
  529.                         contestoEsterno = contestoEsterno + "xml2soap/";
  530.                     }
  531.                     else if(contestoEsterno.endsWith("out")) {
  532.                         contestoEsterno = contestoEsterno + "/xml2soap/";
  533.                     }
  534.                 }
  535.             }
  536.            
  537.            
  538.             boolean useInterfaceName = false;
  539.             if(RuoloContesto.PORTA_APPLICATIVA.equals(ruolo)) {
  540.                 useInterfaceName = protocolFactory.createProtocolIntegrationConfiguration().useInterfaceNameInImplementationInvocationURL(serviceBinding);
  541.             }
  542.             else {
  543.                 useInterfaceName = protocolFactory.createProtocolIntegrationConfiguration().useInterfaceNameInSubscriptionInvocationURL(serviceBinding);
  544.             }
  545.                        
  546.             if(useInterfaceName && interfaceNameNormalizzata!=null && !"".equals(interfaceNameNormalizzata)) {
  547.                 if(contestoEsterno!=null) {
  548.                     contestoEsterno = contestoEsterno + "/" +interfaceNameNormalizzata;
  549.                 }
  550.                 else {
  551.                     contestoEsterno = interfaceNameNormalizzata;
  552.                 }
  553.             }
  554.            
  555.             if(contestoEsterno!=null) {
  556.                 while(contestoEsterno.contains("//")) {
  557.                     contestoEsterno = contestoEsterno.replace("//", "/");
  558.                 }
  559.             }
  560.                        
  561.             if(contestoEsterno!=null &&
  562.                 !contestoEsterno.startsWith("/")) {
  563.                 contestoEsterno = "/"+contestoEsterno;
  564.             }
  565.            
  566.             return contestoEsterno;
  567.            
  568.         }catch(Exception e) {
  569.             throw new DriverConfigurazioneException(e.getMessage(),e);
  570.         }
  571.     }
  572. }