Archived

This forum has been archived. Please start a new discussion on GitHub.

Proxy checkcast failed.

Hi, I have a problem with c++ client to java server.

here is my java server code:
public void StartListen()
throws NwException
{
try
{
iAdapter = getCommunicator().createObjectAdapter("NwSpRes");
Ice.Object object = new NwSpResI();
iAdapter.add(object, Ice.Util.stringToIdentity("NwSpRes"));
iAdapter.activate();
//iCommunicator.waitForShutdown();
UniLog.getInstance().Log(UniLog.INFO, "listen NwSpRes ok");
}
catch (Exception ex)
{
throw new NwException("listen error");
}
}

here is my server config:
NwSpRes.Endpoints=tcp -h 0.0.0.0 -p 6672

when i use java client to get proxy ,it's ok:
private NwSpResPrx getNwSpResPrx()
throws NwException
{
if (nwspResPrx!=null)
return nwspResPrx;

try
{
String reqProxy = getProperties().getProperty("NwSpRes.Proxy");
Ice.ObjectPrx base = getCommunicator().stringToProxy(reqProxy);
if (base ==null)
{
throw new NwException("NwSpReqPrx create failed");
}
nwspResPrx = NwSpResPrxHelper.checkedCast(base.ice_twoway().ice_timeout(
25000).ice_secure(false));
if (nwspResPrx == null)
{
throw new NwException("NwSpReqPrx create failed");
}
return nwspResPrx;
}
catch (Ice.LocalException ex)
{
throw new NwException("create failed");
}
}

and the config is :
NwSpRes.Proxy=NwSpRes:tcp -h 127.0.0.1 -p 6672

but when i use c++ client:
nwice::NwSpResPrx CCterClientDlg::GetSpResPrx(void)
{
try
{
Ice::PropertiesPtr properties = m_ptrCommunicator->getProperties();
const char* proxyProperty = "NwSpRes.Proxy";
string proxy = properties->getProperty(proxyProperty);

if(proxy.empty())
{
MessageBox("ORB ERROR","ERROR");
return 0;
}

Ice::ObjectPrx base = m_ptrCommunicator->stringToProxy(proxy);

m_prxSpRes = NwSpResPrx::checkedCast(
base);

if(!m_prxSpRes)
{
MessageBox("NwSpResPrx failed","ERROR");
return 0;
}

return m_prxSpRes;
}
catch(...)
{
}
}

I CAN'T get the right proxy. m_prxSpRes is always point to null.
here is my client config:
NwSpRes.Proxy=NwSpRes:tcp -h 127.0.0.1 -p 6672
It's the same with java client.

here is the server side trace:
[ colorcat: Network: accepting tcp connections at 0.0.0.0:6672 ]
[ colorcat: Network: accepted tcp connection
local address = 127.0.0.1:6672
remote address = 127.0.0.1:2846 ]
[ colorcat: Protocol: sending validate connection
message type = 3 (validate connection)
compression status = 0 (not compressed; do not compress response, if any)
message size = 14 ]
[ colorcat: Protocol: received request
message type = 0 (request)
compression status = 0 (not compressed; do not compress response, if any)
message size = 61
request id = 1
identity = NwSpRes
facet =
operation = ice_isA
nonmutating = true
context = ]
[ colorcat: Protocol: sending reply
message type = 2 (reply)
compression status = 0 (not compressed; do not compress response, if any)
message size = 26
request id = 1
reply status = 0 (ok) ]
[ colorcat: Protocol: received close connection
message type = 4 (close connection)
compression status = 1 (not compressed; compress response, if any)
message size = 14 ]
[ colorcat: Network: closing tcp connection
local address = 127.0.0.1:6672
remote address = 127.0.0.1:2846 ]


here is the client side trace:
[ Network: tcp connection established
local address = 127.0.0.1:3019
remote address = 127.0.0.1:6672 ][ Protocol: received validate connection
message type = 3 (validate connection)
compression status = 0 (not compressed; do not compress response, if any)
message size = 14 ][ Protocol: sending request
message type = 0 (request)
compression status = 0 (not compressed; do not compress response, if any)
message size = 61
request id = 1
identity = NwSpRes
facet =
operation = ice_isA
idempotent = true
context = ][ Protocol: received reply
message type = 2 (reply)
compression status = 0 (not compressed; do not compress response, if any)
message size = 26
request id = 1
reply status = 0 (ok) ]


I don't know what happened . It seems communicator is ok. but error when downcast to the proxy type.

Please help.

Comments

  • marc
    marc Florida
    I can't see anything wrong in the code. Are you sure you are using the same Slice code for both the client and the server? Also, can you double check that base is not null already?
  • yes, yesterday I use the same ice file to compiler again.
    I have checked base, base is not null.

    I will write a simple test to debug.
    thanks.
  • Hi , I have made a little change with the generated java file.

    I changed the package name.
    Is it make sense?

    in Java:
    package nwice;
    I changed to package com.nw.ice.

    but not changed in c++.
    it is still in nwice namespace.
  • Oh , I get the reason.

    I replaced all of the nwice namespace when I changed the package define.

    Now I only replace "package nwice;" with "package com.nanwang.ice",
    those "::nwice:.." in the code body is remained.

    So the proxy can get correct type match.

    Now everything is Ok.

    Could anyone developing in java tell me how to make the package name correct naturelly. I means when compiled from ice, files can be directly placed into folds such as com/nw/ice.

    Thanks.