You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2012/09/16 21:34:58 UTC
svn commit: r1385356 - in /openejb/branches/openejb-4.1.0:
container/openejb-core/src/main/java/org/apache/openejb/cdi/ThreadSingletonServiceImpl.java
server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java
Author: rmannibucau
Date: Sun Sep 16 19:34:58 2012
New Revision: 1385356
URL: http://svn.apache.org/viewvc?rev=1385356&view=rev
Log:
updating branch with trunk fixes
Modified:
openejb/branches/openejb-4.1.0/container/openejb-core/src/main/java/org/apache/openejb/cdi/ThreadSingletonServiceImpl.java
openejb/branches/openejb-4.1.0/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java
Modified: openejb/branches/openejb-4.1.0/container/openejb-core/src/main/java/org/apache/openejb/cdi/ThreadSingletonServiceImpl.java
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-4.1.0/container/openejb-core/src/main/java/org/apache/openejb/cdi/ThreadSingletonServiceImpl.java?rev=1385356&r1=1385355&r2=1385356&view=diff
==============================================================================
--- openejb/branches/openejb-4.1.0/container/openejb-core/src/main/java/org/apache/openejb/cdi/ThreadSingletonServiceImpl.java (original)
+++ openejb/branches/openejb-4.1.0/container/openejb-core/src/main/java/org/apache/openejb/cdi/ThreadSingletonServiceImpl.java Sun Sep 16 19:34:58 2012
@@ -33,6 +33,7 @@ import org.apache.webbeans.config.OpenWe
import org.apache.webbeans.config.WebBeansContext;
import org.apache.webbeans.intercept.ApplicationScopedBeanInterceptorHandler;
import org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler;
+import org.apache.webbeans.proxy.ProxyFactory;
import org.apache.webbeans.spi.ContainerLifecycle;
import org.apache.webbeans.spi.ContextsService;
import org.apache.webbeans.spi.ConversationService;
@@ -105,7 +106,7 @@ public class ThreadSingletonServiceImpl
services.put(ResourceInjectionService.class, new CdiResourceInjectionService());
services.put(ScannerService.class, new CdiScanner());
services.put(LoaderService.class, new OptimizedLoaderService());
- services.put(org.apache.webbeans.proxy.ProxyFactory.class, new AsmFactory());
+ services.put(org.apache.webbeans.proxy.ProxyFactory.class, new ProxyFactory(new AsmFactory()));
optional(services, ConversationService.class, "org.apache.webbeans.jsf.DefaultConversationService");
@@ -294,3 +295,4 @@ public class ThreadSingletonServiceImpl
}
}
+
Modified: openejb/branches/openejb-4.1.0/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-4.1.0/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java?rev=1385356&r1=1385355&r2=1385356&view=diff
==============================================================================
--- openejb/branches/openejb-4.1.0/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java (original)
+++ openejb/branches/openejb-4.1.0/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java Sun Sep 16 19:34:58 2012
@@ -117,104 +117,111 @@ public abstract class RESTService implem
additionalProviders.addAll(appProviders(appInfo, classLoader));
}
- // The spec says:
- //
- // "The resources and providers that make up a JAX-RS application are configured via an application-supplied
- // subclass of Application. An implementation MAY provide alternate mechanisms for locating resource
- // classes and providers (e.g. runtime class scanning) but use of Application is the only portable means of
- // configuration."
- //
- // The choice here is to deploy using the Application if it exists or to use the scanned classes
- // if there is no Application.
- //
- // Like this providing an Application subclass user can totally control deployed services.
-
- boolean useApp = false;
- String appPrefix = webApp.contextRoot;
- Collection<IdPropertiesInfo> pojoConfigurations = null; // done lazily
- for (String app : webApp.restApplications) { // normally a unique one but we support more
- appPrefix = webApp.contextRoot; // if multiple application classes reinit it
- if (!appPrefix.endsWith("/")) {
- appPrefix += "/";
- }
-
- Application appInstance;
- Class<?> appClazz;
- try {
- appClazz = classLoader.loadClass(app);
- appInstance = Application.class.cast(appClazz.newInstance());
- } catch (Exception e) {
- throw new OpenEJBRestRuntimeException("can't create class " + app, e);
- }
+ final ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(classLoader);
- ApplicationPath path = appClazz.getAnnotation(ApplicationPath.class);
- if (path != null) {
- String appPath = path.value();
- if (appPath.startsWith("/")) {
- appPrefix += appPath.substring(1);
- } else {
- appPrefix += appPath;
+ try {
+ // The spec says:
+ //
+ // "The resources and providers that make up a JAX-RS application are configured via an application-supplied
+ // subclass of Application. An implementation MAY provide alternate mechanisms for locating resource
+ // classes and providers (e.g. runtime class scanning) but use of Application is the only portable means of
+ // configuration."
+ //
+ // The choice here is to deploy using the Application if it exists or to use the scanned classes
+ // if there is no Application.
+ //
+ // Like this providing an Application subclass user can totally control deployed services.
+
+ boolean useApp = false;
+ String appPrefix = webApp.contextRoot;
+ Collection<IdPropertiesInfo> pojoConfigurations = null; // done lazily
+ for (String app : webApp.restApplications) { // normally a unique one but we support more
+ appPrefix = webApp.contextRoot; // if multiple application classes reinit it
+ if (!appPrefix.endsWith("/")) {
+ appPrefix += "/";
+ }
+
+ Application appInstance;
+ Class<?> appClazz;
+ try {
+ appClazz = classLoader.loadClass(app);
+ appInstance = Application.class.cast(appClazz.newInstance());
+ } catch (Exception e) {
+ throw new OpenEJBRestRuntimeException("can't create class " + app, e);
}
- }
- Set<Object> singletons = appInstance.getSingletons();
- for (Object o : singletons) {
- if (o == null) {
- continue;
+ ApplicationPath path = appClazz.getAnnotation(ApplicationPath.class);
+ if (path != null) {
+ String appPath = path.value();
+ if (appPath.startsWith("/")) {
+ appPrefix += appPath.substring(1);
+ } else {
+ appPrefix += appPath;
+ }
}
- if (hasEjbAndIsNotAManagedBean(restEjbs, o.getClass().getName())) {
- // no more a singleton if the ejb is not a singleton...but it is a weird case
- deployEJB(appPrefix, restEjbs.get(o.getClass().getName()).context, additionalProviders, appInfo.services);
- } else {
- pojoConfigurations = PojoUtil.findPojoConfig(pojoConfigurations, appInfo, webApp);
- deploySingleton(appPrefix, o, appInstance, classLoader, additionalProviders,
- new ServiceConfiguration(PojoUtil.findConfiguration(pojoConfigurations, o.getClass().getName()), appInfo.services));
+ Set<Object> singletons = appInstance.getSingletons();
+ for (Object o : singletons) {
+ if (o == null) {
+ continue;
+ }
+
+ if (hasEjbAndIsNotAManagedBean(restEjbs, o.getClass().getName())) {
+ // no more a singleton if the ejb is not a singleton...but it is a weird case
+ deployEJB(appPrefix, restEjbs.get(o.getClass().getName()).context, additionalProviders, appInfo.services);
+ } else {
+ pojoConfigurations = PojoUtil.findPojoConfig(pojoConfigurations, appInfo, webApp);
+ deploySingleton(appPrefix, o, appInstance, classLoader, additionalProviders,
+ new ServiceConfiguration(PojoUtil.findConfiguration(pojoConfigurations, o.getClass().getName()), appInfo.services));
+ }
}
- }
- Set<Class<?>> classes = appInstance.getClasses();
- for (Class<?> clazz : classes) {
- if (hasEjbAndIsNotAManagedBean(restEjbs, clazz.getName())) {
- deployEJB(appPrefix, restEjbs.get(clazz.getName()).context, additionalProviders, appInfo.services);
- } else {
- pojoConfigurations = PojoUtil.findPojoConfig(pojoConfigurations, appInfo, webApp);
- deployPojo(appPrefix, clazz, appInstance, classLoader, injections, context, owbCtx, additionalProviders,
- new ServiceConfiguration(PojoUtil.findConfiguration(pojoConfigurations, clazz.getName()), appInfo.services));
+ Set<Class<?>> classes = appInstance.getClasses();
+ for (Class<?> clazz : classes) {
+ if (hasEjbAndIsNotAManagedBean(restEjbs, clazz.getName())) {
+ deployEJB(appPrefix, restEjbs.get(clazz.getName()).context, additionalProviders, appInfo.services);
+ } else {
+ pojoConfigurations = PojoUtil.findPojoConfig(pojoConfigurations, appInfo, webApp);
+ deployPojo(appPrefix, clazz, appInstance, classLoader, injections, context, owbCtx, additionalProviders,
+ new ServiceConfiguration(PojoUtil.findConfiguration(pojoConfigurations, clazz.getName()), appInfo.services));
+ }
}
- }
-
- useApp = useApp || classes.size() + singletons.size() > 0;
- LOGGER.info("REST application deployed: " + app);
- }
- if (!useApp) {
- final Set<String> restClasses = new HashSet<String>(webApp.restClass);
- restClasses.addAll(webApp.ejbRestServices);
+ useApp = useApp || classes.size() + singletons.size() > 0;
+ LOGGER.info("REST application deployed: " + app);
+ }
- for (String clazz : restClasses) {
- if (restEjbs.containsKey(clazz)) {
- final BeanContext ctx = restEjbs.get(clazz).context;
- if (hasEjbAndIsNotAManagedBean(restEjbs, clazz)) {
- deployEJB(appPrefix, restEjbs.get(clazz).context, additionalProviders, appInfo.services);
+ if (!useApp) {
+ final Set<String> restClasses = new HashSet<String>(webApp.restClass);
+ restClasses.addAll(webApp.ejbRestServices);
+
+ for (String clazz : restClasses) {
+ if (restEjbs.containsKey(clazz)) {
+ final BeanContext ctx = restEjbs.get(clazz).context;
+ if (hasEjbAndIsNotAManagedBean(restEjbs, clazz)) {
+ deployEJB(appPrefix, restEjbs.get(clazz).context, additionalProviders, appInfo.services);
+ } else {
+ deployPojo(appPrefix, ctx.getBeanClass(), null, ctx.getClassLoader(), ctx.getInjections(), context,
+ owbCtx, additionalProviders, new ServiceConfiguration(ctx.getProperties(), appInfo.services));
+ }
} else {
- deployPojo(appPrefix, ctx.getBeanClass(), null, ctx.getClassLoader(), ctx.getInjections(), context,
- owbCtx, additionalProviders, new ServiceConfiguration(ctx.getProperties(), appInfo.services));
- }
- } else {
- try {
- Class<?> loadedClazz = classLoader.loadClass(clazz);
- pojoConfigurations = PojoUtil.findPojoConfig(pojoConfigurations, appInfo, webApp);
- deployPojo(appPrefix, loadedClazz, null, classLoader, injections, context, owbCtx,
- additionalProviders,
- new ServiceConfiguration(PojoUtil.findConfiguration(pojoConfigurations, loadedClazz.getName()), appInfo.services));
- } catch (ClassNotFoundException e) {
- throw new OpenEJBRestRuntimeException("can't find class " + clazz, e);
+ try {
+ Class<?> loadedClazz = classLoader.loadClass(clazz);
+ pojoConfigurations = PojoUtil.findPojoConfig(pojoConfigurations, appInfo, webApp);
+ deployPojo(appPrefix, loadedClazz, null, classLoader, injections, context, owbCtx,
+ additionalProviders,
+ new ServiceConfiguration(PojoUtil.findConfiguration(pojoConfigurations, loadedClazz.getName()), appInfo.services));
+ } catch (ClassNotFoundException e) {
+ throw new OpenEJBRestRuntimeException("can't find class " + clazz, e);
+ }
}
}
}
- }
- restEjbs.clear();
+ restEjbs.clear();
+ } finally {
+ Thread.currentThread().setContextClassLoader(oldLoader);
+ }
}
private boolean hasEjbAndIsNotAManagedBean(final Map<String, EJBRestServiceInfo> restEjbs, final String clazz) {
@@ -599,3 +606,4 @@ public abstract class RESTService implem
return services;
}
}
+