Evidently WebLogic 10.3.6 does not inject Local business interfaces into the JNDI registry.
According to Oracle Support note 1175123.1, one must add an ejb-local-ref
to web.xml
:
<ejb-local-ref>
<ejb-ref-name>[Name of EJB local interface here]</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local>[Fully qualified path to EJB local interface]</local>
</ejb-local-ref>
It's important that the ejb-ref-name
matches the interface name because that is what is obtained by the code below to allow the injection.
The code below is modified from the link above to obtain the simple name for the Interface
, prefixed with java:comp/env/
to conform the the WebLogic 10.3.6 naming standard.
import com.sun.jersey.core.spi.component.ComponentContext;
import com.sun.jersey.core.spi.component.ComponentScope;
import com.sun.jersey.spi.inject.Injectable;
import com.sun.jersey.spi.inject.InjectableProvider;
import java.lang.reflect.Type;
import javax.ejb.EJB;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.ws.rs.ext.Provider;
/**
* JAX-RS EJB Injection provider.
*/
@Provider
public class EJBProvider implements InjectableProvider<EJB, Type> {
public ComponentScope getScope() {
return ComponentScope.Singleton;
}
public Injectable getInjectable(ComponentContext cc, EJB ejb, Type t) {
if (!(t instanceof Class))
return null;
try {
Class c = (Class)t;
Context ic = new InitialContext();
String simpleName = String.format("java:comp/env/%s", c.getSimpleName());
final Object o = ic.lookup(simpleName);
return new Injectable<Object>() {
public Object getValue() {
return o;
}
};
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}