상속: System.ApplicationException
예제 #1
0
        public void SerializeFaultResponse(
            Stream stm,
            XmlRpcFaultException faultEx)
        {
            FaultStruct fs;

            fs.faultCode   = faultEx.FaultCode;
            fs.faultString = faultEx.FaultString;


            XmlWriter xtw = XmlRpcXmlWriter.Create(stm, XmlRpcFormatSettings);

            try
            {
                xtw.WriteStartDocument();
            }
            catch
            {
                const string startDoc = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
                byte[]       data     = XmlRpcFormatSettings.XmlEncoding.GetBytes(startDoc);
                stm.Write(data, 0, data.Length);
            }
            xtw.WriteStartElement("", "methodResponse", "");
            xtw.WriteStartElement("", "fault", "");
            Serialize(xtw, fs, new MappingActions {
                NullMappingAction = NullMappingAction.Error
            });
            WriteFullEndElement(xtw);
            WriteFullEndElement(xtw);
            xtw.Flush();
        }
예제 #2
0
 public Stream Invoke(Stream requestStream)
 {
     try
     {
         XmlRpcSerializer serializer = new XmlRpcSerializer();
         XmlRpcRequest    xmlRpcReq
             = serializer.DeserializeRequest(requestStream, this.GetType());
         XmlRpcResponse xmlRpcResp     = Invoke(xmlRpcReq);
         Stream         responseStream = new MemoryStream();
         serializer.SerializeResponse(responseStream, xmlRpcResp);
         responseStream.Seek(0, SeekOrigin.Begin);
         return(responseStream);
     }
     catch (Exception ex)
     {
         XmlRpcFaultException fex;
         if (ex is XmlRpcException)
         {
             fex = new XmlRpcFaultException("0", ((XmlRpcException)ex).Message);
         }
         else if (ex is XmlRpcFaultException)
         {
             fex = (XmlRpcFaultException)ex;
         }
         else
         {
             fex = new XmlRpcFaultException("0", ex.Message);
         }
         XmlRpcSerializer serializer     = new XmlRpcSerializer();
         Stream           responseStream = new MemoryStream();
         serializer.SerializeFaultResponse(responseStream, fex);
         responseStream.Seek(0, SeekOrigin.Begin);
         return(responseStream);
     }
 }
예제 #3
0
        private XmlRpcException DeserializeFault(IEnumerator <Node> iter)
        {
            MappingStack faultStack = new MappingStack("fault response");
            // TODO: use global action setting
            MappingAction        mappingAction = MappingAction.Error;
            XmlRpcFaultException faultEx       = ParseFault(iter, faultStack, // TODO: fix
                                                            mappingAction);

            throw faultEx;
        }
예제 #4
0
        public ServerProcessing ProcessMessage(
            IServerChannelSinkStack sinkStack,
            IMessage requestMsg,
            ITransportHeaders requestHeaders,
            Stream requestStream,
            out IMessage responseMsg,
            out ITransportHeaders responseHeaders,
            out Stream responseStream)
        {
            // use presence of SOAPAction header to determine if this is a SOAP
            // request - if so pass onto next sink in chain
            string soapAction = (string)requestHeaders["SOAPAction"];

            if (soapAction != null)
            {
                return(_next.ProcessMessage(
                           sinkStack,
                           requestMsg,
                           requestHeaders,
                           requestStream,
                           out responseMsg,
                           out responseHeaders,
                           out responseStream));
            }

            // for time being assume we have an XML-RPC request (need to improve
            // this in case there are other non-SOAP formatters in the chain)
            try
            {
                var mthdCall = DeserializeRequest(requestHeaders, requestStream);
                sinkStack.Push(this, mthdCall);
                // forward to next sink in chain - pass request stream as null to
                // indicate that we have deserialized the request
                _next.ProcessMessage(
                    sinkStack,
                    mthdCall,
                    requestHeaders,
                    null,
                    out responseMsg,
                    out responseHeaders,
                    out responseStream);

                SerializeResponse(responseMsg, ref responseHeaders, ref responseStream);
            }
            catch (Exception ex)
            {
                responseMsg    = new ReturnMessage(ex, (IMethodCallMessage)requestMsg);
                responseStream = new MemoryStream();
                var fex        = new XmlRpcFaultException(0, ex.Message);
                var serializer = new XmlRpcSerializer();
                serializer.SerializeFaultResponse(responseStream, fex);
                responseHeaders = new TransportHeaders();
            }
            return(ServerProcessing.Complete);
        }
예제 #5
0
        public Stream Invoke(Stream requestStream)
        {
            try
            {
                var  serializer   = new XmlRpcResponseSerializer();
                var  deserializer = new XmlRpcRequestDeserializer();
                Type type         = this.GetType();
                XmlRpcServiceAttribute serviceAttr = (XmlRpcServiceAttribute)
                                                     Attribute.GetCustomAttribute(this.GetType(),
                                                                                  typeof(XmlRpcServiceAttribute));

                if (serviceAttr != null)
                {
                    if (serviceAttr.XmlEncoding != null)
                    {
                        serializer.XmlEncoding = Encoding.GetEncoding(serviceAttr.XmlEncoding) ?? Config.DefaultEncoding;
                    }
                    serializer.UseEmptyParamsTag = serviceAttr.UseEmptyElementTags;
                    serializer.UseIntTag         = serviceAttr.UseIntTag;
                    serializer.UseStringTag      = serviceAttr.UseStringTag;
                    serializer.UseIndentation    = serviceAttr.UseIndentation;
                    serializer.Indentation       = serviceAttr.Indentation;
                }

                XmlRpcRequest  xmlRpcReq  = deserializer.DeserializeRequest(requestStream, this.GetType());
                XmlRpcResponse xmlRpcResp = Invoke(xmlRpcReq);

                Stream responseStream = new MemoryStream();
                serializer.SerializeResponse(responseStream, xmlRpcResp);
                responseStream.Seek(0, SeekOrigin.Begin);
                return(responseStream);
            }
            catch (Exception ex)
            {
                XmlRpcFaultException fex;
                if (ex is XmlRpcException)
                {
                    fex = new XmlRpcFaultException(0, ((XmlRpcException)ex).Message);
                }
                else if (ex is XmlRpcFaultException)
                {
                    fex = (XmlRpcFaultException)ex;
                }
                else
                {
                    fex = new XmlRpcFaultException(0, ex.Message);
                }
                XmlRpcSerializer serializer     = new XmlRpcSerializer();
                Stream           responseStream = new MemoryStream();
                serializer.SerializeFaultResponse(responseStream, fex);
                responseStream.Seek(0, SeekOrigin.Begin);
                return(responseStream);
            }
        }
예제 #6
0
    public Stream Invoke(Stream requestStream)
    {
      try
      {
        var serializer = new XmlRpcResponseSerializer();
        var deserializer = new XmlRpcRequestDeserializer();
        Type type = this.GetType();
        XmlRpcServiceAttribute serviceAttr = (XmlRpcServiceAttribute)
          Attribute.GetCustomAttribute(this.GetType(),
          typeof(XmlRpcServiceAttribute));

        if (serviceAttr != null)
        {
            if (serviceAttr.XmlEncoding != null)
            {
                serializer.XmlEncoding = Encoding.GetEncoding(serviceAttr.XmlEncoding) ?? Config.DefaultEncoding;
            }
            serializer.UseEmptyParamsTag = serviceAttr.UseEmptyElementTags;
            serializer.UseIntTag = serviceAttr.UseIntTag;
            serializer.UseStringTag = serviceAttr.UseStringTag;
            serializer.UseIndentation = serviceAttr.UseIndentation;
            serializer.Indentation = serviceAttr.Indentation;
        }

        XmlRpcRequest xmlRpcReq = deserializer.DeserializeRequest(requestStream, this.GetType());
        XmlRpcResponse xmlRpcResp = Invoke(xmlRpcReq);

        Stream responseStream = new MemoryStream();
        serializer.SerializeResponse(responseStream, xmlRpcResp);
        responseStream.Seek(0, SeekOrigin.Begin);
        return responseStream;
      }
      catch (Exception ex)
      {
        XmlRpcFaultException fex;
        if (ex is XmlRpcException)
          fex = new XmlRpcFaultException(0, ((XmlRpcException)ex).Message);
        else if (ex is XmlRpcFaultException)
          fex = (XmlRpcFaultException)ex;
        else 
          fex = new XmlRpcFaultException(0, ex.Message);
        XmlRpcSerializer serializer = new XmlRpcSerializer();
        Stream responseStream = new MemoryStream();
        serializer.SerializeFaultResponse(responseStream, fex);
        responseStream.Seek(0, SeekOrigin.Begin);
        return responseStream;      
      }
    }
예제 #7
0
        public Stream Invoke(Stream requestStream)
        {
            try
            {
                var serializer   = new XmlRpcResponseSerializer();
                var deserializer = new XmlRpcRequestDeserializer();
                var serviceAttr  = Attribute.GetCustomAttribute(GetType(), typeof(XmlRpcServiceAttribute)) as XmlRpcServiceAttribute;
                if (serviceAttr != null)
                {
                    if (serviceAttr.XmlEncoding != null)
                    {
                        serializer.XmlEncoding = Encoding.GetEncoding(serviceAttr.XmlEncoding);
                    }
                    serializer.UseEmptyParamsTag = serviceAttr.UseEmptyElementTags;
                    serializer.UseIntTag         = serviceAttr.UseIntTag;
                    serializer.UseStringTag      = serviceAttr.UseStringTag;
                    serializer.UseIndentation    = serviceAttr.UseIndentation;
                    serializer.Indentation       = serviceAttr.Indentation;
                }

                var xmlRpcReq      = deserializer.DeserializeRequest(requestStream, GetType());
                var xmlRpcResp     = Invoke(xmlRpcReq);
                var responseStream = new MemoryStream();
                serializer.SerializeResponse(responseStream, xmlRpcResp);
                responseStream.Seek(0, SeekOrigin.Begin);
                return(responseStream);
            }
            catch (Exception ex)
            {
                XmlRpcFaultException fex;
                var xmlRpcException = ex as XmlRpcException;
                if (xmlRpcException != null)
                {
                    fex = new XmlRpcFaultException(0, xmlRpcException.Message);
                }
                else
                {
                    fex = (ex as XmlRpcFaultException)
                          ?? new XmlRpcFaultException(0, ex.Message);
                }

                var serializer     = new XmlRpcSerializer();
                var responseStream = new MemoryStream();
                serializer.SerializeFaultResponse(responseStream, fex);
                responseStream.Seek(0, SeekOrigin.Begin);
                return(responseStream);
            }
        }
예제 #8
0
        public void SerializeFaultResponse(Stream stm, XmlRpcFaultException faultEx)
        {
            FaultStruct fs;

            fs.FaultCode   = faultEx.FaultCode;
            fs.FaultString = faultEx.FaultString;
            var xtw = XmlRpcXmlWriter.Create(stm, XmlRpcFormatSettings);

            xtw.WriteStartDocument();
            xtw.WriteStartElement(string.Empty, "methodResponse", string.Empty);
            xtw.WriteStartElement(string.Empty, "fault", string.Empty);
            Serialize(xtw, fs, new MappingActions {
                NullMappingAction = NullMappingAction.Error
            });
            WriteFullEndElement(xtw);
            WriteFullEndElement(xtw);
            xtw.Flush();
        }
예제 #9
0
        public Stream Invoke(Stream requestStream)
        {
            try
            {
                var serializer = new XmlRpcResponseSerializer();
                var deserializer = new XmlRpcRequestDeserializer();
                var serviceAttr = Attribute.GetCustomAttribute(GetType(), typeof(XmlRpcServiceAttribute)) as XmlRpcServiceAttribute;
                if (serviceAttr != null)
                {
                    if (serviceAttr.XmlEncoding != null)
                        serializer.XmlEncoding = Encoding.GetEncoding(serviceAttr.XmlEncoding);
                    serializer.UseEmptyParamsTag = serviceAttr.UseEmptyElementTags;
                    serializer.UseIntTag = serviceAttr.UseIntTag;
                    serializer.UseStringTag = serviceAttr.UseStringTag;
                    serializer.UseIndentation = serviceAttr.UseIndentation;
                    serializer.Indentation = serviceAttr.Indentation;
                }

                var xmlRpcReq = deserializer.DeserializeRequest(requestStream, GetType());
                var xmlRpcResp = Invoke(xmlRpcReq);
                var responseStream = new MemoryStream();
                serializer.SerializeResponse(responseStream, xmlRpcResp);
                responseStream.Seek(0, SeekOrigin.Begin);
                return responseStream;
            }
            catch (Exception ex)
            {
                XmlRpcFaultException fex;
                var xmlRpcException = ex as XmlRpcException;
                if (xmlRpcException != null)
                    fex = new XmlRpcFaultException(0, xmlRpcException.Message);
                else
                {
                    fex = (ex as XmlRpcFaultException)
                        ?? new XmlRpcFaultException(0, ex.Message);
                }

                var serializer = new XmlRpcSerializer();
                var responseStream = new MemoryStream();
                serializer.SerializeFaultResponse(responseStream, fex);
                responseStream.Seek(0, SeekOrigin.Begin);
                return responseStream;
            }
        }
예제 #10
0
 protected internal static OdooException GetException(XmlRpcFaultException e)
 {
     string message = string.Empty;
     string[] messages = e.Message.Split('\n');
     if (messages.Length >= 3)
     {
         try
         {
             message = string.Join("\n", messages.Skip(2));
         }
         catch (Exception)
         {
             message = e.Message;
         }
     }
     else
     {
         message = e.Message;
     }
     return new OdooException(message, e);
 }
        public void SerializeFaultResponse(
      Stream stm, 
      XmlRpcFaultException faultEx)
        {
            FaultStruct fs;
              fs.faultCode = faultEx.FaultCode;
              fs.faultString = faultEx.FaultString;

              XmlTextWriter xtw = new XmlTextWriter(stm, m_encoding);
              ConfigureXmlFormat(xtw);
              xtw.WriteStartDocument();
              xtw.WriteStartElement("", "methodResponse", "");
              xtw.WriteStartElement("", "fault", "");
              Serialize(xtw, fs, MappingAction.Error);
              xtw.WriteEndElement();
              xtw.WriteEndElement();
              xtw.Flush();
        }
    public ServerProcessing ProcessMessage(
      IServerChannelSinkStack sinkStack,
      IMessage requestMsg,
      ITransportHeaders requestHeaders,
      Stream requestStream,
      out IMessage responseMsg,
      out ITransportHeaders responseHeaders,
      out Stream responseStream
      )
    {
      // use presence of SOAPAction header to determine if this is a SOAP
      // request - if so pass onto next sink in chain
      string soapAction = (string) requestHeaders["SOAPAction"];
      if (soapAction != null)
      {
        return m_next.ProcessMessage(sinkStack, requestMsg, requestHeaders, 
          requestStream, out responseMsg, out responseHeaders, 
          out responseStream);
      }

      // for time being assume we have an XML-RPC request (need to improve
      // this in case there are other non-SOAP formatters in the chain)
      try
      {
        MethodCall mthdCall = DeserializeRequest(requestHeaders, requestStream);
        sinkStack.Push(this, mthdCall);
        // forward to next sink in chain - pass request stream as null to 
        // indicate that we have deserialized the request
        m_next.ProcessMessage(sinkStack, mthdCall, requestHeaders, null, 
          out responseMsg, out responseHeaders, out responseStream);
        SerializeResponse(responseMsg, ref responseHeaders, ref responseStream);
      }
      catch (Exception ex)
      {
        responseMsg = new ReturnMessage(ex, (IMethodCallMessage)requestMsg);
        responseStream = new MemoryStream();
        XmlRpcFaultException fex = new XmlRpcFaultException(0, ex.Message);
        XmlRpcSerializer serializer = new XmlRpcSerializer();
        serializer.SerializeFaultResponse(responseStream, 
          (XmlRpcFaultException)fex);
        responseHeaders = new TransportHeaders();
      }
      return ServerProcessing.Complete;
    }
예제 #13
0
    /**
     * This method converts the objects compatible in AdrConvertor to 
     * objects that compatible in XMLRPC.NET library.
     * byte[], MemBlock -> byte[] -> string(base64)
     * other array -> array ( elements converted)
     * IDictionary -> XmlRpcStruct (key -> string)
     * IList -> array
     * float -> double
     * long, ulong -> string
     * AdrException -> XmlRpcFaultException (w/ errorCode added)
     * Exception -> Exception (converted by XmlRpcFaultException by xmlrpc.net)
     * ISender -> string (using ToString())
     * short, ushort, uint, byte, sbyte -> int
     * null -> string.Empty
     */
    public static object Adr2XmlRpc(object o, out bool modified) {
      object retval;
      if(o == null) {
        /*
         * If null is returned when the method is not recursively called by itself,
         * it is OK because XmlRpc.Net will convert it to string.Empty.
         * If not, the null element's outer data structure like Array and IDictionary,
         * which themselves allow null elements, might not be handled correctly: 
         * XmlRpc.Net can't serialize IDictionary and Array with null elements.
         * So we return s.Empty directly from here
         */
        retval = string.Empty;
        modified = true;
        return retval;
      }

      System.Type t = o.GetType();
      // byte arrays are converted to base64 strings in XmlRpc
      // so we treat it as a special case of array
      if(t == typeof(byte[])) {
        retval = o;
        modified = false;
      } 
      // convert each element
      else if (t.IsArray){
        ArrayList list = new ArrayList((ICollection)o);
        bool m;
        modified = false;
        for (int i = 0; i < list.Count; i++) {
          list[i] = Adr2XmlRpc(list[i], out m);
          if (m == true) {
            modified = true;
          }
        }
        retval = list.ToArray();
      }
      //IDictionary -> XmlRpcStruct (string key)
      else if (o is IDictionary) {
        modified = true;
        XmlRpcStruct xrs = new XmlRpcStruct();
        IDictionary dict = o as IDictionary;
        
        IDictionaryEnumerator my_en = dict.GetEnumerator();
        while (my_en.MoveNext()) {
          object key = Adr2XmlRpc(my_en.Key);
          /*
           * XmlRpcStruct requires keys to be strings, we just use ToString() to generate
           * strings.
           */
          string str_key = key.ToString();
          object val = Adr2XmlRpc(my_en.Value);          
          xrs.Add(str_key, val);
        }
        retval = xrs;
      } 
      //XmlRpcSerializer doesn't recognize lists
      //IList -> Array
      else if(o is IList) {
        modified = true;  //list -> array
        ArrayList list = new ArrayList((ICollection)o);
        for (int i = 0; i < list.Count; i++) {
          list[i] = Adr2XmlRpc(list[i]);
        }
        retval = list.ToArray();
      } 
      //Memblock -> byte[]
      else if(o is MemBlock) {
        modified = true;
        MemBlock mb = (MemBlock)o;
        byte[] b = new byte[mb.Length];
        mb.CopyTo(b, 0);
        retval = b;
      }
      //float -> double
      else if(t == typeof(Single)) {
        retval = Convert.ToDouble(o);
        modified = true;
      }
      else if (t == typeof(short) || t == typeof(ushort) || t == typeof(uint) || t == typeof(byte) || t == typeof(sbyte)) {
        retval = Convert.ToInt32(o);
        modified = true;
      } 
      //long-> string
      else if (t == typeof(long) || t == typeof(ulong)) {
        retval = Convert.ToString(o);
        modified = true;
      }
      //AdrException is different from others that it has a code that can
      //be assigned to XmlRpcFaultException
      else if(o is AdrException) {
        AdrException e = (AdrException)o;
        StringBuilder sb = new StringBuilder();
        sb.AppendLine(string.Format("{0}", e.ToString()));
        retval = new XmlRpcFaultException(e.Code, sb.ToString());
        modified = true;
      } 
      //Still exceptions, XmlRpc.net converts it to XmlRpcFaultException
      else if(o is Exception) {
        Exception e = (Exception)o;
        StringBuilder sb = new StringBuilder();
        sb.AppendLine(string.Format("{0}", e.ToString()));
        retval = new Exception(sb.ToString());
        modified = true;
      } else if(o is ISender) {
        ISender s = (ISender)o;
        retval = s.ToString();
        modified = true;
      } else {
        retval = o;
        modified = false;
      }
      return retval;
    }
예제 #14
0
        private bool IsValidUser(string username, string password, out Exception exception)
        {
            if (!authenticator.AuthenticateAndLogin(username, password))
            {
                exception = new XmlRpcFaultException(Convert.ToInt32(HttpStatusCode.Unauthorized), "Unauthorized user!");
                return false;
            }

            exception = null;
            return true;
        }
예제 #15
0
        public void SerializeFaultResponse(
            Stream stm,
            XmlRpcFaultException faultEx)
        {
            FaultStruct fs = new FaultStruct();

            fs.faultCode   = faultEx.FaultCode;
            fs.faultString = faultEx.FaultString;
            XmlWriter xtw = XmlRpcXmlWriter.Create(stm, XmlRpcFormatSettings);

            xtw.WriteStartDocument(false);
            xtw.WriteStartElement("", "methodResponse", "");
            xtw.WriteStartElement("", "fault", "");
            Serialize(xtw, fs, new MappingActions {
                NullMappingAction = NullMappingAction.Error
            });
            WriteFullEndElement(xtw);
            WriteFullEndElement(xtw);
            xtw.Flush();


            #region ×¢ÊÍ

            /*
             * FaultStruct fs=new FaultStruct();
             * fs.faultCode = faultEx.FaultCode;
             * fs.faultString = faultEx.FaultString;
             *
             * XmlWriter xw = XmlWriter.Create(stm);
             * xw.WriteStartDocument();
             *
             * xw.WriteStartElement("", "methodResponse", "");
             * xw.WriteStartElement("", "fault", "");
             * xw.WriteStartElement("value");
             *
             * xw.WriteStartElement("struct");
             *
             * //Member ״̬¿ªÊ¼
             * xw.WriteStartElement("member");
             * xw.WriteStartElement("name");
             * xw.WriteValue("faultCode");
             * xw.WriteEndElement();
             *
             * xw.WriteStartElement("value");
             * xw.WriteStartElement("int");
             * xw.WriteValue(faultEx.FaultCode);
             * xw.WriteEndElement();
             * xw.WriteEndElement();
             *
             * //Member½áÊø
             * xw.WriteEndElement();
             *
             * //Member×Ö·û¿ªÊ¼
             * xw.WriteStartElement("member");
             * xw.WriteStartElement("name");
             * xw.WriteValue("faultString");
             * xw.WriteEndElement();
             *
             * xw.WriteStartElement("value");
             * xw.WriteStartElement("string");
             * xw.WriteValue(faultEx.FaultString);
             * xw.WriteEndElement();
             * xw.WriteEndElement();
             *
             * //Member½áÊø
             * xw.WriteEndElement();
             *
             * //struct½áÊø
             * xw.WriteEndElement();
             *
             * //value½áÊø
             * xw.WriteEndElement();
             *
             *
             * //fault½áÊø
             * xw.WriteEndElement();
             *
             * //methodResponse½áÊø
             * xw.WriteEndElement();
             *
             *
             * // xw.WriteAttributeString("faultCode", fs.faultCode.ToString());
             * //xw.WriteAttributeString("faultString", fs.faultString);
             * // xw.WriteEndElement();
             * // xw.WriteEndElement();
             *
             * xw.WriteEndDocument();
             * xw.Flush();
             *
             * /*
             * <?xml version="1.0" encoding="UTF-8"?>
             * <methodResponse>
             * <fault>
             * <value>
             *  <struct>
             *      <member>
             *          <name>faultCode</name>
             *          <value><int>´íÎóºÅ</int></value>
             *      </member>
             *      <member>
             *          <name>faultString</name>
             *          <value><string>ʧ°ÜÔ­Òò</string></value>
             *      </member>
             *  </struct>
             * </value>
             * </fault>
             * </methodResponse>
             */
            #endregion
        }
예제 #16
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="stm"></param>
 /// <param name="faultEx"></param>
 public void SerializeFaultResponse(
   Stream stm,
   XmlRpcFaultException faultEx)
 {
     FaultStruct fs;
     fs.faultCode = faultEx.FaultCode;
     fs.faultString = faultEx.FaultString;
     XmlWriter xtw = XmlRpcXmlWriter.Create(stm, XmlRpcFormatSettings);
     xtw.WriteStartDocument();
     xtw.WriteStartElement("", "methodResponse", "");
     xtw.WriteStartElement("", "fault", "");
     Serialize(xtw, fs, NullMappingAction.Error);
     WriteFullEndElement(xtw);
     WriteFullEndElement(xtw);
     xtw.Flush();
 }