Skip to content

Commit

Permalink
Fixed stacktraces caused by incorrect JNDI lookup (eclipse-ee4j#4373)
Browse files Browse the repository at this point in the history
* Fixed processing default local interface
  - cause:
    - the stateless bean implemented some interface from library
    - the interface was annotated only with @path
    - neither interface nor class was annotated by @Local or @Remote (then @Local is implicit in ejb3.2)

* Implemented support of Stateless.name attribute
  - it is used in JNDI names on Payara

* Limited default local interfaces
  - partial impl of the ejb 3.2 spec 4.9.7, some interfaces are not allowed

Signed-off-by: David Matejcek <[email protected]>
  • Loading branch information
dmatej committed Feb 19, 2020
1 parent a19a446 commit e17b2b1
Showing 1 changed file with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -92,23 +95,43 @@ private static class EjbFactory<T> implements Supplier<T> {

final InitialContext ctx;
final Class<T> 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 <T> String getBeanName(final Class<T> 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<T> rawType, InitialContext ctx, EjbComponentProvider ejbProvider) {
this.clazz = rawType;
this.ctx = ctx;
this.ejbProvider = ejbProvider;
this.beanName = getBeanName(rawType);
}
}

Expand Down Expand Up @@ -346,9 +369,23 @@ private static List<Class> 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
Expand Down

0 comments on commit e17b2b1

Please sign in to comment.