Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to init sequence on java server?

6 views
Skip to first unread message

brightoc...@hotmail.com

unread,
Sep 10, 2005, 5:28:52 AM9/10/05
to
How do I initialize a sequence to be returned to a
client from a java server?

sample idl :

module someModule {

typedef sequence<octet> Data;

struct SomeStructure {
Data file;
string info;
};

typedef sequence<SomeStructure> results;

interface someObject {
get(in string infotoget, out results results_out, out unsigned long
numberOfItems);
};


};


on client :

.
.
.
String info = "filename";
someModule.resultsHolder rh = new someModule.resultsHolder();
org.omg.CORBA.IntHolder ih = new org.omg.CORBA.IntHolder();
someObject.get(info,rh,ih);

on server :

???

brightoc...@hotmail.com

unread,
Sep 11, 2005, 10:24:18 AM9/11/05
to
I implemented a server but get the following error :

org.omg.CORBA.UNKNOWN: vmcid: SUN minor code: 202 completed: Maybe
Test2 Client Error:
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
at java.lang.Class.newInstance0(Class.java:308)
at java.lang.Class.newInstance(Class.java:261)
at
com.sun.corba.se.internal.iiop.messages.ReplyMessage_1_2.getSystemException(ReplyMessage_1_2.java:90)
at
com.sun.corba.se.internal.iiop.ClientResponseImpl.getSystemException(ClientResponseImpl.java:105)
at
com.sun.corba.se.internal.corba.ClientDelegate.invoke(ClientDelegate.java:314)
at org.omg.CORBA.portable.ObjectImpl._invoke(ObjectImpl.java:457)
at someModule._someObjectStub.get(_someObjectStub.java:20)
at Test2Client.main(Test2Client.java:54)

It seems that I'm doing something wrong in how the sequence is
initialized on the server side in Java.

brightoc...@hotmail.com

unread,
Sep 11, 2005, 10:31:30 AM9/11/05
to
here is my code :

Server side :
--------------

TestServant.java :


import org.omg.CORBA.IntHolder;

import someModule.SomeStructure;

import someModule._someObjectImplBase;

public class TestServant extends _someObjectImplBase{

public void get(String toget, someModule.resultsHolder results_out,
org.omg.CORBA.IntHolder numberOfItems)
{
System.out.println("inside get : " + toget);
someModule.SomeStructure[] srs_array = new
someModule.SomeStructure[1];
srs_array[0].info = "EMPTY";

// create array for octet sequence
byte[] data_array = new byte[1];
data_array[0] = 0;
srs_array[0].file = data_array;
results_out = new someModule.resultsHolder(srs_array);

numberOfItems = new IntHolder(0);

}


}


Test2Server.java :

public class Test2Server {

public static void main(String[] args) {

TestServant testServant = new TestServant();
ServerCorba sc = new ServerCorba();
sc.activate(args, testServant);

}
}


ServerCorba.java :

import org.omg.CORBA.ORB;
import org.omg.CosNaming.NameComponent;
import org.omg.CosNaming.NamingContext;
import org.omg.CosNaming.NamingContextHelper;

public class ServerCorba {

ServerCorba() {

}

void activate(String[] args, TestServant servant) {
try{
// create and initialize the ORB
ORB orb = ORB.init(args, null);
// create the servant and register it with the ORB
orb.connect(servant);
// get the root naming context
org.omg.CORBA.Object objRef =
orb.resolve_initial_references("NameService");
NamingContext ncRef = NamingContextHelper.narrow(objRef);
// Bind the object reference in naming
NameComponent nc = new NameComponent("SearchServer", " ");
NameComponent path[] = {nc};
ncRef.rebind(path, servant);
System.out.println("Server started....");
// 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.getMessage());
e.printStackTrace(System.out);
}
}
}


Client side :
-------------

Test2Client.java :

import org.omg.CORBA.ORB;
import org.omg.CosNaming.NameComponent;
import org.omg.CosNaming.NamingContext;
import org.omg.CosNaming.NamingContextHelper;

import someModule.someObjectHelper;
import someModule.someObjectOperations;

public class Test2Client {

public static void main(String[] args) {
try {
System.out.println("in Test2Client");

// create and initialize the ORB
ORB orb = ORB.init(args, null);

System.out.println("after ORB inited");

// get the root naming context
org.omg.CORBA.Object objRef =
orb.resolve_initial_references("NameService");

System.out.println("after Name Service resolved");

NamingContext ncRef = NamingContextHelper.narrow(objRef);
// The below name is the name used on the server
// when it registers with the Naming Service
NameComponent nc = new NameComponent("SearchServer", " ");

// Resolve the object reference in naming
NameComponent path[] = {nc};

// Here create an object to call operations defined in idl
someObjectOperations someObject =
someObjectHelper.narrow(ncRef.resolve(path));

String get_str = "Test get string";
someModule.resultsHolder srh = new someModule.resultsHolder();


org.omg.CORBA.IntHolder ih = new org.omg.CORBA.IntHolder();

System.out.println("before get called");
someObject.get(get_str, srh, ih);
System.out.println("after get called");

} catch(Exception e) {
System.out.println("Test2 Client Error: " + e.getMessage());
e.printStackTrace();
}



}
}

brightoc...@hotmail.com

unread,
Sep 11, 2005, 1:29:36 PM9/11/05
to
Okay. I passed a sequence of bytes without problem. The issue seems
to be with passing a sequence of structures.

brightoc...@hotmail.com

unread,
Sep 12, 2005, 7:15:41 PM9/12/05
to
Okay, switched Name Service, Server, and Client to Visibroker, and it
still fails. But different message :

org.omg.CORBA.UNKNOWN: vmcid: SUN minor code: 202 completed: Maybe

FileClient Error:


at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
at java.lang.Class.newInstance0(Class.java:308)
at java.lang.Class.newInstance(Class.java:261)
at
com.sun.corba.se.internal.iiop.messages.ReplyMessage_1_2.getSystemException(ReplyMessage_1_2.java:90)
at
com.sun.corba.se.internal.iiop.ClientResponseImpl.getSystemException(ClientResponseImpl.java:105)
at

com.sun.corba.se.internal.POA.GenericPOAClientSC.invoke(GenericPOAClientSC.java:129)
at org.omg.CORBA.portable.ObjectImpl._invoke(ObjectImpl.java:457)
at ARCHIVE_VISI._someObject.search(_someObjectStub.java:47)
at Test2Client.main(Test2Client.java:112)

brightoc...@hotmail.com

unread,
Sep 13, 2005, 3:29:30 AM9/13/05
to
It's not the ORB.

A sequence maps to a java array. But when dealing with a sequence of
structures, defining the array on the server side is not enough. You
need to also create the structures, assign values to them and then
assign the structure to the array.

// this was not enough


someModule.SomeStructure[] srs_array = new
someModule.SomeStructure[1];
srs_array[0].info = "EMPTY";

// this works


someModule.SomeStructure[] srs_array = new
someModule.SomeStructure[1];

SomeStructure someStruct = new SomeStructure();
someStruct.info = "EMPTY";
srs_array[0] = someStruct;

0 new messages