public static PropertyReader[] getPropertyReaders(LbConfig _lbConfig) {
   Properties properties = new Properties();
   properties.setProperty(LoadbalancerReader.HTTPS_ROUTING, _lbConfig.getHttpsRouting());
   properties.setProperty(LoadbalancerReader.REQ_MONITOR_DATA, _lbConfig.getMonitoringEnabled());
   properties.setProperty(
       LoadbalancerReader.RELOAD_INTERVAL, _lbConfig.getReloadPollIntervalInSeconds());
   properties.setProperty(
       LoadbalancerReader.RESP_TIMEOUT, _lbConfig.getResponseTimeoutInSeconds());
   Iterator<Property> propertyList = _lbConfig.getProperty().iterator();
   while (propertyList.hasNext()) {
     Property property = propertyList.next();
     if (property.getName().equals(LbConfig.LAST_APPLIED_PROPERTY)
         || property.getName().equals(LbConfig.LAST_EXPORTED_PROPERTY)) {
       continue;
     }
     properties.setProperty(property.getName(), property.getValue());
   }
   return getPropertyReaders(properties);
 }
Beispiel #2
0
  public static void createRealms(String defaultRealm, List<AuthRealm> realms, String configName) {
    assert (realms != null);

    String goodRealm = null; // need at least one good realm

    for (AuthRealm aRealm : realms) {
      String realmName = aRealm.getName();
      String realmClass = aRealm.getClassname();
      assert (realmName != null);
      assert (realmClass != null);

      try {
        List<Property> realmProps = aRealm.getProperty();
        /*V3 Commented ElementProperty[] realmProps =
        aRealm.getElementProperty();*/
        Properties props = new Properties();
        for (Property realmProp : realmProps) {
          props.setProperty(realmProp.getName(), realmProp.getValue());
        }
        Realm.instantiate(realmName, realmClass, props, configName);
        if (logger.isLoggable(Level.FINE)) {
          logger.fine("Configured realm: " + realmName);
        }

        if (goodRealm == null) {
          goodRealm = realmName;
        }
      } catch (Exception e) {
        logger.log(Level.WARNING, SecurityLoggerInfo.realmConfigDisabledError, realmName);
        logger.log(Level.WARNING, SecurityLoggerInfo.securityExceptionError, e);
      }
    }

    // done loading all realms, check that there is at least one
    // in place and that default is installed, or change default
    // to the first one loaded (arbitrarily).

    if (goodRealm == null) {
      logger.severe(SecurityLoggerInfo.noRealmsError);

    } else {
      try {
        Realm.getInstance(defaultRealm);
      } catch (Exception e) {
        defaultRealm = goodRealm;
      }
      Realm.setDefaultRealm(defaultRealm);
      if (logger.isLoggable(Level.FINE)) {
        logger.fine("Default realm is set to: " + defaultRealm);
      }
    }
  }
  public static synchronized Properties getJTSProperties(
      ServiceLocator serviceLocator, boolean isORBAvailable) {
    if (orbAvailable == isORBAvailable && properties != null) {
      // We will need to update the properties if ORB availability changed
      return properties;
    }

    Properties jtsProperties = new Properties();
    if (serviceLocator != null) {
      jtsProperties.put(HABITAT, serviceLocator);
      ProcessEnvironment processEnv = serviceLocator.getService(ProcessEnvironment.class);
      if (processEnv.getProcessType().isServer()) {
        TransactionService txnService =
            serviceLocator.getService(
                TransactionService.class, ServerEnvironment.DEFAULT_INSTANCE_NAME);

        if (txnService != null) {
          jtsProperties.put(Configuration.HEURISTIC_DIRECTION, txnService.getHeuristicDecision());
          jtsProperties.put(Configuration.KEYPOINT_COUNT, txnService.getKeypointInterval());

          String automaticRecovery = txnService.getAutomaticRecovery();
          boolean isAutomaticRecovery =
              (isValueSet(automaticRecovery) && "true".equals(automaticRecovery));
          if (isAutomaticRecovery) {
            _logger.log(Level.FINE, "Recoverable J2EE Server");
            jtsProperties.put(Configuration.MANUAL_RECOVERY, "true");
          }

          boolean disable_distributed_transaction_logging = false;
          String dbLoggingResource = null;
          for (Property prop : txnService.getProperty()) {
            String name = prop.getName();
            String value = prop.getValue();

            if (name.equals("disable-distributed-transaction-logging")) {
              if (isValueSet(value) && "true".equals(value)) {
                disable_distributed_transaction_logging = true;
              }

            } else if (name.equals("xaresource-txn-timeout")) {
              if (isValueSet(value)) {
                _logger.log(Level.FINE, "XAResource transaction timeout is" + value);
                TransactionManagerImpl.setXAResourceTimeOut(Integer.parseInt(value));
              }

            } else if (name.equals("db-logging-resource")) {
              dbLoggingResource = value;
              _logger.log(Level.FINE, "Transaction DB Logging Resource Name" + dbLoggingResource);
              if (dbLoggingResource != null
                  && (" ".equals(dbLoggingResource) || "".equals(dbLoggingResource))) {
                dbLoggingResource = "jdbc/TxnDS";
              }

            } else if (name.equals("xa-servername")) {
              if (isValueSet(value)) {
                jtsProperties.put(JTS_XA_SERVER_NAME, value);
              }

            } else if (name.equals("pending-txn-cleanup-interval")) {
              if (isValueSet(value)) {
                jtsProperties.put("pending-txn-cleanup-interval", value);
              }

            } else if (name.equals(Configuration.COMMIT_ONE_PHASE_DURING_RECOVERY)) {
              if (isValueSet(value)) {
                jtsProperties.put(Configuration.COMMIT_ONE_PHASE_DURING_RECOVERY, value);
              }
            } else if (name.equals("add-wait-point-during-recovery")) {
              if (isValueSet(value)) {
                try {
                  FailureInducer.setWaitPointRecovery(Integer.parseInt(value));
                } catch (Exception e) {
                  _logger.log(Level.WARNING, e.getMessage());
                }
              }
            }
          }

          if (dbLoggingResource != null) {
            disable_distributed_transaction_logging = true;
            jtsProperties.put(Configuration.DB_LOG_RESOURCE, dbLoggingResource);
          }

          /**
           * JTS_SERVER_ID needs to be unique for each for server instance. This will be used as
           * recovery identifier along with the hostname for example: if the hostname is 'tulsa' and
           * iiop-listener-port is 3700 recovery identifier will be tulsa,P3700
           */
          int jtsServerId = DEFAULT_SERVER_ID; // default value

          if (isORBAvailable) {
            jtsServerId =
                serviceLocator
                    .<GlassFishORBHelper>getService(GlassFishORBHelper.class)
                    .getORBInitialPort();
            if (jtsServerId == 0) {
              // XXX Can this ever happen?
              jtsServerId = DEFAULT_SERVER_ID; // default value
            }
          }
          jtsProperties.put(JTS_SERVER_ID, String.valueOf(jtsServerId));

          /* ServerId is an J2SE persistent server activation
            API.  ServerId is scoped at the ORBD.  Since
            There is no ORBD present in J2EE the value of
            ServerId is meaningless - except it must have
            SOME value if persistent POAs are created.
          */

          // For clusters - all servers in the cluster MUST
          // have the same ServerId so when failover happens
          // and requests are delivered to a new server, the
          // ServerId in the request will match the new server.

          String serverId = String.valueOf(DEFAULT_SERVER_ID);
          System.setProperty(J2EE_SERVER_ID_PROP, serverId);

          ServerContext ctx = serviceLocator.getService(ServerContext.class);
          String instanceName = ctx.getInstanceName();

          /**
           * if the auto recovery is true, always transaction logs will be written irrespective of
           * disable_distributed_transaction_logging. if the auto recovery is false, then
           * disable_distributed_transaction_logging will be used to write transaction logs are
           * not.If disable_distributed_transaction_logging is set to false(by default false) logs
           * will be written, set to true logs won't be written.
           */
          if (!isAutomaticRecovery && disable_distributed_transaction_logging) {
            Configuration.disableFileLogging();
          } else {

            // if (dbLoggingResource == null) {
            Domain domain = serviceLocator.getService(Domain.class);
            Server server = domain.getServerNamed(instanceName);

            // Check if the server system property is set
            String logdir = getTXLogDir(server);

            // if not, check if the cluster system property is set
            if (logdir == null) {
              Cluster cluster = server.getCluster();
              if (cluster != null) {
                logdir = getTXLogDir(cluster);
              }
            }

            // No system properties are set - get tx log dir from transaction service
            if (logdir == null) {
              logdir = txnService.getTxLogDir();
            }

            if (logdir == null) {
              logdir = domain.getLogRoot();
              if (logdir == null) {
                // logdir = FileUtil.getAbsolutePath(".." + File.separator + "logs");
                logdir = ".." + File.separator + "logs";
              }
            } else if (!(new File(logdir)).isAbsolute()) {
              if (_logger.isLoggable(Level.FINE)) {
                _logger.log(
                    Level.FINE,
                    "Relative pathname specified for transaction log directory : " + logdir);
              }
              String logroot = domain.getLogRoot();
              if (logroot != null) {
                logdir = logroot + File.separator + logdir;
              } else {
                // logdir = FileUtil.getAbsolutePath(".." + File.separator + "logs"
                // + File.separator + logdir);
                logdir = ".." + File.separator + "logs" + File.separator + logdir;
              }
            }
            logdir += File.separator + instanceName + File.separator + "tx";

            if (_logger.isLoggable(Level.FINE)) {
              _logger.log(Level.FINE, "JTS log directory: " + logdir);
              _logger.log(Level.FINE, "JTS Server id " + jtsServerId);
            }

            jtsProperties.put(Configuration.LOG_DIRECTORY, logdir);
          }
          jtsProperties.put(Configuration.COMMIT_RETRY, txnService.getRetryTimeoutInSeconds());
          jtsProperties.put(Configuration.INSTANCE_NAME, instanceName);
        }
      }
    }

    properties = jtsProperties;
    orbAvailable = isORBAvailable;

    return properties;
  }
  /**
   * Pull out the MCF configuration properties and return them as an array of
   * ConnectorConfigProperty
   *
   * @param adminPool - The JdbcConnectionPool to pull out properties from
   * @param conConnPool - ConnectorConnectionPool which will be used by Resource Pool
   * @param connDesc - The ConnectorDescriptor for this JDBC RA
   * @return ConnectorConfigProperty [] array of MCF Config properties specified in this JDBC RA
   */
  private ConnectorConfigProperty[] getMCFConfigProperties(
      JdbcConnectionPool adminPool,
      ConnectorConnectionPool conConnPool,
      ConnectorDescriptor connDesc) {

    ArrayList propList = new ArrayList();

    if (adminPool.getResType() != null) {
      if (ConnectorConstants.JAVA_SQL_DRIVER.equals(adminPool.getResType())) {
        propList.add(
            new ConnectorConfigProperty(
                "ClassName",
                adminPool.getDriverClassname() == null ? "" : adminPool.getDriverClassname(),
                "The driver class name",
                "java.lang.String"));
      } else {
        propList.add(
            new ConnectorConfigProperty(
                "ClassName",
                adminPool.getDatasourceClassname() == null
                    ? ""
                    : adminPool.getDatasourceClassname(),
                "The datasource class name",
                "java.lang.String"));
      }
    } else {
      // When resType is null, one of these classnames would be specified
      if (adminPool.getDriverClassname() != null) {
        propList.add(
            new ConnectorConfigProperty(
                "ClassName",
                adminPool.getDriverClassname() == null ? "" : adminPool.getDriverClassname(),
                "The driver class name",
                "java.lang.String"));
      } else if (adminPool.getDatasourceClassname() != null) {
        propList.add(
            new ConnectorConfigProperty(
                "ClassName",
                adminPool.getDatasourceClassname() == null
                    ? ""
                    : adminPool.getDatasourceClassname(),
                "The datasource class name",
                "java.lang.String"));
      }
    }
    propList.add(
        new ConnectorConfigProperty(
            "ConnectionValidationRequired",
            adminPool.getIsConnectionValidationRequired() + "",
            "Is connection validation required",
            "java.lang.String"));

    propList.add(
        new ConnectorConfigProperty(
            "ValidationMethod",
            adminPool.getConnectionValidationMethod() == null
                ? ""
                : adminPool.getConnectionValidationMethod(),
            "How the connection is validated",
            "java.lang.String"));

    propList.add(
        new ConnectorConfigProperty(
            "ValidationTableName",
            adminPool.getValidationTableName() == null ? "" : adminPool.getValidationTableName(),
            "Validation Table name",
            "java.lang.String"));

    propList.add(
        new ConnectorConfigProperty(
            "ValidationClassName",
            adminPool.getValidationClassname() == null ? "" : adminPool.getValidationClassname(),
            "Validation Class name",
            "java.lang.String"));

    propList.add(
        new ConnectorConfigProperty(
            "TransactionIsolation",
            adminPool.getTransactionIsolationLevel() == null
                ? ""
                : adminPool.getTransactionIsolationLevel(),
            "Transaction Isolatin Level",
            "java.lang.String"));

    propList.add(
        new ConnectorConfigProperty(
            "GuaranteeIsolationLevel",
            adminPool.getIsIsolationLevelGuaranteed() + "",
            "Transaction Isolation Guarantee",
            "java.lang.String"));

    propList.add(
        new ConnectorConfigProperty(
            "StatementWrapping",
            adminPool.getWrapJdbcObjects() + "",
            "Statement Wrapping",
            "java.lang.String"));

    propList.add(
        new ConnectorConfigProperty(
            "LogJdbcCalls",
            adminPool.getLogJdbcCalls() + "",
            "Log JDBC Calls",
            "java.lang.String"));

    propList.add(
        new ConnectorConfigProperty(
            "SlowQueryThresholdInSeconds",
            adminPool.getSlowQueryThresholdInSeconds() + "",
            "Slow Query Threshold In Seconds",
            "java.lang.String"));

    propList.add(
        new ConnectorConfigProperty(
            "StatementTimeout",
            adminPool.getStatementTimeoutInSeconds() + "",
            "Statement Timeout",
            "java.lang.String"));

    PoolInfo poolInfo = conConnPool.getPoolInfo();

    propList.add(
        new ConnectorConfigProperty(
            "PoolMonitoringSubTreeRoot",
            ConnectorsUtil.getPoolMonitoringSubTreeRoot(poolInfo, true) + "",
            "Pool Monitoring Sub Tree Root",
            "java.lang.String"));

    propList.add(
        new ConnectorConfigProperty(
            "PoolName", poolInfo.getName() + "", "Pool Name", "java.lang.String"));

    if (poolInfo.getApplicationName() != null) {
      propList.add(
          new ConnectorConfigProperty(
              "ApplicationName",
              poolInfo.getApplicationName() + "",
              "Application Name",
              "java.lang.String"));
    }

    if (poolInfo.getModuleName() != null) {
      propList.add(
          new ConnectorConfigProperty(
              "ModuleName", poolInfo.getModuleName() + "", "Module name", "java.lang.String"));
    }

    propList.add(
        new ConnectorConfigProperty(
            "StatementCacheSize",
            adminPool.getStatementCacheSize() + "",
            "Statement Cache Size",
            "java.lang.String"));

    propList.add(
        new ConnectorConfigProperty(
            "StatementCacheType",
            adminPool.getStatementCacheType() + "",
            "Statement Cache Type",
            "java.lang.String"));

    propList.add(
        new ConnectorConfigProperty(
            "InitSql", adminPool.getInitSql() + "", "InitSql", "java.lang.String"));

    propList.add(
        new ConnectorConfigProperty(
            "SqlTraceListeners",
            adminPool.getSqlTraceListeners() + "",
            "Sql Trace Listeners",
            "java.lang.String"));

    propList.add(
        new ConnectorConfigProperty(
            "StatementLeakTimeoutInSeconds",
            adminPool.getStatementLeakTimeoutInSeconds() + "",
            "Statement Leak Timeout in seconds",
            "java.lang.String"));

    propList.add(
        new ConnectorConfigProperty(
            "StatementLeakReclaim",
            adminPool.getStatementLeakReclaim() + "",
            "Statement Leak Reclaim",
            "java.lang.String"));

    // dump user defined poperties into the list
    Set connDefDescSet = connDesc.getOutboundResourceAdapter().getConnectionDefs();
    // since this a 1.0 RAR, we will have only 1 connDefDesc
    if (connDefDescSet.size() != 1) {
      throw new MissingResourceException("Only one connDefDesc present", null, null);
    }

    Iterator iter = connDefDescSet.iterator();

    // Now get the set of MCF config properties associated with each
    // connection-definition . Each element here is an EnviromnentProperty
    Set mcfConfigProps = null;
    while (iter.hasNext()) {
      mcfConfigProps = ((ConnectionDefDescriptor) iter.next()).getConfigProperties();
    }
    if (mcfConfigProps != null) {

      Map mcfConPropKeys = new HashMap();
      Iterator mcfConfigPropsIter = mcfConfigProps.iterator();
      while (mcfConfigPropsIter.hasNext()) {
        String key = ((ConnectorConfigProperty) mcfConfigPropsIter.next()).getName();
        mcfConPropKeys.put(key.toUpperCase(locale), key);
      }

      String driverProperties = "";
      for (Property rp : adminPool.getProperty()) {
        if (rp == null) {
          continue;
        }
        String name = rp.getName();

        // The idea here is to convert the Environment Properties coming from
        // the admin connection pool to standard pool properties thereby
        // making it easy to compare in the event of a reconfig
        if ("MATCHCONNECTIONS".equals(name.toUpperCase(locale))) {
          // JDBC - matchConnections if not set is decided by the ConnectionManager
          // so default is false
          conConnPool.setMatchConnections(toBoolean(rp.getValue(), false));
          logFine("MATCHCONNECTIONS");

        } else if ("ASSOCIATEWITHTHREAD".equals(name.toUpperCase(locale))) {
          conConnPool.setAssociateWithThread(toBoolean(rp.getValue(), false));
          logFine("ASSOCIATEWITHTHREAD");

        } else if ("LAZYCONNECTIONASSOCIATION".equals(name.toUpperCase(locale))) {
          ConnectionPoolObjectsUtils.setLazyEnlistAndLazyAssocProperties(
              rp.getValue(), adminPool.getProperty(), conConnPool);
          logFine("LAZYCONNECTIONASSOCIATION");

        } else if ("LAZYCONNECTIONENLISTMENT".equals(name.toUpperCase(Locale.getDefault()))) {
          conConnPool.setLazyConnectionEnlist(toBoolean(rp.getValue(), false));
          logFine("LAZYCONNECTIONENLISTMENT");

        } else if ("POOLDATASTRUCTURE".equals(name.toUpperCase(Locale.getDefault()))) {
          conConnPool.setPoolDataStructureType(rp.getValue());
          logFine("POOLDATASTRUCTURE");

        } else if (ConnectorConstants.DYNAMIC_RECONFIGURATION_FLAG.equals(
            name.toLowerCase(locale))) {
          String value = rp.getValue();
          try {
            conConnPool.setDynamicReconfigWaitTimeout(Long.parseLong(rp.getValue()) * 1000L);
            logFine(ConnectorConstants.DYNAMIC_RECONFIGURATION_FLAG);
          } catch (NumberFormatException nfe) {
            _logger.log(
                Level.WARNING,
                "Invalid value for "
                    + "'"
                    + ConnectorConstants.DYNAMIC_RECONFIGURATION_FLAG
                    + "' : "
                    + value);
          }
        } else if ("POOLWAITQUEUE".equals(name.toUpperCase(locale))) {
          conConnPool.setPoolWaitQueue(rp.getValue());
          logFine("POOLWAITQUEUE");

        } else if ("DATASTRUCTUREPARAMETERS".equals(name.toUpperCase(locale))) {
          conConnPool.setDataStructureParameters(rp.getValue());
          logFine("DATASTRUCTUREPARAMETERS");

        } else if ("USERNAME".equals(name.toUpperCase(Locale.getDefault()))
            || "USER".equals(name.toUpperCase(locale))) {

          propList.add(
              new ConnectorConfigProperty("User", rp.getValue(), "user name", "java.lang.String"));

        } else if ("PASSWORD".equals(name.toUpperCase(locale))) {

          propList.add(
              new ConnectorConfigProperty(
                  "Password", rp.getValue(), "Password", "java.lang.String"));

        } else if ("JDBC30DATASOURCE".equals(name.toUpperCase(locale))) {

          propList.add(
              new ConnectorConfigProperty(
                  "JDBC30DataSource", rp.getValue(), "JDBC30DataSource", "java.lang.String"));

        } else if ("PREFER-VALIDATE-OVER-RECREATE".equals(name.toUpperCase(Locale.getDefault()))) {
          String value = rp.getValue();
          conConnPool.setPreferValidateOverRecreate(toBoolean(value, false));
          logFine("PREFER-VALIDATE-OVER-RECREATE : " + value);

        } else if ("STATEMENT-CACHE-TYPE".equals(name.toUpperCase(Locale.getDefault()))) {

          if (adminPool.getStatementCacheType() != null) {
            propList.add(
                new ConnectorConfigProperty(
                    "StatementCacheType", rp.getValue(), "StatementCacheType", "java.lang.String"));
          }

        } else if ("NUMBER-OF-TOP-QUERIES-TO-REPORT"
            .equals(name.toUpperCase(Locale.getDefault()))) {

          propList.add(
              new ConnectorConfigProperty(
                  "NumberOfTopQueriesToReport",
                  rp.getValue(),
                  "NumberOfTopQueriesToReport",
                  "java.lang.String"));

        } else if ("TIME-TO-KEEP-QUERIES-IN-MINUTES"
            .equals(name.toUpperCase(Locale.getDefault()))) {

          propList.add(
              new ConnectorConfigProperty(
                  "TimeToKeepQueriesInMinutes",
                  rp.getValue(),
                  "TimeToKeepQueriesInMinutes",
                  "java.lang.String"));

        } else if (mcfConPropKeys.containsKey(name.toUpperCase(Locale.getDefault()))) {

          propList.add(
              new ConnectorConfigProperty(
                  (String) mcfConPropKeys.get(name.toUpperCase(Locale.getDefault())),
                  rp.getValue() == null ? "" : rp.getValue(),
                  "Some property",
                  "java.lang.String"));
        } else {
          driverProperties =
              driverProperties + "set" + escape(name) + "#" + escape(rp.getValue()) + "##";
        }
      }

      if (!driverProperties.equals("")) {
        propList.add(
            new ConnectorConfigProperty(
                "DriverProperties",
                driverProperties,
                "some proprietarty properties",
                "java.lang.String"));
      }
    }

    propList.add(new ConnectorConfigProperty("Delimiter", "#", "delim", "java.lang.String"));

    propList.add(
        new ConnectorConfigProperty(
            "EscapeCharacter", "\\", "escapeCharacter", "java.lang.String"));

    // create an array of EnvironmentProperties from above list
    ConnectorConfigProperty[] eProps = new ConnectorConfigProperty[propList.size()];
    ListIterator propListIter = propList.listIterator();

    for (int i = 0; propListIter.hasNext(); i++) {
      eProps[i] = (ConnectorConfigProperty) propListIter.next();
    }

    return eProps;
  }