Exemple #1
0
        public void Given_Left_Ior_Then_ToLeftOption_Should_Return_A_Some_With_The_Value()
        {
            var defaultValue = -1;
            var value        = 100;

            Ior.Left <int, int>(value).ToLeftOption().GetOrElse(defaultValue).Should().Be(value);
        }
Exemple #2
0
        /// <summary>creates an IOR for the object described by the Url url</summary>
        /// <param name="url">an url of the form IOR:--hex-- or iiop://addr/key</param>
        /// <param name="targetType">if the url contains no info about the target type, use this type</param>
        public Ior CreateIorForUrl(string url, string repositoryId)
        {
            Ior ior = null;

            if (IsIorString(url))
            {
                ior = new Ior(url);
            }
            else if (url.StartsWith("iiop"))
            {
                // iiop1.0, iiop1.1, iiop1.2 (=iiop); extract version in protocol tag
                IiopLoc iiopLoc = new IiopLoc(url, m_codec,
                                              m_defaultAdditionalTaggedComponents);
                // now create an IOR with the above information
                ior = new Ior(repositoryId, iiopLoc.GetProfiles());
            }
            else if (url.StartsWith("corbaloc"))
            {
                Corbaloc loc = new Corbaloc(url, m_codec,
                                            m_defaultAdditionalTaggedComponents);
                IorProfile[] profiles = loc.GetProfiles();
                ior = new Ior(repositoryId, profiles);
            }
            else
            {
                throw new INV_OBJREF(1963, CompletionStatus.Completed_MayBe);
            }
            return(ior);
        }
Exemple #3
0
        public IMessage SyncProcessMessage(IMessage msg)
        {
            Ior target = DetermineTarget(msg);

            VerifyInterfaceCompatible(target, msg);
            // serialise
            IMessage result          = null;
            int      numberOfRetries = 0;

            while (true)
            {
                try {
                    result = SyncProcessMessageOnce(msg, target);
                    break;
                } catch (Exception e) {
                    if (!CanRetryOnException(e, numberOfRetries))
                    {
                        result = new ReturnMessage(e, (IMethodCallMessage)msg);
                        break;
                    }
                    numberOfRetries++;
                    m_retries.DelayNextRetryIfNeeded();
                }
            }
            return(result);
        }
Exemple #4
0
        private void AsyncProcessMessageOnce(IMessage msg,
                                             Ior target, IMessageSink replySink)
        {
            IIorProfile selectedProfile;
            uint        reqId;

            try {
                // allocate (reserve) connection
                GiopClientConnectionDesc conDesc = AllocateConnection(msg, target, out selectedProfile, out reqId);
                SimpleGiopMsg.SetMessageAsyncRequest(msg); // mark message as async, needed for portable interceptors
                ITransportHeaders requestHeaders;
                Stream            requestStream;
                SerialiseRequest(msg, selectedProfile, conDesc, reqId,
                                 out requestHeaders, out requestStream);
                // pass the serialised GIOP-request to the first stream handling sink
                // this sink is the last sink in the message handling sink chain, therefore the reply sink chain of all the previous message handling
                // sink is passed to the ClientChannelSinkStack, which will inform this chain of the received reply
                ClientChannelSinkStack clientSinkStack = new ClientChannelSinkStack(replySink);
                AsyncProcessingData    asyncData       = new AsyncProcessingData(msg, conDesc);
                clientSinkStack.Push(this, asyncData); // push the formatter onto the sink stack, to get the chance to handle the incoming reply stream
                // forward the message to the next sink
                m_nextSink.AsyncProcessRequest(clientSinkStack, msg, requestHeaders, requestStream);
                // for oneway messages, release the connections for future use
                if ((msg is IMethodCallMessage) && GiopMessageHandler.IsOneWayCall((IMethodCallMessage)msg))
                {
                    m_conManager.RequestOnConnectionCompleted(msg);  // release the connection, because this interaction is complete
                }
            } catch {
                // release the connection, if something went wrong during connection allocation and send
                m_conManager.RequestOnConnectionCompleted(msg); // release the connection, because this interaction is complete
                throw;
            }
        }
Exemple #5
0
        /// <summary>gets a reference to the init service running at the specified host at the specified port</summary>
        private CORBAInitService GetInitService(string host, int port)
        {
            lock (m_initalServices.SyncRoot) {
                CORBAInitService initService = null;
                string           key         = host + ":" + port;
                if (!m_initalServices.ContainsKey(key))
                {
                    IorProfile initServiceProfile =
                        new InternetIiopProfile(new GiopVersion(1, 0),
                                                host, (ushort)port,
                                                IorUtil.GetKeyBytesForId(CORBAInitServiceImpl.INITSERVICE_NAME));
                    // don't add a codeset component, because giop 1.0
                    Ior initServiceIor = new Ior(Repository.GetRepositoryID(typeof(CORBAInitService)),
                                                 new IorProfile[] { initServiceProfile });

                    string iorString = initServiceIor.ToString();
                    initService = (CORBAInitService)RemotingServices.Connect(typeof(CORBAInitService),
                                                                             iorString); // CORBAInitService type not verifiable remote -> make sure that it's possible to verify locally
                    m_initalServices.Add(key, initService);
                }
                else
                {
                    initService = (CORBAInitService)m_initalServices[key];
                }
                return(initService);
            }
        }
Exemple #6
0
        private IMessage SyncProcessMessageOnce(IMessage msg,
                                                Ior target)
        {
            IIorProfile selectedProfile;
            uint        reqId;

            try {
                // allocate (reserve) connection
                GiopClientConnectionDesc conDesc =
                    AllocateConnection(msg, target, out selectedProfile, out reqId);
                ITransportHeaders requestHeaders;
                Stream            requestStream;
                SerialiseRequest(msg, selectedProfile, conDesc, reqId,
                                 out requestHeaders, out requestStream);

                // pass the serialised GIOP-request to the first stream handling sink
                // when the call returns, the response message has been received
                ITransportHeaders responseHeaders;
                Stream            responseStream;
                m_nextSink.ProcessMessage(msg, requestHeaders, requestStream,
                                          out responseHeaders, out responseStream);

                // now deserialise the response
                return(DeserialiseResponse(responseStream,
                                           responseHeaders, msg, conDesc));
            } finally {
                m_conManager.RequestOnConnectionCompleted(msg); // release the connection, because this interaction is complete
            }
        }
Exemple #7
0
        public void Given_Right_Ior_Then_ToEither_Should_Return_A_Right_Either_With_The_Value()
        {
            var value        = 100;
            var defaultValue = -1;

            Ior.Right <int, int>(value).ToEither().Right.GetOrElse(defaultValue).Should().Be(value);
        }
Exemple #8
0
        public void Given_BothIor_Then_Map_Should_Return_A_New_BothIor_With_Same_Left_Value()
        {
            var value        = 100;
            var defaultValue = -1;

            Ior.Both(value, value).Map(i => i * 2).Left.GetOrElse(defaultValue).Should().Be(value);
        }
Exemple #9
0
        public IMessageCtrl AsyncProcessMessage(IMessage msg, IMessageSink replySink)
        {
            Ior target = DetermineTarget(msg);

            VerifyInterfaceCompatible(target, msg);
            int numberOfRetries = 0;

            while (true)
            {
                try {
                    AsyncProcessMessageOnce(msg, target, replySink);
                    break;
                } catch (Exception e) {
                    if (!CanRetryOnException(e, numberOfRetries))
                    {
                        // formulate an exception reply for an non-oneway call
                        IMethodCallMessage methodCallMsg = msg as IMethodCallMessage;
                        if (replySink != null &&
                            methodCallMsg != null && !GiopMessageHandler.IsOneWayCall(methodCallMsg))
                        {
                            IMessage retMsg = new ReturnMessage(e, methodCallMsg);
                            replySink.SyncProcessMessage(retMsg); // process the return message in the reply sink chain
                        }
                        break;
                    }
                    m_retries.DelayNextRetryIfNeeded();
                    numberOfRetries++;
                }
            }
            return(null);  // TODO, it would be possible to return a possiblity to cancel a message ...
        }
Exemple #10
0
        public void Given_RightIor_Then_MapLeft_Should_Return_A_New_RightIor_With_Same_Value()
        {
            var value        = 100;
            var defaultValue = -1;

            Ior.Right <int, int>(value).MapLeft(i => i * 2).Right.GetOrElse(defaultValue).Should().Be(value);
        }
Exemple #11
0
        private bool IsInterfaceCompatible(Ior target, Type neededTargetType, string targetUrl)
        {
            Type interfaceType;

            // local check first otherwise remote
            return(Repository.IsInterfaceCompatible(neededTargetType, target.TypID, out interfaceType) ||
                   CheckAssignableRemote(neededTargetType, targetUrl));
        }
Exemple #12
0
        public void Given_Right_Ior_Then_Bimap_Should_Return_A_New_RightIor_With_Transformed_Value()
        {
            var value            = 100;
            var transformedValue = value * 4;
            var defaultValue     = -1;

            Ior.Right <int, int>(value).Bimap(i => i * 2, i => i * 4).Right.GetOrElse(defaultValue).Should().Be(transformedValue);
        }
Exemple #13
0
        public void Given_Both_Ior_Then_ToLeftOption_Should_Return_A_Some_With_The_Left_Value()
        {
            var defaultValue = -1;
            var lvalue       = 100;
            var rvalue       = 200;

            Ior.Both(lvalue, rvalue).ToLeftOption().GetOrElse(defaultValue).Should().Be(lvalue);
        }
Exemple #14
0
        public void CreateIorForIiopLocUrlWithCodeSetComponent()
        {
            string testIiopLoc = "iiop1.2://localhost:1234/test";
            Ior    iorForUrl   =
                m_iiopUrlUtil.CreateIorForUrl(testIiopLoc, String.Empty);

            CheckIorForUrl(iorForUrl, 1, true);
        }
Exemple #15
0
        public void Given_LeftIor_Then_MapLeft_Should_Return_A_New_LeftIor_With_Transformed_Value()
        {
            var value            = 100;
            var transformedValue = value * 2;
            var defaultValue     = -1;

            Ior.Left <int, int>(value).MapLeft(i => i * 2).Left.GetOrElse(defaultValue).Should().Be(transformedValue);
        }
Exemple #16
0
        public void Given_BothIor_Then_Map_Should_Return_A_New_BothIor_With_Transformed_Right_Value()
        {
            var value            = 100;
            var transformedValue = value * 2;
            var defaultValue     = -1;

            Ior.Both(value, value).Map(i => i * 2).Right.GetOrElse(defaultValue).Should().Be(transformedValue);
        }
Exemple #17
0
        public void Given_Both_Ior_Then_ToEither_Should_Return_A_Right_Either_With_The_Right_Value()
        {
            var lvalue       = 100;
            var rvalue       = 200;
            var defaultValue = -1;

            Ior.Both(lvalue, rvalue).ToEither().Right.GetOrElse(defaultValue).Should().Be(rvalue);
        }
Exemple #18
0
        public void CreateIorForCorbaLocUrlWithCodeSetComponent()
        {
            string testCorbaLoc = "corbaloc:iiop:[email protected]:1234/test";
            Ior    iorForUrl    =
                m_iiopUrlUtil.CreateIorForUrl(testCorbaLoc, String.Empty);

            CheckIorForUrl(iorForUrl, 1, true);
        }
Exemple #19
0
        public void Given_Right_Ior_Then_Deconstruct_Should_Return_A_Some_With_Right_Value_In_Second_Position()
        {
            var value        = 100;
            var defaultValue = -1;
            var ior          = Ior.Right <int, int>(value);

            var(_, right) = ior;
            right.GetOrElse(defaultValue).Should().Be(value);
        }
Exemple #20
0
        public void Given_Right_Ior_Then_Deconstruct_Should_Return_A_None_In_First_Position()
        {
            var value        = 100;
            var defaultValue = -1;
            var ior          = Ior.Right <int, int>(value);

            var(left, _) = ior;
            left.GetOrElse(defaultValue).Should().Be(defaultValue);
        }
Exemple #21
0
        public void CreateIorForIorUrl()
        {
            string testIorLoc =
                "IOR:000000000000000100000000000000010000000000000050000102000000000A6C6F63616C686F73740004D2000000047465737400000001000000010000002800000000000100010000000300010001000100200501000100010109000000020001010000010109";
            Ior iorForUrl =
                m_iiopUrlUtil.CreateIorForUrl(testIorLoc, String.Empty);

            CheckIorForUrl(iorForUrl, 1, true);
        }
Exemple #22
0
        public void Given_Both_Ior_Then_Deconstruct_Should_Return_A_Some_With_Right_Value_In_First_Position()
        {
            var lvalue       = 100;
            var rvalue       = 200;
            var defaultValue = -1;
            var ior          = Ior.Both(lvalue, rvalue);

            var(_, right) = ior;
            right.GetOrElse(defaultValue).Should().Be(rvalue);
        }
 /// <summary>
 /// <see cref="Ch.Elca.Iiop.IClientTransportFactory.CanCreateTransportForIor"/>
 /// </summary>
 public bool CanCreateTranporForIor(Ior target)
 {
     for (int i = 0; i < target.Profiles.Length; i++)
     {
         if (CanUseProfile(target.Profiles[i]))
         {
             return(true);
         }
     }
     return(false);
 }
        public void TestStringToObjectIORUnknownType()
        {
            Ior ior = new Ior("IDL:Ch/Elca/Iiop/Tests/TestClientUnknownIf1:1.0",
                              new IorProfile[] { m_profile });
            string iorString   = ior.ToString();
            object objToString = m_orb.string_to_object(iorString);

            Assert.NotNull(objToString, "obj to string not created");
            Assert.IsTrue(
                RemotingServices.IsTransparentProxy(objToString), "obj not a proxy");
        }
        public void TestStringToObjectIORNormal()
        {
            Ior ior = new Ior("IDL:omg.org/CORBA/Object:1.0",
                              new IorProfile[] { m_profile });
            string iorString   = ior.ToString();
            object objToString = m_orb.string_to_object(iorString);

            Assert.NotNull(objToString, "obj to string not created");
            Assert.IsTrue(
                RemotingServices.IsTransparentProxy(objToString), "obj not a proxy");
        }
Exemple #26
0
        public void TestIorCreation()
        {
            string iorString = "IOR:0000000000000024524d493a48656c6c6f496e746572666163653a3030303030303030303030303030303000000000010000000000000050000102000000000c31302e34302e32302e3531001f9500000000000853617948656C6C6F0000000100000001000000200000000000010001000000020501000100010020000101090000000100010100";
            Ior    ior       = new Ior(iorString);

            Assert.IsTrue(ior.Profiles.Length > 0, "nr of profiles");
            Assert.AreEqual(TAG_INTERNET_IOP.ConstVal, ior.Profiles[0].ProfileId, "first profile type");
            IInternetIiopProfile iiopProf = (IInternetIiopProfile)ior.Profiles[0];

            Assert.AreEqual("10.40.20.51", iiopProf.HostName);
            Assert.AreEqual(8085, iiopProf.Port);
            Assert.AreEqual(1, iiopProf.Version.Major);
            Assert.AreEqual(2, iiopProf.Version.Minor);
            byte[] oid = new byte[] { 0x53, 0x61, 0x79, 0x48, 0x65, 0x6C, 0x6C, 0x6F };
            CheckIorKey(oid, iiopProf.ObjectKey);


            iorString = "IOR:0000000000000024524d493a48656c6c6f496e746572666163653a3030303030303030303030303030303000000000010000000000000050000102000000000c31302e34302e32302e3531007f9500000000000853617948656C6C6F0000000100000001000000200000000000010001000000020501000100010020000101090000000100010100";
            ior       = new Ior(iorString);
            Assert.IsTrue(ior.Profiles.Length > 0, "nr of profiles");
            Assert.AreEqual(TAG_INTERNET_IOP.ConstVal, ior.Profiles[0].ProfileId, "first profile type");
            iiopProf = (IInternetIiopProfile)ior.Profiles[0];
            Assert.AreEqual("10.40.20.51", iiopProf.HostName);
            Assert.AreEqual(32661, iiopProf.Port);
            Assert.AreEqual(1, iiopProf.Version.Major);
            Assert.AreEqual(2, iiopProf.Version.Minor);
            oid = new byte[] { 0x53, 0x61, 0x79, 0x48, 0x65, 0x6C, 0x6C, 0x6F };
            CheckIorKey(oid, iiopProf.ObjectKey);

            iorString = "IOR:0000000000000024524d493a48656c6c6f496e746572666163653a3030303030303030303030303030303000000000010000000000000050000102000000000c31302e34302e32302e3531008f9500000000000853617948656C6C6F0000000100000001000000200000000000010001000000020501000100010020000101090000000100010100";
            ior       = new Ior(iorString);
            Assert.IsTrue(ior.Profiles.Length > 0, "nr of profiles");
            Assert.AreEqual(TAG_INTERNET_IOP.ConstVal, ior.Profiles[0].ProfileId, "first profile type");
            iiopProf = (IInternetIiopProfile)ior.Profiles[0];
            Assert.AreEqual("10.40.20.51", iiopProf.HostName);
            Assert.AreEqual(36757, iiopProf.Port);
            Assert.AreEqual(1, iiopProf.Version.Major);
            Assert.AreEqual(2, iiopProf.Version.Minor);
            oid = new byte[] { 0x53, 0x61, 0x79, 0x48, 0x65, 0x6C, 0x6C, 0x6F };
            CheckIorKey(oid, iiopProf.ObjectKey);

            iorString = "IOR:0000000000000024524d493a48656c6c6f496e746572666163653a3030303030303030303030303030303000000000010000000000000050000102000000000c31302e34302e32302e353100ffff00000000000853617948656C6C6F0000000100000001000000200000000000010001000000020501000100010020000101090000000100010100";
            ior       = new Ior(iorString);
            Assert.IsTrue(ior.Profiles.Length > 0, "nr of profiles");
            Assert.AreEqual(TAG_INTERNET_IOP.ConstVal, ior.Profiles[0].ProfileId, "first profile type");
            iiopProf = (IInternetIiopProfile)ior.Profiles[0];
            Assert.AreEqual("10.40.20.51", iiopProf.HostName);
            Assert.AreEqual(65535, iiopProf.Port);
            Assert.AreEqual(1, iiopProf.Version.Major);
            Assert.AreEqual(2, iiopProf.Version.Minor);
            oid = new byte[] { 0x53, 0x61, 0x79, 0x48, 0x65, 0x6C, 0x6C, 0x6F };
            CheckIorKey(oid, iiopProf.ObjectKey);
        }
Exemple #27
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);
        }
Exemple #28
0
        public void TestNonUsableProfileIncluded()
        {
            string iorString = "IOR:000000000000001b49444c3a636d6956322f5573657241636365737356323a312e3000020000000210ca1000000000650000000800000008646576312d73660033de6f8e0000004d000000020000000855736572504f41000000001043415355736572416363657373563200c3fbedfb0000000e007c4c51000000fd57aacdaf801a0000000e007c4c51000000fd57aacdaf80120000009400000000000000980001023100000008646576312d736600200b00020000004d000000020000000855736572504f41000000001043415355736572416363657373563200c3fbedfb0000000e007c4c51000000fd57aacdaf801a0000000e007c4c51000000fd57aacdaf8012000000140000000200000002000000140000000400000001000000230000000400000001000000000000000800000000cb0e0001";
            Ior    ior       = new Ior(iorString);

            Assert.AreEqual("IDL:cmiV2/UserAccessV2:1.0", ior.TypID, "wrong RepositoryId");
            IInternetIiopProfile iiopProf = ior.FindInternetIiopProfile();

            Assert.NotNull(iiopProf, "iiop ior profile not found");
            Assert.AreEqual("dev1-sf", iiopProf.HostName, "wrong hostname");
            Assert.AreEqual(8203, iiopProf.Port, "wrong port");
            Assert.AreEqual(1, iiopProf.Version.Major, "wrong major");
            Assert.AreEqual(2, iiopProf.Version.Minor, "wrong minor");
            Assert.AreEqual(2, ior.Profiles.Length, "wrong number of profiles");
        }
Exemple #29
0
        public void TestWithSslComponent()
        {
            string iorString = "IOR:000000000000003749444C3A43682F456C63612F49696F702F5475746F7269616C2F47657474696E67537461727465642F4164646572496D706C3A312E30000000000001000000000000005C000102000000000D3139322E3136382E312E33370000000000000005616464657200000000000002000000010000001C0000000000010001000000010001002000010109000000010001010000000014000000080000006000601F97";
            Ior    ior       = new Ior(iorString);

            Assert.AreEqual(1, ior.Profiles.Length, "wrong number of profiles");
            Assert.AreEqual(TAG_INTERNET_IOP.ConstVal, ior.Profiles[0].ProfileId, "first profile type");
            InternetIiopProfile iiopProf = (InternetIiopProfile)ior.Profiles[0];

            Assert.AreEqual("192.168.1.37", iiopProf.HostName, "wrong hostname");
            Assert.AreEqual(1, iiopProf.Version.Major, "wrong major");
            Assert.AreEqual(2, iiopProf.Version.Minor, "wrong minor");
            Assert.AreEqual(2, iiopProf.TaggedComponents.Count, "wrong number of components in profile");
            Assert.NotNull(iiopProf.TaggedComponents.GetComponentData(TAG_SSL_SEC_TRANS.ConstVal, m_codec,
                                                                      Ch.Elca.Iiop.Security.Ssl.SSLComponentData.TypeCode), "no ssl tagged component found");
        }
Exemple #30
0
        public void TestSSLComponent()
        {
            IOrbServices orb       = OrbServices.GetSingleton();
            string       iorString = orb.object_to_string(m_newTestService);
            Ior          ior       = new Ior(iorString);

            Assert.IsTrue(ior.Profiles.Length > 0, "nr of profiles");
            IIorProfile profile = ior.Profiles[0];

            omg.org.IOP.CodecFactory codecFactory = (omg.org.IOP.CodecFactory)
                                                    orb.resolve_initial_references("CodecFactory");
            object sslData =
                profile.TaggedComponents.GetComponentData(20, codecFactory.create_codec(new omg.org.IOP.Encoding(omg.org.IOP.ENCODING_CDR_ENCAPS.ConstVal, 1, 2)),
                                                          SSLComponentData.TypeCode);

            Assert.NotNull(sslData);
            Assert.AreEqual((int)8087, ((SSLComponentData)sslData).GetPort());
        }