Problem:
This article explains VisiBroker’s example on how to encapsulate application data to a CORBA server using org.omg.IOP.Codec.
Resolution:
OMG introduced org.omg.IOP.Codec which can be used to represent application data (using Any datatype) as a CDR encoded sequence of bytes, which is then passed from the client to server.
Then, the server can decode the byte array back into Any type.
Below are code snippet for Client & Server implementation
Client:
// create an any and initialize it
Any serialize_any = orb.create_any();
serialize_any.insert_string("CORBA Any data !!!");
// resolve the CodecFactory
org.omg.CORBA.Object obj = orb.resolve_initial_references("CodecFactory");
org.omg.IOP.Encoding cdr_encoding = new org.omg.IOP.Encoding(org.omg.IOP.ENCODING_CDR_ENCAPS.value, (byte) 1, (byte) 2);
org.omg.IOP.CodecFactory codecFactory = org.omg.IOP.CodecFactoryHelper.narrow(obj);
// create a codec object and use it to encode your any into a byte array
org.omg.IOP.Codec codec = codecFactory.create_codec(cdr_encoding);
byte[] serialized_data = codec.encode(serialize_any);
// invoke on the remote method passing in the byte array as a parameter
Server:
// create an any to deserialize into
org.omg.CORBA.Any retAny = _orb.create_any();
// Get a reference to the CodecFactory
org.omg.CORBA.Object obj = _orb.resolve_initial_references("CodecFactory");
org.omg.IOP.Encoding cdr_encoding = new org.omg.IOP.Encoding(org.omg.IOP.ENCODING_CDR_ENCAPS.value, (byte) 1, (byte) 2);
org.omg.IOP.CodecFactory codecFactory = org.omg.IOP.CodecFactoryHelper.narrow(obj);
// Create a codec object and use it to decode the byte array back into your any
org.omg.IOP.Codec retcodec = codecFactory.create_codec(cdr_encoding);
retAny = retcodec.decode(incoming_byte);
A testcase is attached to the article for your reference.
Attachment:
#Security
#IOP
#VisiBroker
#Codec




