tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject tomee git commit: JAXRS2 ResourceContext
Date Thu, 20 Nov 2014 08:08:00 GMT
Repository: tomee
Updated Branches:
  refs/heads/develop 4c1b88478 -> b31e61b3c


JAXRS2 ResourceContext


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/b31e61b3
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/b31e61b3
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/b31e61b3

Branch: refs/heads/develop
Commit: b31e61b3c118455ebf3d6002296da55d0d549064
Parents: 4c1b884
Author: Romain Manni-Bucau <rmannibucau@apache.org>
Authored: Thu Nov 20 09:07:43 2014 +0100
Committer: Romain Manni-Bucau <rmannibucau@apache.org>
Committed: Thu Nov 20 09:07:43 2014 +0100

----------------------------------------------------------------------
 .../assembler/classic/JndiEncBuilder.java       |  3 ++
 .../openejb/rest/ThreadLocalContextManager.java | 33 +++++++++-------
 .../rest/ThreadLocalResourceContext.java        | 41 ++++++++++++++++++++
 .../apache/openejb/server/cxf/rs/Contexts.java  |  4 ++
 .../openejb/server/cxf/rs/SubResourceTest.java  | 10 ++++-
 5 files changed, 76 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/b31e61b3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java
b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java
index c3ca786..938ca46 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java
@@ -71,6 +71,7 @@ import javax.transaction.TransactionManager;
 import javax.transaction.UserTransaction;
 import javax.validation.Validator;
 import javax.validation.ValidatorFactory;
+import javax.ws.rs.container.ResourceContext;
 import javax.ws.rs.core.Configuration;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.Request;
@@ -330,6 +331,8 @@ public class JndiEncBuilder {
                     reference = new ObjectReference(ThreadLocalContextManager.HTTP_SERVLET_RESPONSE);
                 } else if (javax.ws.rs.container.ResourceInfo.class.equals(type)) {
                     reference = new ObjectReference(ThreadLocalContextManager.RESOURCE_INFO);
+                } else if (ResourceContext.class.equals(type)) {
+                    reference = new ObjectReference(ThreadLocalContextManager.RESOURCE_CONTEXT);
                 } else if (Configuration.class.equals(type)) {
                     reference = new ObjectReference(ThreadLocalContextManager.CONFIGURATION);
                 } else {

http://git-wip-us.apache.org/repos/asf/tomee/blob/b31e61b3/container/openejb-core/src/main/java/org/apache/openejb/rest/ThreadLocalContextManager.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/rest/ThreadLocalContextManager.java
b/container/openejb-core/src/main/java/org/apache/openejb/rest/ThreadLocalContextManager.java
index 1331bd4..ac357a9 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/rest/ThreadLocalContextManager.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/rest/ThreadLocalContextManager.java
@@ -22,6 +22,7 @@ import javax.servlet.ServletContext;
 import javax.servlet.ServletRequest;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.container.ResourceContext;
 import javax.ws.rs.container.ResourceInfo;
 import javax.ws.rs.core.Application;
 import javax.ws.rs.core.Configuration;
@@ -48,6 +49,7 @@ public class ThreadLocalContextManager {
     public static final ThreadLocal<Application> APPLICATION = new ThreadLocal<>();
     public static final ThreadLocalConfiguration CONFIGURATION = new ThreadLocalConfiguration();
     public static final ThreadLocalResourceInfo RESOURCE_INFO = new ThreadLocalResourceInfo();
+    public static final ThreadLocalResourceContext RESOURCE_CONTEXT = new ThreadLocalResourceContext();
     public static final ThreadLocal<Map<String, Object>> OTHERS = new ThreadLocal<Map<String,
Object>>();
 
     public static void reset() {
@@ -65,6 +67,7 @@ public class ThreadLocalContextManager {
         APPLICATION.remove();
         CONFIGURATION.remove();
         RESOURCE_INFO.remove();
+        RESOURCE_CONTEXT.remove();
 
         final Map<String, Object> map = OTHERS.get();
         if (map != null) {
@@ -75,33 +78,35 @@ public class ThreadLocalContextManager {
 
     public static Object findThreadLocal(final Class<?> type) {
         if (Request.class.equals(type)) {
-            return ThreadLocalContextManager.REQUEST;
+            return REQUEST;
         } else if (UriInfo.class.equals(type)) {
-            return ThreadLocalContextManager.URI_INFO;
+            return URI_INFO;
         } else if (HttpHeaders.class.equals(type)) {
-            return ThreadLocalContextManager.HTTP_HEADERS;
+            return HTTP_HEADERS;
         } else if (SecurityContext.class.equals(type)) {
-            return ThreadLocalContextManager.SECURITY_CONTEXT;
+            return SECURITY_CONTEXT;
         } else if (ContextResolver.class.equals(type)) {
-            return ThreadLocalContextManager.CONTEXT_RESOLVER;
+            return CONTEXT_RESOLVER;
         } else if (Providers.class.equals(type)) {
-            return ThreadLocalContextManager.PROVIDERS;
+            return PROVIDERS;
         } else if (ServletRequest.class.equals(type)) {
-            return ThreadLocalContextManager.SERVLET_REQUEST;
+            return SERVLET_REQUEST;
         } else if (HttpServletRequest.class.equals(type)) {
-            return ThreadLocalContextManager.HTTP_SERVLET_REQUEST;
+            return HTTP_SERVLET_REQUEST;
         } else if (HttpServletResponse.class.equals(type)) {
-            return ThreadLocalContextManager.HTTP_SERVLET_RESPONSE;
+            return HTTP_SERVLET_RESPONSE;
         } else if (ServletConfig.class.equals(type)) {
-            return ThreadLocalContextManager.SERVLET_CONFIG;
+            return SERVLET_CONFIG;
         } else if (ServletContext.class.equals(type)) {
-            return ThreadLocalContextManager.SERVLET_CONTEXT;
+            return SERVLET_CONTEXT;
         } else if (ResourceInfo.class.equals(type)) {
-            return ThreadLocalContextManager.RESOURCE_INFO;
+            return RESOURCE_INFO;
+        } else if (ResourceContext.class.equals(type)) {
+            return RESOURCE_CONTEXT;
         } else if (Application.class.equals(type)) {
-            return ThreadLocalContextManager.APPLICATION;
+            return APPLICATION;
         } else if (Configuration.class.equals(type)) {
-            return ThreadLocalContextManager.CONFIGURATION;
+            return CONFIGURATION;
         }
         return null;
     }

http://git-wip-us.apache.org/repos/asf/tomee/blob/b31e61b3/container/openejb-core/src/main/java/org/apache/openejb/rest/ThreadLocalResourceContext.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/rest/ThreadLocalResourceContext.java
b/container/openejb-core/src/main/java/org/apache/openejb/rest/ThreadLocalResourceContext.java
new file mode 100644
index 0000000..811d915
--- /dev/null
+++ b/container/openejb-core/src/main/java/org/apache/openejb/rest/ThreadLocalResourceContext.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.openejb.rest;
+
+import javax.ws.rs.container.ResourceContext;
+import javax.ws.rs.container.ResourceInfo;
+import java.lang.reflect.Method;
+
+public class ThreadLocalResourceContext extends AbstractRestThreadLocalProxy<ResourceContext>
+    implements ResourceContext {
+
+    protected ThreadLocalResourceContext() {
+        super(ResourceContext.class);
+    }
+
+    @Override
+    public <T> T getResource(final Class<T> tClass) {
+        return get().getResource(tClass);
+    }
+
+    @Override
+    public <T> T initResource(final T t) {
+        return get().initResource(t);
+    }
+}

http://git-wip-us.apache.org/repos/asf/tomee/blob/b31e61b3/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/Contexts.java
----------------------------------------------------------------------
diff --git a/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/Contexts.java
b/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/Contexts.java
index fc207bc..62dbc59 100644
--- a/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/Contexts.java
+++ b/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/Contexts.java
@@ -33,6 +33,7 @@ import javax.servlet.ServletContext;
 import javax.servlet.ServletRequest;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.container.ResourceContext;
 import javax.ws.rs.container.ResourceInfo;
 import javax.ws.rs.core.Application;
 import javax.ws.rs.core.Configuration;
@@ -170,6 +171,9 @@ public final class Contexts {
             } else if (ResourceInfo.class.equals(type)) {
                 final ResourceInfo config = JAXRSUtils.createContextValue(exchange.getInMessage(),
null, ResourceInfo.class);
                 ThreadLocalContextManager.RESOURCE_INFO.set(config);
+            } else if (ResourceContext.class.equals(type)) {
+                final ResourceContext config = JAXRSUtils.createContextValue(exchange.getInMessage(),
null, ResourceContext.class);
+                ThreadLocalContextManager.RESOURCE_CONTEXT.set(config);
             } else {
                 final Message message = exchange.getInMessage();
                 final ContextProvider<?> provider = ProviderFactory.getInstance(message).createContextProvider(type,
message);

http://git-wip-us.apache.org/repos/asf/tomee/blob/b31e61b3/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/SubResourceTest.java
----------------------------------------------------------------------
diff --git a/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/SubResourceTest.java
b/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/SubResourceTest.java
index 1b812e0..d996a5f 100644
--- a/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/SubResourceTest.java
+++ b/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/SubResourceTest.java
@@ -31,11 +31,14 @@ import org.junit.runner.RunWith;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
+import javax.ws.rs.container.ResourceContext;
+import javax.ws.rs.core.Context;
 import java.io.IOException;
 import java.net.URL;
 import java.util.Properties;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 
 @RunWith(ApplicationComposer.class)
 public class SubResourceTest {
@@ -68,10 +71,15 @@ public class SubResourceTest {
 
     @Path("/sub1")
     public static class Endpoint1 {
+        @Context
+        private ResourceContext rc;
+
         @Path("sub{i}")
         public Endpoint2 uno(@PathParam("i") final int discr) {
             if (2 == discr) {
-                return new Endpoint2();
+                final Endpoint2 resource = rc.getResource(Endpoint2.class);
+                assertNotNull(resource);
+                return resource;
             }
             return null;
         }


Mime
View raw message