Can't recover EJB client if EJB server is restarted -- requires client restart - Websphere

This is a discussion on Can't recover EJB client if EJB server is restarted -- requires client restart - Websphere ; We have a Session EJB stub that previously communicated with its Session EJB running on a server (WSAD 5.1 WebSphere Test Environment). We then stop the server and restart it. When we try to create a new connection to the ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Can't recover EJB client if EJB server is restarted -- requires client restart

  1. Can't recover EJB client if EJB server is restarted -- requires client restart

    We have a Session EJB stub that previously communicated with its Session EJB running on a server (WSAD 5.1 WebSphere Test Environment). We then stop the server and restart it. When we try to create a new connection to the restarted server from the client, we get a connection refused error returned in a RemoteException and can't proceed -- we need to stop and restart the client. There must be a way to recover when the server has restarted, but in the application code we get as far as calling home.create() and the rest is generated stub code for the Session EJB client code. Is it wrong to use a static method for this kind of communications? Thanks in advance for your help -- details follow. Basic flow is:

    server is stopped and restarted
    plugin (client) calls open for host and port (we've switched the classloader so the dynamic class references in underlying websphere code will have an appropriate path).
    open calls a static method to create the client Session EJB stub called getDmgrSession passing the host and port.
    this method gets to the home.create() call without any problem and calls it.
    control transfers to the DmgrSessionHome_Stub.create() method.
    in the create() method where it gets hung up on a thrown exception (I thought it was on the _invoke but the logic is to recall create() until an exception other than RemarshalException is thrown so the stackTrace below shows the error in _request rather than in _invoke...

    Best Regards, Nat

    In our application, when we attempt to call home.create() for a Session EJB that we've set up using a static method shown below. We get through the calls to get teh initial context, created the home object, and created our stub object (home). But, the home.create() fails with a RemoteException (see exception trace below). We can't fix this unless we stop the client completely (in this case, terminating its JVM as we're running as a plugin in the workbench runtime in WSAD) and restart it. How can we programmatically recover from this exception (appears to be at the underlying CORBA communications layer) so we can keep our program running and re-establish communications to the server.:

    public static DmgrSession getDmgrSession(String strHost, int iPort)
    throws MyException {
    String strHostURL = null;
    if (strHost == null)
    strHost = MyPreferences.getMyServerName();
    if (iPort == UNDEFINED_int)
    iPort = new Integer(MyPreferences.getMyServerPort()).intValue( );
    try {
    Properties p = new Properties();
    p.put(
    Context.INITIAL_CONTEXT_FACTORY,
    "com.ibm.websphere.naming.WsnInitialContextFactory");
    strHostURL = "iiop://" + strHost + ":" + iPort + "/";
    p.put(Context.PROVIDER_URL, strHostURL);
    // System.out.println("Creating session with " + strHostURL);
    InitialContext ic = null;
    try {
    ic = new InitialContext(p);
    } catch (NamingException ne) {
    if (My.getTrace().isLogging()) {
    My.getTrace().exception(
    My.TRC_LOW,
    m_strClassName,
    "getDmgrSession(String strHost,int iPort)",
    ne);
    }
    ne.printStackTrace();
    // System.out.println("Properties:" + p.toString());
    throw new MyException(
    "Naming exception creating initial context " + strHostURL,
    ne);
    }

    Object homeObject =
    ic.lookup("ejb/com/ibm/my/dmgr/session/DmgrSessionHome");
    DmgrSessionHome home =
    (DmgrSessionHome) PortableRemoteObject.narrow(
    homeObject,
    DmgrSessionHome.class);
    return home.create();

    } catch (NamingException e) {
    if (My.getTrace().isLogging()) {
    My.getTrace().exception(
    My.TRC_LOW,
    m_strClassName,
    "getDmgrSession(String strHost,int iPort)",
    e);
    }
    throw new MyException(
    "Naming exception creating session with " + strHostURL,
    e);
    } catch (CreateException e) {
    if (My.getTrace().isLogging()) {
    My.getTrace().text(
    My.TRC_LOW,
    m_strClassName,
    "getDmgrSession(String strHost,int iPort)",
    e.getLocalizedMessage());
    }
    throw new MyException("Unable to create session with " + strHostURL, e);
    } catch (RemoteException e) {
    e.printStackTrace();
    if (My.getTrace().isLogging()) {
    My.getTrace().text(
    My.TRC_LOW,
    m_strClassName,
    "getDmgrSession(String strHost,int iPort)",
    e.getLocalizedMessage());
    }
    throw new MyException(
    "Remote excpetion creating session with " + strHostURL,
    e);
    }
    }


    public DmgrSession create() throws CreateException, RemoteException {
    if (!Util.isLocal(this)) {
    try {
    org.omg.CORBA_2_3.portable.InputStream in = null;
    try {
    org.omg.CORBA.portable.OutputStream out = _request("create", true);
    in = (org.omg.CORBA_2_3.portable.InputStream)_invoke(ou t);
    return (DmgrSession) in.read_Object(DmgrSession.class);
    } catch (ApplicationException ex) {
    in = (org.omg.CORBA_2_3.portable.InputStream) ex.getInputStream();
    String id = in.read_string();
    if (id.equals("IDL:javax/ejb/CreateEx:1.0")) {
    throw (CreateException) in.read_value(CreateException.class);
    }
    throw new UnexpectedException(id);
    } catch (RemarshalException ex) {
    return create();
    } finally {
    _releaseReply(in);
    }
    } catch (SystemException ex) {
    throw Util.mapSystemException(ex);
    }
    } else {
    ServantObject so = _servant_preinvoke("create",com.ibm.my.dmgr.session.DmgrSessionHome.class);
    if (so == null) {
    return create();
    }
    try {
    DmgrSession result = ((com.ibm.my.dmgr.session.DmgrSessionHome)so.serva nt).create();
    return (DmgrSession)Util.copyObject(result,_orb());
    } catch (Throwable ex) {
    Throwable exCopy = (Throwable)Util.copyObject(ex,_orb());
    if (exCopy instanceof CreateException) {
    throw (CreateException)exCopy;
    }
    throw Util.wrapException(exCopy);
    } finally {
    _servant_postinvoke(so);
    }
    }
    }

    Here is the exception we are receiving:

    java.rmi.RemoteException: CORBA TRANSIENT 0x4942f301 No; nested exception is:
    org.omg.CORBA.TRANSIENT: Connection refused: connect:host=myhost.mydomain.com,port=1520 minor code: 4942F301 completed: No
    org.omg.CORBA.TRANSIENT: Connection refused: connect:host=myhost.mydomain.com,port=1520 minor code: 4942F301 completed: No
    at com.ibm.CORBA.transport.TransportConnectionBase.co nnect(TransportConnectionBase.java:450)
    at com.ibm.rmi.transport.TCPTransport.getConnection(T CPTransport.java:188)
    at com.ibm.rmi.iiop.TransportManager.get(TransportMan ager.java:83)
    at com.ibm.rmi.iiop.GIOPImpl.createRequest(GIOPImpl.j ava:130)
    at com.ibm.rmi.iiop.GIOPImpl.createRequest(GIOPImpl.j ava:95)
    at com.ibm.rmi.corba.ClientDelegate._createRequest(Cl ientDelegate.java:1934)
    at com.ibm.rmi.corba.ClientDelegate.createRequest(Cli entDelegate.java:1235)
    at com.ibm.rmi.corba.ClientDelegate.createRequest(Cli entDelegate.java:1168)
    at com.ibm.rmi.corba.ClientDelegate.request(ClientDel egate.java:1830)
    at org.omg.CORBA.portable.ObjectImpl._request(ObjectI mpl.java:245)
    at com.ibm.my.dmgr.session._DmgrSessionHome_Stub.crea te(_DmgrSessionHome_Stub.java:206)
    at com.ibm.my.core.DataManager.getDmgrSession(DataMan ager.java:94)
    at com.ibm.my.core.DataManager.open(DataManager.java: 976)
    at com.ibm.my.myplugin.dialogs.MainDomainSelect$1.wid getSelected(MainDomainSelect.java:264)
    at org.eclipse.swt.widgets.TypedListener.handleEvent( TypedListener.java:89)
    at org.eclipse.swt.widgets.EventTable.sendEvent(Event Table.java(Inlined Compiled Code))
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.ja va(Inlined Compiled Code))
    at org.eclipse.swt.widgets.Display.runDeferredEvents( Display.java(Compiled Code))
    at org.eclipse.swt.widgets.Display.readAndDispatch(Di splay.java(Compiled Code))
    at com.ibm.my.myplugin.dialogs.MainDomainSelect.open( MainDomainSelect.java(Compiled Code))
    at com.ibm.my.myplugin.actions.DelegateMenu$3.widgetS elected(DelegateMenu.java:73)
    at org.eclipse.swt.widgets.TypedListener.handleEvent( TypedListener.java:89)
    at org.eclipse.swt.widgets.EventTable.sendEvent(Event Table.java(Compiled Code))
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.ja va:840)
    at org.eclipse.swt.widgets.Display.runDeferredEvents( Display.java:1838)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Di splay.java(Compiled Code))
    at org.eclipse.ui.internal.Workbench.runEventLoop(Wor kbench.java:1402)
    at org.eclipse.ui.internal.Workbench.run(Workbench.ja va:1385)
    at org.eclipse.core.internal.boot.InternalBootLoader. run(InternalBootLoader.java:858)
    at org.eclipse.core.boot.BootLoader.run(BootLoader.ja va:461)
    at java.lang.reflect.Method.invoke(Native Method)
    at org.eclipse.core.launcher.Main.basicRun(Main.java: 291)
    at org.eclipse.core.launcher.Main.run(Main.java:747)
    at org.eclipse.core.launcher.Main.main(Main.java:583)
    2004.02.23 13:32:46.439 com.ibm.my.core.DataManager getDmgrSession(String strHost,int iPort)
    CORBA TRANSIENT 0x4942f301 No; nested exception is:
    org.omg.CORBA.TRANSIENT: Connection refused: connect:host=myhost.mydomain.com,port=1520 minor code: 4942F301 completed: No


  2. Re: Can't recover EJB client if EJB server is restarted -- requires client restart

    We encontered this problem back in 3.5, the JNDI cache manager caches
    the home interface under the covers. In 3.5, we had to explicitly
    clear the cache to avoid this problem.

    when we migrated to WA 5.x, we had concerns, even though IBM informed
    us this was no longer an issues. i did all kinds of testing in a ND
    environment. my client was always able to reconnect without a
    restart, i thought the issue was fixed. but, recently we have
    discovered it in a different scenario. i have an ejb client running
    on Sun in a ND environement calling a EJB running in base environment
    on Windows 2000. When the EJB server is bounce, the EJB client can no
    longer connect, always the CORBA Transient exception.

    So, i went back and did more testing in my ND environment, can't
    reproduce the problem, the cient can always connect. It must have
    something to do with base edition and single server edition on WAS 5.

    You could try the solution we used in 3.5, which was to clear the JNDI
    cache manager before you do a call, unfortuately, i don't know which
    class that would be under 5.

    Chris

    wnm3 wrote in message news:<1910135688.1078073574130.JavaMail.wasadmin@swg3ws0 06>...
    > We have a Session EJB stub that previously communicated with its

    Session EJB running on a server (WSAD 5.1 WebSphere Test Environment).
    We then stop the server and restart it. When we try to create a new
    connection to the restarted server from the client, we get a
    connection refused error returned in a RemoteException and can't
    proceed -- we need to stop and restart the client. There must be a
    way to recover when the server has restarted, but in the application
    code we get as far as calling home.create() and the rest is generated
    stub code for the Session EJB client code. Is it wrong to use a
    static method for this kind of communications? Thanks in advance for
    your help -- details follow. Basic flow is:
    >
    > server is stopped and restarted
    > plugin (client) calls open for host and port (we've switched the classloader so the dynamic class references in underlying websphere code will have an appropriate path).
    > open calls a static method to create the client Session EJB stub called getDmgrSession passing the host and port.
    > this method gets to the home.create() call without any problem and calls it.
    > control transfers to the DmgrSessionHome_Stub.create() method.
    > in the create() method where it gets hung up on a thrown exception (I thought it was on the _invoke but the logic is to recall create() until an exception other than RemarshalException is thrown so the stackTrace below shows the error in _request rather than in _invoke...
    >
    > Best Regards, Nat
    >
    > In our application, when we attempt to call home.create() for a

    Session EJB that we've set up using a static method shown below. We
    get through the calls to get teh initial context, created the home
    object, and created our stub object (home). But, the home.create()
    fails with a RemoteException (see exception trace below). We can't
    fix this unless we stop the client completely (in this case,
    terminating its JVM as we're running as a plugin in the workbench
    runtime in WSAD) and restart it. How can we programmatically recover
    from this exception (appears to be at the underlying CORBA
    communications layer) so we can keep our program running and
    re-establish communications to the server.:
    >
    > public static DmgrSession getDmgrSession(String strHost, int iPort)
    > throws MyException {
    > String strHostURL = null;
    > if (strHost == null)
    > strHost = MyPreferences.getMyServerName();
    > if (iPort == UNDEFINED_int)
    > iPort = new Integer(MyPreferences.getMyServerPort()).intValue( );
    > try {
    > Properties p = new Properties();
    > p.put(
    > Context.INITIAL_CONTEXT_FACTORY,
    > "com.ibm.websphere.naming.WsnInitialContextFactory");
    > strHostURL = "iiop://" + strHost + ":" + iPort + "/";
    > p.put(Context.PROVIDER_URL, strHostURL);
    > // System.out.println("Creating session with " + strHostURL);
    > InitialContext ic = null;
    > try {
    > ic = new InitialContext(p);
    > } catch (NamingException ne) {
    > if (My.getTrace().isLogging()) {
    > My.getTrace().exception(
    > My.TRC_LOW,
    > m_strClassName,
    > "getDmgrSession(String strHost,int iPort)",
    > ne);
    > }
    > ne.printStackTrace();
    > // System.out.println("Properties:" + p.toString());
    > throw new MyException(
    > "Naming exception creating initial context " + strHostURL,
    > ne);
    > }
    >
    > Object homeObject =
    > ic.lookup("ejb/com/ibm/my/dmgr/session/DmgrSessionHome");
    > DmgrSessionHome home =
    > (DmgrSessionHome) PortableRemoteObject.narrow(
    > homeObject,
    > DmgrSessionHome.class);
    > return home.create();
    >
    > } catch (NamingException e) {
    > if (My.getTrace().isLogging()) {
    > My.getTrace().exception(
    > My.TRC_LOW,
    > m_strClassName,
    > "getDmgrSession(String strHost,int iPort)",
    > e);
    > }
    > throw new MyException(
    > "Naming exception creating session with " + strHostURL,
    > e);
    > } catch (CreateException e) {
    > if (My.getTrace().isLogging()) {
    > My.getTrace().text(
    > My.TRC_LOW,
    > m_strClassName,
    > "getDmgrSession(String strHost,int iPort)",
    > e.getLocalizedMessage());
    > }
    > throw new MyException("Unable to create session with " + strHostURL, e);
    > } catch (RemoteException e) {
    > e.printStackTrace();
    > if (My.getTrace().isLogging()) {
    > My.getTrace().text(
    > My.TRC_LOW,
    > m_strClassName,
    > "getDmgrSession(String strHost,int iPort)",
    > e.getLocalizedMessage());
    > }
    > throw new MyException(
    > "Remote excpetion creating session with " + strHostURL,
    > e);
    > }
    > }
    >
    >
    > public DmgrSession create() throws CreateException, RemoteException {
    > if (!Util.isLocal(this)) {
    > try {
    > org.omg.CORBA_2_3.portable.InputStream in = null;
    > try {
    > org.omg.CORBA.portable.OutputStream out = _request("create", true);
    > in = (org.omg.CORBA_2_3.portable.InputStream)_invoke(ou t);
    > return (DmgrSession) in.read_Object(DmgrSession.class);
    > } catch (ApplicationException ex) {
    > in = (org.omg.CORBA_2_3.portable.InputStream) ex.getInputStream();
    > String id = in.read_string();
    > if (id.equals("IDL:javax/ejb/CreateEx:1.0")) {
    > throw (CreateException) in.read_value(CreateException.class);
    > }
    > throw new UnexpectedException(id);
    > } catch (RemarshalException ex) {
    > return create();
    > } finally {
    > _releaseReply(in);
    > }
    > } catch (SystemException ex) {
    > throw Util.mapSystemException(ex);
    > }
    > } else {
    > ServantObject so = _servant_preinvoke("create",com.ibm.my.dmgr.session.DmgrSessionHome.class);
    > if (so == null) {
    > return create();
    > }
    > try {
    > DmgrSession result = ((com.ibm.my.dmgr.session.DmgrSessionHome)so.serva nt).create();
    > return (DmgrSession)Util.copyObject(result,_orb());
    > } catch (Throwable ex) {
    > Throwable exCopy = (Throwable)Util.copyObject(ex,_orb());
    > if (exCopy instanceof CreateException) {
    > throw (CreateException)exCopy;
    > }
    > throw Util.wrapException(exCopy);
    > } finally {
    > _servant_postinvoke(so);
    > }
    > }
    > }
    >
    > Here is the exception we are receiving:
    >
    > java.rmi.RemoteException: CORBA TRANSIENT 0x4942f301 No; nested exception is:
    > org.omg.CORBA.TRANSIENT: Connection refused: connect:host=myhost.mydomain.com,port=1520 minor code: 4942F301 completed: No
    > org.omg.CORBA.TRANSIENT: Connection refused: connect:host=myhost.mydomain.com,port=1520 minor code: 4942F301 completed: No
    > at com.ibm.CORBA.transport.TransportConnectionBase.co nnect(TransportConnectionBase.java:450)
    > at com.ibm.rmi.transport.TCPTransport.getConnection(T CPTransport.java:188)
    > at com.ibm.rmi.iiop.TransportManager.get(TransportMan ager.java:83)
    > at com.ibm.rmi.iiop.GIOPImpl.createRequest(GIOPImpl.j ava:130)
    > at com.ibm.rmi.iiop.GIOPImpl.createRequest(GIOPImpl.j ava:95)
    > at com.ibm.rmi.corba.ClientDelegate._createRequest(Cl ientDelegate.java:1934)
    > at com.ibm.rmi.corba.ClientDelegate.createRequest(Cli entDelegate.java:1235)
    > at com.ibm.rmi.corba.ClientDelegate.createRequest(Cli entDelegate.java:1168)
    > at com.ibm.rmi.corba.ClientDelegate.request(ClientDel egate.java:1830)
    > at org.omg.CORBA.portable.ObjectImpl._request(ObjectI mpl.java:245)
    > at com.ibm.my.dmgr.session._DmgrSessionHome_Stub.crea te(_DmgrSessionHome_Stub.java:206)
    > at com.ibm.my.core.DataManager.getDmgrSession(DataMan ager.java:94)
    > at com.ibm.my.core.DataManager.open(DataManager.java: 976)
    > at com.ibm.my.myplugin.dialogs.MainDomainSelect$1.wid getSelected(MainDomainSelect.java:264)
    > at org.eclipse.swt.widgets.TypedListener.handleEvent( TypedListener.java:89)
    > at org.eclipse.swt.widgets.EventTable.sendEvent(Event Table.java(Inlined Compiled Code))
    > at org.eclipse.swt.widgets.Widget.sendEvent(Widget.ja va(Inlined Compiled Code))
    > at org.eclipse.swt.widgets.Display.runDeferredEvents( Display.java(Compiled Code))
    > at org.eclipse.swt.widgets.Display.readAndDispatch(Di splay.java(Compiled Code))
    > at com.ibm.my.myplugin.dialogs.MainDomainSelect.open( MainDomainSelect.java(Compiled Code))
    > at com.ibm.my.myplugin.actions.DelegateMenu$3.widgetS elected(DelegateMenu.java:73)
    > at org.eclipse.swt.widgets.TypedListener.handleEvent( TypedListener.java:89)
    > at org.eclipse.swt.widgets.EventTable.sendEvent(Event Table.java(Compiled Code))
    > at org.eclipse.swt.widgets.Widget.sendEvent(Widget.ja va:840)
    > at org.eclipse.swt.widgets.Display.runDeferredEvents( Display.java:1838)
    > at org.eclipse.swt.widgets.Display.readAndDispatch(Di splay.java(Compiled Code))
    > at org.eclipse.ui.internal.Workbench.runEventLoop(Wor kbench.java:1402)
    > at org.eclipse.ui.internal.Workbench.run(Workbench.ja va:1385)
    > at org.eclipse.core.internal.boot.InternalBootLoader. run(InternalBootLoader.java:858)
    > at org.eclipse.core.boot.BootLoader.run(BootLoader.ja va:461)
    > at java.lang.reflect.Method.invoke(Native Method)
    > at org.eclipse.core.launcher.Main.basicRun(Main.java: 291)
    > at org.eclipse.core.launcher.Main.run(Main.java:747)
    > at org.eclipse.core.launcher.Main.main(Main.java:583)
    > 2004.02.23 13:32:46.439 com.ibm.my.core.DataManager getDmgrSession(String strHost,int iPort)
    > CORBA TRANSIENT 0x4942f301 No; nested exception is:
    > org.omg.CORBA.TRANSIENT: Connection refused: connect:host=myhost.mydomain.com,port=1520 minor code: 4942F301 completed: No


+ Reply to Thread