Example #1
0
        private Stream PrepareLocationFwdStream(string host, ushort port,
                                                MarshalByRefObject target)
        {
            // loc fwd ior
            byte[] objectKey    = IorUtil.GetObjectKeyForObj(target);
            string repositoryID = Repository.GetRepositoryID(target.GetType());
            // this server support GIOP 1.2 --> create an GIOP 1.2 profile
            InternetIiopProfile profile = new InternetIiopProfile(new GiopVersion(1, 2), host,
                                                                  port, objectKey);

            profile.AddTaggedComponent(Services.CodeSetService.CreateDefaultCodesetComponent(m_codec));
            Ior locFwdTarget = new Ior(repositoryID, new IorProfile[] { profile });
            CdrOutputStreamImpl iorStream = new CdrOutputStreamImpl(new MemoryStream(),
                                                                    0, new GiopVersion(1, 2));

            locFwdTarget.WriteToStream(iorStream);
            uint encodedIorLength = (uint)iorStream.GetPosition();

            // create the location fwd reply
            MemoryStream        sourceStream = new MemoryStream();
            CdrOutputStreamImpl cdrOut       = new CdrOutputStreamImpl(sourceStream, 0, new GiopVersion(1, 2));

            cdrOut.WriteOpaque(m_giopMagic);
            // version
            cdrOut.WriteOctet(1);
            cdrOut.WriteOctet(2);
            // flags
            cdrOut.WriteOctet(0);
            // msg-type: reply
            cdrOut.WriteOctet(1);

            // msg-length
            cdrOut.WriteULong(28 + encodedIorLength);
            // request-id
            cdrOut.WriteULong(5);
            // reply-status: location fwd
            cdrOut.WriteULong(3);
            // one service context to enforce alignement requirement for giop 1.2
            cdrOut.WriteULong(1);
            cdrOut.WriteULong(162739); // service context id
            cdrOut.WriteULong(2);      // length of svc context
            cdrOut.WriteBool(true);
            cdrOut.WriteBool(false);
            // svc context end
            // body: 8 aligned
            cdrOut.ForceWriteAlign(Aligns.Align8);

            locFwdTarget.WriteToStream(cdrOut);

            sourceStream.Seek(0, SeekOrigin.Begin);
            return(sourceStream);
        }
Example #2
0
        private uint AddFinishFragment(CdrOutputStreamImpl targetStream, GiopVersion version,
                                       byte endianFlags, uint reqId, uint reqContentLength,
                                       uint offsetInMsg)
        {
            byte giopFlags = endianFlags; // no more fragments

            GiopHeader fragmentHeader = new GiopHeader(version.Major, version.Minor,
                                                       endianFlags, GiopMsgTypes.Request);

            uint contentLength = 0;

            if (!((version.Major == 1) && (version.Minor <= 1)))
            {
                // GIOP 1.2
                contentLength = 4 + reqContentLength;
            }
            else
            {
                contentLength = reqContentLength;
            }

            fragmentHeader.WriteToStream(targetStream, contentLength);
            if (!((version.Major == 1) && (version.Minor <= 1)))
            {
                // GIOP 1.2
                targetStream.WriteULong(reqId);
            }

            // more is not needed to write a correct GIOP-message for this test from here
            for (uint i = offsetInMsg; i < (offsetInMsg + reqContentLength); i++)
            {
                targetStream.WriteOctet((byte)(i % 255));
            }
            return(offsetInMsg + reqContentLength);
        }
Example #3
0
        public void TestLocateRequestDeserialisation()
        {
            MemoryStream sourceStream = new MemoryStream();
            // prepare msg
            uint                requestId = 5;
            GiopVersion         version   = new GiopVersion(1, 2);
            CdrOutputStreamImpl cdrOut    = new CdrOutputStreamImpl(sourceStream, 0,
                                                                    version);

            cdrOut.WriteOpaque(m_giopMagic);
            // version
            cdrOut.WriteOctet(version.Major);
            cdrOut.WriteOctet(version.Minor);
            // flags
            cdrOut.WriteOctet(0);
            // msg-type: request
            cdrOut.WriteOctet((byte)GiopMsgTypes.LocateRequest);
            // msg-length
            cdrOut.WriteULong(22);
            // request-id
            cdrOut.WriteULong(requestId);
            // target: key type
            cdrOut.WriteULong(0);
            cdrOut.WriteULong(10);                                                            // key length
            byte[] objectKey = new byte[] { 116, 101, 115, 116, 111, 98, 106, 101, 99, 116 }; // testobject
            cdrOut.WriteOpaque(objectKey);

            // create a connection context: this is needed for request deserialisation
            GiopConnectionDesc conDesc = new GiopConnectionDesc(null, null);

            // go to stream begin
            sourceStream.Seek(0, SeekOrigin.Begin);

            // deserialise request message
            LocateRequestMessage result = m_handler.ParseIncomingLocateRequestMessage(sourceStream);

            // now check if values are correct
            Assert.IsTrue(result != null, "deserialised message is null");
            Assert.AreEqual(requestId, result.RequestId);
            Assert.NotNull(result.ObjectKey);
            Assert.NotNull(result.TargetUri);
            Assert.AreEqual("testobject", result.TargetUri);
        }
Example #4
0
        public void TestReplyDeserialisation()
        {
            // request msg the reply is for
            MethodInfo methodToCall = typeof(TestService).GetMethod("Add");

            object[]    args       = new object[] { ((Int32)1), ((Int32)2) };
            string      uri        = "iiop://localhost:8087/testuri"; // Giop 1.2 will be used because no version spec in uri
            TestMessage requestMsg = new TestMessage(methodToCall, args, uri);

            requestMsg.Properties[SimpleGiopMsg.IDL_METHOD_NAME_KEY] = methodToCall.Name; // done by serialization normally
            // prepare connection desc
            GiopClientConnectionDesc conDesc = new GiopClientConnectionDesc(null, null, new GiopRequestNumberGenerator(), null);
            // create the reply
            MemoryStream        sourceStream = new MemoryStream();
            CdrOutputStreamImpl cdrOut       = new CdrOutputStreamImpl(sourceStream, 0, new GiopVersion(1, 2));

            cdrOut.WriteOpaque(m_giopMagic);
            // version
            cdrOut.WriteOctet(1);
            cdrOut.WriteOctet(2);
            // flags
            cdrOut.WriteOctet(0);
            // msg-type: reply
            cdrOut.WriteOctet(1);
            // msg-length
            cdrOut.WriteULong(16);
            // request-id
            cdrOut.WriteULong(5);
            // reply-status: no-exception
            cdrOut.WriteULong(0);
            // no service contexts
            cdrOut.WriteULong(0);
            // body: 8 aligned
            cdrOut.ForceWriteAlign(Aligns.Align8);
            // result
            cdrOut.WriteLong(3);
            // check deser of msg:
            sourceStream.Seek(0, SeekOrigin.Begin);
            ReturnMessage result = (ReturnMessage)m_handler.ParseIncomingReplyMessage(sourceStream, requestMsg, conDesc);

            Assert.AreEqual(3, result.ReturnValue);
            Assert.AreEqual(0, result.OutArgCount);
        }
Example #5
0
        /// <summary>gets a stringified representation</summary>
        public override string ToString()
        {
            // encode the IOR to a CDR-stream, afterwards write it to the iorStream
            using (MemoryStream content = new MemoryStream()) {
                byte            flags  = 0;
                CdrOutputStream stream = new CdrOutputStreamImpl(content, flags);
                stream.WriteOctet(flags); // writing the flags before the IOR
                // write content to the IORStream
                WriteToStream(stream);

                return(StringConversions.Stringify("IOR:", content.GetBuffer(), (int)content.Length));
            }
        }
Example #6
0
        /// <param name="fragmentContentBlocks">the nr of 4 byte blocks in the content;
        /// must be even for GIOP 1.2</param>
        private CdrOutputStreamImpl AddStartMsg(Stream targetStream, GiopVersion version,
                                                byte endianFlags, uint reqId,
                                                uint fragmentContentBlocks, out uint offsetInMsg)
        {
            byte giopFlags = (byte)(endianFlags | ((byte)2)); // more fragments

            CdrOutputStreamImpl cdrOut = new CdrOutputStreamImpl(targetStream, endianFlags,
                                                                 version);
            GiopHeader startHeader = new GiopHeader(version.Major, version.Minor,
                                                    giopFlags, GiopMsgTypes.Request);

            uint contentLength = 0;

            if (!((version.Major == 1) && (version.Minor <= 1)))
            {
                // GIOP 1.2
                contentLength = (uint)(4 + (fragmentContentBlocks * 4));
            }
            else
            {
                contentLength = (uint)(8 + (fragmentContentBlocks * 4));
            }

            startHeader.WriteToStream(cdrOut, contentLength);
            if ((version.Major == 1) && (version.Minor == 1))
            {
                // GIOP 1.1: add service context list here
                cdrOut.WriteULong(0); // no contexts
            }
            cdrOut.WriteULong(reqId); // request id

            // more is not needed to write a correct GIOP-message for this test from here
            for (uint i = 0; i < fragmentContentBlocks * 4; i++)
            {
                cdrOut.WriteOctet((byte)(i % 255));
            }

            offsetInMsg = fragmentContentBlocks * 4;
            return(cdrOut);
        }
Example #7
0
        /// <summary>gets a stringified representation</summary>
        public override string ToString()
        {
            // encode the IOR to a CDR-stream, afterwards write it to the iorStream
            using (MemoryStream content = new MemoryStream()) {
                byte flags = 0;
                CdrOutputStream stream = new CdrOutputStreamImpl(content, flags);
                stream.WriteOctet(flags); // writing the flags before the IOR
                // write content to the IORStream
                WriteToStream(stream);

                return StringConversions.Stringify("IOR:", content.GetBuffer(), (int)content.Length);
            }
        }
        public void TestLocateRequestDeserialisation() {
            MemoryStream sourceStream = new MemoryStream();
            // prepare msg
            uint requestId = 5;
            GiopVersion version = new GiopVersion(1, 2);
            CdrOutputStreamImpl cdrOut = new CdrOutputStreamImpl(sourceStream, 0,
                                                                 version);
            cdrOut.WriteOpaque(m_giopMagic);
            // version
            cdrOut.WriteOctet(version.Major);
            cdrOut.WriteOctet(version.Minor);
            // flags
            cdrOut.WriteOctet(0);
            // msg-type: request
            cdrOut.WriteOctet((byte)GiopMsgTypes.LocateRequest);
            // msg-length
            cdrOut.WriteULong(22);
            // request-id
            cdrOut.WriteULong(requestId);
            // target: key type
            cdrOut.WriteULong(0);
            cdrOut.WriteULong(10); // key length
            byte[] objectKey = new byte[] { 116, 101, 115, 116, 111, 98, 106, 101, 99, 116 }; // testobject
            cdrOut.WriteOpaque(objectKey);

            // create a connection context: this is needed for request deserialisation
            GiopConnectionDesc conDesc = new GiopConnectionDesc(null, null);

            // go to stream begin
            sourceStream.Seek(0, SeekOrigin.Begin);
 
            // deserialise request message
            LocateRequestMessage result = m_handler.ParseIncomingLocateRequestMessage(sourceStream);

            // now check if values are correct
            Assert.IsTrue(result != null, "deserialised message is null");
            Assert.AreEqual(requestId, result.RequestId);
            Assert.NotNull(result.ObjectKey);
            Assert.NotNull(result.TargetUri);
            Assert.AreEqual("testobject", result.TargetUri);
        }
        private Stream PrepareLocationFwdStream(string host, ushort port,
                                                MarshalByRefObject target) {
            // loc fwd ior
            byte[] objectKey = IorUtil.GetObjectKeyForObj(target);
            string repositoryID = Repository.GetRepositoryID(target.GetType());
            // this server support GIOP 1.2 --> create an GIOP 1.2 profile
            InternetIiopProfile profile = new InternetIiopProfile(new GiopVersion(1, 2), host,
                                                                  port, objectKey);
            profile.AddTaggedComponent(Services.CodeSetService.CreateDefaultCodesetComponent(m_codec));
            Ior locFwdTarget = new Ior(repositoryID, new IorProfile[] { profile });
            CdrOutputStreamImpl iorStream = new CdrOutputStreamImpl(new MemoryStream(),
                                                                    0, new GiopVersion(1, 2));
            locFwdTarget.WriteToStream(iorStream);
            uint encodedIorLength = (uint)iorStream.GetPosition();
 
            // create the location fwd reply
            MemoryStream sourceStream = new MemoryStream();
            CdrOutputStreamImpl cdrOut = new CdrOutputStreamImpl(sourceStream, 0, new GiopVersion(1, 2));
            cdrOut.WriteOpaque(m_giopMagic);
            // version
            cdrOut.WriteOctet(1);
            cdrOut.WriteOctet(2);
            // flags
            cdrOut.WriteOctet(0);
            // msg-type: reply
            cdrOut.WriteOctet(1);
 
            // msg-length
            cdrOut.WriteULong(28 + encodedIorLength);
            // request-id
            cdrOut.WriteULong(5);
            // reply-status: location fwd
            cdrOut.WriteULong(3);
            // one service context to enforce alignement requirement for giop 1.2
            cdrOut.WriteULong(1);
            cdrOut.WriteULong(162739); // service context id
            cdrOut.WriteULong(2); // length of svc context
            cdrOut.WriteBool(true);
            cdrOut.WriteBool(false);
            // svc context end
            // body: 8 aligned
            cdrOut.ForceWriteAlign(Aligns.Align8);

            locFwdTarget.WriteToStream(cdrOut);
 
            sourceStream.Seek(0, SeekOrigin.Begin);
            return sourceStream;
        }
 public void TestReplyDeserialisation() {
     // request msg the reply is for
     MethodInfo methodToCall = typeof(TestService).GetMethod("Add");
     object[] args = new object[] { ((Int32) 1), ((Int32) 2) };
     string uri = "iiop://localhost:8087/testuri"; // Giop 1.2 will be used because no version spec in uri
     TestMessage requestMsg = new TestMessage(methodToCall, args, uri);
     requestMsg.Properties[SimpleGiopMsg.IDL_METHOD_NAME_KEY] = methodToCall.Name; // done by serialization normally
     // prepare connection desc
     GiopClientConnectionDesc conDesc = new GiopClientConnectionDesc(null, null, new GiopRequestNumberGenerator(), null);
     // create the reply
     MemoryStream sourceStream = new MemoryStream();
     CdrOutputStreamImpl cdrOut = new CdrOutputStreamImpl(sourceStream, 0, new GiopVersion(1, 2));
     cdrOut.WriteOpaque(m_giopMagic);
     // version
     cdrOut.WriteOctet(1);
     cdrOut.WriteOctet(2);
     // flags
     cdrOut.WriteOctet(0);
     // msg-type: reply
     cdrOut.WriteOctet(1);
     // msg-length
     cdrOut.WriteULong(16);
     // request-id
     cdrOut.WriteULong(5);
     // reply-status: no-exception
     cdrOut.WriteULong(0);
     // no service contexts
     cdrOut.WriteULong(0);
     // body: 8 aligned
     cdrOut.ForceWriteAlign(Aligns.Align8);
     // result
     cdrOut.WriteLong(3);
     // check deser of msg:
     sourceStream.Seek(0, SeekOrigin.Begin);
     ReturnMessage result = (ReturnMessage) m_handler.ParseIncomingReplyMessage(sourceStream, requestMsg, conDesc);
     Assert.AreEqual(3, result.ReturnValue);
     Assert.AreEqual(0, result.OutArgCount);
 }
        public void TestRequestDeserialisation() {
            MemoryStream sourceStream = new MemoryStream();
            // prepare msg
            uint requestId = 5;
            byte responseFlags = 3;
            string methodName = "Add";
            int nrOfArgs = 2;
            int arg1 = 1;
            int arg2 = 2;
            GiopVersion version = new GiopVersion(1, 2);
            CdrOutputStreamImpl cdrOut = new CdrOutputStreamImpl(sourceStream, 0,
                                                                 version);
            cdrOut.WriteOpaque(m_giopMagic);
            // version
            cdrOut.WriteOctet(version.Major);
            cdrOut.WriteOctet(version.Minor);
            // flags
            cdrOut.WriteOctet(0);
            // msg-type: request
            cdrOut.WriteOctet(0);
            // msg-length
            cdrOut.WriteULong(68);
            // request-id
            cdrOut.WriteULong(requestId);
            // response-flags
            cdrOut.WriteOctet(responseFlags);
            cdrOut.WritePadding(3);
            // target: key type
            cdrOut.WriteULong(0);
            cdrOut.WriteULong(10); // key length
            cdrOut.WriteOpaque(new byte[] { 116, 101, 115, 116, 111, 98, 106, 101, 99, 116 }); // testobject
            // method name
            cdrOut.WriteString(methodName);
            // no service contexts
            cdrOut.WriteULong(0);
            cdrOut.ForceWriteAlign(Aligns.Align8);
            // parameters
            cdrOut.WriteLong(arg1);
            cdrOut.WriteLong(arg2);

            // create a connection context: this is needed for request deserialisation
            GiopConnectionDesc conDesc = new GiopConnectionDesc(null, null);

            // go to stream begin
            sourceStream.Seek(0, SeekOrigin.Begin);
 
            IMessage result = null;
            TestService service = new TestService();
            try {
                // object which should be called
                string uri = "testobject";
                RemotingServices.Marshal(service, uri);

                // deserialise request message
                result = m_handler.ParseIncomingRequestMessage(sourceStream, conDesc);
            } catch (RequestDeserializationException e) {
                throw e;
            } finally {
                RemotingServices.Disconnect(service);
            }

            // now check if values are correct
            Assert.IsTrue(result != null, "deserialised message is null");
            Assert.AreEqual(requestId, result.Properties[SimpleGiopMsg.REQUEST_ID_KEY]);
            Assert.AreEqual(version, result.Properties[SimpleGiopMsg.GIOP_VERSION_KEY]);
            Assert.AreEqual(responseFlags, result.Properties[SimpleGiopMsg.RESPONSE_FLAGS_KEY]);
            Assert.AreEqual("testobject", result.Properties[SimpleGiopMsg.URI_KEY]);
            Assert.AreEqual("Ch.Elca.Iiop.Tests.TestService", result.Properties[SimpleGiopMsg.TYPENAME_KEY]);
            Assert.AreEqual(methodName, result.Properties[SimpleGiopMsg.METHODNAME_KEY]);
            object[] args = (object[])result.Properties[SimpleGiopMsg.ARGS_KEY];
            Assert.IsTrue(args != null, "args is null");
            Assert.AreEqual(nrOfArgs, args.Length);
            Assert.AreEqual(arg1, args[0]);
            Assert.AreEqual(arg2, args[1]);
        }
        private uint AddFinishFragment(CdrOutputStreamImpl targetStream, GiopVersion version,
                                       byte endianFlags, uint reqId, uint reqContentLength,
                                       uint offsetInMsg) {
 
            byte giopFlags = endianFlags; // no more fragments
 
            GiopHeader fragmentHeader = new GiopHeader(version.Major, version.Minor,
                                                       endianFlags, GiopMsgTypes.Request);
 
            uint contentLength = 0;
            if (!((version.Major == 1) && (version.Minor <= 1))) {
                // GIOP 1.2
                contentLength = 4 + reqContentLength;
            } else {
                contentLength = reqContentLength;
            }
 
            fragmentHeader.WriteToStream(targetStream, contentLength);
            if (!((version.Major == 1) && (version.Minor <= 1))) {
                // GIOP 1.2
                targetStream.WriteULong(reqId);
            }
 
            // more is not needed to write a correct GIOP-message for this test from here
            for (uint i = offsetInMsg; i < (offsetInMsg + reqContentLength); i++) {
                targetStream.WriteOctet((byte)(i % 255));
            }
            return offsetInMsg + reqContentLength;
        }
        /// <param name="fragmentContentBlocks">the nr of 4 byte blocks in the content;
        /// must be even for GIOP 1.2</param>
        private CdrOutputStreamImpl AddStartMsg(Stream targetStream, GiopVersion version,
                                                byte endianFlags, uint reqId,
                                                uint fragmentContentBlocks, out uint offsetInMsg) {
 
            byte giopFlags = (byte)(endianFlags | ((byte)2)); // more fragments
 
            CdrOutputStreamImpl cdrOut = new CdrOutputStreamImpl(targetStream, endianFlags,
                                                                 version);
            GiopHeader startHeader = new GiopHeader(version.Major, version.Minor,
                                                    giopFlags, GiopMsgTypes.Request);
 
            uint contentLength = 0;
            if (!((version.Major == 1) && (version.Minor <= 1))) {
                // GIOP 1.2
                contentLength = (uint)(4 + (fragmentContentBlocks * 4));
            } else {
                contentLength = (uint)(8 + (fragmentContentBlocks * 4));
            }
 
            startHeader.WriteToStream(cdrOut, contentLength);
            if ((version.Major == 1) && (version.Minor == 1)) {
                // GIOP 1.1: add service context list here
                cdrOut.WriteULong(0); // no contexts
            }
            cdrOut.WriteULong(reqId); // request id
 
            // more is not needed to write a correct GIOP-message for this test from here
            for (uint i = 0; i < fragmentContentBlocks * 4; i++) {
                cdrOut.WriteOctet((byte)(i % 255));
            }
 
            offsetInMsg = fragmentContentBlocks * 4;
            return cdrOut;
        }
Example #14
0
        public void TestRequestDeserialisation()
        {
            MemoryStream sourceStream = new MemoryStream();
            // prepare msg
            uint                requestId     = 5;
            byte                responseFlags = 3;
            string              methodName    = "Add";
            int                 nrOfArgs      = 2;
            int                 arg1          = 1;
            int                 arg2          = 2;
            GiopVersion         version       = new GiopVersion(1, 2);
            CdrOutputStreamImpl cdrOut        = new CdrOutputStreamImpl(sourceStream, 0,
                                                                        version);

            cdrOut.WriteOpaque(m_giopMagic);
            // version
            cdrOut.WriteOctet(version.Major);
            cdrOut.WriteOctet(version.Minor);
            // flags
            cdrOut.WriteOctet(0);
            // msg-type: request
            cdrOut.WriteOctet(0);
            // msg-length
            cdrOut.WriteULong(68);
            // request-id
            cdrOut.WriteULong(requestId);
            // response-flags
            cdrOut.WriteOctet(responseFlags);
            cdrOut.WritePadding(3);
            // target: key type
            cdrOut.WriteULong(0);
            cdrOut.WriteULong(10);                                                             // key length
            cdrOut.WriteOpaque(new byte[] { 116, 101, 115, 116, 111, 98, 106, 101, 99, 116 }); // testobject
            // method name
            cdrOut.WriteString(methodName);
            // no service contexts
            cdrOut.WriteULong(0);
            cdrOut.ForceWriteAlign(Aligns.Align8);
            // parameters
            cdrOut.WriteLong(arg1);
            cdrOut.WriteLong(arg2);

            // create a connection context: this is needed for request deserialisation
            GiopConnectionDesc conDesc = new GiopConnectionDesc(null, null);

            // go to stream begin
            sourceStream.Seek(0, SeekOrigin.Begin);

            IMessage    result  = null;
            TestService service = new TestService();

            try {
                // object which should be called
                string uri = "testobject";
                RemotingServices.Marshal(service, uri);

                // deserialise request message
                result = m_handler.ParseIncomingRequestMessage(sourceStream, conDesc);
            } catch (RequestDeserializationException e) {
                throw e;
            } finally {
                RemotingServices.Disconnect(service);
            }

            // now check if values are correct
            Assert.IsTrue(result != null, "deserialised message is null");
            Assert.AreEqual(requestId, result.Properties[SimpleGiopMsg.REQUEST_ID_KEY]);
            Assert.AreEqual(version, result.Properties[SimpleGiopMsg.GIOP_VERSION_KEY]);
            Assert.AreEqual(responseFlags, result.Properties[SimpleGiopMsg.RESPONSE_FLAGS_KEY]);
            Assert.AreEqual("testobject", result.Properties[SimpleGiopMsg.URI_KEY]);
            Assert.AreEqual("Ch.Elca.Iiop.Tests.TestService", result.Properties[SimpleGiopMsg.TYPENAME_KEY]);
            Assert.AreEqual(methodName, result.Properties[SimpleGiopMsg.METHODNAME_KEY]);
            object[] args = (object[])result.Properties[SimpleGiopMsg.ARGS_KEY];
            Assert.IsTrue(args != null, "args is null");
            Assert.AreEqual(nrOfArgs, args.Length);
            Assert.AreEqual(arg1, args[0]);
            Assert.AreEqual(arg2, args[1]);
        }