|
Hi Vimalan, I just tried to re generate your error in my machine with the attached sample application. Check out is it the same scenario as yours. But I couldn't regenerate your problem. It looks the Exception is a network related one. Also I would like to add some comments to this scenario too. 1. The spec says you should narrow, but when using the org.openejb.client.RemoteInitialContextFactory, you never have to. We use dynamic proxies which don't require narrowing. 2. You might be able to escape from this Exception if you take property initialization to the out side of for loop. I would think it would be more practical scenario. Regards, Lasantha Ranaweera Arunanthisivam Vimalathithen wrote:
|
package org.apache.geronimo.samples.bank.client; import java.awt.Dimension; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Hashtable;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import org.apache.geronimo.samples.bank.ejb.BankManagerFacade;
import org.apache.geronimo.samples.bank.ejb.BankManagerFacadeHome;
import org.apache.geronimo.samples.bank.util.PropertyLoader;
/**
*
* @author Lasantha Ranaweera
*
*/
public class MainUI extends JFrame implements ActionListener{
JLabel lblAccountNumber;
JLabel lblBalance;
JTextField txtAccountNumber;
JTextField txtBalance;
JButton btnView;
JButton btnUpdate;
BankManagerFacade bankManager = null;
private static final String FACTORY_INITIAL = "java.naming.factory.initial";
private static final String PROVIDER_URL = "java.naming.provider.url";
private static final String SECURITY_PRINCIPAL = "java.naming.security.principal";
private static final String SECURITY_CREDENTIALS = "java.naming.security.credentials";
private static final String JNDI_BANK_MANAGER = "jndi.bankManager";
private static String CLIENT_PROP_FILE = "bank_client.properties";
public MainUI(){
super("Banking Remote Application");
this.setSize(300,190);
this.getContentPane().setLayout(null);
lblAccountNumber = new JLabel("Account Number");
lblBalance = new JLabel("Balance");
txtAccountNumber = new JTextField();
txtBalance = new JTextField();
btnView = new JButton("View");
btnView.addActionListener(this);
btnUpdate = new JButton("Update");
btnUpdate.addActionListener(this);
lblAccountNumber.setBounds(10,10,150,40);
lblBalance.setBounds(10,60,150,40);
txtAccountNumber.setBounds(180,10,100,40);
txtBalance.setBounds(180,60,100,40);
btnView.setBounds(10,110,130,40);
btnUpdate.setBounds(150,110,130,40);
this.getContentPane().add(lblAccountNumber);
this.getContentPane().add(lblBalance);
this.getContentPane().add(txtAccountNumber);
this.getContentPane().add(txtBalance);
this.getContentPane().add(btnView);
this.getContentPane().add(btnUpdate);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
this.setLocation((d.width-this.getWidth())/2, (d.height-this.getHeight())/2);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
this.setVisible(true);
try {
connect();
} catch (Exception e) {
JOptionPane.showMessageDialog(this,"Initialization Failed !!");
e.printStackTrace();
}
}
private void connect() throws Exception {
PropertyLoader propLoader = PropertyLoader.getInstance(CLIENT_PROP_FILE);
for(int i=0;i<2000;i++){
Hashtable env = new Hashtable();
env.put(FACTORY_INITIAL,propLoader.getValue(FACTORY_INITIAL));
env.put(PROVIDER_URL,propLoader.getValue(PROVIDER_URL));
env.put(SECURITY_PRINCIPAL,propLoader.getValue(SECURITY_PRINCIPAL));
env.put(SECURITY_CREDENTIALS,propLoader.getValue(SECURITY_CREDENTIALS));
javax.naming.InitialContext initialContext = new javax.naming.InitialContext(env);
Object objRef = initialContext.lookup(propLoader.getValue(JNDI_BANK_MANAGER));
BankManagerFacadeHome bankManagerHome = (BankManagerFacadeHome)javax.rmi.PortableRemoteObject.narrow(objRef, BankManagerFacadeHome.class);
bankManager = bankManagerHome.create();
System.out.println("Create "+i);
}
}
/**
* @param args
*/
public static void main(String[] args) throws Exception {
new MainUI();
}
public void actionPerformed(ActionEvent e) {
if(e.getSource() == btnView){
try {
String account = txtAccountNumber.getText();
Double balance = new Double(0);
for(int i=0;i<2000;i++){
balance = bankManager.getAccountBalance(account);
}
if(balance != null){
txtBalance.setText(balance.toString());
}else{
JOptionPane.showMessageDialog(this,"Account Number Not Found !!");
}
} catch (Exception e1) {
JOptionPane.showMessageDialog(this,"Remote Exception !!");
e1.printStackTrace();
}
}else if(e.getSource()== btnUpdate){
try {
String account = txtAccountNumber.getText();
String newBalance = txtBalance.getText();
bankManager.changeAccountBalance(account,new Double(newBalance));
txtBalance.setText("");
} catch (NumberFormatException e1) {
JOptionPane.showMessageDialog(this,"Invalid Number Format !!");
e1.printStackTrace();
} catch (Exception e1) {
JOptionPane.showMessageDialog(this,"Remote Exception !!");
e1.printStackTrace();
}
}
}
}
