|
40 | 40 |
|
41 | 41 | package org.glassfish.jersey.gf.ejb.internal; |
42 | 42 |
|
| 43 | +import com.sun.ejb.containers.BaseContainer; |
| 44 | +import com.sun.ejb.containers.EjbContainerUtil; |
| 45 | +import com.sun.ejb.containers.EjbContainerUtilImpl; |
| 46 | +import com.sun.enterprise.config.serverbeans.Application; |
| 47 | +import com.sun.enterprise.config.serverbeans.Applications; |
43 | 48 | import java.lang.annotation.Annotation; |
44 | 49 | import java.lang.reflect.InvocationHandler; |
45 | 50 | import java.lang.reflect.InvocationTargetException; |
|
51 | 56 | import java.util.Collection; |
52 | 57 | import java.util.Collections; |
53 | 58 | import java.util.HashSet; |
| 59 | +import java.util.Iterator; |
54 | 60 | import java.util.LinkedList; |
55 | 61 | import java.util.List; |
56 | 62 | import java.util.Set; |
| 63 | +import java.util.TreeSet; |
57 | 64 | import java.util.concurrent.CopyOnWriteArrayList; |
58 | 65 | import java.util.logging.Level; |
59 | 66 | import java.util.logging.Logger; |
60 | | - |
61 | | -import javax.ws.rs.ext.ExceptionMapper; |
62 | | - |
63 | 67 | import javax.annotation.Priority; |
64 | 68 | import javax.ejb.Local; |
65 | 69 | import javax.ejb.Remote; |
66 | 70 | import javax.inject.Singleton; |
67 | 71 | import javax.naming.InitialContext; |
68 | 72 | import javax.naming.NamingException; |
69 | | - |
70 | | -import org.glassfish.jersey.internal.inject.Injections; |
71 | | -import org.glassfish.jersey.server.ApplicationHandler; |
72 | | -import org.glassfish.jersey.server.model.Invocable; |
73 | | -import org.glassfish.jersey.server.spi.ComponentProvider; |
74 | | -import org.glassfish.jersey.server.spi.internal.ResourceMethodInvocationHandlerProvider; |
75 | | - |
| 73 | +import javax.ws.rs.ext.ExceptionMapper; |
| 74 | +import org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl; |
| 75 | +import org.glassfish.ejb.deployment.descriptor.EjbDescriptor; |
76 | 76 | import org.glassfish.hk2.api.DynamicConfiguration; |
77 | 77 | import org.glassfish.hk2.api.Factory; |
78 | 78 | import org.glassfish.hk2.api.ServiceLocator; |
79 | 79 | import org.glassfish.hk2.utilities.binding.ServiceBindingBuilder; |
80 | | - |
81 | | -import org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl; |
82 | | -import org.glassfish.ejb.deployment.descriptor.EjbDescriptor; |
83 | 80 | import org.glassfish.internal.data.ApplicationInfo; |
| 81 | +import org.glassfish.internal.data.ApplicationRegistry; |
84 | 82 | import org.glassfish.internal.data.ModuleInfo; |
85 | | - |
86 | | -import com.sun.ejb.containers.BaseContainer; |
87 | | -import com.sun.ejb.containers.EjbContainerUtil; |
88 | | -import com.sun.ejb.containers.EjbContainerUtilImpl; |
| 83 | +import org.glassfish.jersey.internal.inject.Injections; |
| 84 | +import org.glassfish.jersey.server.ApplicationHandler; |
| 85 | +import org.glassfish.jersey.server.model.Invocable; |
| 86 | +import org.glassfish.jersey.server.spi.ComponentProvider; |
| 87 | +import org.glassfish.jersey.server.spi.internal.ResourceMethodInvocationHandlerProvider; |
89 | 88 |
|
90 | 89 | /** |
91 | 90 | * EJB component provider. |
@@ -156,12 +155,45 @@ public void initialize(final ServiceLocator locator) { |
156 | 155 | configuration.commit(); |
157 | 156 | } |
158 | 157 |
|
| 158 | + private ApplicationInfo getApplicationInfo(EjbContainerUtil ejbUtil) throws NamingException { |
| 159 | + ApplicationRegistry appRegistry = ejbUtil.getServices().getService(ApplicationRegistry.class); |
| 160 | + Applications applications = ejbUtil.getServices().getService(Applications.class); |
| 161 | + String appNamePrefix = (String) initialContext.lookup("java:app/AppName"); |
| 162 | + Set<String> appNames = appRegistry.getAllApplicationNames(); |
| 163 | + Set<String> disabledApps = new TreeSet<>(); |
| 164 | + for (String appName : appNames) { |
| 165 | + if (appName.startsWith(appNamePrefix)) { |
| 166 | + Application appDesc = applications.getApplication(appName); |
| 167 | + if (appDesc != null && !ejbUtil.getDeployment().isAppEnabled(appDesc)) { |
| 168 | + // skip disabled version of the app |
| 169 | + disabledApps.add(appName); |
| 170 | + } else { |
| 171 | + return ejbUtil.getDeployment().get(appName); |
| 172 | + } |
| 173 | + } |
| 174 | + } |
| 175 | + |
| 176 | + // grab the latest one, there is no way to make |
| 177 | + // sure which one the user is actually enabling, |
| 178 | + // so use the best case, i.e. upgrade |
| 179 | + Iterator<String> it = disabledApps.iterator(); |
| 180 | + String lastDisabledApp = null; |
| 181 | + while (it.hasNext()) { |
| 182 | + lastDisabledApp = it.next(); |
| 183 | + } |
| 184 | + if (lastDisabledApp != null) { |
| 185 | + return ejbUtil.getDeployment().get(lastDisabledApp); |
| 186 | + } |
| 187 | + |
| 188 | + throw new NamingException("Application Information Not Found"); |
| 189 | + } |
| 190 | + |
159 | 191 | private void registerEjbInterceptor() { |
160 | 192 | try { |
161 | 193 | final Object interceptor = new EjbComponentInterceptor(locator); |
162 | 194 | initialContext = getInitialContext(); |
163 | 195 | final EjbContainerUtil ejbUtil = EjbContainerUtilImpl.getInstance(); |
164 | | - final ApplicationInfo appInfo = ejbUtil.getDeployment().get((String) initialContext.lookup("java:app/AppName")); |
| 196 | + final ApplicationInfo appInfo = getApplicationInfo(ejbUtil); |
165 | 197 | final List<String> tempLibNames = new LinkedList<>(); |
166 | 198 | for (ModuleInfo moduleInfo : appInfo.getModuleInfos()) { |
167 | 199 | final String jarName = moduleInfo.getName(); |
|
0 commit comments