Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed stacktraces caused by incorrect JNDI lookup #4373

Merged
merged 1 commit into from
Feb 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
jansupol marked this conversation as resolved.
Show resolved Hide resolved
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