Exemple #1
0
 /**
  * This function should be the first thing called by the Admin Console to initialize the servlet.
  * If SQL config data migration is required, it will be done and periodic status updates will be
  * written to the output stream.
  *
  * @param progress Used to output SQL config data migration status updates.
  * @throws RemoteException Thrown when the DataConfig could not be initialized.
  */
 public static synchronized void initializeAdminService(ProgressManager progress)
     throws RemoteException {
   ConnectionConfig cc = getConnectionConfig();
   if (cc.migrationPending()) {
     _dataConfig = null; // set to null first in case next line fails
     _dataConfig = cc.initializeNewDataConfig(progress);
   }
 }
 static {
   CONNECTION_CONFIG = ConfigFactory.getInstance().getConnectionConfig();
   if (CONNECTION_CONFIG != null) {
     BASE_URI =
         UriBuilder.fromUri(CONNECTION_CONFIG.getContextPath())
             .path(CONNECTION_CONFIG.getBasicUri())
             .host(CONNECTION_CONFIG.getHost())
             .port(CONNECTION_CONFIG.getPort())
             .scheme("http")
             .build();
   } else {
     BASE_URI = null;
   }
 }
 protected HttpURLConnection openConnection(URL url) throws IOException {
   ConnectionConfig config = ConnectionConfig.getInstance();
   HttpURLConnection connection = null;
   if (config.useProxy()) {
     String host = config.getProxyHost();
     int port = Integer.parseInt(config.getProxyPort());
     SocketAddress addres = new InetSocketAddress(host, port);
     Proxy proxy = new Proxy(Proxy.Type.HTTP, addres);
     connection = (HttpURLConnection) url.openConnection(proxy);
   } else {
     connection = (HttpURLConnection) url.openConnection();
   }
   return connection;
 }
Exemple #4
0
  public ConnectionHandler(ConnectionConfig conConfig) {
    this.conConfig = conConfig;

    if (conConfig.isPooled()) {
      initializeConnectionPool();
    } else {
      try {
        Class.forName(conConfig.getDriver());
      } catch (ClassNotFoundException e) {
        throw new IllegalStateException(
            "The configured driver '" + conConfig.getDriver() + "' can not be found.");
      }
    }
  }
Exemple #5
0
  private void initializeConnectionPool() {
    try {
      log.info("Initializing connection " + conConfig.getId());

      // DBCP properties used to create the BasicDataSource
      Properties dbcpProperties = new Properties();

      // DriverClass & url
      dbcpProperties.put("driverClassName", conConfig.getDriver());
      dbcpProperties.put("url", conConfig.getUrl());

      // Username / password
      dbcpProperties.put("username", conConfig.getUsername());
      dbcpProperties.put("password", conConfig.getPassword());

      // Pool size
      dbcpProperties.put("maxActive", Integer.toString(conConfig.getPoolSize()));

      // Let the factory create the pool
      ds = (BasicDataSource) BasicDataSourceFactory.createDataSource(dbcpProperties);

      ds.setMaxWait(conConfig.getMaxWait()); // wait max before throwing an exception.
      ds.setTestOnBorrow(true);
      ds.setValidationQuery(conConfig.getValidationQuery());

      if (!conConfig.isLazyInit()) {
        // The BasicDataSource has lazy initialization
        // borrowing a connection will start the DataSource
        // and make sure it is configured correctly.
        Connection conn = ds.getConnection();
        conn.close();
      }

    } catch (Throwable e) {
      String message = "Unable to create DHCP pool... ";
      log.fatal(message, e);
      if (ds != null) {
        try {
          ds.close();
        } catch (Exception e2) {
          // ignore
        }
        ds = null;
      }
    }
    log.info("Configure ConnectionHandler '" + conConfig.getId() + "' complete");
  }
Exemple #6
0
 /**
  * Borrow a new connection.
  *
  * @return
  * @throws SQLException
  */
 public Connection getConnection() throws SQLException {
   connCount++;
   if (connCount == Long.MAX_VALUE) {
     connCount = Long.MIN_VALUE;
   }
   Connection conn = null;
   if (conConfig.isPooled()) {
     conn = ds.getConnection();
   } else {
     // Open connection directly
     conn =
         DriverManager.getConnection(
             conConfig.getUrl(), conConfig.getUsername(), conConfig.getPassword());
   }
   if (conConfig.isTraced()) {
     TracedConnection tc = new TracedConnection(connCount, this, conn);
     conn = tc;
     connectionList.add(tc);
   }
   return conn;
 }
Exemple #7
0
  /**
   * Close the data source.
   *
   * @throws HibernateException
   */
  public void destroy() throws EIException {
    log.info("Close ConnectionHandler '" + conConfig.getId() + "'");

    if (connectionList.size() > 0) {
      log.warn("There are still " + connectionList.size() + " connections open..");
    }

    try {
      if (ds != null) {
        ds.close();
        ds = null;
      } else {
        log.warn("Cannot close DBCP pool (not initialized)");
      }
    } catch (Exception e) {
      throw new EIException("Could not close DBCP pool", e);
    }
    log.info("Close DBCPConnectionProvider complete");
  }
  /*
   * Important: Each invocation of testConnectivity must be run in its own VM
   */
  public void testConnectivity(ConnectionConfig connConfig) throws Exception {
    connConfig.setLocalConfig();

    try {
      LdapClient.initialize();

      int expectedPort;

      if (connConfig == ConnectionConfig.LDAPI) {
        expectedPort = 1; // LdapServerPool.DUMMY_LDAPI_PORT
      } else if (connConfig == ConnectionConfig.LDAP
          || connConfig == ConnectionConfig.STARTTLS_T_UNTRUSTED_T_MISMATCHED
          || connConfig == ConnectionConfig.STARTTLS_T_UNTRUSTED_F_MISMATCHED
          || connConfig == ConnectionConfig.STARTTLS_F_UNTRUSTED_T_MISMATCHED
          || connConfig == ConnectionConfig.STARTTLS_F_UNTRUSTED_F_MISMATCHED) {
        expectedPort = 389;
      } else {
        expectedPort = 636;
      }

      UBIDLdapContext zlc1 = getContext();
      assertEquals(expectedPort, zlc1.getNative().getConnectedPort());

      ZAttributes attrs = zlc1.getAttributes("cn=zimbra", null);
      assertEquals("Zimbra Systems Application Data", attrs.getAttrString("description"));

      UBIDLdapContext zlc2 = getContext();
      assertEquals(expectedPort, zlc2.getNative().getConnectedPort());

      closeContext(zlc1);
      closeContext(zlc2);
    } finally {
      // so next test can re-initialized UBIDLdapContext and run
      LdapClient.shutdown();
    }
  }
 @Override
 public String getValue(String propertyName) {
   return sessionProperties.getProperty(propertyName, parentConfig.getValue(propertyName));
 }
Exemple #10
0
 /**
  * Returns the id of the connection managed.
  *
  * @return
  */
 public String getConnectionId() {
   return conConfig.getId();
 }