0
votes

I'm using Weblogic 10.3.6, Mojarra 2.0.9 and EJB3. We have @ViewScoped and @SessionScoped JSF Managed beans and we require that in the event of a server failing the use can still continue. I had just about cracked it until I hit upon a problem using EJB injection on the JSF Beans. Here are the simplifed beans

EJB Interface

@JNDIName("our.ejb.jndiname")
@Remote
public interface OurEJBInterface {

    some methods...

}

EJB Bean

@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
public class ourBean implements OurEJBInterface {

    the methods...
}

JSF Backing Bean

@ManagedBean
@ViewScoped
public class OurBackingBean  {


    @EJB
    private OurBeanBeanInterface ourBeanBeanInterface ;


    public void submit()
    {
        ourBeanBeanInterface.doSomethingFromBean(); 
    }

}

When we simulate a failover the session is correctly retrieved from the new server however the reference to the EJB still points to the old server and we get this error:

javax.ejb.EJBException: Could not establish a connection with -1977369784351278190S:MCPVMWLS01:[7030,7030,-1,-1,-1,-1,-1]:Destin8ShowCase:JVM01, java.rmi.ConnectException: Destination unreachable; nested exception is: 
    java.io.IOException: Empty server reply; No available router to destination; nested exception is: 
    java.rmi.ConnectException: Destination unreachable; nested exception is: 
    java.io.IOException: Empty server reply; No available router to destination; nested exception is: java.rmi.ConnectException: Destination unreachable; nested exception is: 
    java.io.IOException: Empty server reply; No available router to destination
java.rmi.ConnectException: Destination unreachable; nested exception is: 
    java.io.IOException: Empty server reply; No available router to destination
    at weblogic.rjvm.ConnectionManager.bootstrap(ConnectionManager.java:470)
    at weblogic.rjvm.ConnectionManager.bootstrap(ConnectionManager.java:402)
    at weblogic.rjvm.RJVMImpl.ensureConnectionEstablished(RJVMImpl.java:306)
    at weblogic.rjvm.RJVMImpl.getOutputStream(RJVMImpl.java:350)
    at weblogic.rjvm.RJVMImpl.getRequestStreamInternal(RJVMImpl.java:612)
    at weblogic.rjvm.RJVMImpl.getRequestStream(RJVMImpl.java:563)
    at weblogic.rjvm.RJVMImpl.getOutboundRequest(RJVMImpl.java:789)
    at weblogic.rmi.internal.BasicRemoteRef.getOutboundRequest(BasicRemoteRef.java:159)
    at weblogic.rmi.internal.BasicRemoteRef.invoke(BasicRemoteRef.java:211)
    at com.mcpplc.destin8.ejbs.manifestenquiry.ManifestEnquiryFacadeBean_qzni2o_ManifestEnquiryFacadeBeanInterfaceImpl_1036_WLStub.doMEQ02(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at weblogic.ejb.container.internal.RemoteBusinessIntfProxy.invoke(RemoteBusinessIntfProxy.java:85)
    at $Proxy286.doMEQ02(Unknown Source)
    at com.mcpplc.destin8.web.jsf.backingbeans.imports.Meq02BackingBean.customProcessing(Meq02BackingBean.java:49)
    at com.mcpplc.destin8.web.jsf.backingbeans.BackingBean.submit(BackingBean.java:179)

Is there any way to get the Managed Bean to reinitialise a new EJB ref pointing to the new server?

I know I can use a service locator with the init placed in the submit method but would like to use @EJB if possible.

Thanks in advance.

2
If I understand correctly, your problem is about testing your patch. During the test you're not able to correctly instantiate your EJB. In this case you should use MocKClasses and also a MockServer. You can do it with arquillian.org, or maybe code.google.com/p/mockito is enough. I hope this helps you.Rodmar Conde
Thanks for reply but this is not test related. This is live code in a failover scenario.andyfinch

2 Answers

0
votes

I come from the JBoss world so I'm not completely sure about it. But can you really inject a remote interface in that way? There must be a lookup defined, I think. However for a local-interface your call should work. And if you use remote-interfaces you should use

@EJB(lookup="jnp://wholeclustername/YourBean/remote")

and your DNS must point your network to both machines.

Another possible workaround can be a @Produce-method and an @Inject where you do the lookup in the producer-method.

Edit:

Yes, unfortunately. I face these hacks from time to time, too:(

Maybe there's another workaround or a solution, I'm not firm enough in Weblogic. If you wanna decouple it from your source you can also use an interceptor and inject a slsb instance each call, maybe because of your failover it work with a @PostConstruct, too. I dont know:

public class LookUpEJBInterceptor {

@AroundInvoke
public Object around(InvocationContext ctx){
    try {
        Class<?> clazzOfEJBImplementation = ctx.getTarget().getClass();
        //look for your field, I just check for the EJB annotation but that's not enough
        for (Field f : clazzOfEJBImplementation.getDeclaredFields()){
            if(f.isAnnotationPresent(EJB.class)){
                f.setAccessible(true);
                f.set(ctx.getTarget(), lookupEJB());
            }
        }

        return ctx.proceed();
    } catch (Exception e) {
        e.printStackTrace();
        throw new EJBException();
    }

}

/**
 * get your ejb
 * 
 * @return
 * @throws NamingException
 */
private Object lookupEJB() throws NamingException{
    return new InitialContext().lookup("Your ejb lookup");
}

Second edit:

If you can use AspectJ you can construct a hack like this:

pointcut checkEJB(OurEJBInterface r): call(void OurEJBInterface.yourVoid()) && target(r);

void around (OurEJBInterface r) : yourVoid(r){
    r = lookupYourEJB();
    return proceed(r);
}

private Object lookupEJB() throws NamingException{
    return new InitialContext().lookup("Your ejb lookup");
}

But both are only hacks

0
votes

Managed to resolve this after some trial and error. As Jan eluded to my set up was injecting only a local jndi name. To ensure the returned EJB proxy was global I needed to remove the @JNDIname annotation from the interface and provide a mappedName to the @stateless and @ejb annotations

@Stateless(mappedName = "MyFacadeBean")

@EJB(mappedName = "MyFacadeBean")
private MyFacadeBean myFacadeBean;