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 2014/12/24 08:34:15 UTC
[2/2] tomee git commit: trying to guess a bit better the WBC if the
request
trying to guess a bit better the WBC if the request
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/02818cc3
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/02818cc3
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/02818cc3
Branch: refs/heads/develop
Commit: 02818cc3878dde5647efdbd4537e7e8d28f77647
Parents: 4c620d6
Author: Romain Manni-Bucau <rm...@apache.org>
Authored: Tue Dec 23 23:55:05 2014 +0100
Committer: Romain Manni-Bucau <rm...@apache.org>
Committed: Tue Dec 23 23:55:05 2014 +0100
----------------------------------------------------------------------
.../server/httpd/OpenEJBHttpRegistry.java | 33 +++++++++++++++-----
tck/cdi-embedded/src/test/resources/failing.xml | 2 +-
2 files changed, 27 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/02818cc3/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/OpenEJBHttpRegistry.java
----------------------------------------------------------------------
diff --git a/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/OpenEJBHttpRegistry.java b/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/OpenEJBHttpRegistry.java
index c884a1c..b2dc7a4 100644
--- a/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/OpenEJBHttpRegistry.java
+++ b/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/OpenEJBHttpRegistry.java
@@ -16,9 +16,12 @@
*/
package org.apache.openejb.server.httpd;
+import org.apache.openejb.AppContext;
import org.apache.openejb.assembler.classic.OpenEjbConfiguration;
import org.apache.openejb.assembler.classic.ServiceInfo;
+import org.apache.openejb.core.WebContext;
import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.spi.ContainerSystem;
import org.apache.openejb.util.LogCategory;
import org.apache.openejb.util.Logger;
import org.apache.webbeans.config.WebBeansContext;
@@ -100,27 +103,43 @@ public class OpenEJBHttpRegistry {
}
public void onMessage(HttpRequest request, HttpResponse response) throws Exception {
- ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
- Thread.currentThread().setContextClassLoader(classLoader);
+ Thread thread = Thread.currentThread();
+ ClassLoader oldCl = thread.getContextClassLoader();
+ thread.setContextClassLoader(classLoader);
+ WebBeansContext wbc = null;
try {
if (request instanceof HttpRequestImpl) {
- initCdi((HttpRequestImpl) request).init();
+ wbc = findWebContext(request.getURI().getPath());
+ initCdi(wbc, (HttpRequestImpl) request).init();
}
delegate.onMessage(request, response);
} finally {
- if (request instanceof HttpRequestImpl) {
+ if (wbc != null) {
((HttpRequestImpl) request).destroy();
}
- Thread.currentThread().setContextClassLoader(oldCl);
+ thread.setContextClassLoader(oldCl);
+ }
+ }
+
+ private static WebBeansContext findWebContext(final String path) { // poor impl, would need registration of app etc to be better
+ for (final AppContext app : SystemInstance.get().getComponent(ContainerSystem.class).getAppContexts()) {
+ for (final WebContext web : app.getWebContexts()) {
+ if (path.startsWith(web.getContextRoot()) || path.startsWith('/' + web.getContextRoot())) {
+ if (web.getWebBeansContext() != null) {
+ return web.getWebBeansContext();
+ }
+ return app.getWebBeansContext();
+ }
+ }
}
+ return WebBeansContext.currentInstance();
}
- private static HttpRequestImpl initCdi(final HttpRequestImpl request) {
+ private static HttpRequestImpl initCdi(final WebBeansContext context, final HttpRequestImpl request) {
try {
- final WebBeansContext context = WebBeansContext.currentInstance();
if (context.getBeanManagerImpl().isInUse()) {
request.setBeginListener(new BeginWebBeansListener(context));
request.setEndListener(new EndWebBeansListener(context));
http://git-wip-us.apache.org/repos/asf/tomee/blob/02818cc3/tck/cdi-embedded/src/test/resources/failing.xml
----------------------------------------------------------------------
diff --git a/tck/cdi-embedded/src/test/resources/failing.xml b/tck/cdi-embedded/src/test/resources/failing.xml
index 3380601..583fe4d 100644
--- a/tck/cdi-embedded/src/test/resources/failing.xml
+++ b/tck/cdi-embedded/src/test/resources/failing.xml
@@ -19,7 +19,7 @@
<test name="CDI TCK">
<!-- -Dopenejb.cdi.filter.classloader=false -Dorg.apache.openejb.assembler.classic.WebAppBuilder=org.apache.openejb.web.LightweightWebAppBuilder -Dopenejb.cdi.debug=true -Dopenejb.http.mock-request=true -->
<classes>
- <class name="org.jboss.cdi.tck.tests.lookup.modules.specialization.SpecializationModularity02Test" />
+ <class name="org.jboss.cdi.tck.tests.context.request.event.RequestScopeEventTest" />
</classes>
</test>
</suite>