Example #1
0
        private void InternalTestTwoFramgents(GiopVersion version)
        {
            Stream msgStream   = new MemoryStream();
            byte   endianFlags = 0;
            uint   reqId       = 11;

            uint startMsgContentBlocks     = 2; // make sure, that start fragment length is a multiple of 8; giop 1.2
            uint lastFragmentContentLength = 13;
            uint currentOffsetInMsg        = 0; // the content offset for the next message
            CdrOutputStreamImpl cdrOut     = AddStartMsg(msgStream, version, endianFlags,
                                                         reqId, startMsgContentBlocks,
                                                         out currentOffsetInMsg);
            uint endOffset = AddFinishFragment(cdrOut, version, endianFlags, reqId,
                                               lastFragmentContentLength,
                                               currentOffsetInMsg);

            msgStream.Seek(0, SeekOrigin.Begin);
            // start fragment
            FragmentedMessageAssembler assembler = new FragmentedMessageAssembler();

            assembler.StartFragment(msgStream);
            // finish fragment
            GiopHeader combinedHeader;
            Stream     resultStream = assembler.FinishFragmentedMsg(msgStream, out combinedHeader);

            CheckAssembledMessage(resultStream, version, endianFlags, reqId,
                                  endOffset);
        }
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
        private CdrOutputStream PrepareStream(MemoryStream baseStream)
        {
            CdrOutputStreamImpl outputStream = new CdrOutputStreamImpl(
                baseStream, 0, new GiopVersion(1, 2));

            return(outputStream);
        }
Example #4
0
        /// <summary>
        /// writes this message header to a stream, using msgLength as
        /// message Length
        /// </summary>
        /// <returns>the outputstream used, positioned just after the header</returns>
        internal CdrOutputStream WriteToStream(Stream stream, uint msgLength)
        {
            CdrOutputStream target = new CdrOutputStreamImpl(stream, GiopFlags,
                                                             Version);

            WriteToStream(target, msgLength);
            return(target);
        }
Example #5
0
        public void TestEncodeLeStream()
        {
            MemoryStream        outStream = new MemoryStream();
            CdrOutputStreamImpl cdrStream = new CdrOutputStreamImpl(outStream, 1, new GiopVersion(1, 1));

            cdrStream.WCharSet = (int)Ch.Elca.Iiop.Services.WCharSet.UTF16;
            cdrStream.WriteWString("Test");
            AssertByteArrayEquals(new byte[] { 6, 0, 0, 0, 0xFF, 0xFE, 84, 0, 101, 0, 115, 0, 116, 0, 0, 0 },
                                  outStream.ToArray());
        }
Example #6
0
        public void TestWriteOctet()
        {
            byte             val          = 1;
            MemoryStream     outputStream = new MemoryStream();
            CdrOutputStream  cdrOut       = new CdrOutputStreamImpl(outputStream, 0, new GiopVersion(1, 2));
            DataOutputStream doStream     = new DataOutputStreamImpl(cdrOut,
                                                                     m_serFactory);

            doStream.write_octet(val);
            outputStream.Seek(0, SeekOrigin.Begin);
            Assert.AreEqual(val, outputStream.ReadByte(), "written");
        }
Example #7
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 #8
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 #9
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 #10
0
        public void TestCantAddFragmentAfterMessageFinished()
        {
            Stream msgStream   = new MemoryStream();
            byte   endianFlags = 0;
            uint   reqId       = 16;

            uint                startMsgContentBlocks     = 2; // make sure, that start fragment length is a multiple of 8; giop 1.2
            uint                lastFragmentContentLength = 13;
            uint                currentOffsetInMsg        = 0; // the content offset for the next message
            GiopVersion         version = new GiopVersion(1, 2);
            CdrOutputStreamImpl cdrOut  = AddStartMsg(msgStream, version, endianFlags,
                                                      reqId, startMsgContentBlocks,
                                                      out currentOffsetInMsg);
            uint endOffset = AddFinishFragment(cdrOut, version, endianFlags, reqId,
                                               lastFragmentContentLength,
                                               currentOffsetInMsg);

            msgStream.Seek(0, SeekOrigin.Begin);
            // start fragment
            FragmentedMessageAssembler assembler = new FragmentedMessageAssembler();

            assembler.StartFragment(msgStream);
            // finish fragment
            GiopHeader combinedHeader;

            assembler.FinishFragmentedMsg(msgStream, out combinedHeader);

            // now check, that no additional finish fragment is supported
            msgStream          = new MemoryStream();
            currentOffsetInMsg = 0; // the content offset for the next message
            cdrOut             = new CdrOutputStreamImpl(msgStream, endianFlags, version);
            AddFinishFragment(cdrOut, version, endianFlags, reqId,
                              lastFragmentContentLength,
                              currentOffsetInMsg);
            msgStream.Seek(0, SeekOrigin.Begin);
            try {
                // finish fragment
                assembler.FinishFragmentedMsg(msgStream, out combinedHeader);
                Assert.Fail("accepted finish fragment, although no start fragment seen");
            } catch (IOException) {
                // ok, no start fragment found
            }
        }
Example #11
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);
        }
        private object[] MarshalAndUnmarshalRequestArgsOnce(MethodInfo testMethod, object[] actual)
        {
            ArgumentsSerializerFactory serFactory = m_argSerFactory;
            ArgumentsSerializer        ser        = serFactory.Create(testMethod.DeclaringType);

            MemoryStream    data         = new MemoryStream();
            GiopVersion     version      = new GiopVersion(1, 2);
            byte            endian       = 0;
            CdrOutputStream targetStream = new CdrOutputStreamImpl(data, endian, version);

            ser.SerializeRequestArgs(testMethod.Name, actual, targetStream, null);

            data.Seek(0, SeekOrigin.Begin);
            CdrInputStreamImpl sourceStream = new CdrInputStreamImpl(data);

            sourceStream.ConfigStream(endian, version);
            IDictionary contextElements;

            object[] deser = ser.DeserializeRequestArgs(testMethod.Name, sourceStream, out contextElements);
            return(deser);
        }
Example #13
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);
        }
        private object MarshalAndUnmarshalResponeArgsOnce(MethodInfo testMethod, object returnValue,
                                                          object[] outArgs, out object[] deserOutArgs)
        {
            ArgumentsSerializerFactory serFactory =
                m_argSerFactory;
            ArgumentsSerializer ser = serFactory.Create(testMethod.DeclaringType);

            MemoryStream    data         = new MemoryStream();
            GiopVersion     version      = new GiopVersion(1, 2);
            byte            endian       = 0;
            CdrOutputStream targetStream = new CdrOutputStreamImpl(data, endian, version);

            ser.SerializeResponseArgs(testMethod.Name, returnValue, outArgs, targetStream);

            data.Seek(0, SeekOrigin.Begin);
            CdrInputStreamImpl sourceStream = new CdrInputStreamImpl(data);

            sourceStream.ConfigStream(endian, version);
            object returnValueDeser = ser.DeserializeResponseArgs(testMethod.Name, out deserOutArgs,
                                                                  sourceStream);

            return(returnValueDeser);
        }
Example #15
0
        public void TestCantAddFragmentIfNotStarted()
        {
            Stream              msgStream   = new MemoryStream();
            byte                endianFlags = 0;
            uint                reqId       = 15;
            uint                lastFragmentContentLength = 13;
            uint                currentOffsetInMsg        = 0; // the content offset for the next message
            GiopVersion         version = new GiopVersion(1, 2);
            CdrOutputStreamImpl cdrOut  = new CdrOutputStreamImpl(msgStream, endianFlags, version);

            AddFinishFragment(cdrOut, version, endianFlags, reqId,
                              lastFragmentContentLength,
                              currentOffsetInMsg);
            msgStream.Seek(0, SeekOrigin.Begin);
            try {
                FragmentedMessageAssembler assembler = new FragmentedMessageAssembler();
                // finish fragment
                GiopHeader combinedHeader;
                assembler.FinishFragmentedMsg(msgStream, out combinedHeader);
                Assert.Fail("accepted finish fragment, although no start fragment seen");
            } catch (IOException) {
                // ok, no start fragment found
            }
        }
 public void TestWCharSetDefinedClient() {
     MethodInfo methodToCall =
         typeof(TestStringInterface).GetMethod("EchoWString");
     object[] args = new object[] { "test" };
     string uri = "iiop://localhost:8087/testuri"; // Giop 1.2 will be used because no version spec in uri
     Ior target = m_iiopUrlUtil.CreateIorForUrl(uri, "");
     IIorProfile targetProfile = target.Profiles[0];
     TestMessage msg = new TestMessage(methodToCall, args, uri);
     msg.Properties[SimpleGiopMsg.REQUEST_ID_KEY] = (uint)5; // set request-id
     msg.Properties[SimpleGiopMsg.TARGET_PROFILE_KEY] = targetProfile;
     
     // prepare connection context
     GiopClientConnectionDesc conDesc = new GiopClientConnectionDesc(null, null, 
                                                                     new GiopRequestNumberGenerator(), null);
                 
     GiopMessageBodySerialiser ser = new GiopMessageBodySerialiser(
                                         new ArgumentsSerializerFactory(m_serFactory));
     GiopClientRequest request = 
         new GiopClientRequest(msg, conDesc,
                               new IInterceptionOption[0]);
     MemoryStream baseStream = new MemoryStream();
     CdrOutputStreamImpl targetStream =
         new CdrOutputStreamImpl(baseStream, 0, new GiopVersion(1,2));
     ser.SerialiseRequest(request, targetStream, targetProfile,
                          conDesc);
     
     Assert.AreEqual(
         new byte[] { 0, 0, 0, 5, 3, 0, 0, 0,
                      0, 0, 0, 0, 
                      0, 0, 0, 7, 116, 101, 115, 116,
                      117, 114, 105, 0,
                      0, 0, 0, 12, 69, 99, 104, 111, 
                      87, 83, 116, 114, 105, 110, 103, 0,
                      0, 0, 0, 1, 0, 0, 0, 1,
                      0, 0, 0, 12, 1, 0, 0, 0,
                      0, 1, 0, 1, 0, 1, 1, 9,
                      0, 0, 0, 8, 0, 116, 0, 101,
                      0, 115, 0, 116},
         baseStream.ToArray(),"serialised message");
 }
        /// <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;
        }
        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 object MarshalAndUnmarshalResponeArgsOnce(MethodInfo testMethod, object returnValue,
                                                          object[] outArgs, out object[] deserOutArgs) {
            ArgumentsSerializerFactory serFactory =
                m_argSerFactory;
            ArgumentsSerializer ser = serFactory.Create(testMethod.DeclaringType);
 
            MemoryStream data = new MemoryStream();
            GiopVersion version = new GiopVersion(1, 2);
            byte endian = 0;
            CdrOutputStream targetStream = new CdrOutputStreamImpl(data, endian, version);
            ser.SerializeResponseArgs(testMethod.Name, returnValue, outArgs, targetStream);
 
            data.Seek(0, SeekOrigin.Begin);
            CdrInputStreamImpl sourceStream = new CdrInputStreamImpl(data);
            sourceStream.ConfigStream(endian, version);
            object returnValueDeser = ser.DeserializeResponseArgs(testMethod.Name, out deserOutArgs,
                                                                  sourceStream);
            return returnValueDeser;
        }
        private object[] MarshalAndUnmarshalRequestArgsOnce(MethodInfo testMethod, object[] actual) {
            ArgumentsSerializerFactory serFactory = m_argSerFactory;
            ArgumentsSerializer ser = serFactory.Create(testMethod.DeclaringType);
 
            MemoryStream data = new MemoryStream();
            GiopVersion version = new GiopVersion(1, 2);
            byte endian = 0;
            CdrOutputStream targetStream = new CdrOutputStreamImpl(data, endian, version);
            ser.SerializeRequestArgs(testMethod.Name, actual, targetStream, null);
 
            data.Seek(0, SeekOrigin.Begin);
            CdrInputStreamImpl sourceStream = new CdrInputStreamImpl(data);
            sourceStream.ConfigStream(endian, version);
            IDictionary contextElements;
            object[] deser = ser.DeserializeRequestArgs(testMethod.Name, sourceStream, out contextElements);
            return deser;
        }
 public void TestEncodeLeStream()
 {
     MemoryStream outStream = new MemoryStream();
     CdrOutputStreamImpl cdrStream = new CdrOutputStreamImpl(outStream, 1, new GiopVersion(1, 1));
     cdrStream.WCharSet = (int)Ch.Elca.Iiop.Services.WCharSet.UTF16;
     cdrStream.WriteWString("Test");
     AssertByteArrayEquals(new byte[] { 6, 0, 0, 0, 0xFF, 0xFE, 84, 0, 101, 0, 115, 0, 116, 0, 0, 0 },
                           outStream.ToArray());
 }
        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;
        }
 public void TestCantAddFragmentIfNotStarted() {
     Stream msgStream = new MemoryStream();
     byte endianFlags = 0;
     uint reqId = 15;
     uint lastFragmentContentLength = 13;
     uint currentOffsetInMsg = 0; // the content offset for the next message
     GiopVersion version = new GiopVersion(1,2);
     CdrOutputStreamImpl cdrOut = new CdrOutputStreamImpl(msgStream, endianFlags, version);
     AddFinishFragment(cdrOut, version, endianFlags, reqId,
                       lastFragmentContentLength,
                       currentOffsetInMsg);
     msgStream.Seek(0, SeekOrigin.Begin);
     try {
         FragmentedMessageAssembler assembler = new FragmentedMessageAssembler();
         // finish fragment
         GiopHeader combinedHeader;
         assembler.FinishFragmentedMsg(msgStream, out combinedHeader);
         Assert.Fail("accepted finish fragment, although no start fragment seen");
     } catch (IOException) {
         // ok, no start fragment found
     }
 }
Example #27
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]);
        }
 public void TestWriteOctet() {
     byte val = 1;
     MemoryStream outputStream = new MemoryStream();
     CdrOutputStream cdrOut = new CdrOutputStreamImpl(outputStream, 0, new GiopVersion(1,2));
     DataOutputStream doStream = new DataOutputStreamImpl(cdrOut,
                                                          m_serFactory);
     doStream.write_octet(val);
     outputStream.Seek(0, SeekOrigin.Begin);
     Assert.AreEqual(val, outputStream.ReadByte(), "written");
 }
 private CdrOutputStream PrepareStream(MemoryStream baseStream)
 {
     CdrOutputStreamImpl outputStream = new CdrOutputStreamImpl(
         baseStream, 0, new GiopVersion(1, 2));
     return outputStream;
 }
        public void TestCantAddFragmentAfterMessageFinished() {
            Stream msgStream = new MemoryStream();
            byte endianFlags = 0;
            uint reqId = 16;
 
            uint startMsgContentBlocks = 2; // make sure, that start fragment length is a multiple of 8; giop 1.2
            uint lastFragmentContentLength = 13;
            uint currentOffsetInMsg = 0; // the content offset for the next message
            GiopVersion version = new GiopVersion(1,2);
            CdrOutputStreamImpl cdrOut = AddStartMsg(msgStream, version, endianFlags,
                                                     reqId, startMsgContentBlocks,
                                                     out currentOffsetInMsg);
            uint endOffset = AddFinishFragment(cdrOut, version, endianFlags, reqId,
                                               lastFragmentContentLength,
                                               currentOffsetInMsg);
 
            msgStream.Seek(0, SeekOrigin.Begin);
            // start fragment
            FragmentedMessageAssembler assembler = new FragmentedMessageAssembler();
            assembler.StartFragment(msgStream);
            // finish fragment
            GiopHeader combinedHeader;
            assembler.FinishFragmentedMsg(msgStream, out combinedHeader);

            // now check, that no additional finish fragment is supported
            msgStream = new MemoryStream();
            currentOffsetInMsg = 0; // the content offset for the next message
            cdrOut = new CdrOutputStreamImpl(msgStream, endianFlags, version);
            AddFinishFragment(cdrOut, version, endianFlags, reqId,
                              lastFragmentContentLength,
                              currentOffsetInMsg);
            msgStream.Seek(0, SeekOrigin.Begin);
            try {
                // finish fragment
                assembler.FinishFragmentedMsg(msgStream, out combinedHeader);
                Assert.Fail("accepted finish fragment, although no start fragment seen");
            } catch (IOException) {
                // ok, no start fragment found
            }
        }
 public void TestWCharSetNotDefinedClient() {
     MethodInfo methodToCall =
         typeof(TestStringInterface).GetMethod("EchoWString");
     object[] args = new object[] { "test" };
     string uri = 
         "IOR:000000000000000100000000000000010000000000000020000102000000000A6C6F63616C686F73740004D2000000047465737400000000";
     Ior target = m_iiopUrlUtil.CreateIorForUrl(uri, "");
     IIorProfile targetProfile = target.Profiles[0];
     TestMessage msg = new TestMessage(methodToCall, args, uri);
     msg.Properties[SimpleGiopMsg.REQUEST_ID_KEY] = (uint)5; // set request-id
     msg.Properties[SimpleGiopMsg.TARGET_PROFILE_KEY] = targetProfile;
     
     // prepare connection context
     GiopClientConnectionDesc conDesc = new GiopClientConnectionDesc(null, null, 
                                                                     new GiopRequestNumberGenerator(), null);
     
     GiopMessageBodySerialiser ser = new GiopMessageBodySerialiser(
                                         new ArgumentsSerializerFactory(m_serFactory));
     GiopClientRequest request = 
         new GiopClientRequest(msg, conDesc,
                               new IInterceptionOption[0]);
     CdrOutputStreamImpl targetStream = 
         new CdrOutputStreamImpl(new MemoryStream(), 0, new GiopVersion(1,2));
     ser.SerialiseRequest(request, targetStream, targetProfile,
                          conDesc);
 }
Example #32
0
 /// <summary>
 /// writes this message header to a stream, using msgLength as 
 /// message Length
 /// </summary>
 /// <returns>the outputstream used, positioned just after the header</returns>
 internal CdrOutputStream WriteToStream(Stream stream, uint msgLength) {
     CdrOutputStream target = new CdrOutputStreamImpl(stream, GiopFlags,
                                                      Version);
     WriteToStream(target, msgLength);
     return target;
 }        
Example #33
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 TestSameServiceIdMultiple() {
     // checks if service contexts with the same id, doesn't throw an exception
     // checks, that the first service context is considered, others are thrown away
     GiopMessageBodySerialiser ser = new GiopMessageBodySerialiser(
                                         new ArgumentsSerializerFactory(m_serFactory));
     MemoryStream stream = new MemoryStream();
     CdrOutputStreamImpl cdrOut = new CdrOutputStreamImpl(stream, 0, new GiopVersion(1,2));
     cdrOut.WriteULong(2); // nr of contexts
     cdrOut.WriteULong(1234567); // id of context 1
     CdrEncapsulationOutputStream encap = new CdrEncapsulationOutputStream(0);
     cdrOut.WriteEncapsulation(encap);
     cdrOut.WriteULong(1234567); // id of context 2
     encap = new CdrEncapsulationOutputStream(0);
     cdrOut.WriteEncapsulation(encap);
     // reset stream
     stream.Seek(0, SeekOrigin.Begin);
     CdrInputStreamImpl cdrIn = new CdrInputStreamImpl(stream);
     cdrIn.ConfigStream(0, new GiopVersion(1,2));
     omg.org.IOP.ServiceContextList result = new ServiceContextList(cdrIn);
     // check if context is present
     Assert.IsTrue(result.ContainsServiceContext(1234567), "expected context not in collection");
 }