PorteDelegateResponseCaching.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.web.ctrlstat.servlet.pd;

  21. import java.util.ArrayList;
  22. import java.util.List;

  23. import javax.servlet.http.HttpServletRequest;
  24. import javax.servlet.http.HttpServletResponse;
  25. import javax.servlet.http.HttpSession;

  26. import org.apache.commons.lang.StringUtils;
  27. import org.apache.struts.action.Action;
  28. import org.apache.struts.action.ActionForm;
  29. import org.apache.struts.action.ActionForward;
  30. import org.apache.struts.action.ActionMapping;
  31. import org.openspcoop2.core.config.Configurazione;
  32. import org.openspcoop2.core.config.PortaDelegata;
  33. import org.openspcoop2.core.config.ResponseCachingConfigurazione;
  34. import org.openspcoop2.core.config.ResponseCachingConfigurazioneControl;
  35. import org.openspcoop2.core.config.ResponseCachingConfigurazioneGenerale;
  36. import org.openspcoop2.core.config.ResponseCachingConfigurazioneHashGenerator;
  37. import org.openspcoop2.core.config.ResponseCachingConfigurazioneRegola;
  38. import org.openspcoop2.core.config.constants.StatoFunzionalita;
  39. import org.openspcoop2.core.config.constants.StatoFunzionalitaCacheDigestQueryParameter;
  40. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  41. import org.openspcoop2.web.ctrlstat.costanti.CostantiControlStation;
  42. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  43. import org.openspcoop2.web.ctrlstat.servlet.config.ConfigurazioneCore;
  44. import org.openspcoop2.web.lib.mvc.Costanti;
  45. import org.openspcoop2.web.lib.mvc.DataElement;
  46. import org.openspcoop2.web.lib.mvc.ForwardParams;
  47. import org.openspcoop2.web.lib.mvc.GeneralData;
  48. import org.openspcoop2.web.lib.mvc.PageData;
  49. import org.openspcoop2.web.lib.mvc.Parameter;
  50. import org.openspcoop2.web.lib.mvc.ServletUtils;
  51. import org.openspcoop2.web.lib.mvc.TipoOperazione;

  52. /**
  53.  * PorteDelegateResponseCaching
  54.  *
  55.  * @author Andrea Poli (apoli@link.it)
  56.  * @author Giuliano Pintori (pintori@link.it)
  57.  * @author $Author$
  58.  * @version $Rev$, $Date$
  59.  *
  60.  */
  61. public class PorteDelegateResponseCaching extends Action {

  62.     @Override
  63.     public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {

  64.         TipoOperazione tipoOperazione = TipoOperazione.OTHER;

  65.         HttpSession session = request.getSession(true);

  66.         // Inizializzo PageData
  67.         PageData pd = new PageData();

  68.         GeneralHelper generalHelper = new GeneralHelper(session);

  69.         // Inizializzo GeneralData
  70.         GeneralData gd = generalHelper.initGeneralData(request);

  71.         String userLogin = ServletUtils.getUserLoginFromSession(session);  

  72.         try {
  73.             PorteDelegateHelper porteDelegateHelper = new PorteDelegateHelper(request, pd, session);
  74.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte delegate
  75.             Integer parentPD = ServletUtils.getIntegerAttributeFromSession(PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT, session, request);
  76.             if(parentPD == null) parentPD = PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_NONE;
  77.             String id = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID);
  78.             int idInt = Integer.parseInt(id);
  79.             String idSoggFruitore = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO);
  80.             String idAsps = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS);
  81.             if(idAsps == null)
  82.                 idAsps = "";
  83.             String idFruizione= porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE);
  84.             if(idFruizione == null)
  85.                 idFruizione = "";
  86.            
  87.             String idTab = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_ID_TAB);
  88.             if(!porteDelegateHelper.isModalitaCompleta() && StringUtils.isNotEmpty(idTab)) {
  89.                 ServletUtils.setObjectIntoSession(request, session, idTab, CostantiControlStation.PARAMETRO_ID_TAB);
  90.             }

  91.             // Preparo il menu
  92.             porteDelegateHelper.makeMenu();
  93.            
  94.             // Prendo il nome della porta
  95.             PorteDelegateCore porteDelegateCore = new PorteDelegateCore();
  96.             ConfigurazioneCore confCore = new ConfigurazioneCore(porteDelegateCore);

  97.             PortaDelegata portaDelegata = porteDelegateCore.getPortaDelegata(idInt);
  98.             String idporta = portaDelegata.getNome();
  99.            
  100.             boolean showStato = true;
  101.             String statoResponseCachingPorta = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_CONFIGURAZIONE_RESPONSE_CACHING_STATO_PORTA);
  102.             String responseCachingEnabledTmp = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_CONFIGURAZIONE_RESPONSE_CACHING_STATO);
  103.             boolean responseCachingEnabled = ServletUtils.isCheckBoxEnabled(responseCachingEnabledTmp);
  104.            
  105.             String responseCachingSecondsTmp = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_CONFIGURAZIONE_RESPONSE_CACHING_TIMEOUT);
  106.             int responseCachingSeconds = 1;
  107.             if(responseCachingSecondsTmp != null) {
  108.                 try {
  109.                     responseCachingSeconds = Integer.parseInt(responseCachingSecondsTmp);
  110.                 }catch(Exception e) {
  111.                     // ignore
  112.                 }
  113.             }
  114.            
  115.            
  116.             String responseCachingMaxResponseSizeTmp = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_CONFIGURAZIONE_RESPONSE_CACHING_MAX_RESPONSE_SIZE);
  117.             boolean responseCachingMaxResponseSize = ServletUtils.isCheckBoxEnabled(responseCachingMaxResponseSizeTmp);
  118.            
  119.             String responseCachingMaxResponseSizeBytesTmp = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_CONFIGURAZIONE_RESPONSE_CACHING_MAX_RESPONSE_SIZE_BYTES);
  120.             long responseCachingMaxResponseSizeBytes = 1;
  121.             if(responseCachingMaxResponseSizeBytesTmp != null) {
  122.                 try {
  123.                     responseCachingMaxResponseSizeBytes = Integer.parseInt(responseCachingMaxResponseSizeBytesTmp);
  124.                 }catch(Exception e) {
  125.                     // ignore
  126.                 }
  127.             }
  128.             String responseCachingDigestUrlInvocazioneTmp = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_CONFIGURAZIONE_RESPONSE_CACHING_RESPONSE_DIGEST_URI_INVOCAZIONE);
  129.             boolean responseCachingDigestUrlInvocazione = ServletUtils.isCheckBoxEnabled(responseCachingDigestUrlInvocazioneTmp);
  130.             String responseCachingDigestHeadersTmp = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_CONFIGURAZIONE_RESPONSE_CACHING_RESPONSE_DIGEST_HEADERS);
  131.             boolean responseCachingDigestHeaders = ServletUtils.isCheckBoxEnabled(responseCachingDigestHeadersTmp);
  132.             String responseCachingDigestPayloadTmp = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_CONFIGURAZIONE_RESPONSE_CACHING_RESPONSE_DIGEST_PAYLOAD);
  133.             boolean responseCachingDigestPayload = ServletUtils.isCheckBoxEnabled(responseCachingDigestPayloadTmp);
  134.             String responseCachingDigestHeadersNomiHeaders = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_CONFIGURAZIONE_RESPONSE_CACHING_RESPONSE_DIGEST_HEADERS_NOMI_HEADERS);
  135.             StatoFunzionalitaCacheDigestQueryParameter responseCachingDigestQueryParameter = null;
  136.             String responseCachingDigestQueryParameterTmp = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_CONFIGURAZIONE_RESPONSE_CACHING_RESPONSE_DIGEST_QUERY_PARAMETERS);
  137.             if(responseCachingDigestQueryParameterTmp!=null && !"".equals(responseCachingDigestQueryParameterTmp)) {
  138.                 responseCachingDigestQueryParameter = StatoFunzionalitaCacheDigestQueryParameter.toEnumConstant(responseCachingDigestQueryParameterTmp, true);
  139.             }
  140.             String responseCachingDigestNomiParametriQuery = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_CONFIGURAZIONE_RESPONSE_CACHING_RESPONSE_DIGEST_QUERY_PARAMETERS_NOMI);
  141.            
  142.            
  143.             String responseCachingCacheControlNoCacheTmp = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_CONFIGURAZIONE_RESPONSE_CACHING_CACHE_CONTROL_NO_CACHE);
  144.             boolean responseCachingCacheControlNoCache = ServletUtils.isCheckBoxEnabled(responseCachingCacheControlNoCacheTmp);
  145.             String responseCachingCacheControlMaxAgeTmp = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_CONFIGURAZIONE_RESPONSE_CACHING_CACHE_CONTROL_MAX_AGE);
  146.             boolean responseCachingCacheControlMaxAge = ServletUtils.isCheckBoxEnabled(responseCachingCacheControlMaxAgeTmp);
  147.             String responseCachingCacheControlNoStoreTmp = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_CONFIGURAZIONE_RESPONSE_CACHING_CACHE_CONTROL_NO_STORE);
  148.             boolean responseCachingCacheControlNoStore = ServletUtils.isCheckBoxEnabled(responseCachingCacheControlNoStoreTmp);
  149.            
  150.             String servletResponseCachingConfigurazioneRegolaList = PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_RESPONSE_CACHING_CONFIGURAZIONE_REGOLA_LIST;
  151.             List<Parameter> paramsResponseCachingConfigurazioneRegolaList = new ArrayList<>();
  152.             paramsResponseCachingConfigurazioneRegolaList.add(new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID, id));
  153.             paramsResponseCachingConfigurazioneRegolaList.add(new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO, idSoggFruitore));
  154.             paramsResponseCachingConfigurazioneRegolaList.add(new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS, idAsps));
  155.             paramsResponseCachingConfigurazioneRegolaList.add(new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE, idFruizione));

  156.             ResponseCachingConfigurazione oldConfigurazione = portaDelegata.getResponseCaching();
  157.             boolean visualizzaLinkConfigurazioneRegola = porteDelegateHelper.isResponseCachingAbilitato(oldConfigurazione) && responseCachingEnabled;
  158.             List<ResponseCachingConfigurazioneRegola> listaRegoleCachingConfigurazione = oldConfigurazione != null ?  oldConfigurazione.getRegolaList() : null;
  159.             int numeroResponseCachingConfigurazioneRegola = porteDelegateHelper.numeroRegoleResponseCaching(oldConfigurazione);
  160.            
  161.             boolean initConfigurazione = false;
  162.             String postBackElementName = porteDelegateHelper.getPostBackElementName();
  163.             if(postBackElementName != null ){
  164.                 if(postBackElementName.equalsIgnoreCase(CostantiControlStation.PARAMETRO_CONFIGURAZIONE_RESPONSE_CACHING_STATO_PORTA)){
  165.                     initConfigurazione = true;
  166.                 }
  167.                
  168.                 if(postBackElementName.equalsIgnoreCase(CostantiControlStation.PARAMETRO_CONFIGURAZIONE_RESPONSE_CACHING_STATO)){
  169.                     if(!porteDelegateHelper.isResponseCachingAbilitato(oldConfigurazione) && responseCachingEnabled) {
  170.                         ResponseCachingConfigurazione configurazioneTmp = new ResponseCachingConfigurazione();
  171.                        
  172.                         responseCachingSeconds = configurazioneTmp.getCacheTimeoutSeconds() != null ? configurazioneTmp.getCacheTimeoutSeconds().intValue() : 1;
  173.                        
  174.                         responseCachingMaxResponseSize = false;
  175.                         if(configurazioneTmp.getMaxMessageSize() != null) {
  176.                             responseCachingMaxResponseSize = true;
  177.                             responseCachingMaxResponseSizeBytes = configurazioneTmp.getMaxMessageSize().longValue();
  178.                         }
  179.                        
  180.                         responseCachingDigestUrlInvocazione = true;
  181.                         responseCachingDigestQueryParameter = StatoFunzionalitaCacheDigestQueryParameter.ABILITATO;
  182.                         responseCachingDigestHeaders = false;
  183.                         responseCachingDigestPayload = true;
  184.                         configurazioneTmp.setHashGenerator(new ResponseCachingConfigurazioneHashGenerator());
  185.                         if(configurazioneTmp.getHashGenerator() != null) {
  186.                            
  187.                             if(configurazioneTmp.getHashGenerator().getQueryParameters() != null)
  188.                                 responseCachingDigestQueryParameter = configurazioneTmp.getHashGenerator().getQueryParameters();
  189.                            
  190.                             if(configurazioneTmp.getHashGenerator().getQueryParameterList() != null)  
  191.                                 responseCachingDigestNomiParametriQuery = StringUtils.join(configurazioneTmp.getHashGenerator().getQueryParameterList(), ",");
  192.                            
  193.                             if(configurazioneTmp.getHashGenerator().getHeaders() != null)  
  194.                                 responseCachingDigestHeaders = configurazioneTmp.getHashGenerator().getHeaders().equals(StatoFunzionalita.ABILITATO);
  195.                            
  196.                             if(configurazioneTmp.getHashGenerator().getHeaderList() != null)  
  197.                                 responseCachingDigestHeadersNomiHeaders = StringUtils.join(configurazioneTmp.getHashGenerator().getHeaderList(), ",");
  198.                            
  199.                             if(configurazioneTmp.getHashGenerator().getRequestUri() != null)
  200.                                 responseCachingDigestUrlInvocazione = configurazioneTmp.getHashGenerator().getRequestUri().equals(StatoFunzionalita.ABILITATO);
  201.                            
  202.                             if(configurazioneTmp.getHashGenerator().getPayload() != null)
  203.                                 responseCachingDigestPayload = configurazioneTmp.getHashGenerator().getPayload().equals(StatoFunzionalita.ABILITATO);
  204.                         }
  205.                        
  206.                         responseCachingCacheControlNoCache = true;
  207.                         responseCachingCacheControlMaxAge = true;
  208.                         responseCachingCacheControlNoStore = true;
  209.                         configurazioneTmp.setControl(new ResponseCachingConfigurazioneControl());
  210.                         if(configurazioneTmp.getControl() != null) {
  211.                             responseCachingCacheControlNoCache = configurazioneTmp.getControl().isNoCache();
  212.                             responseCachingCacheControlMaxAge = configurazioneTmp.getControl().isMaxAge();
  213.                             responseCachingCacheControlNoStore = configurazioneTmp.getControl().isNoStore();
  214.                         }
  215.                        
  216.                         numeroResponseCachingConfigurazioneRegola= configurazioneTmp.sizeRegolaList();
  217.                     }
  218.                 }
  219.             }
  220.            
  221.             // setto la barra del titolo
  222.             List<Parameter> lstParam = porteDelegateHelper.getTitoloPD(parentPD, idSoggFruitore, idAsps, idFruizione);
  223.            
  224.             String labelPerPorta = null;
  225.             if(parentPD!=null && (parentPD.intValue() == PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_CONFIGURAZIONE)) {
  226.                 labelPerPorta = porteDelegateCore.getLabelRegolaMappingFruizionePortaDelegata(
  227.                         PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_RESPONSE_CACHING_CONFIGURAZIONE_CONFIG_DI,
  228.                         PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_RESPONSE_CACHING_CONFIGURAZIONE,
  229.                         portaDelegata);
  230.             }
  231.             else {
  232.                 labelPerPorta = PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_RESPONSE_CACHING_CONFIGURAZIONE_CONFIG_DI+idporta;
  233.             }
  234.            
  235.             lstParam.add(new Parameter(labelPerPorta,  null));
  236.            
  237.             // imposto menu' contestuale
  238.             porteDelegateHelper.impostaComandiMenuContestualePD(idSoggFruitore, idAsps, idFruizione);
  239.            
  240.             // edit in progress
  241.             if (porteDelegateHelper.isEditModeInProgress()) {
  242.                 ServletUtils.setPageDataTitle(pd, lstParam);
  243.                
  244.                 if(statoResponseCachingPorta == null) {
  245.                     if(oldConfigurazione == null) {
  246.                         statoResponseCachingPorta = CostantiControlStation.VALUE_PARAMETRO_RESPONSE_CACHING_STATO_DEFAULT;  
  247.                     } else {
  248.                         statoResponseCachingPorta = CostantiControlStation.VALUE_PARAMETRO_RESPONSE_CACHING_STATO_RIDEFINITO;
  249.                         responseCachingEnabled = false;
  250.                         if(oldConfigurazione != null && oldConfigurazione.getStato().equals(StatoFunzionalita.ABILITATO)) {
  251.                             responseCachingEnabled = true;
  252.                            
  253.                             responseCachingSeconds = oldConfigurazione.getCacheTimeoutSeconds() != null ? oldConfigurazione.getCacheTimeoutSeconds().intValue() : 1;
  254.                            
  255.                             responseCachingMaxResponseSize = false;
  256.                             if(oldConfigurazione.getMaxMessageSize() != null) {
  257.                                 responseCachingMaxResponseSize = true;
  258.                                 responseCachingMaxResponseSizeBytes = oldConfigurazione.getMaxMessageSize().longValue();
  259.                             }
  260.                            
  261.                             responseCachingDigestUrlInvocazione = true;
  262.                             responseCachingDigestQueryParameter = StatoFunzionalitaCacheDigestQueryParameter.ABILITATO;
  263.                             responseCachingDigestHeaders = false;
  264.                             responseCachingDigestPayload = true;
  265.                             responseCachingDigestHeadersNomiHeaders = "";
  266.                             if(oldConfigurazione.getHashGenerator() != null) {
  267.                                
  268.                                 if(oldConfigurazione.getHashGenerator().getQueryParameters() != null)
  269.                                     responseCachingDigestQueryParameter = oldConfigurazione.getHashGenerator().getQueryParameters();
  270.                                
  271.                                 if(oldConfigurazione.getHashGenerator().getQueryParameterList() != null)  
  272.                                     responseCachingDigestNomiParametriQuery = StringUtils.join(oldConfigurazione.getHashGenerator().getQueryParameterList(), ",");
  273.                                
  274.                                 if(oldConfigurazione.getHashGenerator().getHeaders() != null)  
  275.                                     responseCachingDigestHeaders = oldConfigurazione.getHashGenerator().getHeaders().equals(StatoFunzionalita.ABILITATO);
  276.                                
  277.                                 if(oldConfigurazione.getHashGenerator().getHeaderList() != null)  
  278.                                     responseCachingDigestHeadersNomiHeaders = StringUtils.join(oldConfigurazione.getHashGenerator().getHeaderList(), ",");
  279.                                
  280.                                 if(oldConfigurazione.getHashGenerator().getRequestUri() != null)
  281.                                     responseCachingDigestUrlInvocazione = oldConfigurazione.getHashGenerator().getRequestUri().equals(StatoFunzionalita.ABILITATO);
  282.                                
  283.                                 if(oldConfigurazione.getHashGenerator().getPayload() != null)
  284.                                     responseCachingDigestPayload = oldConfigurazione.getHashGenerator().getPayload().equals(StatoFunzionalita.ABILITATO);
  285.                             }
  286.                            
  287.                             responseCachingCacheControlNoCache = true;
  288.                             responseCachingCacheControlMaxAge = true;
  289.                             responseCachingCacheControlNoStore = true;
  290.                             if(oldConfigurazione.getControl() != null) {
  291.                                 responseCachingCacheControlNoCache = oldConfigurazione.getControl().isNoCache();
  292.                                 responseCachingCacheControlMaxAge = oldConfigurazione.getControl().isMaxAge();
  293.                                 responseCachingCacheControlNoStore = oldConfigurazione.getControl().isNoStore();
  294.                             }
  295.                            
  296.                             visualizzaLinkConfigurazioneRegola = porteDelegateHelper.isResponseCachingAbilitato(oldConfigurazione) && responseCachingEnabled;
  297.                             listaRegoleCachingConfigurazione = oldConfigurazione.getRegolaList();
  298.                             numeroResponseCachingConfigurazioneRegola = porteDelegateHelper.numeroRegoleResponseCaching(oldConfigurazione);
  299.                         }
  300.                     }
  301.                 }
  302.                
  303.                 if(initConfigurazione) {
  304.                     if(statoResponseCachingPorta.equals(CostantiControlStation.VALUE_PARAMETRO_RESPONSE_CACHING_STATO_RIDEFINITO)) {
  305.                         Configurazione configurazione = confCore.getConfigurazioneGenerale();
  306.                         ResponseCachingConfigurazioneGenerale responseCachingGenerale = configurazione.getResponseCaching();
  307.                         responseCachingEnabled = false;
  308.                         if(responseCachingGenerale != null) {
  309.                             oldConfigurazione = responseCachingGenerale.getConfigurazione();
  310.                             if(oldConfigurazione != null && oldConfigurazione.getStato().equals(StatoFunzionalita.ABILITATO)) {
  311.                                 responseCachingEnabled = true;
  312.                                
  313.                                 responseCachingSeconds = oldConfigurazione.getCacheTimeoutSeconds() != null ? oldConfigurazione.getCacheTimeoutSeconds().intValue() : 1;
  314.                                
  315.                                 responseCachingMaxResponseSize = false;
  316.                                 if(oldConfigurazione.getMaxMessageSize() != null) {
  317.                                     responseCachingMaxResponseSize = true;
  318.                                     responseCachingMaxResponseSizeBytes = oldConfigurazione.getMaxMessageSize().longValue();
  319.                                 }
  320.                                
  321.                                 responseCachingDigestUrlInvocazione = true;
  322.                                 responseCachingDigestQueryParameter = StatoFunzionalitaCacheDigestQueryParameter.ABILITATO;
  323.                                 responseCachingDigestHeaders = false;
  324.                                 responseCachingDigestPayload = true;
  325.                                 if(oldConfigurazione.getHashGenerator() != null) {
  326.                                    
  327.                                     if(oldConfigurazione.getHashGenerator().getQueryParameters() != null)
  328.                                         responseCachingDigestQueryParameter = oldConfigurazione.getHashGenerator().getQueryParameters();
  329.                                    
  330.                                     if(oldConfigurazione.getHashGenerator().getQueryParameterList() != null)  
  331.                                         responseCachingDigestNomiParametriQuery = StringUtils.join(oldConfigurazione.getHashGenerator().getQueryParameterList(), ",");
  332.                                    
  333.                                     if(oldConfigurazione.getHashGenerator().getHeaders() != null)  
  334.                                         responseCachingDigestHeaders = oldConfigurazione.getHashGenerator().getHeaders().equals(StatoFunzionalita.ABILITATO);
  335.                                    
  336.                                     if(oldConfigurazione.getHashGenerator().getHeaderList() != null)  
  337.                                         responseCachingDigestHeadersNomiHeaders = StringUtils.join(oldConfigurazione.getHashGenerator().getHeaderList(), ",");
  338.                                    
  339.                                     if(oldConfigurazione.getHashGenerator().getRequestUri() != null)
  340.                                         responseCachingDigestUrlInvocazione = oldConfigurazione.getHashGenerator().getRequestUri().equals(StatoFunzionalita.ABILITATO);
  341.                                    
  342.                                     if(oldConfigurazione.getHashGenerator().getPayload() != null)
  343.                                         responseCachingDigestPayload = oldConfigurazione.getHashGenerator().getPayload().equals(StatoFunzionalita.ABILITATO);
  344.                                 }
  345.                                
  346.                                 responseCachingCacheControlNoCache = true;
  347.                                 responseCachingCacheControlMaxAge = true;
  348.                                 responseCachingCacheControlNoStore = true;
  349.                                 if(oldConfigurazione.getControl() != null) {
  350.                                     responseCachingCacheControlNoCache = oldConfigurazione.getControl().isNoCache();
  351.                                     responseCachingCacheControlMaxAge = oldConfigurazione.getControl().isMaxAge();
  352.                                     responseCachingCacheControlNoStore = oldConfigurazione.getControl().isNoStore();
  353.                                 }
  354.                                
  355.                             }
  356.                             else {
  357.                                
  358.                                 responseCachingEnabled = true;
  359.                                
  360.                                 ResponseCachingConfigurazione configurazioneTmp = new ResponseCachingConfigurazione();
  361.                                
  362.                                 responseCachingSeconds = configurazioneTmp.getCacheTimeoutSeconds() != null ? configurazioneTmp.getCacheTimeoutSeconds().intValue() : 1;
  363.                                
  364.                                 responseCachingMaxResponseSize = false;
  365.                                 if(configurazioneTmp.getMaxMessageSize() != null) {
  366.                                     responseCachingMaxResponseSize = true;
  367.                                     responseCachingMaxResponseSizeBytes = configurazioneTmp.getMaxMessageSize().longValue();
  368.                                 }
  369.                                
  370.                                 responseCachingDigestUrlInvocazione = true;
  371.                                 responseCachingDigestQueryParameter = StatoFunzionalitaCacheDigestQueryParameter.ABILITATO;
  372.                                 responseCachingDigestHeaders = false;
  373.                                 responseCachingDigestPayload = true;
  374.                                 configurazioneTmp.setHashGenerator(new ResponseCachingConfigurazioneHashGenerator());
  375.                                 if(configurazioneTmp.getHashGenerator() != null) {
  376.                                    
  377.                                     if(configurazioneTmp.getHashGenerator().getQueryParameters() != null)
  378.                                         responseCachingDigestQueryParameter = configurazioneTmp.getHashGenerator().getQueryParameters();
  379.                                    
  380.                                     if(configurazioneTmp.getHashGenerator().getQueryParameterList() != null)  
  381.                                         responseCachingDigestNomiParametriQuery = StringUtils.join(configurazioneTmp.getHashGenerator().getQueryParameterList(), ",");
  382.                                    
  383.                                     if(configurazioneTmp.getHashGenerator().getHeaders() != null)  
  384.                                         responseCachingDigestHeaders = configurazioneTmp.getHashGenerator().getHeaders().equals(StatoFunzionalita.ABILITATO);
  385.                                    
  386.                                     if(configurazioneTmp.getHashGenerator().getHeaderList() != null)  
  387.                                         responseCachingDigestHeadersNomiHeaders = StringUtils.join(configurazioneTmp.getHashGenerator().getHeaderList(), ",");
  388.                                    
  389.                                     if(configurazioneTmp.getHashGenerator().getRequestUri() != null)
  390.                                         responseCachingDigestUrlInvocazione = configurazioneTmp.getHashGenerator().getRequestUri().equals(StatoFunzionalita.ABILITATO);
  391.                                    
  392.                                     if(configurazioneTmp.getHashGenerator().getPayload() != null)
  393.                                         responseCachingDigestPayload = configurazioneTmp.getHashGenerator().getPayload().equals(StatoFunzionalita.ABILITATO);
  394.                                 }
  395.                                
  396.                                 responseCachingCacheControlNoCache = true;
  397.                                 responseCachingCacheControlMaxAge = true;
  398.                                 responseCachingCacheControlNoStore = true;
  399.                                 configurazioneTmp.setControl(new ResponseCachingConfigurazioneControl());
  400.                                 if(configurazioneTmp.getControl() != null) {
  401.                                     responseCachingCacheControlNoCache = configurazioneTmp.getControl().isNoCache();
  402.                                     responseCachingCacheControlMaxAge = configurazioneTmp.getControl().isMaxAge();
  403.                                     responseCachingCacheControlNoStore = configurazioneTmp.getControl().isNoStore();
  404.                                 }
  405.                                
  406.                                 visualizzaLinkConfigurazioneRegola = false;
  407.                                 listaRegoleCachingConfigurazione = configurazioneTmp.getRegolaList();
  408.                                 numeroResponseCachingConfigurazioneRegola = porteDelegateHelper.numeroRegoleResponseCaching(configurazioneTmp);
  409.                             }
  410.                         }
  411.                     }
  412.                 }

  413.                 // preparo i campi
  414.                 List<DataElement> dati = new ArrayList<>();
  415.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  416.                 porteDelegateHelper.addConfigurazioneResponseCachingPorteToDati(tipoOperazione, dati, showStato, statoResponseCachingPorta,
  417.                         responseCachingEnabled, responseCachingSeconds, responseCachingMaxResponseSize, responseCachingMaxResponseSizeBytes,
  418.                         responseCachingDigestUrlInvocazione, responseCachingDigestHeaders, responseCachingDigestPayload, responseCachingDigestHeadersNomiHeaders, responseCachingDigestQueryParameter, responseCachingDigestNomiParametriQuery,
  419.                         responseCachingCacheControlNoCache, responseCachingCacheControlMaxAge, responseCachingCacheControlNoStore, visualizzaLinkConfigurazioneRegola,
  420.                         servletResponseCachingConfigurazioneRegolaList, paramsResponseCachingConfigurazioneRegolaList, numeroResponseCachingConfigurazioneRegola );
  421.                
  422.                 dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.OTHER,id, idSoggFruitore, null,idAsps,
  423.                         idFruizione, portaDelegata.getTipoSoggettoProprietario(), portaDelegata.getNomeSoggettoProprietario(), dati);

  424.                 pd.setDati(dati);

  425.                 ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  426.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_RESPONSE_CACHING,  ForwardParams.OTHER(""));
  427.             }

  428.             // Controlli sui campi immessi
  429.             boolean isOk = porteDelegateHelper.checkDataConfigurazioneResponseCachingPorta(tipoOperazione, showStato, statoResponseCachingPorta);
  430.             if (!isOk) {

  431.                 ServletUtils.setPageDataTitle(pd, lstParam);

  432.                 // preparo i campi
  433.                 List<DataElement> dati = new ArrayList<>();
  434.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  435.                
  436.                 porteDelegateHelper.addConfigurazioneResponseCachingPorteToDati(tipoOperazione, dati, showStato, statoResponseCachingPorta,
  437.                         responseCachingEnabled, responseCachingSeconds, responseCachingMaxResponseSize, responseCachingMaxResponseSizeBytes,
  438.                         responseCachingDigestUrlInvocazione, responseCachingDigestHeaders, responseCachingDigestPayload, responseCachingDigestHeadersNomiHeaders, responseCachingDigestQueryParameter, responseCachingDigestNomiParametriQuery,
  439.                         responseCachingCacheControlNoCache, responseCachingCacheControlMaxAge, responseCachingCacheControlNoStore, visualizzaLinkConfigurazioneRegola,
  440.                         servletResponseCachingConfigurazioneRegolaList, paramsResponseCachingConfigurazioneRegolaList, numeroResponseCachingConfigurazioneRegola );
  441.                
  442.                 dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.OTHER,id, idSoggFruitore, null,idAsps,
  443.                         idFruizione, portaDelegata.getTipoSoggettoProprietario(), portaDelegata.getNomeSoggettoProprietario(), dati);

  444.                 pd.setDati(dati);

  445.                 ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  446.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_RESPONSE_CACHING,  ForwardParams.OTHER(""));
  447.             }
  448.            
  449.             ResponseCachingConfigurazione newConfigurazione = null;
  450.             if(statoResponseCachingPorta.equals(CostantiControlStation.VALUE_PARAMETRO_RESPONSE_CACHING_STATO_RIDEFINITO)) {
  451.                 newConfigurazione = porteDelegateHelper.getResponseCaching(responseCachingEnabled, responseCachingSeconds, responseCachingMaxResponseSize,
  452.                         responseCachingMaxResponseSizeBytes, responseCachingDigestUrlInvocazione, responseCachingDigestHeaders, responseCachingDigestPayload, responseCachingDigestHeadersNomiHeaders, responseCachingDigestQueryParameter, responseCachingDigestNomiParametriQuery,
  453.                         responseCachingCacheControlNoCache, responseCachingCacheControlMaxAge, responseCachingCacheControlNoStore,listaRegoleCachingConfigurazione);
  454.             }
  455.            
  456.             portaDelegata.setResponseCaching(newConfigurazione);

  457.             porteDelegateCore.performUpdateOperation(userLogin, porteDelegateHelper.smista(), portaDelegata);
  458.        
  459.             // Preparo la lista
  460.             pd.setMessage(PorteDelegateCostanti.LABEL_PORTE_DELEGATE_RESPONSE_CACHING_CON_SUCCESSO, Costanti.MESSAGE_TYPE_INFO);

  461.             portaDelegata = porteDelegateCore.getPortaDelegata(idInt);
  462.             idporta = portaDelegata.getNome();

  463.             ServletUtils.setPageDataTitle(pd, lstParam);

  464.             // preparo i campi
  465.             List<DataElement> dati = new ArrayList<>();
  466.             dati.add(ServletUtils.getDataElementForEditModeFinished());
  467.            
  468.             ResponseCachingConfigurazione configurazioneAggiornata  = portaDelegata.getResponseCaching();
  469.            
  470.             if(configurazioneAggiornata == null) {
  471.                 statoResponseCachingPorta = CostantiControlStation.VALUE_PARAMETRO_RESPONSE_CACHING_STATO_DEFAULT;
  472.             } else {
  473.                 statoResponseCachingPorta = CostantiControlStation.VALUE_PARAMETRO_RESPONSE_CACHING_STATO_RIDEFINITO;
  474.                 if(configurazioneAggiornata.getStato() != null && configurazioneAggiornata.getStato().equals(StatoFunzionalita.ABILITATO)) {
  475.                     responseCachingEnabled = false;
  476.                     if(configurazioneAggiornata != null && configurazioneAggiornata.getStato().equals(StatoFunzionalita.ABILITATO)) {
  477.                         responseCachingEnabled = true;
  478.                        
  479.                         responseCachingSeconds = configurazioneAggiornata.getCacheTimeoutSeconds() != null ? configurazioneAggiornata.getCacheTimeoutSeconds().intValue() : 1;
  480.                        
  481.                         responseCachingMaxResponseSize = false;
  482.                         if(configurazioneAggiornata.getMaxMessageSize() != null) {
  483.                             responseCachingMaxResponseSize = true;
  484.                             responseCachingMaxResponseSizeBytes = configurazioneAggiornata.getMaxMessageSize().longValue();
  485.                         }
  486.                        
  487.                         responseCachingDigestUrlInvocazione = true;
  488.                         responseCachingDigestQueryParameter = StatoFunzionalitaCacheDigestQueryParameter.ABILITATO;
  489.                         responseCachingDigestHeaders = false;
  490.                         responseCachingDigestPayload = true;
  491.                         if(configurazioneAggiornata.getHashGenerator() != null) {
  492.                            
  493.                             if(configurazioneAggiornata.getHashGenerator().getQueryParameters() != null)
  494.                                 responseCachingDigestQueryParameter = configurazioneAggiornata.getHashGenerator().getQueryParameters();
  495.                            
  496.                             if(configurazioneAggiornata.getHashGenerator().getQueryParameterList() != null)  
  497.                                 responseCachingDigestNomiParametriQuery = StringUtils.join(configurazioneAggiornata.getHashGenerator().getQueryParameterList(), ",");
  498.                            
  499.                             if(configurazioneAggiornata.getHashGenerator().getHeaders() != null)  
  500.                                 responseCachingDigestHeaders = configurazioneAggiornata.getHashGenerator().getHeaders().equals(StatoFunzionalita.ABILITATO);
  501.                            
  502.                             if(configurazioneAggiornata.getHashGenerator().getHeaderList() != null)  
  503.                                 responseCachingDigestHeadersNomiHeaders = StringUtils.join(configurazioneAggiornata.getHashGenerator().getHeaderList(), ",");
  504.                            
  505.                             if(configurazioneAggiornata.getHashGenerator().getRequestUri() != null)
  506.                                 responseCachingDigestUrlInvocazione = configurazioneAggiornata.getHashGenerator().getRequestUri().equals(StatoFunzionalita.ABILITATO);
  507.                            
  508.                             if(configurazioneAggiornata.getHashGenerator().getPayload() != null)
  509.                                 responseCachingDigestPayload = configurazioneAggiornata.getHashGenerator().getPayload().equals(StatoFunzionalita.ABILITATO);
  510.                         }
  511.                        
  512.                         responseCachingCacheControlNoCache = true;
  513.                         responseCachingCacheControlMaxAge = true;
  514.                         responseCachingCacheControlNoStore = true;
  515.                         if(configurazioneAggiornata.getControl() != null) {
  516.                             responseCachingCacheControlNoCache = configurazioneAggiornata.getControl().isNoCache();
  517.                             responseCachingCacheControlMaxAge = configurazioneAggiornata.getControl().isMaxAge();
  518.                             responseCachingCacheControlNoStore = configurazioneAggiornata.getControl().isNoStore();
  519.                         }
  520.                        
  521.                         numeroResponseCachingConfigurazioneRegola= configurazioneAggiornata.sizeRegolaList();
  522.                         visualizzaLinkConfigurazioneRegola = true;
  523.                     }
  524.                 }
  525.             }
  526.            
  527.             porteDelegateHelper.addConfigurazioneResponseCachingPorteToDati(tipoOperazione, dati, showStato, statoResponseCachingPorta,
  528.                     responseCachingEnabled, responseCachingSeconds, responseCachingMaxResponseSize, responseCachingMaxResponseSizeBytes,
  529.                     responseCachingDigestUrlInvocazione, responseCachingDigestHeaders, responseCachingDigestPayload, responseCachingDigestHeadersNomiHeaders, responseCachingDigestQueryParameter, responseCachingDigestNomiParametriQuery,
  530.                     responseCachingCacheControlNoCache, responseCachingCacheControlMaxAge, responseCachingCacheControlNoStore, visualizzaLinkConfigurazioneRegola,
  531.                     servletResponseCachingConfigurazioneRegolaList, paramsResponseCachingConfigurazioneRegolaList, numeroResponseCachingConfigurazioneRegola );
  532.            
  533.             dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.OTHER,id, idSoggFruitore, null,idAsps,
  534.                     idFruizione, portaDelegata.getTipoSoggettoProprietario(), portaDelegata.getNomeSoggettoProprietario(), dati);

  535.             pd.setDati(dati);

  536.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  537.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_RESPONSE_CACHING, ForwardParams.OTHER(""));
  538.         } catch (Exception e) {
  539.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  540.                     PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_RESPONSE_CACHING, ForwardParams.OTHER(""));
  541.         }
  542.     }

  543. }