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

PAYARA-3121 Jersey Crashes for EJB Classes of Same Name #3950

Merged
merged 4 commits into from
Jun 24, 2019
Merged
Changes from 1 commit
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
Next Next commit
PAYARA-3121 Jersey Crashes for EJB Classes of Same Name
Signed-off-by: Gaurav Gupta <[email protected]>
  • Loading branch information
jGauravGupta committed Sep 28, 2018
commit 5421ff02b0695627da9c9280fb17c6371f537354
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
// Portions Copyright [2018] [Payara Foundation and/or its affiliates]

package org.glassfish.jersey.gf.ejb.internal;

Expand Down Expand Up @@ -331,7 +332,7 @@ private void logLookupException(final Method method, final Class<?> component, C
LocalizationMessages.EJB_INTERFACE_HANDLING_METHOD_LOOKUP_EXCEPTION(method, component, iFace), ex);
}

private List<Class> remoteAndLocalIfaces(final Class<?> resourceClass) {
private static List<Class> remoteAndLocalIfaces(final Class<?> resourceClass) {
final List<Class> allLocalOrRemoteIfaces = new LinkedList<>();
if (resourceClass.isAnnotationPresent(Remote.class)) {
allLocalOrRemoteIfaces.addAll(Arrays.asList(resourceClass.getAnnotation(Remote.class).value()));
Expand All @@ -357,18 +358,22 @@ private static InitialContext getInitialContext() {
}
}

private static Object lookup(InitialContext ic, Class<?> c, String name, EjbComponentProvider provider)
private static Object lookup(InitialContext ic, Class<?> rawType, String name, EjbComponentProvider provider)
throws NamingException {
try {
return lookupSimpleForm(ic, name, provider);
return lookupSimpleForm(ic, rawType, name, provider);
} catch (NamingException ex) {
LOGGER.log(Level.WARNING, LocalizationMessages.EJB_CLASS_SIMPLE_LOOKUP_FAILED(c.getName()), ex);
LOGGER.log(Level.WARNING, LocalizationMessages.EJB_CLASS_SIMPLE_LOOKUP_FAILED(rawType.getName()), ex);

return lookupFullyQualifiedForm(ic, c, name, provider);
return lookupFullyQualifiedForm(ic, rawType, name, provider);
}
}

private static Object lookupSimpleForm(InitialContext ic, String name, EjbComponentProvider provider) throws NamingException {
private static Object lookupSimpleForm(
InitialContext ic,
Class<?> rawType,
String name,
EjbComponentProvider provider) throws NamingException {
if (provider.libNames.isEmpty()) {
String jndiName = "java:module/" + name;
return ic.lookup(jndiName);
Expand All @@ -380,8 +385,16 @@ private static Object lookupSimpleForm(InitialContext ic, String name, EjbCompon
try {
result = ic.lookup(jndiName);
if (result != null) {
return result;
if (rawType.isInstance(result)
|| remoteAndLocalIfaces(rawType)
.stream()
.filter(iFaces -> iFaces.isInstance(result))
.findAny()
.isPresent()) {
return result;
}
}

} catch (NamingException e) {
ne = e;
}
Expand All @@ -390,20 +403,30 @@ private static Object lookupSimpleForm(InitialContext ic, String name, EjbCompon
}
}

private static Object lookupFullyQualifiedForm(InitialContext ic, Class<?> c, String name, EjbComponentProvider provider)
throws NamingException {
private static Object lookupFullyQualifiedForm(
InitialContext ic,
Class<?> rawType,
String name,
EjbComponentProvider provider) throws NamingException {
if (provider.libNames.isEmpty()) {
String jndiName = "java:module/" + name + "!" + c.getName();
String jndiName = "java:module/" + name + "!" + rawType.getName();
return ic.lookup(jndiName);
} else {
NamingException ne = null;
for (String moduleName : provider.libNames) {
String jndiName = "java:app/" + moduleName + "/" + name + "!" + c.getName();
String jndiName = "java:app/" + moduleName + "/" + name + "!" + rawType.getName();
Object result;
try {
result = ic.lookup(jndiName);
if (result != null) {
return result;
if (rawType.isInstance(result)
jGauravGupta marked this conversation as resolved.
Show resolved Hide resolved
|| remoteAndLocalIfaces(rawType)
.stream()
.filter(iFaces -> iFaces.isInstance(result))
.findAny()
.isPresent()) {
return result;
}
}
} catch (NamingException e) {
ne = e;
Expand Down