Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Run CORBA-Client from Servlet

843841Dec 20 2005
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 17 2006
Added on Dec 20 2005
0 comments
135 views