public bool Handle(Object obj)
 {
     try
     {
         OperationResponsePart part =
             new OperationResponsePart(null, obj);
         _connection.WriteObject(part);
         _count++;
         if (_count % PAUSE_INTERVAL == 0)
         {
             _connection.WriteObject(new OperationResponsePause());
             Object message =
                 _connection.ReadObject();
             return(message is OperationRequestMoreData);
         }
         else
         {
             return(true);
         }
     }
     catch (IOException e)
     {
         throw new BrokenConnectionException(e);
     }
 }
        public Object Invoke(Object proxy, MethodInfo method, Object[] args)
        {
            //don't proxy toString, hashCode, or equals
            if (method.DeclaringType.Equals(typeof(object)))
            {
                return(method.Invoke(this, args));
            }

            //partition arguments into arguments that can
            //be simply marshalled as part of the request and
            //those that are response handlers
            IList <Object> simpleMarshallArgs =
                CollectionUtil.NewList(args);
            ObjectStreamHandler streamHandlerArg =
                ExtractStreamHandler(ReflectionUtil.GetParameterTypes(method), simpleMarshallArgs);

            //build the request object
            RemoteConnectorInfoImpl connectorInfo =
                (RemoteConnectorInfoImpl)_configuration.ConnectorInfo;
            RemoteFrameworkConnectionInfo connectionInfo =
                connectorInfo.RemoteConnectionInfo;
            OperationRequest request = new OperationRequest(
                connectorInfo.ConnectorKey,
                _configuration,
                _operation,
                method.Name,
                simpleMarshallArgs);

            //create the connection
            RemoteFrameworkConnection connection =
                new RemoteFrameworkConnection(connectionInfo);

            try
            {
                connection.WriteObject(CultureInfo.CurrentUICulture);
                connection.WriteObject(connectionInfo.Key);
                //send the request
                connection.WriteObject(request);

                //now process each response stream (if any)
                if (streamHandlerArg != null)
                {
                    HandleStreamResponse(connection, streamHandlerArg);
                }

                //finally return the actual return value
                OperationResponsePart response =
                    (OperationResponsePart)connection.ReadObject();
                if (response.Exception != null)
                {
                    throw response.Exception;
                }
                return(response.Result);
            }
            finally
            {
                connection.Dispose();
            }
        }
        public void TestOperationResponsePart()
        {
            Exception             ex = new Exception("foo", new ArgumentException("Cause"));
            OperationResponsePart v1 = new OperationResponsePart(ex, "bar");
            OperationResponsePart v2 = (OperationResponsePart)CloneObject(v1);

            Assert.IsNotNull(v2.Exception);
            Assert.AreEqual("bar", v2.Result);
        }
Exemple #4
0
        /// <summary>
        /// Handles a stream response until the end of the stream
        /// </summary>
        private static void HandleStreamResponse(RemoteFrameworkConnection connection, ObjectStreamHandler streamHandler)
        {
            Object response;
            bool   handleMore = true;

            while (true)
            {
                response = connection.ReadObject();
                if (response is OperationResponsePart)
                {
                    OperationResponsePart part = (OperationResponsePart)response;
                    if (part.Exception != null)
                    {
                        throw part.Exception;
                    }
                    object obj =
                        part.Result;
                    if (handleMore)
                    {
                        handleMore = streamHandler.Handle(obj);
                    }
                }
                else if (response is OperationResponsePause)
                {
                    if (handleMore)
                    {
                        connection.WriteObject(new OperationRequestMoreData());
                    }
                    else
                    {
                        connection.WriteObject(new OperationRequestStopData());
                    }
                }
                else if (response is OperationResponseEnd)
                {
                    break;
                }
                else
                {
                    throw new ConnectorException("Unexpected response: " + response);
                }
            }
        }
        private bool ProcessRequest()
        {
            CultureInfo locale;

            try
            {
                locale = (CultureInfo)_connection.ReadObject();
            }
            catch (EndOfStreamException)
            {
                return(false);
            }

            //We can't set this because C# does not like language-neutral
            //cultures for CurrentCulture - this tends to blow up
            //TODO: think more about this...
            //Thread.CurrentThread.CurrentCulture = locale;
            Thread.CurrentThread.CurrentUICulture = locale;

            GuardedString key = (GuardedString)_connection.ReadObject();

            bool authorized;

            try
            {
                authorized = key.VerifyBase64SHA1Hash(_server.KeyHash);
            }
            finally
            {
                key.Dispose();
            }
            Org.IdentityConnectors.Framework.Common.Exceptions.InvalidCredentialException authException = null;
            if (!authorized)
            {
                authException = new Org.IdentityConnectors.Framework.Common.Exceptions.InvalidCredentialException("Remote framework key is invalid");
            }
            Object requestObject = _connection.ReadObject();

            if (requestObject is HelloRequest)
            {
                if (authException != null)
                {
                    HelloResponse response =
                        new HelloResponse(authException, null, null, null);
                    _connection.WriteObject(response);
                }
                else
                {
                    HelloResponse response =
                        ProcessHelloRequest((HelloRequest)requestObject);
                    _connection.WriteObject(response);
                }
            }
            else if (requestObject is OperationRequest)
            {
                if (authException != null)
                {
                    OperationResponsePart part =
                        new OperationResponsePart(authException, null);
                    _connection.WriteObject(part);
                }
                else
                {
                    OperationRequest opRequest =
                        (OperationRequest)requestObject;
                    OperationResponsePart part =
                        ProcessOperationRequest(opRequest);
                    _connection.WriteObject(part);
                }
            }
            else if (requestObject is EchoMessage)
            {
                if (authException != null)
                {
                    //echo message probably doesn't need auth, but
                    //it couldn't hurt - actually it does for test connection
                    EchoMessage part =
                        new EchoMessage(authException, null);
                    _connection.WriteObject(part);
                }
                else
                {
                    EchoMessage message = (EchoMessage)requestObject;
                    Object      obj     = message.Object;
                    String      xml     = message.ObjectXml;
                    if (xml != null)
                    {
                        Console.WriteLine("xml: \n" + xml);
                        Object xmlClone =
                            SerializerUtil.DeserializeXmlObject(xml, true);
                        xml =
                            SerializerUtil.SerializeXmlObject(xmlClone, true);
                    }
                    EchoMessage message2 = new EchoMessage(obj, xml);
                    _connection.WriteObject(message2);
                }
            }
            else
            {
                throw new Exception("Unexpected request: " + requestObject);
            }
            return(true);
        }
Exemple #6
0
 public bool Handle(Object obj)
 {
     try
     {
         OperationResponsePart part =
             new OperationResponsePart(null, obj);
         _connection.WriteObject(part);
         _count++;
         if (_count % PAUSE_INTERVAL == 0)
         {
             _connection.WriteObject(new OperationResponsePause());
             Object message =
                 _connection.ReadObject();
             return message is OperationRequestMoreData;
         }
         else
         {
             return true;
         }
     }
     catch (IOException e)
     {
         throw new BrokenConnectionException(e);
     }
 }
Exemple #7
0
        private bool ProcessRequest()
        {
            CultureInfo locale;
            try
            {
                locale = (CultureInfo)_connection.ReadObject();
            }
            catch (EndOfStreamException)
            {
                return false;
            }

            //We can't set this because C# does not like language-neutral
            //cultures for CurrentCulture - this tends to blow up
            //TODO: think more about this...
            //Thread.CurrentThread.CurrentCulture = locale;
            Thread.CurrentThread.CurrentUICulture = locale;

            GuardedString key = (GuardedString)_connection.ReadObject();

            bool authorized;
            try
            {
                authorized = key.VerifyBase64SHA1Hash(_server.KeyHash);
            }
            finally
            {
                key.Dispose();
            }
            Org.IdentityConnectors.Framework.Common.Exceptions.InvalidCredentialException authException = null;
            if (!authorized)
            {
                authException = new Org.IdentityConnectors.Framework.Common.Exceptions.InvalidCredentialException("Remote framework key is invalid");
            }
            Object requestObject = _connection.ReadObject();
            if (requestObject is HelloRequest)
            {
                if (authException != null)
                {
                    HelloResponse response =
                        new HelloResponse(authException, null, null, null);
                    _connection.WriteObject(response);
                }
                else
                {
                    HelloResponse response =
                        ProcessHelloRequest((HelloRequest)requestObject);
                    _connection.WriteObject(response);
                }
            }
            else if (requestObject is OperationRequest)
            {
                if (authException != null)
                {
                    OperationResponsePart part =
                        new OperationResponsePart(authException, null);
                    _connection.WriteObject(part);
                }
                else
                {
                    OperationRequest opRequest =
                        (OperationRequest)requestObject;
                    OperationResponsePart part =
                        ProcessOperationRequest(opRequest);
                    _connection.WriteObject(part);
                }
            }
            else if (requestObject is EchoMessage)
            {
                if (authException != null)
                {
                    //echo message probably doesn't need auth, but
                    //it couldn't hurt - actually it does for test connection
                    EchoMessage part =
                        new EchoMessage(authException, null);
                    _connection.WriteObject(part);
                }
                else
                {
                    EchoMessage message = (EchoMessage)requestObject;
                    Object obj = message.Object;
                    String xml = message.ObjectXml;
                    if (xml != null)
                    {
                        Console.WriteLine("xml: \n" + xml);
                        Object xmlClone =
                            SerializerUtil.DeserializeXmlObject(xml, true);
                        xml =
                            SerializerUtil.SerializeXmlObject(xmlClone, true);
                    }
                    EchoMessage message2 = new EchoMessage(obj, xml);
                    _connection.WriteObject(message2);
                }
            }
            else
            {
                throw new Exception("Unexpected request: " + requestObject);
            }
            return true;
        }