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

Need help with Java and CORBA

2 views
Skip to first unread message

Ryan

unread,
Feb 21, 2000, 3:00:00 AM2/21/00
to
I am having some problems with my java code and CORBA. The code works
but I am trying to change the CORBA server object to read an entire file
and return it. Currently I can only get it to work reading one line.

Below is the WORKING method I use in my Server object:

public String getFileContents()
{
System.out.println("Storm: ORB Server being used.");
String data = "";
try {
BufferedReader in = new BufferedReader(new
FileReader("/var/adm/messages"));
data = in.readLine(); // THIS IS WHERE THE PROBLEM IS.
}
in.close();
} catch (IOException e) {
}
return data;
}

Now if I change the line above (where the problem is) to do this
instead:

public String getFileContents()
{
System.out.println("Storm: ORB Server being used.");
String data = "";
try {
BufferedReader in = new BufferedReader(new
FileReader("/var/adm/messages"));
while((data=in.readLine()) != null) {
data = in.readLine(); // THIS IS WHERE THE PROBLEM IS.
}
in.close();
} catch (IOException e) {
}
return data;
}

I get the following error when executing the CLIENT CORBA code.

rain% java MonitorClient -ORBInitialPort 9999
ERROR : org.omg.CosNaming.NamingContextPackage.NotFound
org.omg.CosNaming.NamingContextPackage.NotFound
at java.lang.Throwable.fillInStackTrace(Native Method)
at java.lang.Throwable.<init>(Throwable.java:82)
at java.lang.Exception.<init>(Exception.java:33)
at org.omg.CORBA.UserException.<init>(UserException.java:34)
at
org.omg.CosNaming.NamingContextPackage.NotFound.<init>(NotFound.java:29)
at
org.omg.CosNaming.NamingContextPackage.NotFoundHelper.read(Compiled
Code)
at
org.omg.CosNaming.NamingContextPackage.NotFoundHelper.extract(NotFoundHe
lper.java:54)
at
org.omg.CosNaming._NamingContextStub.resolve(_NamingContextStub.java:165
)
at MonitorClient.main(MonitorClient.java:21)

Here is the code from the MonitorClient.java (client file):

public String getFileContents()
{
System.out.println("Storm: ORB Server being used.");
// give the file read a whirl
String data = "";
try {
BufferedReader in = new BufferedReader(new
FileReader("/var/adm/messages"));
data = in.readLine();
}
in.close();
} catch (IOException e) {
}
return data;
}

Like I said, if I take the while loop out of the server code it works
fine except that it only returns one line from the messages file.

Any help would be most appreciated.
Ryan


Sent via Deja.com http://www.deja.com/
Before you buy.

ted lu

unread,
Feb 21, 2000, 3:00:00 AM2/21/00
to
Hi, All:

I am using Visibroker 3.3 for Java, the one came with Inprise JBuilder3. My
project requires me to send complex data messages like the one (message: A)
defined in following IDL file. (Those messages are translated from ASN.1, so
full of levels of Choice, Sequence, etc.) Be briefly, I need to send message
with a "union/enum" type ("CType") defined inside a "struct type" ("A"), (It
works fine for a "struct" type ("BType") inside a "struct type"("A")). I
tried the methods given in IDL generated "CType.java" to set/get the
initiation parameters for the message:

// Initialize the parameters
generated.A a =
new generated.BType(false, 1),
new generated.CType ());
a.a2.c1 (0); // methods defined in idl generated
CType.java
a.a2.c2 ("test string");

It complied but later with run time error as following attached. The problem
is how to work out the "generated.CType.java" and
"generated.CTypeChoice.java" to assign the parameter values.

I know "... Standard CORBA only supports pass by value for non-object types,
making use of passing by reference for objects..." Does this fit in that
case? If I use Caffeine compiler in Visibroker 3.3, I need to work out how
to describe "Choice" in Java, which doesn't support "Union", so might be too
much changes on the original data type definitions. I know visibroker 4.0
supports pass by value with "valuetype", do I need to use that to pass my
messages?

Thanks so much for your concern.

Best regards,

Ted

// You might take a look below.

/*Error message:
D:\JBUILDER3\myprojects\TEST>vbj Client
org.omg.CORBA.BAD_OPERATION: minor code: 0 completed: No
at java.lang.Class.newInstance0(Native Method)
at java.lang.Class.newInstance(Compiled Code)
at com.visigenic.vbroker.orb.SE.read(SE.java:28)
at
com.visigenic.vbroker.orb.GiopStubDelegate.invoke(GiopStubDelegate.ja
va:576)
at
com.visigenic.vbroker.orb.GiopStubDelegate.invoke(GiopStubDelegate.ja
va:476)
at
com.inprise.vbroker.CORBA.portable.ObjectImpl._invoke(ObjectImpl.java
:60)
at generated._st_ComplexTest.transferIndication(Compiled Code)
at Client.main(Client.java:28)
*/


// Test.idl
module generated {

struct BType {
boolean b1;
unsigned long b2;
};

enum CTypeChoice {
c1Choice ,
c2Choice
};

union CType switch (BTypeChoice) {
case c1Choice : unsigned long c1;
case c2Choice : string c2;
};

struct A {
BType a1;
CType a2;
};

interface ComplexTest
{
boolean transferIndication (in A a);
};
};

// My client code likes this:
// Client.java
public class Client
{
static boolean returnValue;
public static void main(String[] args)
{
try
{
org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, null);
generated.ComplexTest complexTest =
generated.ComplexTestHelper.bind (orb, "Client2");
// Initialize the parameter
generated.A a =
new generated.BType(false, 1),
new generated.CType ());

// Initialize
a.a2.c1 (0);
a.a2.c2 ("test string");

//Call the remote method

boolean returnValue = complexTest.transferIndication (a);
if (returnValue)
System.out.println("\n Transfer Ack");
else
System.out.println("\n Transfer Reject");
}
catch (org.omg.CORBA.SystemException ex)
{
ex.printStackTrace();
}
}
}

// part of ComplexTestImpl.java

...
public boolean transferIndication (generated.A a)
{

if ((((a.a1.b1 == false)&&(a.a1.b2 == 1))&&(a.a2.c1()
==0))&&(a.a2.c2().equals("test string")))
return true;
else
return false;
}
...


Derek Thomson

unread,
Feb 22, 2000, 3:00:00 AM2/22/00
to
Ryan wrote:
>
>
> Now if I change the line above (where the problem is) to do this
> instead:
>
> public String getFileContents()
> {
> System.out.println("Storm: ORB Server being used.");
> String data = "";
> try {
> BufferedReader in = new BufferedReader(new
> FileReader("/var/adm/messages"));
> while((data=in.readLine()) != null) {
> data = in.readLine(); // THIS IS WHERE THE PROBLEM IS.
> }
> in.close();
> } catch (IOException e) {
> }
> return data;
> }

At the "return data;" statement at the end of the method, "data" is null as the
loop will only terminate when data == null (or on an IOException). You are
returning null.

You are also calling readLine twice each time around the loop, and you are
losing the previous line each time you read a new line.

Try something like:

public String getFileContents()


try {
BufferedReader in = new BufferedReader(new FileReader("/var/adm/messages"));

StringBuffer data = new StringBuffer();

String line;
while ((line = in.readLine()) != null) {
data.append(line);
}

in.close();

return data.toString();

} catch (IOException ex) {
// Do something appropriate, maybe throw CORBA user or system exception
}
}

I haven't compiled this so it may not be perfect, but I'm sure you get the idea.

Regards,
Derek

0 new messages