コード例 #1
0
  @SuppressWarnings({})
  public static void main(String[] args) {
    try {
      try {
        String logConfigFile = ConfigReader.readConfig("logConfigFile", "StatPortalOpenData");
        SpodLogger.configureLogger(logConfigFile);
      } catch (Exception ex) {
        // si perde il logging ma l'applicazione continua a funzionare
      }

      String configDir = ConfigReader.getConfigDir();
      String appContextFile = "file:" + configDir + "applicationContext.xml";
      FileSystemXmlApplicationContext cpac;
      try {
        cpac = new FileSystemXmlApplicationContext(appContextFile);
      } catch (Exception ex) {
        SpodLogger.log(LogType.FATAL, ex);
        SpodLogger.log(LogType.FATAL, "Il file " + appContextFile + " non esiste.");
        throw new ServiceConfigurationError("Non riesco a trovare " + appContextFile);
      }

      String urlRegex =
          "(ftp|http|https):\\/\\/(\\w+:{0,1}\\w*@)?(\\S+)(:[0-9]+)?(\\/|\\/([\\w#!:.?+=&%@!\\-\\/]))";
      String endpointUri = ConfigReader.readConfig("url", "StatPortalOpenData");
      if (endpointUri == null) {
        throw new Exception("Manca il parametro url");
      }
      if (!endpointUri.matches(urlRegex)) {
        throw new Exception("Chiave url non valida");
      }
      String namespace = "StatPortal";

      final StatPortalJPAProducer jpaProducer = new StatPortalJPAProducer(namespace, 50, cpac);
      String numDistinctValuesStr =
          ConfigReader.readConfig("numDistinctValues", "StatPortalOpenData");
      int numDistinctValues = 20;
      if (numDistinctValuesStr != null && !"".equalsIgnoreCase(numDistinctValuesStr)) {
        try {
          numDistinctValues = Integer.parseInt(numDistinctValuesStr);
        } catch (Exception e) {
          SpodLogger.log(LogType.WARNING, "Valore di numDistinctValues non valido", e);
        }
      }

      final it.sister.statportal.odata.StatPortalProducer producer =
          new it.sister.statportal.odata.StatPortalProducer(jpaProducer, numDistinctValues);

      // register the producer as the static instance, then launch the
      // http server
      ODataProducerProvider.setInstance(producer);
      SpodLogger.log(LogType.INFO, "Starting service");
      ProducerUtil.hostODataServer(endpointUri);
    } catch (Exception ex) {
      SpodLogger.log(LogType.FATAL, ex);
    }
  }
 @Override
 public void init(ServletConfig config) throws ServletException {
   // Inizializzazione connessione al DB site
   super.init(config);
   // Custom param config
   enabled =
       Boolean.parseBoolean(
           ConfigReader.readConfig("bulkUpdateVisibilityServletEnabled", "SpodCkanApi"));
 }