示例#1
0
        protected OperationResponse InvokeOperation(string targetOperationId, string targetMethod, object[] operationArgs)
        {
            OperationRequest request = new OperationRequest()
            {
                TargetOperationId = targetOperationId,
                TargetMethod = targetMethod,
                OperationArgs = operationArgs,
                InvokerType = InvokerType.AppInvoker
            };

            return OperationProcessor.ProcessRequest(request);
        }
示例#2
0
        public static OperationResponse ProcessRequest(OperationRequest request)
        {
            var st = new Stopwatch();
            st.Start();

            OperationResponse response = new OperationResponse()
            {
                Request = new OperationRequest()
                {
                    TargetOperationId = request.TargetOperationId,
                    TargetMethod = request.TargetMethod,
                    Url = request.Url,
                    InvokerType = request.InvokerType
                }
            };

            try
            {
                object targetOperation = SpringContext.GetObject(request.TargetOperationId);
                if (Log.IsDebugEnabled)
                    Log.DebugFormat("Looking up operation object by id '{0}'", request.TargetOperationId);

                if (targetOperation == null)
                    throw new ObjectDefinitionStoreException(string.Format("The operation id named '{0}' could not be found in spring context.", request.TargetOperationId));

                MethodInvoker methodInvoker = new MethodInvoker();
                methodInvoker.TargetObject = targetOperation;
                methodInvoker.TargetMethod = request.TargetMethod;

                object[] deserializedArguments = null;

                if (request.InvokerType == InvokerType.WEB)
                    deserializedArguments = SerializerUtils.DeserializeBinary((Byte[])request.OperationArgs);
                else
                    deserializedArguments = (object[])request.OperationArgs;

                methodInvoker.Arguments = deserializedArguments;
                methodInvoker.Prepare();

                object result = InvokeOperation(methodInvoker);

                if (request.InvokerType == InvokerType.WEB)
                {
                    byte[] serializedResult = SerializerUtils.SerializeBinary(new object[] { result });
                    byte[] compressedResult = SevenZipUtils.CompressBytes(serializedResult);
                    response.Result.Value = compressedResult;
                }
                else
                {
                    response.Result.Value = result;
                }

                response.Result.Type = OperationResultType.Ok;
            }
            catch (NoSuchObjectDefinitionException ex)
            {
                response.Result.Message = ex.Message;
            }
            catch (ObjectDefinitionStoreException ex)
            {
                response.Result.Message = ex.Message;
            }
            catch (System.MissingMethodException ex)
            {
                response.Result.Message = ex.Message;
            }
            catch (Spring.Core.MethodInvocationException ex)
            {
                response.Result.Message = ex.Message;
            }
            catch (OperationAccessException ex)
            {
                response.Result.Message = ex.Message;
            }
            catch (Exception ex)
            {
                response.Result.Message = ex.Message;
                Log.Error(ex);
            }
            finally
            {
                st.Stop();
                response.ElapsedTotalSeconds = st.Elapsed.TotalSeconds;

                string messageFormat = "Invoking method [{0}] of operation [{1}] done in {2} seconds.";
                if (Log.IsDebugEnabled)
                {
                    Log.DebugFormat
                        ( messageFormat
                        , response.Request.TargetMethod
                        , response.Request.TargetOperationId
                        , response.ElapsedTotalSeconds
                        );
                }
            }

            return response;
        }
示例#3
0
 public OperationResponse Post(OperationRequest request)
 {
     request.InvokerType = InvokerType.WebInvoker;
     return OperationProcessor.ProcessRequest(request);
 }