Hi All!
I'm trying to run a CORBA-client from my serwlet. I have run a tnameserv.exe without any parametrs, a Orbd -ORBInitialPort 1050 -ORBInitialHost localhost, and Serwer which has written in CORBA. So servlet must invoke a method HelloWorld() by Client CORBA. This method contain System.out.println("Some String To Print at Server Site") this must to be print on server site but it isn't work,didn't write at server site. All is well when I run Client-Corba as normal application without servlet. Problem is when I put the sdource into servlet class. I can't connect with server. I have an Exception :
java.io.EOFException
at java.io.ObjectInputStream$PeekInputStream.readFully(Unknown Source)
at java.io.ObjectInputStream$BlockDataInputStream.readShort(Unknown Source)
at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
...
...
All looks well. I tried to do that same like in tutorial at Sun's site. So I don't have any ideas what may be wrong. Please help me. I'm crushed ;-)
Servlet Source :
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try{
String args[] = null;
Properties props = new Properties();
props.put("org.omg.CORBA.ORBInitialPort", "1050");
props.put("org.omg.CORBA.ORBInitialHost", "localhost");
// create and initialize the ORB
ORB orb = ORB.init(args, props);
// get the root naming context
org.omg.CORBA.Object objRef =
orb.resolve_initial_references("NameService");
ncRef = NamingContextHelper.narrow(objRef);
// resolve the Object Reference in Naming
// make sure there are no spaces between ""
nc = new NameComponent("Hello","");
NameComponent path[] = {nc};
helloRef = HelloHelper.narrow(ncRef.resolve(path));
hello=helloRef.sayHello();
ObjectInputStream in = new ObjectInputStream(request.getInputStream());
tmp = (byte[])in.readObject();
tmp2 = (String)in.readObject();
in.close();
ObjectOutputStream out = new ObjectOutputStream(response.getOutputStream());
out.writeObject(tmp);
out.writeObject(tmp2);
out.flush();
out.close();
}catch(Exception e){}
}
ServerCorba site:
public class Serwer {
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");
// create and initialize the ORB
ORB orb = ORB.init(args, null);
// create servant and register it with the ORB
HelloServant helloRef = new HelloServant();
orb.connect(helloRef);
// 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
// make sure there are no spaces between ""
NameComponent nc = new NameComponent("Hello","");
NameComponent path[] = {nc};
ncRef.rebind(path, helloRef);
System.out.println("ok");
// 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);
}
}
}
THX for all sugestions Chudzik