use of org.apache.openejb.OpenEJBRuntimeException in project tomee by apache.
the class ListConfigurator method getList.
public static <T> List<T> getList(final Properties properties, final String key, final ClassLoader classloader, final Class<T> filter) {
if (properties == null) {
return null;
}
final String features = properties.getProperty(key);
if (features == null) {
return null;
}
final List<T> list = new ArrayList<T>();
final String[] split = features.trim().split(",");
for (final String feature : split) {
if (feature == null || feature.trim().isEmpty()) {
continue;
}
final String prefix = key + "." + feature + ".";
final ObjectRecipe recipe = new ObjectRecipe(feature);
for (final Map.Entry<Object, Object> entry : properties.entrySet()) {
final String current = entry.getKey().toString();
if (current.startsWith(prefix)) {
final String property = current.substring(prefix.length());
recipe.setProperty(property, entry.getValue());
}
}
final Object instance = recipe.create(classloader);
if (!filter.isInstance(instance)) {
throw new OpenEJBRuntimeException(feature + " is not an abstract feature");
}
list.add(filter.cast(instance));
}
if (list.isEmpty()) {
return null;
}
return list;
}
use of org.apache.openejb.OpenEJBRuntimeException in project tomee by apache.
the class DynamicProxyImplFactory method newProxy.
public static Object newProxy(final BeanContext context, final InvocationHandler invocationHandler) {
if (QueryProxy.class.isInstance(invocationHandler)) {
EntityManager em = null;
for (final Injection injection : context.getInjections()) {
if (QueryProxy.class.equals(injection.getTarget())) {
try {
em = (EntityManager) context.getJndiEnc().lookup(injection.getJndiName());
} catch (final NamingException e) {
throw new OpenEJBRuntimeException("a dynamic bean should reference at least one correct PersistenceContext", e);
}
}
}
if (em == null) {
throw new OpenEJBRuntimeException("can't find the entity manager to use for the dynamic bean " + context.getEjbName());
}
QueryProxy.class.cast(invocationHandler).setEntityManager(em);
}
return newProxy(context.getBeanClass(), invocationHandler);
}
use of org.apache.openejb.OpenEJBRuntimeException in project tomee by apache.
the class OpenEJBLifecycle method startApplication.
@Override
public void startApplication(final Object startupObject) {
if (ServletContextEvent.class.isInstance(startupObject)) {
// TODO: check it is relevant
startServletContext(ServletContext.class.cast(getServletContext(startupObject)));
return;
} else if (!StartupObject.class.isInstance(startupObject)) {
logger.debug("startupObject is not of StartupObject type; ignored");
return;
}
final StartupObject stuff = (StartupObject) startupObject;
final ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
// Initalize Application Context
logger.info("OpenWebBeans Container is starting...");
final long begin = System.currentTimeMillis();
try {
Thread.currentThread().setContextClassLoader(stuff.getClassLoader());
final AppContext appContext = stuff.getAppContext();
if (stuff.getWebContext() == null) {
// do it before any other things to keep our singleton finder working
appContext.setWebBeansContext(webBeansContext);
}
//Load all plugins
webBeansContext.getPluginLoader().startUp();
//Get Plugin
final CdiPlugin cdiPlugin = (CdiPlugin) webBeansContext.getPluginLoader().getEjbPlugin();
cdiPlugin.setClassLoader(stuff.getClassLoader());
cdiPlugin.setWebBeansContext(webBeansContext);
//Configure EJB Deployments
cdiPlugin.configureDeployments(stuff.getBeanContexts());
//Resournce Injection Service
final CdiResourceInjectionService injectionService = (CdiResourceInjectionService) webBeansContext.getService(ResourceInjectionService.class);
// todo use startupObject allDeployments to find Comp in priority (otherwise we can keep N times comps and loose time at injection time
injectionService.setAppContext(stuff.getAppContext(), stuff.getBeanContexts() != null ? stuff.getBeanContexts() : Collections.<BeanContext>emptyList());
//Deploy the beans
CdiScanner cdiScanner = null;
try {
//Scanning process
logger.debug("Scanning classpaths for beans artifacts.");
if (CdiScanner.class.isInstance(scannerService)) {
cdiScanner = CdiScanner.class.cast(scannerService);
cdiScanner.setContext(webBeansContext);
cdiScanner.init(startupObject);
} else {
cdiScanner = new CdiScanner();
cdiScanner.setContext(webBeansContext);
cdiScanner.init(startupObject);
}
//Scan
this.scannerService.scan();
// just to let us write custom CDI Extension using our internals easily
CURRENT_APP_INFO.set(stuff.getAppInfo());
// before next event which can register custom beans (JAX-RS)
addInternalBeans();
SystemInstance.get().fireEvent(new WebBeansContextBeforeDeploy(webBeansContext));
//Deploy bean from XML. Also configures deployments, interceptors, decorators.
deployer.deploy(scannerService);
// fire app event and also starts SingletonContext and ApplicationContext
contextsService.init(startupObject);
} catch (final Exception e1) {
SystemInstance.get().getComponent(Assembler.class).logger.error("CDI Beans module deployment failed", e1);
throw new OpenEJBRuntimeException(e1);
} finally {
CURRENT_APP_INFO.remove();
}
final Collection<Class<?>> ejbs = new ArrayList<>(stuff.getBeanContexts().size());
for (final BeanContext bc : stuff.getBeanContexts()) {
ejbs.add(bc.getManagedClass());
final CdiEjbBean cdiEjbBean = bc.get(CdiEjbBean.class);
if (cdiEjbBean == null) {
continue;
}
if (AbstractProducer.class.isInstance(cdiEjbBean)) {
AbstractProducer.class.cast(cdiEjbBean).defineInterceptorStack(cdiEjbBean, cdiEjbBean.getAnnotatedType(), cdiEjbBean.getWebBeansContext());
}
bc.mergeOWBAndOpenEJBInfo();
bc.set(InterceptorResolutionService.BeanInterceptorInfo.class, InjectionTargetImpl.class.cast(cdiEjbBean.getInjectionTarget()).getInterceptorInfo());
cdiEjbBean.initInternals();
}
//Start actual starting on sub-classes
if (beanManager instanceof WebappBeanManager) {
((WebappBeanManager) beanManager).afterStart();
}
for (final Class<?> clazz : cdiScanner.getStartupClasses()) {
if (ejbs.contains(clazz)) {
continue;
}
starts(beanManager, clazz);
}
} finally {
Thread.currentThread().setContextClassLoader(oldCl);
// cleanup threadlocal used to enrich cdi context manually
OptimizedLoaderService.ADDITIONAL_EXTENSIONS.remove();
}
logger.info("OpenWebBeans Container has started, it took {0} ms.", Long.toString(System.currentTimeMillis() - begin));
}
use of org.apache.openejb.OpenEJBRuntimeException in project tomee by apache.
the class CdiPlugin method getSessionBeanProxy.
@Override
public Object getSessionBeanProxy(final Bean<?> inBean, final Class<?> interfce, final CreationalContext<?> creationalContext) {
Object instance = cacheProxies.get(inBean);
if (instance != null) {
return instance;
}
synchronized (inBean) {
// singleton for the app so safe to sync on it
instance = cacheProxies.get(inBean);
if (instance != null) {
return instance;
}
final Class<? extends Annotation> scopeClass = inBean.getScope();
final CdiEjbBean<Object> cdiEjbBean = (CdiEjbBean<Object>) inBean;
final CreationalContext<Object> cc = (CreationalContext<Object>) creationalContext;
if (scopeClass == null || Dependent.class == scopeClass) {
// no need to add any layer, null = @New
return cdiEjbBean.createEjb(cc);
}
// only stateful normally
final InstanceBean<Object> bean = new InstanceBean<Object>(cdiEjbBean);
if (webBeansContext.getBeanManagerImpl().isNormalScope(scopeClass)) {
final BeanContext beanContext = cdiEjbBean.getBeanContext();
final Provider provider = webBeansContext.getNormalScopeProxyFactory().getInstanceProvider(beanContext.getClassLoader(), cdiEjbBean);
if (!beanContext.isLocalbean()) {
final List<Class> interfaces = new ArrayList<Class>();
final InterfaceType type = beanContext.getInterfaceType(interfce);
if (type != null) {
interfaces.addAll(beanContext.getInterfaces(type));
} else {
// can happen when looked up from impl instead of API in OWB -> default to business local
interfaces.addAll(beanContext.getInterfaces(InterfaceType.BUSINESS_LOCAL));
}
interfaces.add(Serializable.class);
interfaces.add(IntraVmProxy.class);
if (BeanType.STATEFUL.equals(beanContext.getComponentType()) || BeanType.MANAGED.equals(beanContext.getComponentType())) {
interfaces.add(BeanContext.Removable.class);
}
try {
instance = ProxyManager.newProxyInstance(interfaces.toArray(new Class<?>[interfaces.size()]), new InvocationHandler() {
@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
try {
return method.invoke(provider.get(), args);
} catch (final InvocationTargetException ite) {
throw ite.getCause();
}
}
});
} catch (final IllegalAccessException e) {
throw new OpenEJBRuntimeException(e);
}
} else {
final NormalScopeProxyFactory normalScopeProxyFactory = webBeansContext.getNormalScopeProxyFactory();
final Class<?> proxyClass = normalScopeProxyFactory.createProxyClass(beanContext.getClassLoader(), beanContext.getBeanClass());
instance = normalScopeProxyFactory.createProxyInstance(proxyClass, provider);
}
cacheProxies.put(inBean, instance);
} else {
final Context context = webBeansContext.getBeanManagerImpl().getContext(scopeClass);
instance = context.get(bean, cc);
}
bean.setOwbProxy(instance);
return instance;
}
}
use of org.apache.openejb.OpenEJBRuntimeException in project tomee by apache.
the class StaticDESPasswordCipher method decrypt.
/**
* @throws RuntimeException in any case of error.
* @see org.apache.openejb.cipher.PasswordCipher#decrypt(char[])
*/
public String decrypt(final char[] encodedPassword) {
if (null == encodedPassword || encodedPassword.length == 0) {
throw new IllegalArgumentException("encodedPassword cannot be null nor empty.");
}
try {
final byte[] cipherText = Base64.decodeBase64(String.valueOf(encodedPassword).getBytes());
// Get a 3DES Cipher object
final Cipher cipher = Cipher.getInstance(TRANSFORMATION);
// Set it into decryption mode
cipher.init(Cipher.DECRYPT_MODE, KEY);
// Decrypt data
return new String(cipher.doFinal(cipherText));
} catch (final Exception e) {
throw new OpenEJBRuntimeException(e);
}
}
Aggregations