I have an active client EJB. If I restart the server I get exceptions because the underlying connection remains open to an invalid server. I don't know how to clean up this problem (tried using remove() but this didn't work. This problem plagues us even in WSAD 5.1.2 with 5.1 Test Environment. I suspect the generated Stub code should be able to clean up if it encounters this situation. I have a simple EJB project with a Stateful SessionBean that returns a Date object for the getDate() method and that easily recreates this problem. The client Tester.java code is pasted here with hopes someone can see how to fix the static method I've used to provide access to the server EJB:

package test;

import java.rmi.RemoteException;
import java.util.Date;
import java.util.Properties;

import javax.ejb.CreateException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;

public class Tester {

public static String read(String strPrompt) {
boolean bDone = false;
if ((strPrompt != null) && (strPrompt.length() != 0)) {
System.out.println(strPrompt);
}
StringBuffer buf = new StringBuffer(255);
int c;
try {
while (bDone == false) {
while ((c = System.in.read()) != -1) {
char ch = (char) c;
if (ch == '\r') {
continue; // skip the carriage return
}
if (ch == '\n') {
bDone = true;
break; // end when newline is reached
}
buf.append(ch);
}
}
} catch (java.io.IOException e) {
System.err.println(e);
}
if (buf.length() == 0) {
return null;
}
return buf.toString().trim();
}

public static SessionTest getSessionTest(String strHostName, int iPortNumber)
throws Exception {
String strHostURL = null;
if (strHostName == null)
strHostName = "localhost";
if (iPortNumber == -1)
iPortNumber = 2809;
try {
Properties p = new Properties();
p.put(
Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.websphere.naming.WsnInitialContextFactory");
strHostURL = "iiop://" + strHostName + ":" + iPortNumber + "/";
p.put(Context.PROVIDER_URL, strHostURL);
// System.out.println("Creating session with " + strHostURL);
InitialContext ic = null;
try {
ic = new InitialContext(p);
} catch (NamingException ne) {
ne.printStackTrace();
// System.out.println("Properties:" + p.toString());
throw new Exception(
"Naming exception creating initial context " + strHostURL);
}
Object homeObject =
ic.lookup("ejb/test/SessionTestHome");
SessionTestHome home =
(SessionTestHome) PortableRemoteObject.narrow(
homeObject,
SessionTestHome.class);
// was return home.create(); but added below to release context
SessionTest dmgr = home.create();
try {
ic.close();
} catch (NamingException ne) {
ne.printStackTrace();
}
return dmgr;
} catch (NamingException e) {
throw new Exception(
"Naming exception creating session with " + strHostURL);
} catch (CreateException e) {
throw new Exception("Unable to create session with " + strHostURL);
} catch (RemoteException e) {
e.printStackTrace();
throw new Exception(
"Remote excpetion creating session with " + strHostURL);
}
}
public static void main(String[] args) {
try {
System.out.println("Attempting to open the SessionTest");
SessionTest st = getSessionTest("localhost",2809);
System.out.println("Attempting to get date...");
Date date = st.getDate();
System.out.println("Got date: "+date);
read("Now, stop and restart the server and press enter when it has started.");
System.out.println("Attempting to get date again...");
try {
// expect exception here...
date = st.getDate();
System.out.println("Got date: "+date);
} catch (Exception e) {
// try closing and reopening
try {
st.remove();
} catch (Exception e1) {
System.out.println("Expected error since connection is no longer valid.");
e1.printStackTrace();
// don't stop, try to reopen session (don't know how to do this...)
}
try {
System.out.println("Attempting to open the SessionTest again");
st = getSessionTest("localhost",2809);
System.out.println("Attempting to get date yet again...");
date = st.getDate();
System.out.println("Got date: "+date);
} catch (Exception e2) {
}
}
st.remove();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Goodbye.");
}
}

The exception reported is:
Attempting to open the SessionTest
Attempting to get date...
Got date: Mon Jun 21 19:57:04 EDT 2004
Now, stop and restart the server and press enter when it has started.

Attempting to get date again...
java.rmi.RemoteException: CORBA TRANSIENT 0x4942f301 No; nested exception is:
org.omg.CORBA.TRANSIENT: Connection refused: connect:host=wnm3,port=1753 minor code: 4942F301 completed: No
org.omg.CORBA.TRANSIENT: Connection refused: connect:host=wnm3,port=1753 minor code: 4942F301 completed: No
at com.ibm.CORBA.transport.TransportConnectionBase.co nnect(TransportConnectionBase.java:457)
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:1924)
at com.ibm.rmi.corba.ClientDelegate.createRequest(Cli entDelegate.java:1225)
at com.ibm.rmi.corba.ClientDelegate.createRequest(Cli entDelegate.java:1158)
at com.ibm.rmi.corba.ClientDelegate.request(ClientDel egate.java:1820)
at org.omg.CORBA.portable.ObjectImpl._request(ObjectI mpl.java:245)
at test._SessionTest_Stub.remove(_SessionTest_Stub.ja va:112)
at test.Tester.main(Tester.java:110)
Expected error since connection is no longer valid.
Attempting to open the SessionTest again
java.rmi.RemoteException: CORBA TRANSIENT 0x4942f301 No; nested exception is:
org.omg.CORBA.TRANSIENT: Connection refused: connect:host=wnm3,port=1753 minor code: 4942F301 completed: No
org.omg.CORBA.TRANSIENT: Connection refused: connect:host=wnm3,port=1753 minor code: 4942F301 completed: No
at com.ibm.CORBA.transport.TransportConnectionBase.co nnect(TransportConnectionBase.java:457)
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:1924)
at com.ibm.rmi.corba.ClientDelegate.createRequest(Cli entDelegate.java:1225)
at com.ibm.rmi.corba.ClientDelegate.createRequest(Cli entDelegate.java:1158)
at com.ibm.rmi.corba.ClientDelegate.request(ClientDel egate.java:1820)
at org.omg.CORBA.portable.ObjectImpl._request(ObjectI mpl.java:245)
at test._SessionTestHome_Stub.create(_SessionTestHome _Stub.java:206)
at test.Tester.getSessionTest(Tester.java:76)
at test.Tester.main(Tester.java:118)
java.rmi.RemoteException: CORBA TRANSIENT 0x4942f301 No; nested exception is:
org.omg.CORBA.TRANSIENT: Connection refused: connect:host=wnm3,port=1753 minor code: 4942F301 completed: NoGoodbye.

org.omg.CORBA.TRANSIENT: Connection refused: connect:host=wnm3,port=1753 minor code: 4942F301 completed: No
at com.ibm.CORBA.transport.TransportConnectionBase.co nnect(TransportConnectionBase.java:457)
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:1924)
at com.ibm.rmi.corba.ClientDelegate.createRequest(Cli entDelegate.java:1225)
at com.ibm.rmi.corba.ClientDelegate.createRequest(Cli entDelegate.java:1158)
at com.ibm.rmi.corba.ClientDelegate.request(ClientDel egate.java:1820)
at org.omg.CORBA.portable.ObjectImpl._request(ObjectI mpl.java:245)
at test._SessionTest_Stub.remove(_SessionTest_Stub.ja va:112)
at test.Tester.main(Tester.java:125)