I am trying to develop and execute a simple hello program using java
and corba with
jdk1.3. I actually took a sample that was posted on this newsgroup and I
am having the following problem.
The server side runs and generates a stringified reference and
writes it to a file. The client side reads the stringified reference but
fails to resolve the reference.
Server output looks like
C:\hcj\server\HelloApp>java -cp .;.. HelloServer
IOR:000000000000001749444c3a48656c6c6f4170702f48656c6c6f3a312e300000000000010000
000000000054000101000000000e3139322e3136382e302e3134350007b400000018afabcafe0000
000258f9385b00000008000000000000000000000001000000010000001400000000000100200000
00000001010000000000
Clinet output looks like
C:\hcj\client\HelloApp>java -cp .;.. HelloClient
In Try
orb init
reading from file
IOR:000000000000001749444c3a48656c6c6f4170702f48656c6c6f3a312e300000000000010000
000000000054000101000000000e3139322e3136382e302e3134350007b400000018afabcafe0000
000258f9385b00000008000000000000000000000001000000010000001400000000000100200000
00000001010000000000
ERROR : org.omg.CORBA.DATA_CONVERSION: minor code: 1398079489
completed: No
org.omg.CORBA.DATA_CONVERSION: minor code: 1398079489 completed: No
at com.sun.corba.se.internal.corba.ORB.hexOf(Unknown Source)
at com.sun.corba.se.internal.corba.ORB.string_to_object(Unknown
Source)
at HelloClient.main(HelloClient.java:34)
I am including the idl, server and the client program. Guidance is
appreciated. Thankyou
-Babru
ba...@lantercom.com
=========================================
============Hello World IDL File=============
=========================================
module HelloApp
{
interface Hello
{
string sayHello();
};
};
=========================================
============Hello World Client=============
=========================================
import HelloApp.*;
import org.omg.CosNaming.*;
import org.omg.CORBA.*;
import java.util.*;
import java.io.FileInputStream;
import java.io.IOException;
public class HelloClient
{
public static void main(String args[]) throws IOException
{
FileInputStream fis = new FileInputStream("ior.txt");
String strref;
byte [] byteref = new byte[300];
int len;
try{
System.out.println("In Try");
// create and initialize the ORB
Properties props = new Properties();
props.put("org.com.CORBA.ORBClass", "com.sun.CORBA.iiop.ORB");
props.put("org.com.CORBA.ORBSingletonClass","com.sun.CORBA.iiop.ORB");
props.put("org.omg.CORBA.ORBInitialPort", "1050");
props.put("org.omg.CORBA.ORBInitialHost", "192.168.0.145");
System.out.println("orb init");
ORB orb = org.omg.CORBA.ORB.init(args,props);
System.out.println("reading from file");
len = fis.read(byteref);
strref = new String(byteref);
fis.close();
System.out.println(strref);
Hello helloRef =
HelloHelper.narrow(orb.string_to_object(strref)); // <--- Error
System.out.println("resolve the Object Reference in Naming OK!!");
// call the Hello server object and print results
String hello = helloRef.sayHello();
System.out.println(hello);
} catch (Exception e) {
System.out.println("ERROR : " + e) ;
e.printStackTrace(System.out);
}
}
}
=======================================================
==========Server Code==================================
=======================================================
import HelloApp.*;
import java.util.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
import java.io.FileOutputStream;
import java.io.IOException;
class HelloServant extends _HelloImplBase
{
public String sayHello()
{
return "\nHello world !!\n";
}
}
public class HelloServer {
public static void main(String args[]) throws IOException
{
FileOutputStream fos = new FileOutputStream("ior.txt");
String strref;
try{
// Initialize the ORB.
Properties props = new Properties();
props.put("org.omg.CORBA.ORBInitialHost", "192.168.0.145");
props.put("org.omg.CORBA.ORBInitialPort", "1050");
ORB orb = org.omg.CORBA.ORB.init(args, props);
// create servant and register it with the ORB
HelloServant helloRef = new HelloServant();
orb.connect(helloRef);
strref = orb.object_to_string(helloRef);
System.out.println(strref);
fos.write(strref.getBytes());
fos.close();
// wait for invocations from clients
java.lang.Object sync = new java.lang.Object();
synchronized (sync) {
sync.wait();
}
} catch (Exception e) {
System.err.println("ERROR: " + e);
e.printStackTrace(System.out);
}
}
}