Corbaloc

Hi everybody,

I am just trying to learn how to make available a remote object through corbaloc, but there is not way to may it work...

I have do the same using corbaname and it works and for that reason I am going mad...

These are my sources:

The server:

public class HelloServer {

public static void main(String args[]) {

try{

Properties props = new Properties();

props.put("org.omg.CORBA.ORBInitialPort", "1050");

props.put("org.omg.CORBA.ORBInitialHost", "localhost");

String s[] = null;

ORB orb = ORB.init(s,props);

HelloImpl helloImpl = new HelloImpl();

POA rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));

rootpoa.the_POAManager().activate();

org.omg.CORBA.Object obj = orb.resolve_initial_references("NameService" );

NamingContextExt rootContext = NamingContextExtHelper.narrow(obj);

NameComponent[] nc = rootContext.to_name("Hello");

rootContext.rebind(nc,rootpoa.servant_to_reference(helloImpl));

System.out.println("HelloServer ready and waiting ...");

orb.run();

}

catch (Exception e) {

System.err.println("ERROR: " + e);

e.printStackTrace(System.out);

}

System.out.println("HelloServer Exiting ...");

}

}

The client that works:

public class HelloClient3

{

public static void main(String args[]){

try{

Properties props = new Properties();

props.put("org.omg.CORBA.ORBInitialPort", "1050");

props.put("org.omg.CORBA.ORBInitialHost", "localhost");

String s[] = null;

ORB orb = ORB.init(s,props);

Hello helloImpl = HelloHelper.narrow(orb.string_to_object("corbaname::localhost:1050#Hello"));

System.out.println("Obtained a handle on server object: " + helloImpl);

System.out.println(helloImpl.sayHello());

} catch (Exception e) {

System.out.println("ERROR : " + e) ;

e.printStackTrace(System.out);

}

}

}

The client that do not works:

public class HelloClient3

{

public static void main(String args[]){

try{

Properties props = new Properties();

props.put("org.omg.CORBA.ORBInitialPort", "1050");

props.put("org.omg.CORBA.ORBInitialHost", "localhost");

String s[] = null;

ORB orb = ORB.init(s,props);

helloImpl = HelloHelper.narrow(orb.string_to_object("corbaloc::localhost:1050/Hello"));

System.out.println("Obtained a handle on server object: " + helloImpl);

System.out.println(helloImpl.sayHello());

} catch (Exception e) {

System.out.println("ERROR : " + e) ;

e.printStackTrace(System.out);

}

}

}

I am really lost with this and I really need a hand. I will be really greatfull if somebody could help or show me other example that works.

Thanks in advance,

Oliver.

[2942 byte] By [obermudeza] at [2007-11-26 17:16:46]
# 1

That's not the correct format for a corbaloc reference. The JDK documentation says it is like this:

corbaloc:iiop:1.2@MyBank.com:2050/TraderService

so in your case something like

corbaloc:iiop:1.2@localhost:1050/Hello

See http://java.sun.com/j2se/1.5.0/docs/guide/idl/INStutorial.html#corbaloc

ejpa at 2007-7-8 23:44:50 > top of Java-index,Core,Core APIs...
# 2

Thanks,

As far as I know corbaloc::localhost:1050/Hello is the same than corbaloc:iiop:1.2@localhost:1050/Hello because internally the missing parts are the default ones.

Anyway, I have tested it and It do not work also. The point is why is working corbaname::localhost:1050/Hello and it is not working corbaloc::localhost:1050#Hello?

Any Idea?

obermudeza at 2007-7-8 23:44:50 > top of Java-index,Core,Core APIs...
# 3

> As far as I know corbaloc::localhost:1050/Hello is

> the same than corbaloc:iiop:1.2@localhost:1050/Hello

> because internally the missing parts are the default

> ones.

Almost correct. corbaloc::localhost:1050/Hello is actually the same as corbaloc:iiop:1.0@localhost:1050/Hello. The difference is unimportant though.

>

> Anyway, I have tested it and It do not work also. The

> point is why is working

> corbaname::localhost:1050/Hello and it is not working

> corbaloc::localhost:1050#Hello?

Because they mean completely different things. corbaname means look up the name 'Hello' in the name service running on port 1050 on localhost. corbaloc means the server itself is running at port 1050.

Your server code does not create a server running at port 1050. It registers with a NS running at that location. If you want to use a client with a corbaloc you need a server like the INSServer.java at:

http://java.sun.com/j2se/1.4.2/docs/guide/idl/INStutorial.html#server

Replace "PingServer" with "Hello", or whatever name you want, and change the fixed port property as required.

simonmcqueena at 2007-7-8 23:44:50 > top of Java-index,Core,Core APIs...
# 4

Thanks,

It have sense...

I am afraid it do not works,

I have test with this:

public class HelloServer{

public static void main(String args[]) {

try {

Properties properties = System.getProperties( );

properties.put( "com.sun.CORBA.POA.ORBPersistentServerPort",Integer.toString(1060) );

ORB orb = ORB.init( args, properties );

HelloImpl helloImpl = new HelloImpl();

POA rootPOA = POAHelper.narrow( orb.resolve_initial_references( "RootPOA" ));

rootPOA.the_POAManager().activate();

rootPOA.activate_object( helloImpl );

((com.sun.corba.se.internal.Interceptors.PIORB) orb).register_initial_reference("Hello", rootPOA.servant_to_reference(helloImpl) );

System.out.println( "INS Server is Ready..." );

orb.run( );

} catch ( Exception e ) {

System.err.println( "Error in setup : " + e );

}

}

}

My target is to run it on 1.6 and the result of triyng to run this is:

Error in setup : java.lang.ClassCastException: com.sun.corba.se.impl.orb.ORBImpl cannot be cast to com.sun.corba.se.internal.Interceptors.PIORB

I have tested also in 1.5 and the result is:

Error in setup : java.lang.ClassCastException: com.sun.corba.se.impl.orb.ORBImpl

Finally, I have tried to make it work in 1.4 and the result is:

java.lang.UnsupportedClassVersionError: eu/ts/test/corba/HelloServer4 (Unsupported major.minor version 49.0)

at java.lang.ClassLoader.defineClass0(Native Method)

at java.lang.ClassLoader.defineClass(ClassLoader.java:539)

at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)

at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)

at java.net.URLClassLoader.access$100(URLClassLoader.java:55)

at java.net.URLClassLoader$1.run(URLClassLoader.java:194)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(URLClassLoader.java:187)

at java.lang.ClassLoader.loadClass(ClassLoader.java:289)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)

at java.lang.ClassLoader.loadClass(ClassLoader.java:235)

at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)

Exception in thread "main"

I think this is the way but I have no idea how to continue

Any idea?

Thanks

obermudeza at 2007-7-8 23:44:50 > top of Java-index,Core,Core APIs...
# 5
How about casting to com.sun.corba.se.impl.orb.ORBImpl instead then.Note that the link that I posted referred to 1.4.x and had a disclaimer that the API may well change somewhat (as it seems that it has).
simonmcqueena at 2007-7-8 23:44:50 > top of Java-index,Core,Core APIs...
# 6
... and the error when you use 1.4.x looks suspiciously like you've tried to run your 1.5+ compiled bytecode with a 1.4 VM, but you wouldn't be doing anything as daft as that though would you ?
simonmcqueena at 2007-7-8 23:44:50 > top of Java-index,Core,Core APIs...
# 7
Thanks ?br>I was very interested on doing this on 1.6 and casting to com.sun.corba.se.impl.orb.ORBImpl was the right thing to do   I think I never could find this without your help.Thanks a lot... my friend.
obermudeza at 2007-7-8 23:44:50 > top of Java-index,Core,Core APIs...