diff --git a/containers/glassfish/jersey-gf-ejb/src/main/java/org/glassfish/jersey/gf/ejb/internal/EjbComponentProvider.java b/containers/glassfish/jersey-gf-ejb/src/main/java/org/glassfish/jersey/gf/ejb/internal/EjbComponentProvider.java index 2602c3f0cc..669e1d2a6f 100644 --- a/containers/glassfish/jersey-gf-ejb/src/main/java/org/glassfish/jersey/gf/ejb/internal/EjbComponentProvider.java +++ b/containers/glassfish/jersey-gf-ejb/src/main/java/org/glassfish/jersey/gf/ejb/internal/EjbComponentProvider.java @@ -16,6 +16,8 @@ */ package org.glassfish.jersey.gf.ejb.internal; +import java.io.Externalizable; +import java.io.Serializable; import java.lang.annotation.Annotation; import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationTargetException; @@ -42,6 +44,7 @@ import javax.annotation.Priority; import javax.ejb.Local; import javax.ejb.Remote; +import javax.ejb.Stateless; import javax.inject.Singleton; import javax.naming.InitialContext; import javax.naming.NamingException; @@ -92,23 +95,43 @@ private static class EjbFactory implements Supplier { final InitialContext ctx; final Class clazz; + final String beanName; final EjbComponentProvider ejbProvider; @SuppressWarnings("unchecked") @Override public T get() { try { - return (T) lookup(ctx, clazz, clazz.getSimpleName(), ejbProvider); + return (T) lookup(ctx, clazz, beanName, ejbProvider); } catch (NamingException ex) { Logger.getLogger(ApplicationHandler.class.getName()).log(Level.SEVERE, null, ex); return null; } } + private static String getBeanName(final Class clazz) { + final Stateless stateless = clazz.getAnnotation(Stateless.class); + if (stateless != null) { + if (stateless.name().isEmpty()) { + return clazz.getSimpleName(); + } + return stateless.name(); + } + final javax.ejb.Singleton singleton = clazz.getAnnotation(javax.ejb.Singleton.class); + if (singleton != null) { + if (singleton.name().isEmpty()) { + return clazz.getSimpleName(); + } + return singleton.name(); + } + return clazz.getSimpleName(); + } + public EjbFactory(Class rawType, InitialContext ctx, EjbComponentProvider ejbProvider) { this.clazz = rawType; this.ctx = ctx; this.ejbProvider = ejbProvider; + this.beanName = getBeanName(rawType); } } @@ -346,9 +369,23 @@ private static List remoteAndLocalIfaces(final Class resourceClass) { allLocalOrRemoteIfaces.add(i); } } + if (allLocalOrRemoteIfaces.isEmpty()) { + for (Class i : resourceClass.getInterfaces()) { + if (isAcceptableLocalInterface(i)) { + allLocalOrRemoteIfaces.add(i); + } + } + } return allLocalOrRemoteIfaces; } + private static boolean isAcceptableLocalInterface(final Class iface) { + if ("javax.ejb".equals(iface.getPackage().getName())) { + return false; + } + return !Serializable.class.equals(iface) && !Externalizable.class.equals(iface); + } + private static InitialContext getInitialContext() { try { // Deployment on Google App Engine will