CheckStatoPdD.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.services.connector;

  21. import java.io.IOException;
  22. import java.util.ArrayList;
  23. import java.util.List;

  24. import javax.servlet.ServletException;
  25. import javax.servlet.http.HttpServlet;
  26. import javax.servlet.http.HttpServletRequest;
  27. import javax.servlet.http.HttpServletResponse;

  28. import org.apache.commons.lang.StringUtils;
  29. import org.openspcoop2.core.commons.CoreException;
  30. import org.openspcoop2.pdd.config.OpenSPCoop2Properties;
  31. import org.openspcoop2.pdd.core.CostantiPdD;
  32. import org.openspcoop2.pdd.logger.Dump;
  33. import org.openspcoop2.pdd.logger.MsgDiagnostico;
  34. import org.openspcoop2.pdd.logger.OpenSPCoop2Logger;
  35. import org.openspcoop2.pdd.logger.Tracciamento;
  36. import org.openspcoop2.pdd.services.OpenSPCoop2Startup;
  37. import org.openspcoop2.pdd.timers.TimerMonitoraggioRisorseThread;
  38. import org.openspcoop2.pdd.timers.TimerThresholdThread;
  39. import org.openspcoop2.utils.BooleanNullable;
  40. import org.openspcoop2.utils.LoggerWrapperFactory;
  41. import org.openspcoop2.utils.transport.http.HttpConstants;
  42. import org.openspcoop2.utils.transport.http.HttpRequest;
  43. import org.openspcoop2.utils.transport.http.HttpRequestMethod;
  44. import org.openspcoop2.utils.transport.http.HttpResponse;
  45. import org.openspcoop2.utils.transport.http.HttpServletCredential;
  46. import org.openspcoop2.utils.transport.http.HttpUtilities;
  47. import org.slf4j.Logger;

  48. /**
  49.  * Servlet che serve per verificare l'installazione di OpenSPCoop.
  50.  * Ritorna 200 in caso l'installazione sia correttamente inizializzata e tutte le risorse disponibili.
  51.  * Ritorna 500 in caso la PdD non sia in funzione
  52.  *
  53.  * @author Poli Andrea (apoli@link.it)
  54.  * @author $Author$
  55.  * @version $Rev$, $Date$
  56.  */

  57. public class CheckStatoPdD extends HttpServlet {

  58.      /**
  59.      * serialVersionUID
  60.      */
  61.     private static final long serialVersionUID = 1L;

  62.     private static void sendError(HttpServletResponse res, Logger log, String msg, int code) {
  63.         sendError(res, log, msg, code, msg, null);
  64.     }
  65.     private static void sendError(HttpServletResponse res, Logger log, String msg, int code, Throwable e) {
  66.         sendError(res, log, msg, code, msg, e);
  67.     }
  68.     private static void sendError(HttpServletResponse res, Logger log, String msg, int code, String logMsg) {
  69.         sendError(res, log, msg, code, logMsg, null);
  70.     }
  71.     private static void sendError(HttpServletResponse res, Logger log, String msg, int code, String logMsg, Throwable e)  {
  72.         String prefix = "[GovWayCheck] ";
  73.         String msgLog = prefix+logMsg;
  74.         if(e!=null) {
  75.             log.error(msgLog, e);
  76.         }
  77.         else {
  78.             log.error(msgLog);
  79.         }
  80.         res.setStatus(code);
  81.         res.setContentType(HttpConstants.CONTENT_TYPE_PLAIN);
  82.         try {
  83.             res.getOutputStream().write(msg.getBytes());
  84.         }catch(Exception t) {
  85.             log.error("[CheckStato] SendError failed: "+t.getMessage(),t);
  86.         }
  87.     }
  88.    
  89.     private String getPrefixLetturaRisorsa(String resourceName) {
  90.         return "Lettura risorsa ["+resourceName+"] ";
  91.     }
  92.     private String getMsgRisorsaNonAutorizzata(String resourceName) {
  93.         return getPrefixLetturaRisorsa(resourceName)+"non autorizzata";
  94.     }

  95.     private String getMsgDellaRisorsaNonRiuscita(String resourceName) {
  96.          return "della risorsa ["+resourceName+"] non riuscita";
  97.     }
  98.    
  99.     public static void serializeNotInitializedResponse(HttpServletResponse res, Logger log)  {
  100.         String msg = "API Gateway GovWay non inzializzato";
  101.         sendError(res, log, msg, 503);  // viene volutamente utilizzato il codice 503
  102.     }

  103.     @Override public void doGet(HttpServletRequest req, HttpServletResponse res)
  104.     throws ServletException, IOException {
  105.                
  106.         Logger log = OpenSPCoop2Logger.getLoggerOpenSPCoopCore();
  107.         if(log==null)
  108.             log = LoggerWrapperFactory.getLogger(CheckStatoPdD.class);
  109.        
  110.         if( !OpenSPCoop2Startup.initialize){
  111.             serializeNotInitializedResponse(res, log);
  112.             return;
  113.         }
  114.        
  115.         OpenSPCoop2Properties properties = OpenSPCoop2Properties.getInstance();
  116.            
  117.         // verifico se l'invocazione richiede una lettura di una risorsa jmx
  118.         boolean richiestaRisorsaJmx = false;
  119.         String resourceName = req.getParameter(CostantiPdD.CHECK_STATO_PDD_RESOURCE_NAME);
  120.         if(resourceName!=null && !"".equals(resourceName)){

  121.             boolean checkReadEnabled = false;
  122.             if(properties!=null && properties.isCheckReadJMXResourcesEnabled() ){
  123.                 checkReadEnabled = true;
  124.             }
  125.             if(!checkReadEnabled){
  126.                 String msg = "Servizio non abilitato";
  127.                 sendError(res, log, msg, 500);
  128.                 return;
  129.             }
  130.            
  131.             // prima di procedere verifico una eventuale autenticazione
  132.             String username = properties.getCheckReadJMXResourcesUsername();
  133.             String password = properties.getCheckReadJMXResourcesPassword();
  134.             if(username!=null && password!=null){
  135.                 HttpServletCredential identity = new HttpServletCredential(req, log);
  136.                 if(!username.equals(identity.getUsername())){
  137.                     String msg = getMsgRisorsaNonAutorizzata(resourceName);
  138.                     String logMsg = msg+". Richiesta effettuata da username ["+identity.getUsername()+"] sconosciuto";
  139.                     sendError(res, log, msg, 500, logMsg);
  140.                     return;
  141.                 }
  142.                 if(!password.equals(identity.getPassword())){
  143.                     String msg = getMsgRisorsaNonAutorizzata(resourceName);
  144.                     String logMsg = msg+". Richiesta effettuata da username ["+identity.getUsername()+"] (password errata)";
  145.                     sendError(res, log, msg, 500, logMsg);
  146.                     return;
  147.                 }
  148.             }
  149.            
  150.             String attributeName = req.getParameter(CostantiPdD.CHECK_STATO_PDD_ATTRIBUTE_NAME);
  151.             String attributeValue = req.getParameter(CostantiPdD.CHECK_STATO_PDD_ATTRIBUTE_VALUE);
  152.             String attributeBooleanValue = req.getParameter(CostantiPdD.CHECK_STATO_PDD_ATTRIBUTE_BOOLEAN_VALUE);
  153.             String methodName = req.getParameter(CostantiPdD.CHECK_STATO_PDD_METHOD_NAME);
  154.             if(attributeName!=null){
  155.                 if(attributeValue!=null || attributeBooleanValue!=null){
  156.                     try{
  157.                         Object v = attributeValue;
  158.                         if(attributeBooleanValue!=null){
  159.                             v = Boolean.parseBoolean(attributeBooleanValue);
  160.                         }
  161.                         OpenSPCoop2Startup.gestoreRisorseJMX_staticInstance.setAttribute(resourceName, attributeName, v);
  162.                         richiestaRisorsaJmx = true; // se è stata richiesta una operazione jmx non si deve proseguire con il check  
  163.                     }catch(Exception e){
  164.                         String msg = "Aggiornamento attributo ["+attributeName+"] "+getMsgDellaRisorsaNonRiuscita(resourceName)+" (valore:"+attributeValue+"): "+e.getMessage();
  165.                         sendError(res, log, msg, 500, e);  
  166.                         return;
  167.                     }
  168.                 }
  169.                 else{
  170.                     try{
  171.                         Object value = OpenSPCoop2Startup.gestoreRisorseJMX_staticInstance.getAttribute(resourceName, attributeName);
  172.                         res.setContentType(HttpConstants.CONTENT_TYPE_PLAIN);
  173.                         res.getOutputStream().write(value.toString().getBytes());  
  174.                         richiestaRisorsaJmx = true; // se è stata richiesta una operazione jmx non si deve proseguire con il check
  175.                     }catch(Exception e){
  176.                         String msg = "Lettura attributo ["+attributeName+"] "+getMsgDellaRisorsaNonRiuscita(resourceName)+": "+e.getMessage();
  177.                         sendError(res, log, msg, 500, e);  
  178.                         return;
  179.                     }
  180.                 }
  181.             }
  182.             else if(attributeValue!=null){
  183.                 String msg = getPrefixLetturaRisorsa(resourceName)+"non effettuata, fornito un valore di attributo senza aver indicato il nome";
  184.                 sendError(res, log, msg, 500);  
  185.                 return;
  186.             }
  187.             else if(methodName!=null){
  188.                
  189.                 Object [] params = null;
  190.                 String [] signatures = null;
  191.                 try {
  192.                     List<Object> paramsL = new ArrayList<>();
  193.                     List<String> signaturesL = new ArrayList<>();
  194.                     addParameter(paramsL, signaturesL, req);
  195.                     if(!paramsL.isEmpty() && !signaturesL.isEmpty()) {
  196.                         params = paramsL.toArray(new Object[1]);
  197.                         signatures = signaturesL.toArray(new String[1]);
  198.                     }
  199.                 }catch(Exception e) {
  200.                     String msg = "Invocazione metodo ["+methodName+"] "+getMsgDellaRisorsaNonRiuscita(resourceName)+": "+e.getMessage();
  201.                     sendError(res, log, msg, 500, e);
  202.                     return;
  203.                 }
  204.                
  205.                 try{
  206.                     Object value = OpenSPCoop2Startup.gestoreRisorseJMX_staticInstance.invoke(resourceName, methodName, params, signatures);
  207.                     res.setContentType(HttpConstants.CONTENT_TYPE_PLAIN);
  208.                     res.getOutputStream().write(value.toString().getBytes());
  209.                     richiestaRisorsaJmx = true; // se è stata richiesta una operazione jmx non si deve proseguire con il check
  210.                 }catch(Exception e){
  211.                     String msg = "Invocazione metodo ["+methodName+"] "+getMsgDellaRisorsaNonRiuscita(resourceName)+": "+e.getMessage();
  212.                     sendError(res, log, msg, 500, e);
  213.                     return;
  214.                 }
  215.             }
  216.             else{
  217.                 String msg = getPrefixLetturaRisorsa(resourceName)+"non effettuata, nessun attributo o metodo richiesto";
  218.                 sendError(res, log, msg, 500);
  219.                 return;
  220.             }
  221.            
  222.         }
  223.        
  224.         if(richiestaRisorsaJmx) {
  225.             return; // se è stata richiesta una operazione jmx non si deve proseguire con il check
  226.         }
  227.        
  228.         CheckStatoPdDHealthCheckStats check = readHealthCheckStats(req, properties);
  229.         if(check!=null) {
  230.             try {
  231.                 CheckStatoPdDHealthCheckStatsUtils.verificaInformazioniStatistiche(log, properties,check);
  232.                 return; // se è staa richiesta manualmente una verifica delle statistiche non si deve proseguire con il check
  233.             }catch(Exception t) {
  234.                 String msg = "Statistics HealthCheck failed\n"+t.getMessage();
  235.                 sendError(res, log, msg, 500, t);
  236.                 return;
  237.             }
  238.         }
  239.        
  240.         boolean checkEnabled = false;
  241.         if(properties!=null && properties.isCheckEnabled() ){
  242.             checkEnabled = true;
  243.         }
  244.         if(!checkEnabled){
  245.             String msg = "Servizio non abilitato";
  246.             sendError(res, log, msg, 500);
  247.             return;
  248.         }
  249.        
  250.                        
  251.         if( !OpenSPCoop2Startup.initialize){
  252.             serializeNotInitializedResponse(res, log);
  253.             return;
  254.         }
  255.         else if( !TimerMonitoraggioRisorseThread.isRisorseDisponibili()){
  256.             String msg = "Risorse di sistema non disponibili: "+TimerMonitoraggioRisorseThread.getRisorsaNonDisponibile().getMessage();
  257.             sendError(res, log, msg, 500, TimerMonitoraggioRisorseThread.getRisorsaNonDisponibile());
  258.             return;
  259.         }
  260.         else if( !TimerThresholdThread.freeSpace){
  261.             String msg = "Non sono disponibili abbastanza risorse per la gestione della richiesta";
  262.             sendError(res, log, msg, 500);
  263.             return;
  264.         }
  265.         else if( !Tracciamento.tracciamentoDisponibile){
  266.             String msg = "Tracciatura non disponibile: "+Tracciamento.motivoMalfunzionamentoTracciamento.getMessage();
  267.             sendError(res, log, msg, 500, Tracciamento.motivoMalfunzionamentoTracciamento);
  268.             return;
  269.         }
  270.         else if( !MsgDiagnostico.gestoreDiagnosticaDisponibile){
  271.             String msg = "Sistema di diagnostica non disponibile: "+MsgDiagnostico.motivoMalfunzionamentoDiagnostici.getMessage();
  272.             sendError(res, log, msg, 500, MsgDiagnostico.motivoMalfunzionamentoDiagnostici);    
  273.             return;
  274.         }
  275.         else if( !Dump.isSistemaDumpDisponibile()){
  276.             String msg = "Sistema di dump dei contenuti applicativi non disponibile: "+Dump.getMotivoMalfunzionamentoDump().getMessage();
  277.             sendError(res, log, msg, 500, Dump.getMotivoMalfunzionamentoDump());
  278.             return;
  279.         }
  280.        
  281.         if(properties.isCheckHealthCheckStatsEnabled()) {
  282.             try {
  283.                 CheckStatoPdDHealthCheckStatsUtils.verificaInformazioniStatistiche(log, properties);
  284.             }catch(Exception t) {
  285.                 String msg = "Statistics HealthCheck failed\n"+t.getMessage();
  286.                 sendError(res, log, msg, 500, t);
  287.                 return;
  288.             }
  289.         }
  290.        
  291.         if(properties.isCheckHealthCheckApiRestEnabled()) {
  292.             String endpoint = properties.getCheckHealthCheckApiRestEndpoint();
  293.            
  294.             HttpRequest request = new HttpRequest();
  295.             if(endpoint.toLowerCase().startsWith("https")) {
  296.                 request.setHostnameVerifier(false);
  297.                 request.setTrustAllCerts(true);
  298.             }
  299.             request.setMethod(HttpRequestMethod.GET);
  300.             request.setUrl(endpoint);
  301.            
  302.             try {
  303.                 HttpResponse response = HttpUtilities.httpInvoke(request);
  304.                
  305.                 if(response.getResultHTTPOperation()!=200) {
  306.                     StringBuilder sb = new StringBuilder();
  307.                     if(response.getHeadersValues()!=null && !response.getHeadersValues().isEmpty()) {
  308.                         for (String hdrName : response.getHeadersValues().keySet()) {
  309.                             if(HttpConstants.RETURN_CODE.equals(hdrName)) {
  310.                                 continue;
  311.                             }
  312.                             List<String> values = response.getHeaderValues(hdrName);
  313.                             if(values!=null && !values.isEmpty()) {
  314.                                 for (String v : values) {
  315.                                     sb.append("\n").append(hdrName).append(":").append(v);
  316.                                 }
  317.                             }
  318.                         }
  319.                     }
  320.                     else {
  321.                         if(response.getContentType()!=null) {
  322.                             sb.append("\n").append(HttpConstants.CONTENT_TYPE).append(":").append(response.getContentType());  
  323.                         }
  324.                     }
  325.                     if(response.getContent()!=null) {
  326.                         sb.append("\n\n").append(new String(response.getContent()));
  327.                     }
  328.                     throw new CoreException("HTTP Result:"+response.getResultHTTPOperation()+sb.toString());
  329.                 }
  330.                
  331.             }catch(Exception t) {
  332.                 String msg = "API REST HealthCheck failed ("+endpoint+")\n"+t.getMessage();
  333.                 sendError(res, log, msg, 500, t);
  334.                 return;
  335.             }
  336.         }
  337.        
  338.         if(properties.isCheckHealthCheckApiSoapEnabled()) {
  339.             String endpoint = properties.getCheckHealthCheckApiSoapEndpoint();
  340.            
  341.             HttpRequest request = new HttpRequest();
  342.             if(endpoint.toLowerCase().startsWith("https")) {
  343.                 request.setHostnameVerifier(false);
  344.                 request.setTrustAllCerts(true);
  345.             }
  346.             request.setContentType(HttpConstants.CONTENT_TYPE_SOAP_1_1);
  347.             request.addHeader(HttpConstants.SOAP11_MANDATORY_HEADER_HTTP_SOAP_ACTION, "echo");
  348.             request.setMethod(HttpRequestMethod.POST);
  349.             request.setUrl(endpoint);
  350.             request.setContent("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Body><ns1:getStatus xmlns:ns1=\"https://govway.org/apiStatus\"/></soapenv:Body></soapenv:Envelope>".getBytes());
  351.            
  352.             try {
  353.                 HttpResponse response = HttpUtilities.httpInvoke(request);
  354.                
  355.                 if(response.getResultHTTPOperation()!=200) {
  356.                     StringBuilder sb = new StringBuilder();
  357.                     if(response.getHeadersValues()!=null && !response.getHeadersValues().isEmpty()) {
  358.                         for (String hdrName : response.getHeadersValues().keySet()) {
  359.                             if(HttpConstants.RETURN_CODE.equals(hdrName)) {
  360.                                 continue;
  361.                             }
  362.                             List<String> values = response.getHeaderValues(hdrName);
  363.                             if(values!=null && !values.isEmpty()) {
  364.                                 for (String v : values) {
  365.                                     sb.append("\n").append(hdrName).append(":").append(v);
  366.                                 }
  367.                             }
  368.                         }
  369.                     }
  370.                     else {
  371.                         if(response.getContentType()!=null) {
  372.                             sb.append("\n").append(HttpConstants.CONTENT_TYPE).append(":").append(response.getContentType());
  373.                         }
  374.                     }
  375.                     if(response.getContent()!=null) {
  376.                         sb.append("\n\n").append(new String(response.getContent()));
  377.                     }
  378.                     throw new ServletException("HTTP Result:"+response.getResultHTTPOperation()+sb.toString());
  379.                 }
  380.                
  381.             }catch(Exception t) {
  382.                 String msg = "API SOAP HealthCheck failed ("+endpoint+")\n"+t.getMessage();
  383.                 sendError(res, log, msg, 500, t);
  384.             }
  385.         }

  386.     }
  387.    
  388.     private BooleanNullable readBooleanParam(HttpServletRequest req, String paramName) {
  389.         String p = req.getParameter(paramName);
  390.         if("true".equalsIgnoreCase(p)) {
  391.             return BooleanNullable.TRUE();
  392.         }
  393.         else if("false".equalsIgnoreCase(p)) {
  394.             return BooleanNullable.FALSE();
  395.         }
  396.         return BooleanNullable.NULL();
  397.     }
  398.     private Integer readIntegerParam(HttpServletRequest req, String paramName) {
  399.         String p = req.getParameter(paramName);
  400.         if(p!=null && StringUtils.isNotEmpty(p)) {
  401.             return Integer.valueOf(p);
  402.         }
  403.         return null;
  404.     }
  405.     private CheckStatoPdDHealthCheckStats readHealthCheckStats(HttpServletRequest req, OpenSPCoop2Properties properties) {
  406.         BooleanNullable healthCheckStats = readBooleanParam(req,CostantiPdD.CHECK_STATO_PDD_EXECUTE_HEALTH_CHECK_STATS);
  407.         BooleanNullable hourlyHealthCheckStats = readBooleanParam(req,CostantiPdD.CHECK_STATO_PDD_EXECUTE_HOURLY_HEALTH_CHECK_STATS);
  408.         BooleanNullable dailyHealthCheckStats = readBooleanParam(req,CostantiPdD.CHECK_STATO_PDD_EXECUTE_DAILY_HEALTH_CHECK_STATS);
  409.         BooleanNullable weeklyHealthCheckStats = readBooleanParam(req,CostantiPdD.CHECK_STATO_PDD_EXECUTE_WEEKLY_HEALTH_CHECK_STATS);
  410.         BooleanNullable monthlyHealthCheckStats = readBooleanParam(req,CostantiPdD.CHECK_STATO_PDD_EXECUTE_MONTHLY_HEALTH_CHECK_STATS);
  411.        
  412.         CheckStatoPdDHealthCheckStats check = null;
  413.         if(hourlyHealthCheckStats!=null && hourlyHealthCheckStats.getValue()!=null) {
  414.             check = new CheckStatoPdDHealthCheckStats();
  415.             check.setVerificaStatisticaOraria(hourlyHealthCheckStats.getValue().booleanValue());
  416.             Integer p = readIntegerParam(req, CostantiPdD.CHECK_STATO_PDD_EXECUTE_HOURLY_HEALTH_CHECK_STATS_THRESHOLD);
  417.             if(p!=null && p.intValue()>=0) {
  418.                 check.setVerificaStatisticaOrariaSoglia(p.intValue());
  419.             }
  420.             else {
  421.                 check.setVerificaStatisticaOrariaSoglia(properties.getCheckHealthCheckStatsHourlyThreshold());
  422.             }
  423.         }
  424.         if(dailyHealthCheckStats!=null && dailyHealthCheckStats.getValue()!=null) {
  425.             if(check==null) {
  426.                 check = new CheckStatoPdDHealthCheckStats();
  427.             }
  428.             check.setVerificaStatisticaGiornaliera(dailyHealthCheckStats.getValue().booleanValue());
  429.             Integer p = readIntegerParam(req, CostantiPdD.CHECK_STATO_PDD_EXECUTE_DAILY_HEALTH_CHECK_STATS_THRESHOLD);
  430.             if(p!=null && p.intValue()>=0) {
  431.                 check.setVerificaStatisticaGiornalieraSoglia(p.intValue());
  432.             }
  433.             else {
  434.                 check.setVerificaStatisticaGiornalieraSoglia(properties.getCheckHealthCheckStatsDailyThreshold());
  435.             }
  436.         }
  437.         if(weeklyHealthCheckStats!=null && weeklyHealthCheckStats.getValue()!=null) {
  438.             if(check==null) {
  439.                 check = new CheckStatoPdDHealthCheckStats();
  440.             }
  441.             check.setVerificaStatisticaSettimanale(weeklyHealthCheckStats.getValue().booleanValue());
  442.             Integer p = readIntegerParam(req, CostantiPdD.CHECK_STATO_PDD_EXECUTE_WEEKLY_HEALTH_CHECK_STATS_THRESHOLD);
  443.             if(p!=null && p.intValue()>=0) {
  444.                 check.setVerificaStatisticaSettimanaleSoglia(p.intValue());
  445.             }
  446.             else {
  447.                 check.setVerificaStatisticaSettimanaleSoglia(properties.getCheckHealthCheckStatsWeeklyThreshold());
  448.             }
  449.         }
  450.         if(monthlyHealthCheckStats!=null && monthlyHealthCheckStats.getValue()!=null) {
  451.             if(check==null) {
  452.                 check = new CheckStatoPdDHealthCheckStats();
  453.             }
  454.             check.setVerificaStatisticaMensile(monthlyHealthCheckStats.getValue().booleanValue());
  455.             Integer p = readIntegerParam(req, CostantiPdD.CHECK_STATO_PDD_EXECUTE_MONTHLY_HEALTH_CHECK_STATS_THRESHOLD);
  456.             if(p!=null && p.intValue()>=0) {
  457.                 check.setVerificaStatisticaMensileSoglia(p.intValue());
  458.             }
  459.             else {
  460.                 check.setVerificaStatisticaMensileSoglia(properties.getCheckHealthCheckStatsMonthlyThreshold());
  461.             }
  462.         }
  463.         if(check == null &&
  464.             healthCheckStats!=null && healthCheckStats.getValue()!=null && healthCheckStats.getValue().booleanValue()) {
  465.             check = CheckStatoPdDHealthCheckStats.readProprietaVerificaInformazioniStatistiche(properties);
  466.         }
  467.        
  468.         return check;
  469.     }
  470.    

  471.     private void addParameter(List<Object> params, List<String> signatures, HttpServletRequest req) throws CoreException {
  472.        
  473.         boolean add = addParameter(params, signatures, req,
  474.                 CostantiPdD.CHECK_STATO_PDD_PARAM_VALUE,
  475.                 CostantiPdD.CHECK_STATO_PDD_PARAM_INT_VALUE,
  476.                 CostantiPdD.CHECK_STATO_PDD_PARAM_LONG_VALUE,
  477.                 CostantiPdD.CHECK_STATO_PDD_PARAM_BOOLEAN_VALUE);
  478.         if(!add) {
  479.             return;
  480.         }
  481.        
  482.         add = addParameter(params, signatures, req,
  483.                 CostantiPdD.CHECK_STATO_PDD_PARAM_VALUE_2,
  484.                 CostantiPdD.CHECK_STATO_PDD_PARAM_INT_VALUE_2,
  485.                 CostantiPdD.CHECK_STATO_PDD_PARAM_LONG_VALUE_2,
  486.                 CostantiPdD.CHECK_STATO_PDD_PARAM_BOOLEAN_VALUE_2);
  487.         if(!add) {
  488.             return;
  489.         }
  490.        
  491.         add = addParameter(params, signatures, req,
  492.                 CostantiPdD.CHECK_STATO_PDD_PARAM_VALUE_3,
  493.                 CostantiPdD.CHECK_STATO_PDD_PARAM_INT_VALUE_3,
  494.                 CostantiPdD.CHECK_STATO_PDD_PARAM_LONG_VALUE_3,
  495.                 CostantiPdD.CHECK_STATO_PDD_PARAM_BOOLEAN_VALUE_3);
  496.        
  497.         if(!add) {
  498.             return;
  499.         }
  500.        
  501.         addParameter(params, signatures, req,
  502.                 CostantiPdD.CHECK_STATO_PDD_PARAM_VALUE_4,
  503.                 CostantiPdD.CHECK_STATO_PDD_PARAM_INT_VALUE_4,
  504.                 CostantiPdD.CHECK_STATO_PDD_PARAM_LONG_VALUE_4,
  505.                 CostantiPdD.CHECK_STATO_PDD_PARAM_BOOLEAN_VALUE_4);
  506.            
  507.     }
  508.    
  509.     private boolean addParameter(List<Object> params, List<String> signatures, HttpServletRequest req,
  510.             String stringNameParameter, String intNameParameter, String longNameParameter, String booleanNameParameter) throws CoreException {
  511.        
  512.         int count = 0;
  513.         List<String> pFound = new ArrayList<>();
  514.        
  515.         String paramStringValue = req.getParameter(stringNameParameter);
  516.         boolean paramStringDefined = paramStringValue!=null && !"".equals(paramStringValue);
  517.         if(paramStringDefined) {
  518.             count++;
  519.             pFound.add(stringNameParameter);
  520.         }
  521.        
  522.         String paramIntValue = req.getParameter(intNameParameter);
  523.         boolean paramIntDefined = paramIntValue!=null && !"".equals(paramIntValue);
  524.         if(paramIntDefined) {
  525.             count++;
  526.             pFound.add(intNameParameter);
  527.         }
  528.        
  529.         String paramLongValue = req.getParameter(longNameParameter);
  530.         boolean paramLongDefined = paramLongValue!=null && !"".equals(paramLongValue);
  531.         if(paramLongDefined) {
  532.             count++;
  533.             pFound.add(longNameParameter);
  534.         }
  535.        
  536.         String paramBooleanValue = req.getParameter(booleanNameParameter);
  537.         boolean paramBooleanDefined = paramBooleanValue!=null && !"".equals(paramBooleanValue);
  538.         if(paramBooleanDefined) {
  539.             count++;
  540.             pFound.add(booleanNameParameter);
  541.         }
  542.        
  543.         if(count==0) {
  544.             return false;
  545.         }
  546.         if(count>1) {
  547.             throw new CoreException("È stato fornito più di un tipo di parametro per la stessa posizione: "+pFound);
  548.         }
  549.        
  550.         if(paramStringDefined){
  551.             params.add(paramStringValue);
  552.             signatures.add(String.class.getName());
  553.         }
  554.         else if(paramIntDefined){
  555.             params.add(Integer.valueOf(paramIntValue));
  556.             signatures.add(Integer.class.getName());
  557.         }
  558.         else if(paramLongDefined){
  559.             params.add(Long.valueOf(paramLongValue));
  560.             signatures.add(Long.class.getName());
  561.         }
  562.         /**else if(paramBooleanDefined){*/
  563.         else {
  564.             params.add(Boolean.valueOf(paramBooleanValue));
  565.             signatures.add(Boolean.class.getName());
  566.         }
  567.         return true;
  568.        
  569.     }
  570. }