Search in sources :

Example 41 with OpenEJBRuntimeException

use of org.apache.openejb.OpenEJBRuntimeException in project tomee by apache.

the class ReloadableEntityManagerFactory method createDelegate.

public void createDelegate() {
    JPAThreadContext.infos.put("properties", entityManagerFactoryCallable.getUnitInfo().getProperties());
    final long start = System.nanoTime();
    try {
        delegate = entityManagerFactoryCallable.call();
    } catch (final Exception e) {
        throw new OpenEJBRuntimeException(e);
    } finally {
        final long time = TimeUnit.MILLISECONDS.convert(System.nanoTime() - start, TimeUnit.NANOSECONDS);
        LOGGER.info("assembler.buildingPersistenceUnit", unitInfoImpl.getPersistenceUnitName(), unitInfoImpl.getPersistenceProviderClassName(), String.valueOf(time));
        if (LOGGER.isDebugEnabled()) {
            for (final Map.Entry<Object, Object> entry : unitInfoImpl.getProperties().entrySet()) {
                LOGGER.debug(entry.getKey() + "=" + entry.getValue());
            }
        }
        JPAThreadContext.infos.clear();
    }
}
Also used : OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) Map(java.util.Map) NamingException(javax.naming.NamingException) InvalidObjectException(java.io.InvalidObjectException) OpenEJBException(org.apache.openejb.OpenEJBException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ObjectStreamException(java.io.ObjectStreamException) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException)

Example 42 with OpenEJBRuntimeException

use of org.apache.openejb.OpenEJBRuntimeException in project tomee by apache.

the class StaticDESPasswordCipher method encrypt.

/**
 * @throws RuntimeException in any case of error.
 * @see org.apache.openejb.cipher.PasswordCipher#encrypt(String)
 */
public char[] encrypt(final String plainPassword) {
    if (null == plainPassword || plainPassword.length() == 0) {
        throw new IllegalArgumentException("plainPassword cannot be null nor empty.");
    }
    final byte[] plaintext = plainPassword.getBytes();
    try {
        // Get a 3DES Cipher object
        final Cipher cipher = Cipher.getInstance(TRANSFORMATION);
        // Set it into encryption mode
        cipher.init(Cipher.ENCRYPT_MODE, KEY);
        // Encrypt data
        final byte[] cipherText = cipher.doFinal(plaintext);
        return new String(Base64.encodeBase64(cipherText)).toCharArray();
    } catch (final Exception e) {
        throw new OpenEJBRuntimeException(e);
    }
}
Also used : OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) Cipher(javax.crypto.Cipher) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException)

Example 43 with OpenEJBRuntimeException

use of org.apache.openejb.OpenEJBRuntimeException in project tomee by apache.

the class NameNode method createSubcontext.

public IvmContext createSubcontext(final ParsedName name, final boolean createReadOnlyContext) throws NameAlreadyBoundException {
    try {
        bind(name, null);
        name.reset();
        return (IvmContext) resolve(name, createReadOnlyContext);
    } catch (final NameNotFoundException exception) {
        exception.printStackTrace();
        throw new OpenEJBRuntimeException(exception);
    }
}
Also used : OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) NameNotFoundException(javax.naming.NameNotFoundException)

Example 44 with OpenEJBRuntimeException

use of org.apache.openejb.OpenEJBRuntimeException in project tomee by apache.

the class CDILoginModule method initialize.

@Override
public void initialize(final Subject subject, final CallbackHandler callbackHandler, final Map<String, ?> sharedState, final Map<String, ?> options) {
    final WebBeansContext webBeansContext = WebBeansContext.currentInstance();
    final BeanManagerImpl bm = webBeansContext.getBeanManagerImpl();
    if (!bm.isInUse()) {
        throw new OpenEJBRuntimeException("CDI not activated");
    }
    String delegate = String.valueOf(options.get("delegate"));
    if ("null".equals(delegate)) {
        final String app = findAppName(webBeansContext);
        delegate = String.valueOf(options.get(app));
        if ("null".equals(delegate)) {
            throw new OpenEJBRuntimeException("Please specify a delegate class");
        }
    }
    final Class<?> clazz;
    try {
        clazz = Thread.currentThread().getContextClassLoader().loadClass(delegate);
    } catch (final ClassNotFoundException e) {
        throw new OpenEJBRuntimeException(e.getMessage(), e);
    }
    cc = bm.createCreationalContext(null);
    final String cdiName = String.valueOf(options.get("cdiName"));
    if ("true".equals(String.valueOf(options.get("loginModuleAsCdiBean")))) {
        final Set<Bean<?>> beans;
        if ("null".equals(cdiName)) {
            beans = bm.getBeans(clazz);
        } else {
            beans = bm.getBeans(cdiName);
        }
        loginModule = LoginModule.class.cast(bm.getReference(bm.resolve(beans), clazz, cc));
    } else {
        try {
            loginModule = LoginModule.class.cast(clazz.newInstance());
            OWBInjector.inject(bm, loginModule, cc);
        } catch (final Exception e) {
            throw new OpenEJBRuntimeException("Can't inject into delegate class " + loginModule, e);
        }
    }
    loginModule.initialize(subject, callbackHandler, sharedState, options);
}
Also used : OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) WebBeansContext(org.apache.webbeans.config.WebBeansContext) BeanManagerImpl(org.apache.webbeans.container.BeanManagerImpl) LoginModule(javax.security.auth.spi.LoginModule) LoginException(javax.security.auth.login.LoginException) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) Bean(javax.enterprise.inject.spi.Bean)

Example 45 with OpenEJBRuntimeException

use of org.apache.openejb.OpenEJBRuntimeException in project tomee by apache.

the class EjbTimerServiceImpl method shutdown.

private static void shutdown(final Scheduler s) throws OpenEJBRuntimeException {
    try {
        if (null != s && !s.isShutdown() && s.isStarted()) {
            try {
                s.pauseAll();
            } catch (final SchedulerException e) {
            // no-op
            }
            long timeout = SystemInstance.get().getOptions().get(QuartzResourceAdapter.OPENEJB_QUARTZ_TIMEOUT, 10000L);
            if (timeout < 1000L) {
                timeout = 1000L;
            }
            final CountDownLatch shutdownWait = new CountDownLatch(1);
            final AtomicReference<Throwable> ex = new AtomicReference<Throwable>();
            String n = "Unknown";
            try {
                n = s.getSchedulerName();
            } catch (final SchedulerException e) {
                log.warning("EjbTimerService scheduler has no name");
            }
            final String name = n;
            Thread stopThread = new Thread(name + " shutdown wait") {

                @Override
                public void run() {
                    try {
                        s.getListenerManager().addSchedulerListener(new SchedulerListenerSupport() {

                            @Override
                            public void schedulerShutdown() {
                                shutdownWait.countDown();
                            }
                        });
                        // Shutdown, but give running jobs a chance to complete.
                        // User scheduled jobs should really implement InterruptableJob
                        s.shutdown(true);
                    } catch (final Throwable e) {
                        ex.set(e);
                        shutdownWait.countDown();
                    }
                }
            };
            stopThread.setDaemon(true);
            stopThread.start();
            boolean stopped = false;
            try {
                stopped = shutdownWait.await(timeout, TimeUnit.MILLISECONDS);
            } catch (final InterruptedException e) {
            // Ignore
            }
            try {
                if (!stopped || !s.isShutdown()) {
                    stopThread = new Thread(name + " shutdown forced") {

                        @Override
                        public void run() {
                            try {
                                // Force a shutdown without waiting for jobs to complete.
                                s.shutdown(false);
                                log.warning("Forced " + name + " shutdown - Jobs may be incomplete");
                            } catch (final Throwable e) {
                                ex.set(e);
                            }
                        }
                    };
                    stopThread.setDaemon(true);
                    stopThread.start();
                    try {
                        // Give the forced shutdown a chance to complete
                        stopThread.join(timeout);
                    } catch (final InterruptedException e) {
                    // Ignore
                    }
                }
            } catch (final Throwable e) {
                ex.set(e);
            }
            final Throwable t = ex.get();
            if (null != t) {
                throw new OpenEJBRuntimeException("Unable to shutdown " + name + " scheduler", t);
            }
        }
    } catch (final SchedulerException e) {
    // Ignore - This can only be a shutdown issue that we have no control over.
    }
}
Also used : SchedulerException(org.apache.openejb.quartz.SchedulerException) SchedulerListenerSupport(org.apache.openejb.quartz.listeners.SchedulerListenerSupport) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException)

Aggregations

OpenEJBRuntimeException (org.apache.openejb.OpenEJBRuntimeException)55 IOException (java.io.IOException)20 OpenEJBException (org.apache.openejb.OpenEJBException)17 ArrayList (java.util.ArrayList)13 Properties (java.util.Properties)12 NamingException (javax.naming.NamingException)9 MalformedURLException (java.net.MalformedURLException)8 BeanContext (org.apache.openejb.BeanContext)8 ObjectStreamException (java.io.ObjectStreamException)6 URISyntaxException (java.net.URISyntaxException)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 File (java.io.File)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 Method (java.lang.reflect.Method)4 URL (java.net.URL)4 ApplicationException (org.apache.openejb.ApplicationException)4 InvalidObjectException (java.io.InvalidObjectException)3 AccessException (java.rmi.AccessException)3 RemoteException (java.rmi.RemoteException)3