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();
}
}
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);
}
}
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);
}
}
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);
}
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.
}
}
Aggregations