-
Hello, I wanted to write a simple application to show how dynamic invoke and dispatch works in Ice. I decided to write the client in python and the server in java. I have looked into the docs, but I have no idea how to do it in practice. When I start up the client I get an Ice.OperationNotExistException. Does anyone know how to do this right? (yeah I know that exception handling in the client is a joke but I don't want to deal with that right now). IceServer.java: package sr.ice.server;
import com.zeroc.Ice.*;
import java.lang.Exception;
public class IceServer {
public void t1(String[] args) {
int status = 0;
Communicator communicator = null;
try {
communicator = Util.initialize(args);
ObjectAdapter adapter = communicator.createObjectAdapterWithEndpoints("Adapter1", "tcp -h 127.0.0.2 -p 10000 -z : udp -h 127.0.0.2 -p 10000 -z");
OperationsI operationsServant = new OperationsI();
adapter.add(operationsServant, new Identity("add", "add"));
adapter.activate();
System.out.println("Entering event processing loop...");
communicator.waitForShutdown();
} catch (Exception e) {
e.printStackTrace(System.err);
status = 1;
}
if (communicator != null) {
try {
communicator.destroy();
} catch (Exception e) {
e.printStackTrace(System.err);
status = 1;
}
}
System.exit(status);
}
public static void main(String[] args) {
IceServer app = new IceServer();
app.t1(args);
}
} OperationsI.java: package sr.ice.server;
import Demo.Operations;
import com.zeroc.Ice.Blobject;
import com.zeroc.Ice.Current;
import com.zeroc.Ice.UserException;
import com.zeroc.Ice.OperationNotExistException;
public class OperationsI implements Blobject {
@Override
public Ice_invokeResult ice_invoke(byte[] inParams, Current current) throws UserException {
if(current.operation.equals("add"))
{
com.zeroc.Ice.Communicator communicator = current.adapter.getCommunicator();
com.zeroc.Ice.InputStream in = new com.zeroc.Ice.InputStream(communicator, inParams);
in.startEncapsulation();
int x = in.readInt();
int y = in.readInt();
in.endEncapsulation();
com.zeroc.Ice.OutputStream out = new com.zeroc.Ice.OutputStream(communicator);
com.zeroc.Ice.Object.Ice_invokeResult r = new com.zeroc.Ice.Object.Ice_invokeResult();
out.startEncapsulation();
out.writeInt(x + y);
out.endEncapsulation();
r.outParams = out.finished();
r.returnValue = true;
return r;
}
else
{
OperationNotExistException ex = new OperationNotExistException();
ex.id = current.id;
ex.facet = current.facet;
ex.operation = current.operation;
throw ex;
}
}
} IceClient.py import Ice
import Demo
with Ice.initialize() as communicator:
base = communicator.stringToProxy("add/add:tcp -h 127.0.0.2 -p 10000 -z : udp -h 127.0.0.2 -p 10000 -z")
demo = Demo.OperationsPrx.checkedCast(base)
if not demo:
raise RuntimeError("Invalid proxy")
try:
[ok, outParams] = demo.ice_invoke("add", Ice.OperationMode.Normal, [3, 5])
if ok:
print("add result:", outParams.returnValue)
else:
print("error")
except Ice.LocalException as ex:
print("exception") slice file:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
It seems that the issue is related to the
The Your Blobject implementation is throwing an ObjectNotExistException because it doesn't support the required operation. I would suggest replacing the Cheers, |
Beta Was this translation helpful? Give feedback.
It seems that the issue is related to the
checkedCast
invocation in the following code:The
checkedCast
method makes a remote invocation to theice_isA
operation, which is a part of theIce::Object
interface.Your Blobject implementation is throwing an ObjectNotExistException because it doesn't support the required operation. I would suggest replacing the
checkedCast
call withuncheckedCast
, which does not make any remote calls. This approach is perfectly safe for your use case and should resolve the problem.Cheers,
Jose