Search in sources :

Example 1 with GlassFishORBHelper

use of org.glassfish.enterprise.iiop.api.GlassFishORBHelper in project Payara by payara.

the class TransactionServiceProperties method getJTSProperties.

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
                 */
                // default value
                int jtsServerId = DEFAULT_SERVER_ID;
                if (isORBAvailable) {
                    jtsServerId = serviceLocator.<GlassFishORBHelper>getService(GlassFishORBHelper.class).getORBInitialPort();
                    if (jtsServerId == 0) {
                        // XXX Can this ever happen?
                        // default value
                        jtsServerId = DEFAULT_SERVER_ID;
                    }
                }
                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;
}
Also used : TransactionService(com.sun.enterprise.transaction.config.TransactionService) Server(com.sun.enterprise.config.serverbeans.Server) Cluster(com.sun.enterprise.config.serverbeans.Cluster) GlassFishORBHelper(org.glassfish.enterprise.iiop.api.GlassFishORBHelper) Properties(java.util.Properties) ProcessEnvironment(org.glassfish.api.admin.ProcessEnvironment) ServerContext(org.glassfish.internal.api.ServerContext) Domain(com.sun.enterprise.config.serverbeans.Domain) Property(org.jvnet.hk2.config.types.Property) SystemProperty(com.sun.enterprise.config.serverbeans.SystemProperty) File(java.io.File)

Example 2 with GlassFishORBHelper

use of org.glassfish.enterprise.iiop.api.GlassFishORBHelper in project Payara by payara.

the class SafeProperties method initializeProtocolManager.

protected void initializeProtocolManager() {
    try {
        GlassFishORBHelper orbHelper = ejbContainerUtilImpl.getORBHelper();
        protocolMgr = orbHelper.getProtocolManager();
    } catch (Throwable t) {
        throw new RuntimeException("IIOP Protocol Manager initialization failed.  " + "Possible cause is that ORB is not available in this " + ((ejbContainerUtilImpl.isEmbeddedServer()) ? "embedded container, or server instance is running and required ports are in use" : "container"), t);
    }
}
Also used : GlassFishORBHelper(org.glassfish.enterprise.iiop.api.GlassFishORBHelper)

Example 3 with GlassFishORBHelper

use of org.glassfish.enterprise.iiop.api.GlassFishORBHelper in project Payara by payara.

the class SerializableS1ASEJBObjectReference method doRemoteRefClassLoaderConversion.

protected static java.rmi.Remote doRemoteRefClassLoaderConversion(java.rmi.Remote reference) throws IOException {
    Thread currentThread = Thread.currentThread();
    ClassLoader contextClassLoader = currentThread.getContextClassLoader();
    java.rmi.Remote returnReference = reference;
    if (reference.getClass().getClassLoader() != contextClassLoader) {
        try {
            byte[] serializedRef = EJBObjectOutputStreamHandler._javaEEIOUtils.serializeObject(reference, false);
            returnReference = (java.rmi.Remote) EJBObjectOutputStreamHandler._javaEEIOUtils.deserializeObject(serializedRef, false, contextClassLoader);
            GlassFishORBHelper orbHelper = EjbContainerUtilImpl.getInstance().getORBHelper();
            ProtocolManager protocolMgr = orbHelper.getProtocolManager();
            protocolMgr.connectObject(returnReference);
        } catch (IOException ioe) {
            throw ioe;
        } catch (Exception e) {
            IOException ioEx = new IOException(e.getMessage());
            ioEx.initCause(e);
            throw ioEx;
        }
    }
    return returnReference;
}
Also used : ProtocolManager(org.glassfish.enterprise.iiop.api.ProtocolManager) GlassFishORBHelper(org.glassfish.enterprise.iiop.api.GlassFishORBHelper) IOException(java.io.IOException) IOException(java.io.IOException) NamingException(javax.naming.NamingException)

Example 4 with GlassFishORBHelper

use of org.glassfish.enterprise.iiop.api.GlassFishORBHelper in project Payara by payara.

the class EjbNamingReferenceManagerImpl method resolveEjbReference.

@Override
public Object resolveEjbReference(EjbReferenceDescriptor ejbRefDesc, Context context) throws NamingException {
    Object jndiObj = null;
    boolean resolved = false;
    if (ejbRefDesc.isLocal()) {
        // Otherwise, the ejb will be resolved by EJBUtils.
        if (ejbRefDesc.hasLookupName()) {
            jndiObj = context.lookup(ejbRefDesc.getLookupName());
            resolved = true;
        }
    } else if (!ejbRefDesc.hasJndiName() && ejbRefDesc.hasLookupName()) {
        // loader to the thread.  Issue 17376.
        try {
            jndiObj = context.lookup(ejbRefDesc.getLookupName());
        } catch (NamingException e) {
            ClassLoader oldLoader = null;
            try {
                oldLoader = Utility.setContextClassLoader(ejbRefDesc.getReferringBundleDescriptor().getClassLoader());
                jndiObj = context.lookup(ejbRefDesc.getLookupName());
            } finally {
                Utility.setContextClassLoader(oldLoader);
            }
        }
        resolved = true;
    } else if (ejbRefDesc.hasJndiName() && ejbRefDesc.getJndiName().startsWith("java:app/") && !ejbRefDesc.getJndiName().startsWith("java:app/env/")) {
        // This could be an @EJB dependency in an appclient whose target name
        // is a portable java:app ejb name.  Try the global version.  If that
        // doesn't work, the javaURLContext logic should be able to figure it
        // out.
        String remoteJndiName = ejbRefDesc.getJndiName();
        String appName = (String) context.lookup("java:app/AppName");
        String newPrefix = "java:global/" + appName + "/";
        int javaAppLength = "java:app/".length();
        String globalLookup = newPrefix + remoteJndiName.substring(javaAppLength);
        jndiObj = context.lookup(globalLookup);
        resolved = true;
    } else {
        // Get actual jndi-name from ejb module.
        String remoteJndiName = EJBUtils.getRemoteEjbJndiName(ejbRefDesc);
        // We could be resolving an ejb-ref as part of a remote lookup thread.  In that
        // case the context class loader won't be set appropriately on the thread
        // being used to process the remote naming request.   We can't just always
        // set the context class loader to the class loader of the application module
        // that defined the ejb reference.  That would cause ClassCastExceptions
        // when the returned object is assigned within a cross-application intra-server
        // lookup. So, just try to lookup the interface associated with the ejb-ref
        // using the context class loader.  If that doesn't work, explicitly use the
        // defining application's class loader.
        ClassLoader origClassLoader = Utility.getClassLoader();
        boolean setCL = false;
        try {
            try {
                String refInterface = ejbRefDesc.isEJB30ClientView() ? ejbRefDesc.getEjbInterface() : ejbRefDesc.getHomeClassName();
                origClassLoader.loadClass(refInterface);
            } catch (ClassNotFoundException e) {
                ClassLoader referringBundleClassLoader = ejbRefDesc.getReferringBundleDescriptor().getClassLoader();
                Utility.setContextClassLoader(referringBundleClassLoader);
                setCL = true;
            }
            /* For remote ejb refs, first lookup the target remote object
                 * and pass it to the next stage of ejb ref resolution.
                 * If the string is a "corbaname:...." URL
                 * the lookup happens thru the corbanameURL context,
                 * else it happens thru the context provided by the NamingManager.
                 *
                 * NOTE : we might need some additional logic to handle cross-server
                 * MEJB resolution for cluster support post V3 FCS.
                 */
            if (remoteJndiName.startsWith(CORBANAME)) {
                GlassFishORBHelper orbHelper = glassFishORBHelperProvider.get();
                ORB orb = orbHelper.getORB();
                jndiObj = (Object) orb.string_to_object(remoteJndiName);
            } else {
                jndiObj = context.lookup(remoteJndiName);
            }
        } catch (Exception e) {
            // Important to make the real underlying lookup name part of the exception.
            NamingException ne = new NamingException("Exception resolving Ejb for '" + ejbRefDesc + "' .  Actual (possibly internal) Remote JNDI name used for lookup is '" + remoteJndiName + "'");
            ne.initCause(e);
            throw ne;
        } finally {
            if (setCL) {
                Utility.setContextClassLoader(origClassLoader);
            }
        }
    }
    return resolved ? jndiObj : EJBUtils.resolveEjbRefObject(ejbRefDesc, jndiObj);
}
Also used : NamingException(javax.naming.NamingException) GlassFishORBHelper(org.glassfish.enterprise.iiop.api.GlassFishORBHelper) ORB(org.omg.CORBA.ORB) NamingException(javax.naming.NamingException)

Aggregations

GlassFishORBHelper (org.glassfish.enterprise.iiop.api.GlassFishORBHelper)4 NamingException (javax.naming.NamingException)2 Cluster (com.sun.enterprise.config.serverbeans.Cluster)1 Domain (com.sun.enterprise.config.serverbeans.Domain)1 Server (com.sun.enterprise.config.serverbeans.Server)1 SystemProperty (com.sun.enterprise.config.serverbeans.SystemProperty)1 TransactionService (com.sun.enterprise.transaction.config.TransactionService)1 File (java.io.File)1 IOException (java.io.IOException)1 Properties (java.util.Properties)1 ProcessEnvironment (org.glassfish.api.admin.ProcessEnvironment)1 ProtocolManager (org.glassfish.enterprise.iiop.api.ProtocolManager)1 ServerContext (org.glassfish.internal.api.ServerContext)1 Property (org.jvnet.hk2.config.types.Property)1 ORB (org.omg.CORBA.ORB)1