RMI query

G

Glenn Robinson

Hello,

I'm using RMI for the first time and I'm having a slight problem.

I've created client and server classes for my application and I can use
these ok on my Windows machine.

If I take the three classes I have over to my Linux machine and try to use
them I get an error:

I/O Error or Bad URL

I start rmiregistry and I can see it's listening on port 1099.
I start my server class and it sits there waiting for an imcoming request
The above error occurs when I run my client code and it tries to execute the
line:

RmtServer server =
(RmtServer) Naming.lookup("rmi://" + host + "/RMIServer");

When I run the client class I pass the name of the host where rmiregistry is
running, I've been using localhost so far.

I've tried recompiling all three classes again and running rmic on the
server class but I get the same error.

Any ideas where I'm going wrong?
 
I

iksrazal

Glenn Robinson said:
Hello,

I'm using RMI for the first time and I'm having a slight problem.

I've created client and server classes for my application and I can use
these ok on my Windows machine.

If I take the three classes I have over to my Linux machine and try to use
them I get an error:

I/O Error or Bad URL

I start rmiregistry and I can see it's listening on port 1099.
I start my server class and it sits there waiting for an imcoming request
The above error occurs when I run my client code and it tries to execute the
line:

RmtServer server =
(RmtServer) Naming.lookup("rmi://" + host + "/RMIServer");

When I run the client class I pass the name of the host where rmiregistry is
running, I've been using localhost so far.

I've tried recompiling all three classes again and running rmic on the
server class but I get the same error.

Any ideas where I'm going wrong?

Not really, your invokation line looks correct but without the full
code and stacktrace, its nearly impossible to say.

Two quick thoughts:

1) Try doing a netstat to verify your 1099 port is indeed connected to
the process you think it is. I just seen that problem last week. Make
sure everything is killed and try again.
2) Doesn't seem to be your problem, but it wouldn't hurt using a
policy file that opens up everything until you get it worked out. I
usually have to have one on *nix. Sorta like:

nohup java -Djava.security.policy=policy.txt RmiServer &

Where policy.txt is like:

grant {
permission java.security.AllPermission "", "";
};

HTH

Outsource to an American programmer living in brazil!
http://www.braziloutsource.com/
iksrazal
 
G

Glenn Robinson

iksrazal said:
"Glenn Robinson" <[email protected]> wrote in message

Not really, your invokation line looks correct but without the full
code and stacktrace, its nearly impossible to say.

Two quick thoughts:

1) Try doing a netstat to verify your 1099 port is indeed connected to
the process you think it is. I just seen that problem last week. Make
sure everything is killed and try again.
2) Doesn't seem to be your problem, but it wouldn't hurt using a
policy file that opens up everything until you get it worked out. I
usually have to have one on *nix. Sorta like:

nohup java -Djava.security.policy=policy.txt RmiServer &

Where policy.txt is like:

grant {
permission java.security.AllPermission "", "";
};

HTH

Outsource to an American programmer living in brazil!
http://www.braziloutsource.com/
iksrazal

Thank, but no different I'm afraid. Here's the source:

*********************************
/**
* @author Glenn Robinson
* Interface to declare specific methods as remote
*/
import java.rmi.*;

public interface RmtServer extends Remote {

String getRecord() throws RemoteException;
boolean dltAll() throws RemoteException;
}

**************************************

/**
* @author Glenn Robinson
*
*/
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;


public class MyServer extends java.rmi.server.UnicastRemoteObject
// causes this class to listen for requests on the RMI port
implements RmtServer { // implements - references this class back to the
interface
private ResultSet rs;
private boolean rsFetched = false;
private int i = 0;

public MyServer() throws RemoteException {
} // constructor - must throw RemoteException

// open the database file and select the records

private void openDBF() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:eek:dbc:clipper";
Connection con = DriverManager.getConnection(url);
System.out.println("Connection to clipper successful.");

Statement stmt = con.createStatement();
String query = "SELECT * FROM customerDetail.dbf";
rs = stmt.executeQuery(query);
rsFetched = true;
} catch (Exception e) {
System.err.println(e.toString());
}
}

// get a record set from the database
public String getRecord() throws RemoteException {
try {
if (!rsFetched) {
System.out.println("rsFetched = " + rsFetched);
openDBF();
}
while (rs.next()) {
i = i + 1;
return Integer.toString(i);
}
return null;

} catch (Exception e) {
System.err.println("Exception occurred: " + e.toString());
} finally {
closeFile();
}
return null;
}


public boolean dltAll() throws RemoteException {
return true;
}

public static void main(String args[]) {
try {
RmtServer server = new MyServer();
// create an instance of this class
Naming.rebind("GPRServer", server);
System.out.println(
"GPRServer registered with RMI. waiting for incoming requests.");
// register the object with the RMI registry
} catch (java.io.IOException e) {
System.err.println(
"A problem occurred trying to register the object with the RMI
registry.");
// problem registering server
}
}
}

**********************************************

/**
* @author Glenn Robinson
*
* */
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

public class MyClient {

public static void main(String[] args) throws RemoteException {
new MyClient(args[0]); // Create an instance of this class
}

public MyClient(String host) { // Constructor
String col1;
try {
RmtServer server =
(RmtServer) Naming.lookup("rmi://" + host + "/GPRServer");
System.out.println("Reading entire table, please wait . . . . . ");
while (1 > 0) {
col1 = server.getRecord();
if (!col1.equals(null)) {
// System.out.println("Reading entire table, please wait . . . . . ");
//System.out.println(col1);
} else {
System.out.println(col1);
break;
}
}
} catch (java.io.IOException e) {
System.err.println("I/O Error or Bad URL");
// I/O Error or bad URL
} catch (NotBoundException e) {
System.err.println("Select RMI registry entry is not registered");
// NiftyServer isn't registered
}
}
}

**************************************************

I javac all three java files, rmic MyServer, rmiserver &, java MyServer &
and then java MyClient localhost

I then get the error on my non-Windows systems!!!!

Hope this helps. Any suggestions welcome.

Glenn
 
I

iksrazal

snip
[/QUOTE]

Your code catches I/O exception and prints this error. Bad move. Try
printing out the stacktrace. I took your code, took out all the sql,
and ran it and it worked (on linux of course). My guess is that your
I/O error is being generated somewhere in you SQL code.

Here's my edited versions of your classes. Try these, and you should
be past having a RMI problem, and on to your SQL or business logic
looking for something creating an I/O exception, which a stacktrace
should convienantly point you to.

One other thought: Your RMI server code could be throwing somehow and
causing this. Be sure to print out stacktraces on both sides.

Lastly, that doen't really explain why it runs on windows and not
linux, except for possible format or OS dependencies in your business
logic. Such as writing or reading files, LF and CR, etc. Moral of the
story: print or log liberally, and don't catch exceptions with
evaluating stacktraces - that's what there for.

HTH

Outsource to an American programmer living in brazil!
http://www.braziloutsource.com/
iksrazal

/**
* @author Glenn Robinson
*
*/
import java.rmi.Naming;
import java.rmi.RemoteException;


// causes this class to listen for requests on the RMI port
public class MyServer extends java.rmi.server.UnicastRemoteObject
implements RmtServer
{ // implements - references this class back to the interface

public MyServer() throws RemoteException
{
} // constructor - must throw RemoteException

// get a record set from the database
public String getRecord() throws RemoteException
{
try
{
System.out.println("getRecord called successfully");
return "hello from get record";
}
catch (Exception e)
{
System.err.println("Exception occurred: " + e.toString());
return "get record said BOOM!";
}
}

public boolean dltAll() throws RemoteException
{
return true;
}

public static void main(String args[])
{
try
{
RmtServer server = new MyServer();
// create an instance of this class
Naming.rebind("GPRServer", server);
System.out.println("GPRServer registered with RMI. waiting for
incoming requests.");
// register the object with the RMI registry
}
catch (java.io.IOException e)
{
System.err.println("A problem occurred trying to register the
object with the RMI registry.");
// problem registering server
}
}
}

/**
* @author Glenn Robinson
* Interface to declare specific methods as remote
*/
import java.rmi.*;

public interface RmtServer extends Remote {

String getRecord() throws RemoteException;
boolean dltAll() throws RemoteException;
}

/**
* @author Glenn Robinson
*
* */
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

public class MyClient
{
public static void main(String[] args) throws RemoteException
{
new MyClient(args[0]); // Create an instance of this class
}

public MyClient(String host)
{ // Constructor
String col1;
try
{
RmtServer server = (RmtServer) Naming.lookup("rmi://" + host +
"/GPRServer");
col1 = server.getRecord();
System.out.println("get record returned: " + col1);
}
catch (java.io.IOException e)
{
e.printStackTrace();
}
catch (NotBoundException e)
{
e.printStackTrace();
}
}
}
 
G

Glenn Robinson

Thanks for that. I tried you're version and it works on my Linux system now.

You're right, it's not the RMI part but the SQL part.

Thanks

Glenn
iksrazal said:
"Glenn Robinson" <[email protected]> wrote in message
snip
to
use

Your code catches I/O exception and prints this error. Bad move. Try
printing out the stacktrace. I took your code, took out all the sql,
and ran it and it worked (on linux of course). My guess is that your
I/O error is being generated somewhere in you SQL code.

Here's my edited versions of your classes. Try these, and you should
be past having a RMI problem, and on to your SQL or business logic
looking for something creating an I/O exception, which a stacktrace
should convienantly point you to.

One other thought: Your RMI server code could be throwing somehow and
causing this. Be sure to print out stacktraces on both sides.

Lastly, that doen't really explain why it runs on windows and not
linux, except for possible format or OS dependencies in your business
logic. Such as writing or reading files, LF and CR, etc. Moral of the
story: print or log liberally, and don't catch exceptions with
evaluating stacktraces - that's what there for.

HTH

Outsource to an American programmer living in brazil!
http://www.braziloutsource.com/
iksrazal

/**
* @author Glenn Robinson
*
*/
import java.rmi.Naming;
import java.rmi.RemoteException;


// causes this class to listen for requests on the RMI port
public class MyServer extends java.rmi.server.UnicastRemoteObject
implements RmtServer
{ // implements - references this class back to the interface

public MyServer() throws RemoteException
{
} // constructor - must throw RemoteException

// get a record set from the database
public String getRecord() throws RemoteException
{
try
{
System.out.println("getRecord called successfully");
return "hello from get record";
}
catch (Exception e)
{
System.err.println("Exception occurred: " + e.toString());
return "get record said BOOM!";
}
}

public boolean dltAll() throws RemoteException
{
return true;
}

public static void main(String args[])
{
try
{
RmtServer server = new MyServer();
// create an instance of this class
Naming.rebind("GPRServer", server);
System.out.println("GPRServer registered with RMI. waiting for
incoming requests.");
// register the object with the RMI registry
}
catch (java.io.IOException e)
{
System.err.println("A problem occurred trying to register the
object with the RMI registry.");
// problem registering server
}
}
}

/**
* @author Glenn Robinson
* Interface to declare specific methods as remote
*/
import java.rmi.*;

public interface RmtServer extends Remote {

String getRecord() throws RemoteException;
boolean dltAll() throws RemoteException;
}

/**
* @author Glenn Robinson
*
* */
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

public class MyClient
{
public static void main(String[] args) throws RemoteException
{
new MyClient(args[0]); // Create an instance of this class
}

public MyClient(String host)
{ // Constructor
String col1;
try
{
RmtServer server = (RmtServer) Naming.lookup("rmi://" + host +
"/GPRServer");
col1 = server.getRecord();
System.out.println("get record returned: " + col1);
}
catch (java.io.IOException e)
{
e.printStackTrace();
}
catch (NotBoundException e)
{
e.printStackTrace();
}
}
}
 
Joined
Feb 15, 2009
Messages
1
Reaction score
0
this code given for RMI query is not working properly....in d client class where the instance of the class is created using new operator...its giving an error ARRAYINDEXOUTOFBOUND: args[0].
can you please check the code and guide me further!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
DewittMill
Top