예제 #1
0
  /** JNDI object factory so the proxy can be used as a resource. */
  public Object getObjectInstance(
      Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
    Reference ref = (Reference) obj;

    String api = null;
    String url = null;
    String user = null;
    String password = null;

    for (int i = 0; i < ref.size(); i++) {
      RefAddr addr = ref.get(i);

      String type = addr.getType();
      String value = (String) addr.getContent();

      if (type.equals("type")) api = value;
      else if (type.equals("url")) url = value;
      else if (type.equals("user")) setUser(value);
      else if (type.equals("password")) setPassword(value);
    }

    if (url == null) throw new NamingException("`url' must be configured for HessianProxyFactory.");
    // XXX: could use meta protocol to grab this
    if (api == null)
      throw new NamingException("`type' must be configured for HessianProxyFactory.");

    ClassLoader loader = Thread.currentThread().getContextClassLoader();
    Class apiClass = Class.forName(api, false, loader);

    return create(apiClass, url);
  }
예제 #2
0
  public static void main(String[] args)
      throws SQLException, ClassNotFoundException, JSONException {
    PostgresDb db = new PostgresDb();
    // db.setUrl("jdbc:postgresql://localhost:5432/powaaim");

    try {
      Class.forName("org.postgresql.Driver");
      c = DriverManager.getConnection(db.getUrl(), db.getUser(), db.getPass());
    } catch (ClassNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    st = c.createStatement();
    rs = st.executeQuery("SELECT id, name, externalshopid from shop where name='David_3'");
    System.out.println("id" + " " + "name" + " " + "externalshopid");
    c.close();
    obj = new JSONObject();

    while (rs.next()) {
      int id = rs.getInt("id");
      String externaId = rs.getString("externalshopid");
      String name = rs.getString("name");
      // System.out.println(id+ " " + " "+ name + " " +" "+ externaId);
      System.out.println();
      obj.put("id", id);
      obj.put("name", name);
      obj.put("externalshopid", externaId);
      System.out.print(obj);
    }
  }
예제 #3
0
  /**
   * Tests that we can get a connection from the DataSource bound in JNDI during test setup
   *
   * @throws Exception if an error occurs
   */
  public void testDataSource() throws Exception {
    NameParser nameParser = this.ctx.getNameParser("");
    Name datasourceName = nameParser.parse("_test");
    Object obj = this.ctx.lookup(datasourceName);
    DataSource boundDs = null;

    if (obj instanceof DataSource) {
      boundDs = (DataSource) obj;
    } else if (obj instanceof Reference) {
      //
      // For some reason, this comes back as a Reference instance under CruiseControl !?
      //
      Reference objAsRef = (Reference) obj;
      ObjectFactory factory =
          (ObjectFactory) Class.forName(objAsRef.getFactoryClassName()).newInstance();
      boundDs =
          (DataSource)
              factory.getObjectInstance(
                  objAsRef, datasourceName, this.ctx, new Hashtable<Object, Object>());
    }

    assertTrue("Datasource not bound", boundDs != null);

    Connection con = boundDs.getConnection();
    con.close();
    assertTrue("Connection can not be obtained from data source", con != null);
  }
예제 #4
0
 private Connection getMYSQLConnection() {
   try {
     Class.forName("org.gjt.mm.mysql.Driver");
     return DriverManager.getConnection("jdbc:mysql://localhost/WebNmsDB", "root", null);
   } catch (Exception e) {
     e.printStackTrace();
     return null;
   }
 }
예제 #5
0
 private Connection getSYBASEConnection() {
   try {
     Class.forName("com.sybase.jdbc2.jdbc.SybDriver");
     return DriverManager.getConnection("jdbc:sybase:Tds:fe-test:2048/feDB", "sa", null);
   } catch (Exception e) {
     e.printStackTrace();
     return null;
   }
 }
예제 #6
0
 private Connection getSOLIDConnection() {
   try {
     Class.forName("solid.jdbc.SolidDriver");
     return DriverManager.getConnection("jdbc:solid://nms-clienttest1:1313/dba/dba", "dba", "dba");
   } catch (Exception e) {
     e.printStackTrace();
     return null;
   }
 }
예제 #7
0
 private Connection getTIMESTENConnection() {
   try {
     Class.forName("com.timesten.jdbc.TimesTenDriver");
     return DriverManager.getConnection("jdbc:timesten:direct:WebNmsDB", "root", null);
   } catch (Exception e) {
     e.printStackTrace();
     return null;
   }
 }
예제 #8
0
 public static Connection createConnection() throws NamingException {
   try {
     Class.forName("com.mysql.jdbc.Driver");
     con = DriverManager.getConnection("jdbc:mysql://sc0181:3306/forms_db", "test", "123321");
   } catch (SQLException e) {
     e.printStackTrace();
   } catch (Exception e) {
     e.printStackTrace();
   }
   return con;
 }
 public Connection createConnection() throws Exception {
   Connection con;
   try {
     Class.forName(dbClass);
     con = DriverManager.getConnection(dbUrl, dbUser, dbPassword);
   } catch (Exception e) {
     e.printStackTrace();
     throw e;
   }
   return con;
 }
예제 #10
0
  private Connection getORACLEConnection() {
    try {

      Class.forName("oracle.jdbc.driver.OracleDriver");
      return DriverManager.getConnection(
          "jdbc:oracle:thin:@kernel-win:1521:oracle", "BFW3", "BFW3");
    } catch (Exception e) {
      e.printStackTrace();
      return null;
    }
  }
예제 #11
0
  /**
   * Establece una conexión con la base de datos, usando el usuario y clave especificados. Si ya hay
   * una conexi�n, esta es cerrada.
   *
   * @param usuario Una cadena con el nombre de usuario
   * @param clave Una cadena con la clave
   * @return Regresa verdadero (true) si pudo establecer la conexión de lo contrario regresa falso
   *     (false).
   */
  protected boolean conectar(String usuario, String clave) throws Exception {

    // Registra el controlador de manera implicita
    Class.forName(controlador).newInstance();
    // Obtiene la conexión
    System.err.println(url + "," + usuario + "," + clave + ":OK!!!");
    this.conexión = DriverManager.getConnection(url, usuario, clave);
    // Actualiza usuario y clave del middler
    this.usuario = usuario;
    this.clave = clave;
    return this.conexión != null;
  } // Fin conectar
 private void updateDB() {
   try {
     // Class.forName("com.inet.ora.OraDriver");
     Class.forName("org.apache.derby.jdbc.ClientDriver");
     //// String url = "jdbc:inetora::wrx.india.sun.com:1521:dbsmpl1";
     String url = "jdbc:derby://localhost:1527/testdb;create=true;";
     java.sql.Connection con = DriverManager.getConnection(url, "dbuser", "dbpassword");
     String qry = "update lifecycle_test1 set status=1";
     con.createStatement().executeUpdate(qry);
     con.close();
   } catch (Exception e) {
     System.out.println("Error:" + e.getMessage());
   }
 }
예제 #13
0
 /** Set up a pool with a given key. */
 public synchronized ConnectionPool addAlias(
     String poolKey,
     String driverClassName,
     String dbURL,
     String userName,
     String password,
     int maxSize,
     long expiration)
     throws ClassNotFoundException, InstantiationException, IllegalAccessException {
   Class.forName(driverClassName).newInstance();
   ConnectionPool cp = new ConnectionPool(dbURL, userName, password, maxSize, expiration, debug);
   poolMap.put(poolKey, cp);
   return cp;
 }
예제 #14
0
  /**
   * Creates a new proxy with the specified URL. The API class uses the java.api.class value from
   * _hessian_
   *
   * @param url the URL where the client object is located.
   * @return a proxy to the object with the specified interface.
   */
  public Object create(String url) throws MalformedURLException, ClassNotFoundException {
    HessianMetaInfoAPI metaInfo;

    metaInfo = (HessianMetaInfoAPI) create(HessianMetaInfoAPI.class, url);

    String apiClassName = (String) metaInfo._hessian_getAttribute("java.api.class");

    if (apiClassName == null) throw new HessianRuntimeException(url + " has an unknown api.");

    ClassLoader loader = Thread.currentThread().getContextClassLoader();

    Class apiClass = Class.forName(apiClassName, false, loader);

    return create(apiClass, url);
  }
  // The default constructor
  public CrownCounselIndexGetList_Access() {
    String traceProp = null;
    if ((traceProp = System.getProperty(HOSTPUBLISHER_ACCESSBEAN_TRACE)) != null) {
      try {
        Class c = Class.forName(HOSTPUBLISHER_ACCESSTRACE_OBJECT);
        Method m = c.getMethod("getInstance", null);
        o = m.invoke(null, null);
        Class parmTypes[] = {String.class};
        m = c.getMethod("initTrace", parmTypes);
        Object initTraceArgs[] = {traceProp};
        BitSet tracingBS = (BitSet) m.invoke(o, initTraceArgs);
        Class parmTypes2[] = {Object.class, String.class};
        traceMethod = c.getMethod("trace", parmTypes2);
        tracing = tracingBS.get(HOSTPUBLISHER_ACCESSBEAN_TRACING);
        Class parmTypes3[] = {String.class, HttpSession.class};
        auditMethod = c.getMethod("audit", parmTypes3);
        auditing = tracingBS.get(HOSTPUBLISHER_ACCESSBEAN_AUDITING);
      } catch (Exception e) {
        // no tracing will be done
        System.err.println(
            (new Date(System.currentTimeMillis())).toString()
                + " hostpublisher.accessbean.trace="
                + traceProp
                + ", Exception="
                + e.toString());
      }
    }

    if (tracing == true) {
      traceArgs[0] = this;
      traceArgs[1] = " CrownCounselIndexGetList_Access()";
      try {
        traceMethod.invoke(o, traceArgs);
      } catch (Exception x) {
        System.err.println(
            (new Date(System.currentTimeMillis())).toString()
                + " traceMethod.invoke(null, traceArgs)"
                + ", Exception="
                + x.toString());
      }
    }
    inputProps = new CrownCounselIndexGetList_Properties();
    return;
  }
 public static void createConnectionPool() {
   Context context;
   try {
     context = new InitialContext();
     Class.forName("org.firebirdsql.jdbc.FBDriver");
     ds = (DataSource) context.lookup("java:comp/env/jdbc/PanelTrackDB");
     Connection c = ds.getConnection();
   } catch (NamingException e) {
     // TODO Auto-generated catch block
     errorLogger.error("An Error Occured:", e);
     e.printStackTrace();
   } catch (ClassNotFoundException e) {
     errorLogger.error("An Error Occured:", e);
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (SQLException e) {
     errorLogger.error("An Error Occured:", e);
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
  @Override
  public void contextInitialized(ServletContextEvent arg0) {
    final String S_ProcName = "contextInitialized";

    Properties props = System.getProperties();
    if (null == CFBamSchemaPool.getSchemaPool()) {
      try {
        Context ctx = new InitialContext();
        String poolClassName = (String) ctx.lookup("java:comp/env/CFBam24PoolClass");
        if ((poolClassName == null) || (poolClassName.length() <= 0)) {
          throw CFLib.getDefaultExceptionFactory()
              .newNullArgumentException(
                  getClass(), S_ProcName, 0, "JNDI lookup for CFBam24PoolClass");
        }

        Class poolClass = Class.forName(poolClassName);
        if (poolClass == null) {
          throw CFLib.getDefaultExceptionFactory()
              .newNullArgumentException(
                  getClass(),
                  S_ProcName,
                  0,
                  "CFBam24PoolClass \"" + poolClassName + "\" not found.");
        }

        Object obj = poolClass.newInstance();
        if (obj instanceof CFBamSchemaPool) {
          CFBamSchemaPool newPool = (CFBamSchemaPool) obj;
          newPool.setConfigurationFile(null);
          newPool.setJndiName("java:comp/env/CFBam24Connection");
          CFBamSchemaPool.setSchemaPool(newPool);
        } else {
          throw CFLib.getDefaultExceptionFactory()
              .newRuntimeException(
                  getClass(), S_ProcName, "Problems constructing an instance of " + poolClassName);
        }

        String smtpHost = (String) ctx.lookup("java:comp/env/CFBam24SmtpHost");
        if ((smtpHost == null) || (smtpHost.length() <= 0)) {
          throw CFLib.getDefaultExceptionFactory()
              .newNullArgumentException(
                  getClass(), S_ProcName, 0, "JNDI lookup for CFBam24SmtpHost");
        }
        props.setProperty("mail.smtp.host", smtpHost);

        String smtpStartTLS = (String) ctx.lookup("java:comp/env/CFBam24SmtpStartTLS");
        if ((smtpHost == null) || (smtpHost.length() <= 0)) {
          throw CFLib.getDefaultExceptionFactory()
              .newNullArgumentException(
                  getClass(), S_ProcName, 0, "JNDI lookup for CFBam24SmtpStartTLS");
        }
        props.setProperty("mail.smtp.starttls.enable", smtpStartTLS);

        String smtpSocketFactoryClass =
            (String) ctx.lookup("java:comp/env/CFBam24SmtpSocketFactoryClass");
        if ((smtpSocketFactoryClass == null) || (smtpSocketFactoryClass.length() <= 0)) {
          throw CFLib.getDefaultExceptionFactory()
              .newNullArgumentException(
                  getClass(), S_ProcName, 0, "JNDI lookup for CFBam24SmtpSocketFactoryClass");
        }
        props.setProperty("mail.smtp.socketFactory.class", smtpSocketFactoryClass);

        props.setProperty("mail.smtp.socketFactory.fallback", "false");

        String smtpPort = (String) ctx.lookup("java:comp/env/CFBam24SmtpPort");
        if ((smtpPort == null) || (smtpPort.length() <= 0)) {
          throw CFLib.getDefaultExceptionFactory()
              .newNullArgumentException(
                  getClass(), S_ProcName, 0, "JNDI lookup for CFBam24SmtpPort");
        }
        props.setProperty("mail.smtp.port", smtpPort);
        props.setProperty("mail.smtp.socketFactory.port", smtpPort);

        props.setProperty("mail.smtps.auth", "true");

        props.put("mail.smtps.quitwait", "false");

        String smtpEmailFrom = (String) ctx.lookup("java:comp/env/CFBam24SmtpEmailFrom");
        if ((smtpEmailFrom == null) || (smtpEmailFrom.length() <= 0)) {
          throw CFLib.getDefaultExceptionFactory()
              .newNullArgumentException(
                  getClass(), S_ProcName, 0, "JNDI lookup for CFBam24SmtpEmailFrom");
        }

        smtpUsername = (String) ctx.lookup("java:comp/env/CFBam24SmtpUsername");
        if ((smtpUsername == null) || (smtpUsername.length() <= 0)) {
          throw CFLib.getDefaultExceptionFactory()
              .newNullArgumentException(
                  getClass(), S_ProcName, 0, "JNDI lookup for CFBam24SmtpUsername");
        }

        smtpPassword = (String) ctx.lookup("java:comp/env/CFBam24SmtpPassword");
        if ((smtpPassword == null) || (smtpPassword.length() <= 0)) {
          throw CFLib.getDefaultExceptionFactory()
              .newNullArgumentException(
                  getClass(), S_ProcName, 0, "JNDI lookup for CFBam24SmtpPassword");
        }

        String serverKeyStore;
        try {
          serverKeyStore = (String) ctx.lookup("java:comp/env/CFBam24ServerKeyStore");
        } catch (NamingException e) {
          serverKeyStore = null;
        }

        String keyStorePassword;
        try {
          keyStorePassword = (String) ctx.lookup("java:comp/env/CFBam24KeyStorePassword");
        } catch (NamingException e) {
          keyStorePassword = null;
        }

        String keyName;
        try {
          keyName = (String) ctx.lookup("java:comp/env/CFBam24KeyName");
        } catch (NamingException e) {
          keyName = null;
        }

        String keyPassword;
        try {
          keyPassword = (String) ctx.lookup("java:comp/env/CFBam24KeyPassword");
        } catch (NamingException e) {
          keyPassword = null;
        }

        if (((serverKeyStore != null) && (serverKeyStore.length() > 0))
            && (keyStorePassword != null)
            && ((keyName != null) && (keyName.length() > 0))
            && (keyPassword != null)) {
          KeyStore keyStore = null;
          File keystoreFile = new File(serverKeyStore);
          if (!keystoreFile.exists()) {
            throw CFLib.getDefaultExceptionFactory()
                .newUsageException(
                    getClass(),
                    S_ProcName,
                    "CFBam24ServerKeyStore file \"" + serverKeyStore + "\" does not exist.");
          } else if (!keystoreFile.isFile()) {
            throw CFLib.getDefaultExceptionFactory()
                .newUsageException(
                    getClass(),
                    S_ProcName,
                    "CFBam24ServerKeyStore file \"" + serverKeyStore + "\" is not a file.");
          } else if (!keystoreFile.canRead()) {
            throw CFLib.getDefaultExceptionFactory()
                .newUsageException(
                    getClass(),
                    S_ProcName,
                    "Permission denied attempting to read CFBam24ServerKeyStore file \""
                        + serverKeyStore
                        + "\".");
          }

          try {
            keyStore = KeyStore.getInstance("jceks");
            char[] caPassword = keyStorePassword.toCharArray();
            FileInputStream input = new FileInputStream(serverKeyStore);
            keyStore.load(input, caPassword);
            input.close();
            Certificate publicKeyCertificate = keyStore.getCertificate(keyName);
            if (publicKeyCertificate == null) {
              throw CFLib.getDefaultExceptionFactory()
                  .newUsageException(
                      getClass(),
                      S_ProcName,
                      "Could not read CFBam24KeyName \""
                          + keyName
                          + "\" from CFBam24ServerKeyStore file \""
                          + serverKeyStore
                          + "\".");
            }
            publicKey = publicKeyCertificate.getPublicKey();
            char[] caKeyPassword = keyPassword.toCharArray();
            Key key = keyStore.getKey(keyName, caKeyPassword);
            if (key instanceof PrivateKey) {
              privateKey = (PrivateKey) key;
            } else {
              throw CFLib.getDefaultExceptionFactory()
                  .newUnsupportedClassException(getClass(), S_ProcName, "key", key, "PrivateKey");
            }

            getServerInfo();
          } catch (CertificateException x) {
            publicKey = null;
            privateKey = null;
            throw CFLib.getDefaultExceptionFactory()
                .newRuntimeException(
                    getClass(),
                    S_ProcName,
                    "Could not open keystore due to CertificateException -- " + x.getMessage(),
                    x);
          } catch (IOException x) {
            publicKey = null;
            privateKey = null;
            throw CFLib.getDefaultExceptionFactory()
                .newRuntimeException(
                    getClass(),
                    S_ProcName,
                    "Could not open keystore due to IOException -- " + x.getMessage(),
                    x);
          } catch (KeyStoreException x) {
            publicKey = null;
            privateKey = null;
            throw CFLib.getDefaultExceptionFactory()
                .newRuntimeException(
                    getClass(),
                    S_ProcName,
                    "Could not open keystore due to KeyStoreException -- " + x.getMessage(),
                    x);
          } catch (NoSuchAlgorithmException x) {
            publicKey = null;
            privateKey = null;
            throw CFLib.getDefaultExceptionFactory()
                .newRuntimeException(
                    getClass(),
                    S_ProcName,
                    "Could not open keystore due to NoSuchAlgorithmException -- " + x.getMessage(),
                    x);
          } catch (UnrecoverableKeyException x) {
            publicKey = null;
            privateKey = null;
            throw CFLib.getDefaultExceptionFactory()
                .newRuntimeException(
                    getClass(),
                    S_ProcName,
                    "Could not access key due to UnrecoverableKeyException -- " + x.getMessage(),
                    x);
          } catch (RuntimeException x) {
            publicKey = null;
            privateKey = null;
            throw x;
          }
        } else if ((serverKeyStore != null)
            || (keyStorePassword != null)
            || (keyName != null)
            || (keyPassword != null)) {
          publicKey = null;
          privateKey = null;
          throw CFLib.getDefaultExceptionFactory()
              .newUsageException(
                  getClass(),
                  S_ProcName,
                  "All or none of CFBam24ServerKeyStore, "
                      + "CFBam24KeyStorePassword, "
                      + "CFBam24KeyName, and "
                      + "CFBam24KeyPassword must be configured");
        } else {
          getServerInfo();
          try {
            serverInfo.initServerKeys();
          } catch (Exception x) {
            throw CFLib.getDefaultExceptionFactory()
                .newRuntimeException(
                    getClass(),
                    S_ProcName,
                    "Caught "
                        + x.getClass().getName()
                        + " during initServerKeys() -- "
                        + x.getMessage(),
                    x);
          }
        }
      } catch (ClassNotFoundException e) {
        publicKey = null;
        privateKey = null;
        throw CFLib.getDefaultExceptionFactory()
            .newRuntimeException(
                getClass(), S_ProcName, "Caught ClassNotFoundException -- " + e.getMessage(), e);
      } catch (IllegalAccessException e) {
        publicKey = null;
        privateKey = null;
        throw CFLib.getDefaultExceptionFactory()
            .newRuntimeException(
                getClass(),
                S_ProcName,
                "Caught IllegalAccessException trying to construct newInstance() -- "
                    + e.getMessage(),
                e);
      } catch (InstantiationException e) {
        publicKey = null;
        privateKey = null;
        throw CFLib.getDefaultExceptionFactory()
            .newRuntimeException(
                getClass(),
                S_ProcName,
                "Caught InstantiationException trying to construct newInstance() -- "
                    + e.getMessage(),
                e);
      } catch (NamingException e) {
        publicKey = null;
        privateKey = null;
        throw CFLib.getDefaultExceptionFactory()
            .newRuntimeException(
                getClass(), S_ProcName, "Caught NamingException -- " + e.getMessage(), e);
      }
    }
  }