Search in sources :

Example 1 with StringManager

use of com.sun.enterprise.util.i18n.StringManager in project Payara by payara.

the class AdminObjectConfigParserImpl method getAdminObject.

private AdminObject getAdminObject(ConnectorDescriptor desc, String adminObjectInterface, String adminObjectClass) throws ConnectorRuntimeException {
    if (desc == null || adminObjectInterface == null) {
        throw new ConnectorRuntimeException("Invalid arguments");
    }
    Set adminObjectSet = desc.getAdminObjects();
    if (adminObjectSet == null || adminObjectSet.size() == 0) {
        return null;
    }
    AdminObject adminObject = null;
    Iterator iter = adminObjectSet.iterator();
    Properties mergedVals = null;
    boolean adminObjectFound = false;
    while (iter.hasNext()) {
        adminObject = (AdminObject) iter.next();
        if (adminObjectInterface.equals(adminObject.getAdminObjectInterface()) && (adminObjectClass == null || adminObjectClass.equals(adminObject.getAdminObjectClass()))) {
            adminObjectFound = true;
            break;
        }
    }
    if (!adminObjectFound) {
        StringManager localStrings = StringManager.getManager(AdminObjectConfigParserImpl.class);
        String msg = localStrings.getString("no_adminobject_interface_found_in_raxml", adminObjectInterface);
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, msg);
        }
        throw new ConnectorRuntimeException(msg);
    }
    return adminObject;
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) StringManager(com.sun.enterprise.util.i18n.StringManager)

Example 2 with StringManager

use of com.sun.enterprise.util.i18n.StringManager in project Payara by payara.

the class DBControl method createDBLog.

/**
 * create a db.log file that stdout/stderr will redirect to. dbhome is the
 * h2.system.home directory where derb.log gets created. if user specified
 * --dbhome options, ${db}.log will be created there.
 *
 * @param dbHome
 * @return
 * @throws java.lang.Exception
 */
private String createDBLog(final String dbHome) throws Exception {
    // dbHome must exist and  have write permission
    final File fDBHome = new File(dbHome);
    String dbLogFilePath;
    final StringManager localManager = StringManager.getManager(this.getClass());
    if (fDBHome.isDirectory() && fDBHome.canWrite()) {
        final File fDBLog = new File(dbHome, getLogFileName());
        dbLogFilePath = fDBLog.toString();
        // if the file exists, check if it is writeable
        if (fDBLog.exists() && !fDBLog.canWrite()) {
            System.out.println(localManager.getString("UnableToAccessDatabaseLog", getLogFileName(), dbLogFilePath));
            System.out.println(localManager.getString("ContinueStartingDatabase"));
            // if exist but not able to write then create a temporary
            // log file and persist on starting the database
            dbLogFilePath = createTempLogFile();
        } else if (!fDBLog.exists()) {
            // Create the log file
            if (!fDBLog.createNewFile()) {
                System.out.println(localManager.getString("UnableToCreateDatabaseLog", getLogFileName(), dbLogFilePath));
            }
        }
    } else {
        System.out.println(localManager.getString("InvalidDBDirectory", dbHome));
        System.out.println(localManager.getString("ContinueStartingDatabase"));
        // if directory does not exist then create a temporary log file
        // and persist on starting the database
        dbLogFilePath = createTempLogFile();
    }
    return dbLogFilePath;
}
Also used : File(java.io.File) StringManager(com.sun.enterprise.util.i18n.StringManager)

Example 3 with StringManager

use of com.sun.enterprise.util.i18n.StringManager in project Payara by payara.

the class DBControl method createTempLogFile.

/**
 * creates a temporary log file.
 *
 * @return
 * @throws org.glassfish.api.admin.CommandException
 */
private String createTempLogFile() throws CommandException {
    String tempFileName = "";
    try {
        final File fTemp = File.createTempFile("foo", null);
        fTemp.deleteOnExit();
        tempFileName = fTemp.toString();
    } catch (IOException ioe) {
        final StringManager localManager = StringManager.getManager(this.getClass());
        throw new CommandException(localManager.getString("UnableToAccessDatabaseLog", tempFileName));
    }
    return tempFileName;
}
Also used : IOException(java.io.IOException) CommandException(org.glassfish.api.admin.CommandException) File(java.io.File) StringManager(com.sun.enterprise.util.i18n.StringManager)

Example 4 with StringManager

use of com.sun.enterprise.util.i18n.StringManager in project Payara by payara.

the class CPManagedConnectionFactory method createManagedConnection.

/**
 * Creates a new physical connection to the underlying EIS resource
 * manager.
 *
 * @param subject       <code>Subject</code> instance passed by the application server
 * @param cxRequestInfo <code>ConnectionRequestInfo</code> which may be created
 *                      as a result of the invocation <code>getConnection(user, password)</code>
 *                      on the <code>DataSource</code> object
 * @return <code>ManagedConnection</code> object created
 * @throws ResourceException           if there is an error in instantiating the
 *                                     <code>DataSource</code> object used for the
 *                                     creation of the <code>ManagedConnection</code> object
 * @throws SecurityException           if there ino <code>PasswordCredential</code> object
 *                                     satisfying this request
 * @throws ResourceAllocationException if there is an error in allocating the
 *                                     physical connection
 */
public javax.resource.spi.ManagedConnection createManagedConnection(javax.security.auth.Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException {
    logFine("In createManagedConnection");
    PasswordCredential pc = SecurityUtils.getPasswordCredential(this, subject, cxRequestInfo);
    javax.sql.ConnectionPoolDataSource dataSource = getDataSource();
    javax.sql.PooledConnection cpConn = null;
    ManagedConnectionImpl mc = null;
    try {
        /* For the case where the user/passwd of the connection pool is
            * equal to the PasswordCredential for the connection request
            * get a connection from this pool directly.
            * for all other conditions go create a new connection
            */
        String user = getUser();
        if (user == null || isEqual(pc, user, getPassword())) {
            cpConn = dataSource.getPooledConnection();
        } else {
            cpConn = dataSource.getPooledConnection(pc.getUserName(), new String(pc.getPassword()));
        }
    } catch (java.sql.SQLException sqle) {
        // _logger.log(Level.SEVERE, "jdbc.exc_create_ds_conn",sqle);
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, "jdbc.exc_create_ds_conn", sqle);
        }
        StringManager sm = StringManager.getManager(DataSourceObjectBuilder.class);
        String msg = sm.getString("jdbc.cannot_allocate_connection", sqle.getMessage());
        ResourceAllocationException rae = new ResourceAllocationException(msg, sqle);
        throw rae;
    }
    try {
        mc = constructManagedConnection(cpConn, null, pc, this);
        mc.initializeConnectionType(ManagedConnectionImpl.ISPOOLEDCONNECTION);
        // GJCINT
        validateAndSetIsolation(mc);
    } finally {
        if (mc == null) {
            if (cpConn != null) {
                try {
                    cpConn.close();
                } catch (SQLException e) {
                    _logger.log(Level.FINEST, "Exception while closing connection : createManagedConnection" + cpConn);
                }
            }
        }
    }
    return mc;
}
Also used : SQLException(java.sql.SQLException) DataSourceObjectBuilder(com.sun.gjc.common.DataSourceObjectBuilder) SQLException(java.sql.SQLException) PasswordCredential(javax.resource.spi.security.PasswordCredential) ResourceAllocationException(javax.resource.spi.ResourceAllocationException) StringManager(com.sun.enterprise.util.i18n.StringManager)

Example 5 with StringManager

use of com.sun.enterprise.util.i18n.StringManager in project Payara by payara.

the class DSManagedConnectionFactory method createManagedConnection.

/**
 * Creates a new physical connection to the underlying EIS resource
 * manager.
 *
 * @param subject       <code>Subject</code> instance passed by the application server
 * @param cxRequestInfo <code>ConnectionRequestInfo</code> which may be created
 *                      as a result of the invocation <code>getConnection(user, password)</code>
 *                      on the <code>DataSource</code> object
 * @return <code>ManagedConnection</code> object created
 * @throws ResourceException           if there is an error in instantiating the
 *                                     <code>DataSource</code> object used for the
 *                                     creation of the <code>ManagedConnection</code> object
 * @throws SecurityException           if there ino <code>PasswordCredential</code> object
 *                                     satisfying this request
 * @throws ResourceAllocationException if there is an error in allocating the
 *                                     physical connection
 */
public javax.resource.spi.ManagedConnection createManagedConnection(javax.security.auth.Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException {
    logFine("In createManagedConnection");
    PasswordCredential pc = SecurityUtils.getPasswordCredential(this, subject, cxRequestInfo);
    javax.sql.DataSource dataSource = getDataSource();
    java.sql.Connection dsConn = null;
    ManagedConnectionImpl mc = null;
    try {
        /* For the case where the user/passwd of the connection pool is
            * equal to the PasswordCredential for the connection request
            * get a connection from this pool directly.
            * for all other conditions go create a new connection
            */
        String user = getUser();
        if (user == null || isEqual(pc, user, getPassword())) {
            dsConn = dataSource.getConnection();
        } else {
            dsConn = dataSource.getConnection(pc.getUserName(), new String(pc.getPassword()));
        }
    } catch (java.sql.SQLException sqle) {
        // _logger.log(Level.WARNING, "jdbc.exc_create_conn", sqle.getMessage());
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, "jdbc.exc_create_conn", sqle.getMessage());
        }
        StringManager localStrings = StringManager.getManager(DataSourceObjectBuilder.class);
        String msg = localStrings.getString("jdbc.cannot_allocate_connection", sqle.getMessage());
        ResourceAllocationException rae = new ResourceAllocationException(msg);
        rae.initCause(sqle);
        throw rae;
    }
    try {
        mc = constructManagedConnection(null, dsConn, pc, this);
        // GJCINT
        validateAndSetIsolation(mc);
    } finally {
        if (mc == null) {
            if (dsConn != null) {
                try {
                    dsConn.close();
                } catch (SQLException e) {
                    _logger.log(Level.FINEST, "Exception while closing connection : " + "createManagedConnection" + dsConn);
                }
            }
        }
    }
    return mc;
}
Also used : SQLException(java.sql.SQLException) DataSourceObjectBuilder(com.sun.gjc.common.DataSourceObjectBuilder) SQLException(java.sql.SQLException) PasswordCredential(javax.resource.spi.security.PasswordCredential) ResourceAllocationException(javax.resource.spi.ResourceAllocationException) StringManager(com.sun.enterprise.util.i18n.StringManager)

Aggregations

StringManager (com.sun.enterprise.util.i18n.StringManager)7 DataSourceObjectBuilder (com.sun.gjc.common.DataSourceObjectBuilder)3 SQLException (java.sql.SQLException)3 ResourceAllocationException (javax.resource.spi.ResourceAllocationException)3 PasswordCredential (javax.resource.spi.security.PasswordCredential)3 File (java.io.File)2 IOException (java.io.IOException)2 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)1 SecurityUtils.getPasswordCredential (com.sun.gjc.util.SecurityUtils.getPasswordCredential)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 UnrecoverableKeyException (java.security.UnrecoverableKeyException)1 CertificateException (java.security.cert.CertificateException)1 CommandException (org.glassfish.api.admin.CommandException)1