You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2021/04/07 04:30:32 UTC
[tomee] 04/04: [TOMEE-2995] Support constructor injection of JAX-RS
Application
This is an automated email from the ASF dual-hosted git repository.
dblevins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomee.git
commit a061c74e929b5cda52c3da411d2bf902c88ab019
Author: David Blevins <da...@gmail.com>
AuthorDate: Tue Apr 6 21:29:57 2021 -0700
[TOMEE-2995] Support constructor injection of JAX-RS Application
---
.../openejb/rest/ThreadLocalApplication.java | 67 ++++++++++++++++++++++
.../openejb/rest/ThreadLocalContextManager.java | 2 +-
2 files changed, 68 insertions(+), 1 deletion(-)
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/rest/ThreadLocalApplication.java b/container/openejb-core/src/main/java/org/apache/openejb/rest/ThreadLocalApplication.java
new file mode 100644
index 0000000..30eccfb
--- /dev/null
+++ b/container/openejb-core/src/main/java/org/apache/openejb/rest/ThreadLocalApplication.java
@@ -0,0 +1,67 @@
+/*
+ * 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 org.apache.openejb.loader.SystemInstance;
+
+import javax.ws.rs.core.Application;
+import java.util.Map;
+import java.util.Set;
+
+public class ThreadLocalApplication extends Application {
+ private final ThreadLocal<Application> infos = new ThreadLocal<>();
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ return super.getClasses();
+ }
+
+ @Override
+ public Set<Object> getSingletons() {
+ return super.getSingletons();
+ }
+
+ @Override
+ public Map<String, Object> getProperties() {
+ return super.getProperties();
+ }
+
+ public Application get() {
+ Application t = infos.get();
+ if (t == null) {
+ t = find();
+ }
+ return t;
+ }
+
+ public Application find() {
+ final RESTResourceFinder finder = SystemInstance.get().getComponent(RESTResourceFinder.class);
+ if (finder != null) {
+ return finder.find(Application.class);
+ }
+ return null;
+ }
+
+ public void remove() {
+ infos.remove();
+ }
+
+ public void set(final Application value) {
+ infos.set(value);
+ }
+
+}
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 216819f..3f4e6ed 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
@@ -46,7 +46,7 @@ public class ThreadLocalContextManager {
public static final ThreadLocalSecurityContext SECURITY_CONTEXT = new ThreadLocalSecurityContext();
public static final ThreadLocalContextResolver CONTEXT_RESOLVER = new ThreadLocalContextResolver();
public static final ThreadLocalProviders PROVIDERS = new ThreadLocalProviders();
- public static final ThreadLocal<Application> APPLICATION = new ThreadLocal<>();
+ public static final ThreadLocalApplication APPLICATION = new ThreadLocalApplication();
public static final ThreadLocalConfiguration CONFIGURATION = new ThreadLocalConfiguration();
public static final ThreadLocalResourceInfo RESOURCE_INFO = new ThreadLocalResourceInfo();
public static final ThreadLocalResourceContext RESOURCE_CONTEXT = new ThreadLocalResourceContext();