Ejemplo n.º 1
0
        /// <summary>
        /// sends a giop error message as result of a problematic message
        /// </summary>
        internal void SendErrorResponseMessage()
        {
            GiopVersion version            = new GiopVersion(1, 2); // use highest number supported
            Stream      messageErrorStream = PrepareMessageErrorMessage(version);

            SendResponse(messageErrorStream);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// send a close connection message to the peer.
        /// </summary>
        internal void SendConnectionCloseMessage()
        {
            GiopVersion version            = new GiopVersion(1, 0);
            Stream      messageCloseStream = PrepareMessageCloseMessage(version);

            SendMessage(messageCloseStream);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// create a close connection message
        /// </summary>
        /// <param name="version"></param>
        /// <returns></returns>
        private Stream PrepareMessageCloseMessage(GiopVersion version)
        {
            Debug.WriteLine("create a close connection message");
            Stream     targetStream = new MemoryStream();
            GiopHeader header       = new GiopHeader(version.Major, version.Minor, m_headerFlags, GiopMsgTypes.CloseConnection);

            header.WriteToStream(targetStream, 0);
            targetStream.Seek(0, SeekOrigin.Begin);
            return(targetStream);
        }
Ejemplo n.º 4
0
        /// <summary>serialises the .NET msg to a GIOP reply message</summary>
        private void SerialiseResponse(IServerResponseChannelSinkStack sinkStack, IMessage requestMsg,
                                       GiopServerConnection con, IMessage responseMsg,
                                       ref ITransportHeaders headers, out Stream stream)
        {
            GiopVersion version = (GiopVersion)requestMsg.Properties[SimpleGiopMsg.GIOP_VERSION_KEY];

            PrepareResponseHeaders(ref headers, con);
            // get the stream into which the message should be serialied from a stream handling
            // sink in the stream handling chain
            stream = GetResponseStreamFor(sinkStack, responseMsg, headers);
            m_messageHandler.SerialiseOutgoingReplyMessage(responseMsg, requestMsg, version, stream, con.ConDesc);
        }
Ejemplo n.º 5
0
        public NamingContext GetNameService(string host, int port, GiopVersion version) {
            string nsKey = String.Format("NameService:{0}:{1}:{2}.{3}", host, port, 
                                         version.Major, version.Minor);

            lock(m_initalServices.SyncRoot) {
                NamingContext result = null;
                if (!m_initalServices.ContainsKey(nsKey)) {
                    string corbaLoc = String.Format("corbaloc:iiop:{0}.{1}@{2}:{3}/{4}",
                                                    version.Major, version.Minor, 
                                                    host, port, 
                                                    InitialCOSNamingContextImpl.INITIAL_NAMING_OBJ_NAME);
                
                    result = (NamingContext)RemotingServices.Connect(typeof(NamingContext), 
                                                                     corbaLoc);
                    m_initalServices.Add(nsKey, result);
                } else {
                    result = (NamingContext)m_initalServices[nsKey];
                }
                return result;
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// creates a giop header from buffer
 /// </summary>
 /// <param name="buffer">first 12 byte of array are used to parse a giop-header from</param>
 internal GiopHeader(byte[] readBuffer)
 {
     if ((readBuffer == null) || (readBuffer.Length < 12))
     {
         throw new ArgumentException("can't create giop header from buffer");
     }
     if (!((readBuffer[0] == m_giop_magic[0]) && (readBuffer[1] == m_giop_magic[1]) &&
           (readBuffer[2] == m_giop_magic[2]) && (readBuffer[3] == m_giop_magic[3])))
     {
         // no GIOP
         Trace.WriteLine("received non GIOP-Message");
         throw new omg.org.CORBA.MARSHAL(19, omg.org.CORBA.CompletionStatus.Completed_No);
     }
     m_version = new GiopVersion(readBuffer[4], readBuffer[5]);
     if (m_version.Major != 1)
     {
         Trace.WriteLine("unknown GIOP Verision: " + m_version);
         throw new omg.org.CORBA.MARSHAL(20, omg.org.CORBA.CompletionStatus.Completed_No);
     }
     m_flags = readBuffer[6];
     m_type  = ConvertType(readBuffer[7]);
     if (BitConverter.IsLittleEndian == IsLittleEndian())
     {
         m_msgLength = BitConverter.ToUInt32(readBuffer, 8);
     }
     else
     {
         // BitConverter uses a different endian, convert to other endian variant
         byte[] msgLengthBuffer = new byte[4]; // make sure to not change input array
         msgLengthBuffer[0] = readBuffer[11];
         msgLengthBuffer[1] = readBuffer[10];
         msgLengthBuffer[2] = readBuffer[9];
         msgLengthBuffer[3] = readBuffer[8];
         m_msgLength        = BitConverter.ToUInt32(msgLengthBuffer, 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);
        }
        public void TestLocateReplySerialisation() {
            uint requestId = 5;
            byte[] objectKey = new byte[] { 116, 101, 115, 116, 111, 98, 106, 101, 99, 116 }; // testobject
            string targetUri = "testobject";
            GiopVersion version = new GiopVersion(1, 2);
            LocateRequestMessage locReq = new LocateRequestMessage(requestId, objectKey, targetUri);
            // create a connection context
            GiopConnectionDesc conDesc = new GiopConnectionDesc(null, null);

            // create the reply
            LocateStatus replyStatus = LocateStatus.OBJECT_HERE;
            LocateReplyMessage locReply = new LocateReplyMessage(replyStatus);
 
            MemoryStream targetStream = new MemoryStream();
 
            m_handler.SerialiseOutgoingLocateReplyMessage(locReply, locReq, version, targetStream, conDesc);
 
            // check to serialised stream
            targetStream.Seek(0, SeekOrigin.Begin);

            CdrInputStreamImpl cdrIn = new CdrInputStreamImpl(targetStream);
            cdrIn.ConfigStream(0, version);
 
            // first is Giop-magic
            byte data;
            AssertBytesFollowing(m_giopMagic, cdrIn);
            // Giop version
            data = (byte) cdrIn.ReadOctet();
            Assert.AreEqual(1, data);
            data = (byte) cdrIn.ReadOctet();
            Assert.AreEqual(2, data);
            // flags: big-endian, no fragements
            data = (byte) cdrIn.ReadOctet();
            Assert.AreEqual(0, data);
            // Giop Msg type: locate reply
            data = (byte) cdrIn.ReadOctet();
            Assert.AreEqual((byte)GiopMsgTypes.LocateReply, data);
            // Giop Msg length
            uint msgLength = cdrIn.ReadULong();
            cdrIn.SetMaxLength(msgLength);
            // req-id
            Assert.AreEqual(requestId, cdrIn.ReadULong());
            // the location status
            Assert.AreEqual((uint)replyStatus, cdrIn.ReadULong());
        }
        public void TestReplySerialisation() {
            // 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
            GiopVersion version = new GiopVersion(1, 2);
            TestMessage msg = new TestMessage(methodToCall, args, uri);
            msg.Properties[SimpleGiopMsg.REQUEST_ID_KEY] = (uint)5;
            msg.Properties[SimpleGiopMsg.GIOP_VERSION_KEY] = version;
            msg.Properties[SimpleGiopMsg.CALLED_METHOD_KEY] = methodToCall;
            msg.Properties[SimpleGiopMsg.IDL_METHOD_NAME_KEY] = methodToCall.Name; // done by serialization normally
            // create a connection context
            GiopConnectionDesc conDesc = new GiopConnectionDesc(null, null);

            // create the reply
            ReturnMessage retMsg = new ReturnMessage((Int32) 3, new object[0], 0, null, msg);
 
            MemoryStream targetStream = new MemoryStream();
 
            m_handler.SerialiseOutgoingReplyMessage(retMsg, msg, version,
                                                    targetStream, conDesc);
 
            // check to serialised stream
            targetStream.Seek(0, SeekOrigin.Begin);

            CdrInputStreamImpl cdrIn = new CdrInputStreamImpl(targetStream);
            cdrIn.ConfigStream(0, new GiopVersion(1, 2));
 
            // first is Giop-magic
            byte data;
            AssertBytesFollowing(m_giopMagic, cdrIn);
            // Giop version
            data = (byte) cdrIn.ReadOctet();
            Assert.AreEqual(1, data);
            data = (byte) cdrIn.ReadOctet();
            Assert.AreEqual(2, data);
            // flags: big-endian, no fragements
            data = (byte) cdrIn.ReadOctet();
            Assert.AreEqual(0, data);
            // Giop Msg type: reply
            data = (byte) cdrIn.ReadOctet();
            Assert.AreEqual(1, data);
            // Giop Msg length
            uint msgLength = cdrIn.ReadULong();
            cdrIn.SetMaxLength(msgLength);
            // req-id
            Assert.AreEqual(5, cdrIn.ReadULong());
            // response status: NO_EXCEPTION
            Assert.AreEqual(0, cdrIn.ReadULong());
            // ignore service contexts
            SkipServiceContexts(cdrIn);
            // Giop 1.2, must be aligned on 8
            cdrIn.ForceReadAlign(Aligns.Align8);
            // now return value is following
            Assert.AreEqual(3, cdrIn.ReadLong());
        }
Ejemplo n.º 10
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]);
        }
Ejemplo n.º 11
0
 internal GiopHeader(byte GIOP_major, byte GIOP_minor, byte flags, GiopMsgTypes type) {
     m_version = new GiopVersion(GIOP_major, GIOP_minor);
     m_flags = flags;
     m_type = type;
 }
        /// <param name="expectedContentLength">length in bytes after the request-id</param>
        private void CheckAssembledMessage(Stream msgStream, GiopVersion version,
                                           byte endianFlags, uint reqId,
                                           uint expectedContentLength) {
 
            CdrInputStreamImpl inStream = new CdrInputStreamImpl(msgStream);
            GiopHeader header = new GiopHeader(inStream);
 
            Assert.AreEqual(GiopMsgTypes.Request, header.GiopType);
            Assert.AreEqual(version, header.Version);
 
            uint contentLength = 0;
            uint msgReqId = 0;
            if (!((version.Major == 1) && (version.Minor <= 1))) {
                // GIOP 1.2
                // req-id
                contentLength = (uint)(4 + expectedContentLength);
                msgReqId = inStream.ReadULong();
            } else {
                // svc-cntx + req-id
                contentLength = (uint)(8 + expectedContentLength);
                inStream.ReadULong(); // svc-cnxt
                msgReqId = inStream.ReadULong();
            }
 
            Assert.AreEqual(contentLength, header.ContentMsgLength);
            Assert.AreEqual(endianFlags, header.GiopFlags);

            for (int i = 0; i < expectedContentLength; i++) {
                Assert.AreEqual(i % 255, inStream.ReadOctet());
            }
 
        }
        /// <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;
        }
Ejemplo n.º 14
0
 internal CodecImplEncap(GiopVersion version, SerializerFactory serFactory) {
     m_version = version;
     m_serFactory = serFactory;
     m_serializerForAnyType = 
         m_serFactory.Create(ReflectionHelper.ObjectType,
                             AttributeExtCollection.EmptyCollection);
 }
Ejemplo n.º 15
0
 /// <summary>
 /// send a close connection message to the peer.
 /// </summary>
 internal void SendConnectionCloseMessage() {
     GiopVersion version = new GiopVersion(1, 0);
     Stream messageCloseStream = PrepareMessageCloseMessage(version);
     SendMessage(messageCloseStream);
 }
Ejemplo n.º 16
0
 internal GiopHeader(byte GIOP_major, byte GIOP_minor, byte flags, GiopMsgTypes type)
 {
     m_version = new GiopVersion(GIOP_major, GIOP_minor);
     m_flags   = flags;
     m_type    = type;
 }
Ejemplo n.º 17
0
 /// <summary>
 /// sends a giop error message as result of a problematic message
 /// </summary>
 internal void SendErrorResponseMessage() {
     GiopVersion version = new GiopVersion(1, 2); // use highest number supported
     Stream messageErrorStream = PrepareMessageErrorMessage(version);
     SendResponse(messageErrorStream);
 }
Ejemplo n.º 18
0
 /// <summary>
 /// create a close connection message
 /// </summary>
 /// <param name="version"></param>
 /// <returns></returns>
 private Stream PrepareMessageCloseMessage(GiopVersion version) {
     Debug.WriteLine("create a close connection message");
     Stream targetStream = new MemoryStream();
     GiopHeader header = new GiopHeader(version.Major, version.Minor, m_headerFlags, GiopMsgTypes.CloseConnection);
     header.WriteToStream(targetStream, 0);
     targetStream.Seek(0, SeekOrigin.Begin);
     return targetStream;
 }
Ejemplo n.º 19
0
 /// <summary>
 /// creates a giop header from buffer
 /// </summary>
 /// <param name="buffer">first 12 byte of array are used to parse a giop-header from</param>
 internal GiopHeader(byte[] readBuffer) {
     if ((readBuffer == null) || (readBuffer.Length < 12)) {
         throw new ArgumentException("can't create giop header from buffer");
     }
     if (!((readBuffer[0] == m_giop_magic[0]) && (readBuffer[1] == m_giop_magic[1]) && 
         (readBuffer[2] == m_giop_magic[2]) && (readBuffer[3] == m_giop_magic[3]))) {
         // no GIOP
         Trace.WriteLine("received non GIOP-Message");
         throw new omg.org.CORBA.MARSHAL(19, omg.org.CORBA.CompletionStatus.Completed_No);
     }
     m_version = new GiopVersion(readBuffer[4], readBuffer[5]);
     if (m_version.Major != 1) {
         Trace.WriteLine("unknown GIOP Verision: " + m_version);
         throw new omg.org.CORBA.MARSHAL(20, omg.org.CORBA.CompletionStatus.Completed_No);
     }
     m_flags = readBuffer[6];
     m_type = ConvertType(readBuffer[7]);            
     if (BitConverter.IsLittleEndian == IsLittleEndian()) {
         m_msgLength = BitConverter.ToUInt32(readBuffer, 8);    
     } else {
         // BitConverter uses a different endian, convert to other endian variant
         byte[] msgLengthBuffer = new byte[4]; // make sure to not change input array
         msgLengthBuffer[0] = readBuffer[11];
         msgLengthBuffer[1] = readBuffer[10];
         msgLengthBuffer[2] = readBuffer[9];
         msgLengthBuffer[3] = readBuffer[8];
         m_msgLength = BitConverter.ToUInt32(msgLengthBuffer, 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;
        }
 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
     }
 }
Ejemplo n.º 22
0
 public Codec create_codec (Encoding enc) {
     GiopVersion version = new GiopVersion(enc.major_version, enc.minor_version);
     if (enc.format == omg.org.IOP.ENCODING_CDR_ENCAPS.ConstVal) {
         Codec impl = new CodecImplEncap(version, m_serFactory);
         return impl;
     } else {
         throw new omg.org.IOP.CodecFactory_package.UnknownEncoding();
     }
 }        
        private void InternalTestThreeFramgents(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 middleMsgContentBlocks = 4; // make sure, that middle 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);
 
            currentOffsetInMsg = AddFragmentInTheMiddle(cdrOut, version, endianFlags,
                                                        reqId, middleMsgContentBlocks,
                                                        currentOffsetInMsg);
 
            uint endOffset = AddFinishFragment(cdrOut, version, endianFlags, reqId,
                                               lastFragmentContentLength,
                                               currentOffsetInMsg);
 
            msgStream.Seek(0, SeekOrigin.Begin);
            // start fragment
            FragmentedMessageAssembler assembler = new FragmentedMessageAssembler();
            assembler.StartFragment(msgStream);
            // middle fragment
            assembler.AddFragment(msgStream);
            // finish fragment
            GiopHeader combinedHeader;
            Stream resultStream = assembler.FinishFragmentedMsg(msgStream, out combinedHeader);
 
            CheckAssembledMessage(resultStream, version, endianFlags, reqId,
                                  endOffset);

        }
        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 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
            }
        }
        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;
        }
Ejemplo n.º 27
0
        /// <summary>
        /// create the sink chain for the url and return a reference to the first sink in the chain
        /// </summary>
        public IMessageSink CreateMessageSink(string url, object remoteChannelData, out string objectURI)
        {
            objectURI = null;
            if ((url != null) && IiopUrlUtil.IsUrl(url) &&
                (m_conManager.CanConnectToIor(m_iiopUrlUtil.CreateIorForUrl(url, ""))))
            {
                GiopVersion version = new GiopVersion(1, 0);
                m_iiopUrlUtil.ParseUrl(url, out objectURI, out version);

                IClientChannelSink sink = m_providerChain.CreateSink(this, url, remoteChannelData);
                if (!(sink is IMessageSink))
                {
                    throw new Exception("first sink in the client side channel must be a message-sink");
                }
                return (IMessageSink)sink;
            }
            else if ((url == null) && (remoteChannelData is IiopChannelData))
            {
                // check remoteChannelData
                Trace.WriteLine("url null, remote channel data: " + remoteChannelData);
                //                IiopChannelData chanData = (IiopChannelData)remoteChannelData;
                //                IClientChannelSink sink = m_providerChain.CreateSink(this, url, chanData);
                //                if (!(sink is IMessageSink)) { 
                //                    throw new Exception("first sink in the client side channel must be a message-sink"); 
                //                }
                //                return (IMessageSink) sink;
                return null; // TODO
            }
            else
            {
                return null;
            }
        }