View Single Post
  #1 (permalink)  
Old 09-28-2004
vsonnathi vsonnathi is offline
Registered User
 
Name: Venkat Ramana
Organization: Amazon.com
Project: Prototype
 
Join Date: May 2004
Posts: 39
package metadata directive - ClassCast Exception

Hi,

I am getting ClassCast Exception when I use the package metadata directive.

I am using Ice 1.5.1 distribution running on Win2K pro, JDK 1.4.2.

Here's my Slice definition:
Printer.ice
----------------
[["javaackage:com.testing"]]

module print {
class Data {
string name;
int number;
};

interface Printer {
void printString(Data s);
};
};


PrinterI.java
----------------
package com.testing.print;

import Ice.Current;

/**
* The <code>PrinterI </code>
*
* @author Venkat Ramana Sonnathi (HTC Global Svc. Inc.)
* @version 1.0
*/
public class PrinterI extends _PrinterDisp{
public void printString(Data s, Current __current) {
System.out.println("s = " + s.name);
}
}

Server.java
---------------
public class Server {
public static void
main(String[] args) {
int status = 0;
Ice.Communicator ic = null;
try {
ic = Ice.Util.initialize(args);
Ice.ObjectAdapter adapter
= ic.createObjectAdapterWithEndpoints("SimplePrinter Adapter", "default -p 10000");
Ice.Object object = new PrinterI();
adapter.add(object,
Ice.Util.stringToIdentity("SimplePrinter"));
adapter.activate();
ic.waitForShutdown();
} catch (Ice.LocalException e) {
e.printStackTrace();
status = 1;
} catch (Exception e) {
System.err.println(e.getMessage());
status = 1;
} finally {
if (ic != null)
ic.destroy();
}
System.exit(status);
}
}

Client.java
--------------
public class Client {
public static void
main(String[] args) {
int status = 0;
Ice.Communicator ic = null;
try {
ic = Ice.Util.initialize(args);
Ice.ObjectPrx base = ic.stringToProxy("SimplePrinter:default -p 10000");
PrinterPrx printer
= PrinterPrxHelper.checkedCast(base);
if (printer == null)
throw new Error("Invalid proxy");
Data data = new Data();
data.name = "Testing";
printer.printString(data);
} catch (Ice.LocalException e) {
e.printStackTrace();
status = 1;
} catch (Exception e) {
System.err.println(e.getMessage());
status = 1;
} finally {
if (ic != null)
ic.destroy();
}
System.exit(status);
}
}

When run the client, I get the following error:

Ice.UnknownLocalException
unknown = "Ice.NoObjectFactoryException
type = ":rint:ata"
at IceInternal.BasicStream.patchReferences(BasicStrea m.java:1604)
at IceInternal.BasicStream.readObject(BasicStream.jav a:1365)
at IceInternal.BasicStream.readPendingObjects(BasicSt ream.java:1487)
at com.testing.print._PrinterDisp.___printString(_Pri nterDisp.java:59)
at com.testing.print._PrinterDisp.__dispatch(_Printer Disp.java:102)
at IceInternal.Incoming.invoke(Incoming.java:152)
at IceInternal.Connection.message(Connection.java:117 3)
at IceInternal.ThreadPool.run(ThreadPool.java:689)
at IceInternal.ThreadPool.access$100(ThreadPool.java: 12)
at IceInternal.ThreadPool$EventHandlerThread.run(Thre adPool.java:1103)
Caused by: java.lang.ClassCastException
at com.testing.print.DataHolder$Patcher.patch(DataHol der.java:32)
at IceInternal.BasicStream.patchReferences(BasicStrea m.java:1600)
... 9 more
"
at IceInternal.Outgoing.invoke(Outgoing.java:158)
at com.testing.print._PrinterDelM.printString(_Printe rDelM.java:26)
at com.testing.print.PrinterPrxHelper.printString(Pri nterPrxHelper.java:32)
at com.testing.print.PrinterPrxHelper.printString(Pri nterPrxHelper.java:19)
at Client.main(Client.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.intellij.rt.execution.application.AppMain.main (AppMain.java:78)

Looks like the package metadata is not added to the object identities.

Thanks,
--Venkat.
Reply With Quote