hai
i have bank,store,client application.
client interact with store .store interact with bank and bank
intercat with client.
1.rmiregistry
2.bank
up to this no problem
3.store
then i got this exception
Remote Exception: java.rmi.ConnectException: Connection refused to host: localhost; nested exception is:
java.net.ConnectException: Connection refused
4.applet
then i got this error
java.security.AccessControlException: access denied (java.net.SocketPermission null resolve)
*************************
bank code
**********
import java.io.IOException;
import java.net.MalformedURLException;
import java.rmi.server.*;
import java.rmi.*;
public class BankSystemServer {
// public No-argument constructor
public BankSystemServer() {
}
public static void main(
String args[]) {
new BankSystemServer();
String bankHost;
String bankPort;
String bankService;
BankManager bm = null;
bankHost = "localhost";
bankPort = "8099";
System.setSecurityManager (new RMISecurityManager() {
public void checkConnect (String host, int port) {}
public void checkConnect (String host, int port, Object context) {}
});
//if (System.getSecurityManager() == null)
//{ System.setSecurityManager(new RMISecurityManager()); }
try {
// Create a BankManager object
bm = new BankManagerImpl();
// Export it to RMI
UnicastRemoteObject.exportObject( bm );
} catch (RemoteException remoteException) {
System.err.println("Failure during object export to RMI: " + remoteException);
}
// Register an external name for the service
try {
Naming.rebind("//" + bankHost + "/BankSystem", bm);
} catch (RemoteException remoteException) {
System.err.println("Failure during Name registration: " + remoteException);
} catch (MalformedURLException malformedException) {
System.err.println("Failure during Name registration: " + malformedException);
}
System.out.println("Bank System Server started.");
System.out.println("Enter <CR> to end.");
try {
int i = System.in.read();
} catch (IOException ioException) {
}
System.exit(0);
}
}
******************8
store server
**************
//File:StoreServer.java
//Purpose:main program of store server
import java.io.IOException;
import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;
import java.net.MalformedURLException;
public class StoreServer {
//constructor
public StoreServer() {
}
public static void main(String args[]) {
String storeHost;
String storePort;
String storeType;
String bankHost;
String bankPort;
// an instance of itself
new StoreServer();
StoreManager sm = null;
/*storeHost = args[0];
storePort = args[1];
storeType = args[2];
bankHost = args[3];
bankPort = args[4];*/
//if(storeHost==null)
storeHost = "localhost";
//if(storePort==null)
storePort = "9099";
//if(storePort==null)
storeType = "GiftStore";
bankHost="localhost";
bankPort="8099";
System.setSecurityManager (new RMISecurityManager() {
public void checkConnect (String host, int port) {}
public void checkConnect (String host, int port, Object context) {}
});
try { //sm: store service creation
// Create a StoreManager object
sm = new StoreManagerImpl(storeType, bankHost, bankPort);
// Export them to RMI
UnicastRemoteObject.exportObject( sm );
} catch (RemoteException remoteException) {
System.err.println(
"StoreServer: Failure during object export to RMI: " +
remoteException);
}
// Register an external name for the store services
try {
Naming.rebind("//"+ storeHost +"/" + storeType, sm);
} catch (RemoteException remoteException) {
System.err.println(
"StoreServer: Failure during Name registration: " +
remoteException);
} catch (MalformedURLException malformedException) {
System.err.println(
"StoreServer: Failure during Name registration: " +
malformedException);
}
System.out.println(storeType + " Server started.");
System.out.println("Enter <CR> to end.");
try {
int i = System.in.read();
} catch (IOException ioException) {
}
System.exit(0);
}
}
***********8
client
**************
//File:StoreShopperApplet.java
//Purpose:user interface for shopper as a client to access store
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.rmi.*;
import java.net.MalformedURLException;
import java.io.IOException;
import java.rmi.server.UnicastRemoteObject;
import java.net.MalformedURLException;
public class StoreShopperApplet extends Appletimplements ActionListener {
//GUI
String host;
Button button1; //gift store
Button button2; //book store
TextArea display;
String newline;
Font fn;
//rmi host cfg to get from html
private final String storeHostParam1 = "giftstorehost";
private final String storePortParam1 = "giftstoreport";
private final String storeService1 = "GiftStore";
private final String storeHostParam2 = "bookstorehost";
private final String storePortParam2 = "bookstoreport";
private final String storeService2 = "BookStore";
private final String shoppingHost = "shoppinghost";
private final String shoppingService = "shoppingserver";
private final String shoppingPort = "shoppingport";
String storeHostValue1;
String storeHostValue2;
String storePortValue1;
String storePortValue2;
String shoppingHostValue;
String shoppingServiceValue;
String shoppingPortValue;
//thread mem
ShopperThrdFrame thread1;
ShopperThrdFrame thread2;
ShopperConFrame m_Confirm1;
ShopperConFrame m_Confirm2;
//rmi shopper server
ShoppingManager shm = null;
//{member methods:
// the entry point for the
applet public void init() {
//init GUI
initForm();
usePageParams();
//any other constructor code
//start shopperServer
//applet doesn't need to set up security manager.
try {
// Create a ShoppingManager object
shm = new ShoppingManagerImpl(this);
// Export it to RMI
UnicastRemoteObject.exportObject( shm );
} catch (RemoteException remoteException) {
display.append("ShoppingServer: Failure during object export to RMI: " +
remoteException + newline);
disableEntry();
return;
}
// Register an external name for the shopping service
try {
Naming.rebind("//" + shoppingHostValue + "/" + shoppingServiceValue, shm);
} catch (RemoteException remoteException) {
display.append(shoppingServiceValue +" Failure during Name registration: " +
remoteException + newline);
disableEntry();
return;
} catch (MalformedURLException malformedException) {
display.append(shoppingServiceValue+" Failure during Name registration: " +
malformedException + newline);
disableEntry();
return;
}
//Create two frames to be prepared for bank confirmation
m_Confirm1 = new ShopperConFrame(this, storeService1);
m_Confirm2 = new ShopperConFrame(this, storeService2);
display.append( shoppingServiceValue + " started. Please click on buttons to enter stores."
+ newline);
}
//disable buttons to enter stores
private void disableEntry() {
button1.setEnabled(false);
button2.setEnabled(false);
}
// read parameters from the applet's HTML host and sets applet
// properties
private void usePageParams() {
//read in the parameters from html shopper.html
storeHostValue1 = getParameter(storeHostParam1);
storePortValue1 = getParameter(storePortParam1);
storeHostValue2 = getParameter(storeHostParam2);
storePortValue2 = getParameter(storePortParam2);
shoppingHostValue = getParameter(shoppingHost);
shoppingServiceValue = getParameter(shoppingService);
shoppingPortValue = getParameter(shoppingPort);
}
//init values for the applet and its componets
void initForm() {
this.setBackground(Color.lightGray);
this.setForeground(Color.black);
//font
fn = new Font("TimesRoman", Font.BOLD + Font.ITALIC, 25);
//layout components
GridBagLayout gridBag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
setLayout(gridBag);
setFont(new Font("TimesRoman", Font.PLAIN, 15));
display = new TextArea(10, 60);
display.setEditable(false);
c.gridy = 80;
c.gridwidth = GridBagConstraints.REMAINDER;
c.fill = GridBagConstraints.BOTH;
gridBag.setConstraints(display, c);
this.add(display);
button1 = new Button("Gift Store");
c.fill = GridBagConstraints.BOTH;
c.gridwidth = 1;
c.gridy = 140;
c.weightx = 1.0;
gridBag.setConstraints(button1, c);
button1.addActionListener(this);
this.add(button1);
button2 = new Button("Book Store");
c.fill = GridBagConstraints.BOTH;
c.weightx = 1.0;
c.gridwidth = GridBagConstraints.REMAINDER;
gridBag.setConstraints(button2, c);
button2.addActionListener(this);
this.add(button2);
newline = System.getProperty("line.separator");
}
public void paint(Graphics g) {
g.setFont(fn);
g.setColor(Color.green);
g.drawString("WELCOME TO RMI E-STORES", 20, 20);
}
//action listener
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand() == "Gift Store") {
display.append("Received your request to Gift store on " +
storeHostValue1 + " port " + storePortValue1 + newline);
//in case user clicks it again
button1.setEnabled(false);
//Create a
thread and a dialog for Giftstore
thread1 = new ShopperThrdFrame(this, storePortValue1,
storeService1,
storeHostValue1);
thread1.start();
}
if(e.getActionCommand() == "Book Store") {
display.append("Received your request to Book store on " +
storeHostValue2 + " port " + storePortValue2 + newline);
//in case user clicks it again
button2.setEnabled(false);
//Create a thread and a dialog for Furniture Store
thread2 = new ShopperThrdFrame(this, storePortValue2,
storeService2,
storeHostValue2);
thread2.start();
}
}
//finalize
private void mfinalize( ) {
//when it exits, clean up threads!
}
}
******************8
pls help me (urgent)